Prompt
How do I set up least-privilege access for secrets by environment?
Latest observation
A good pattern is to make environment the primary boundary for secret access, and then grant only the specific workload/service account access to the secrets it needs in that environment.
Core principles
-
Separate secrets by environment
- Use distinct namespaces/folders/projects for
dev,staging,prod. - Never reuse prod secrets in lower environments.
- Use distinct namespaces/folders/projects for
-
Grant access to identities, not people
- Assign permissions to app service accounts, CI/CD identities, or workload identities.
- Avoid broad human access; use break-glass access only when needed.
-
Scope access to the minimum secret set
- Prefer per-secret or per-secret-group permissions.
- If a service only needs DB credentials, don’t give it access to API keys or TLS certs.
-
Use deny-by-default
- Start with no access, then explicitly allow only what is required.
-
Separate read/write/admin
- Most app runtimes need read-only.
- Only a small automation path should be able to create/update secrets.
A practical setup
1) Organize secrets by environment
Example structure:
secrets/dev/...secrets/staging/...secrets/prod/...
Or use separate cloud projects/accounts:
myapp-devmyapp-stagingmyapp-prod
2) Create environment-specific service identities
Examples:
app-dev-saapp-staging-saapp-prod-sa
Give each identity access only to its environment’s secrets.
3) Apply per-environment policies
Typical rules:
- Dev app: access only
devsecrets - Staging app: access only
stagingsecrets - Prod app: access only
prodsecrets - CI/CD pipeline: can write to
dev/staging, but not directly toprodunless approved - Humans: usually no direct secret read access in prod
4) Use tags/labels or paths for finer control
If your secrets manager supports it, label secrets like:
env=devenv=stagingenv=prodservice=billingowner=platform
Then write policies based on those labels.
5) Rotate and audit
- Rotate secrets regularly.
- Log every access.
- Alert on unusual access patterns, especially prod reads.
Example policy model
For a service billing:
billing-dev-sacan read:dev/billing/db-passworddev/billing/api-key
billing-prod-sacan read:prod/billing/db-passwordprod/billing/api-key
- No other environment access.
If you’re using a cloud secret manager
The exact mechanism depends on the platform:
-
AWS Secrets Manager / IAM
- Use separate secret ARNs or paths per environment.
- IAM policies restrict
secretsmanager:GetSecretValueto specific ARNs.
-
GCP Secret Manager / IAM
- Use separate projects or secret names with IAM bindings.
- Grant
roles/secretmanager.secretAccessoronly on the needed secret or project.
-
Azure Key Vault
- Use separate vaults per environment when possible.
- Assign
get/listpermissions only to the workload identity.
-
Kubernetes
- Prefer external secret stores + workload identity.
- If using K8s Secrets, restrict RBAC by namespace and service account.
Common mistakes to avoid
- One shared “app” identity across all environments
- Giving CI/CD full admin access to production secrets
- Storing all secrets in one vault with no partitioning
- Allowing
listwhen onlygetis needed - Letting developers read prod secrets by default
Recommended default blueprint
- Separate secret store per environment
- Separate workload identity per service/environment
- Read-only access for runtime
- Write access only for deployment automation
- Auditing, rotation, and break-glass access for prod
If you want, I can show you a concrete example for AWS, Azure, GCP, or Kubernetes.