Prompt
Need secret rotation for Kubernetes and GitHub Actions
Latest observation
Here’s a practical way to do secret rotation for Kubernetes and GitHub Actions with a secure, low-friction setup.
Recommended approach
Use a central secret manager and avoid storing long-lived secrets directly in Kubernetes or GitHub if possible.
Good options:
- HashiCorp Vault
- AWS Secrets Manager
- GCP Secret Manager
- Azure Key Vault
- 1Password Secrets Automation
- Doppler
Then:
- Kubernetes pulls secrets at runtime or syncs them automatically
- GitHub Actions gets secrets just-in-time using OIDC or a secret manager integration
1) Kubernetes secret rotation
Best practices
- Avoid plain Kubernetes
Secretobjects as the source of truth - Use External Secrets Operator or Secrets Store CSI Driver
- Prefer dynamic credentials if supported by your backend
- Rotate underlying secrets in the external store, not manually in K8s
Common patterns
Option A: External Secrets Operator
Kubernetes syncs secrets from a secret manager.
Flow:
- Secret is rotated in Vault/AWS/GCP/etc.
- Operator syncs updated value into Kubernetes Secret
- Pods pick it up via rollout or runtime reload
Example:
apiVersion: external-secrets.io/v1beta1
kind: ExternalSecret
metadata:
name: app-secret
spec:
refreshInterval: 1h
secretStoreRef:
name: my-secret-store
kind: SecretStore
target:
name: app-secret
data:
- secretKey: password
remoteRef:
key: prod/app/password
Rotation considerations
- Set a short
refreshInterval - Make apps reload secrets:
- restart pods on change, or
- support hot reload via file watch/config reload
- Use rollout automation if needed
If using Kubernetes Secrets directly
If you must use native K8s Secrets:
- Store them in Git only if encrypted with Sealed Secrets or SOPS
- Rotate by updating the encrypted secret and redeploying
- Use an automated pipeline to patch secret and restart workloads
2) GitHub Actions secret rotation
Best practice: avoid static GitHub secrets
Use OIDC federation so GitHub Actions assumes cloud roles without stored credentials.
Examples:
- GitHub Actions → AWS IAM role via OIDC
- GitHub Actions → GCP Workload Identity Federation
- GitHub Actions → Azure federated credentials
This eliminates the need to rotate long-lived cloud access keys in GitHub.
If you must use GitHub secrets
GitHub Secrets are manually managed at:
- repository level
- organization level
- environment level
Rotation process:
- Generate new secret in secret manager or provider
- Update GitHub secret via API or CLI
- Deploy workflows using the new value
- Revoke old secret after verification
Example with GitHub CLI:
gh secret set MY_SECRET --body "new-value"
Or at org level:
gh secret set MY_SECRET --org my-org --body "new-value"
Better: pull secret at runtime
Instead of storing the secret in GitHub, fetch it during workflow execution from:
- Vault
- AWS Secrets Manager
- GCP Secret Manager
- Azure Key Vault
3) Suggested rotation architecture
For Kubernetes
- Store secret in external secret manager
- Sync via External Secrets Operator or CSI Driver
- Rotate backend secret on schedule
- Reload pods automatically
For GitHub Actions
- Prefer OIDC to cloud providers
- Store only non-sensitive configuration in GitHub
- Pull sensitive values from secret manager at runtime if needed
4) Rotation policy suggestions
A good starting policy:
- High-risk credentials: rotate every 30 days
- Service API keys: 30–90 days
- Database credentials: use dynamic creds if possible, otherwise 30 days
- GitHub PATs: avoid if possible; if required, rotate very frequently and scope narrowly
Also:
- Keep old and new credentials valid briefly during transition
- Automate validation before revoking old secrets
- Log rotations and alert on failures
5) Automation example
A simple automation flow:
- Generate new secret in secret manager
- Update Kubernetes sync target or trigger refresh
- Update GitHub secret if still needed
- Wait for app validation
- Revoke old secret
This can be run from:
- Terraform
- GitHub Actions
- Argo CD / Flux
- A scheduled job
6) What I recommend for you
If you want the most secure and maintainable setup:
- Kubernetes: External Secrets Operator + Vault/Cloud Secret Manager
- GitHub Actions: OIDC instead of stored cloud keys
- Fallback: GitHub Secrets only for low-risk values or when integration isn’t possible
If you want, I can give you:
- a step-by-step implementation for AWS/GCP/Azure,
- a Kubernetes YAML example, or
- a GitHub Actions workflow for automated secret rotation.