Prompt
How do I build a secrets workflow for Kubernetes and GitHub Actions?
Latest observation
A solid secrets workflow for Kubernetes + GitHub Actions usually has one core rule:
Don’t store long-lived application secrets in GitHub or plain Kubernetes manifests.
Instead, keep secrets in a real secrets backend, and let workloads fetch them at runtime or inject them safely during deploy.
Recommended architecture
1) Use a central secrets manager
Pick one:
- Cloud-native: AWS Secrets Manager / Parameter Store, GCP Secret Manager, Azure Key Vault
- Platform-agnostic: HashiCorp Vault
- Kubernetes-native syncing: External Secrets Operator, Secrets Store CSI Driver
This becomes the source of truth for sensitive values like:
- DB passwords
- API keys
- TLS material
- private service tokens
2) Use GitHub Actions only for non-secret CI/CD coordination
GitHub Actions should ideally store only:
- short-lived cloud credentials via OIDC
- deployment metadata
- non-sensitive environment config
Avoid:
- committing
.envfiles - hardcoding Kubernetes Secrets in YAML
- using long-lived cloud access keys in GitHub Secrets if you can use OIDC instead
3) Use OIDC from GitHub Actions to cloud provider
Instead of storing cloud access keys in GitHub Secrets, configure:
- GitHub Actions OIDC identity provider
- IAM role / workload identity / federated identity in your cloud
Then the workflow gets short-lived credentials only when needed.
Example uses:
- authenticate to AWS, then fetch from Secrets Manager
- authenticate to GCP, then read Secret Manager
- authenticate to Azure, then read Key Vault
4) Inject secrets into Kubernetes at runtime
Best options:
Option A: External Secrets Operator
Kubernetes ExternalSecret objects reference secrets in your external store. The operator syncs them into K8s Secrets.
Pros:
- simple
- native K8s integration
- good for app teams
Cons:
- secret still ends up as a Kubernetes Secret object in etcd
- you must secure etcd and RBAC carefully
Option B: Secrets Store CSI Driver
Pods mount secrets directly from the provider into the filesystem.
Pros:
- can avoid storing secret material in Kubernetes Secrets
- good for rotation and ephemeral access
Cons:
- app needs to read from mounted files
- more moving parts
Option C: App fetches secrets at runtime
The application authenticates to the secrets backend itself.
Pros:
- strongest model
- no secret material in Kubernetes manifests or GitHub
Cons:
- app complexity increases
- requires auth design per service
A practical workflow
Build-time / deploy-time
- Developer merges code to main
- GitHub Actions runs tests and builds image
- GitHub Actions uses OIDC to authenticate to cloud
- Workflow deploys manifests or Helm charts
- Kubernetes workload gets secrets from external store via CSI or External Secrets
Runtime
- Pod starts
- Pod receives secret as mounted file or synced K8s Secret
- App reads secret from environment or file
- Secret rotates in backend
- Operator/CSI driver refreshes pod secret automatically or on restart
Example: GitHub Actions with OIDC + Kubernetes deploy
GitHub Actions permissions
permissions:
id-token: write
contents: read
Authenticate to cloud
Provider-specific step examples:
- AWS:
aws-actions/configure-aws-credentials - Azure:
azure/login - GCP:
google-github-actions/auth
Then deploy
- name: Deploy
run: |
helm upgrade --install myapp ./chart \
--namespace myns \
--set image.tag=${{ github.sha }}
The workflow should not embed secret values directly.
Example: External Secrets Operator
Secret in backend
Store prod/db-password in AWS Secrets Manager or Vault.
ExternalSecret YAML
apiVersion: external-secrets.io/v1beta1
kind: ExternalSecret
metadata:
name: db-secret
spec:
refreshInterval: 1h
secretStoreRef:
name: my-secret-store
kind: ClusterSecretStore
target:
name: db-secret
creationPolicy: Owner
data:
- secretKey: password
remoteRef:
key: prod/db-password
App uses it
env:
- name: DB_PASSWORD
valueFrom:
secretKeyRef:
name: db-secret
key: password
Example: Secrets Store CSI Driver
Mount secret as a file:
volumes:
- name: secrets-store
csi:
driver: secrets-store.csi.k8s.io
readOnly: true
volumeAttributes:
secretProviderClass: my-secrets
App reads /mnt/secrets-store/db-password.
Best practices
Do
- Use OIDC for GitHub Actions auth
- Keep secrets in external secret store
- Rotate secrets regularly
- Use least-privilege IAM/RBAC
- Separate dev/staging/prod
- Audit access to secrets
- Encrypt Kubernetes secrets at rest if you use them
Don’t
- Put secrets in GitHub repo secrets unless necessary
- Commit Kubernetes Secret manifests with plaintext values
- Base64-encode and call it “encryption”
- Share one cluster-wide secret store for everything without access controls
Suggested secure pattern
If you want a clean default architecture:
- GitHub Actions: OIDC to cloud provider
- Secrets backend: cloud secret manager or Vault
- Kubernetes: External Secrets Operator or CSI driver
- Apps: read secrets from env vars or mounted files
- Rotation: backend-managed, synced to cluster automatically
If you want the simplest good setup
For most teams:
- GitHub Actions + OIDC
- AWS Secrets Manager / GCP Secret Manager / Azure Key Vault
- External Secrets Operator
- Helm or Kustomize for deployments
That gives a good balance of security and operational simplicity.
If you want, I can give you a reference implementation for:
- AWS + EKS + GitHub Actions,
- GCP + GKE + GitHub Actions, or
- Vault + Kubernetes + GitHub Actions.