Prompt
How do I store and rotate cloud access keys across AWS and GCP?
Latest observation
A good cross-cloud pattern is:
- Never hardcode keys
- Store them in a central secrets manager
- Use short-lived credentials where possible
- Automate rotation
- Audit access and usage
Here’s a practical way to do it for AWS and GCP.
1) Prefer short-lived identity over long-lived keys
AWS
Use:
- IAM Roles for workloads running in AWS
- AWS STS for temporary credentials
- IAM Identity Center / federation for humans
Avoid long-lived access keys unless you absolutely need them.
GCP
Use:
- Service accounts with Workload Identity Federation where possible
- Short-lived tokens via impersonation or metadata server in GCP
- Avoid downloading and distributing service account JSON keys unless necessary
If you can eliminate static keys entirely, that’s the best answer.
2) If you must store keys, use a secrets manager
Use a dedicated secrets store, not config files or env vars in code repos.
Common options
- AWS Secrets Manager
- AWS Systems Manager Parameter Store for lower-cost/simple cases
- GCP Secret Manager
- A third-party vault like HashiCorp Vault if you want one system across clouds
Cross-cloud recommendation
If you manage both AWS and GCP together, a common setup is:
- Store AWS credentials in AWS Secrets Manager
- Store GCP service account material in GCP Secret Manager
- Or centralize everything in Vault if you want cloud-agnostic secret lifecycle management
3) Rotation strategy by platform
AWS access keys
Best practice
- Create two access keys max per IAM user if you still use IAM users
- Rotate by:
- Create a new key
- Update the consuming app/secret
- Verify it works
- Disable old key
- Delete old key after a grace period
Automate with
- AWS Secrets Manager rotation Lambda for supported secret types
- Custom Lambda for IAM access key rotation if needed
- CI/CD pipeline or automation tooling to update dependent apps
Reduce blast radius
- Use separate IAM users per app
- Scope permissions tightly
- Set CloudTrail alerts for unused or old keys
GCP service account keys
Best practice
Avoid static JSON keys if possible.
Preferred alternatives:
- Workload Identity Federation for external workloads
- Service account impersonation for humans/automation
- Metadata server credentials for workloads on GCP
If static keys are unavoidable
- Store the JSON key in GCP Secret Manager or Vault
- Rotate by:
- Create a new service account key
- Update secret reference/version
- Deploy or reload consumers
- Verify
- Delete the old key
Important
GCP service account keys are easy to leak and hard to control at scale. Treat them as last resort.
4) Use a consistent secret naming and versioning scheme
Example:
prod/aws/app1/access-keyprod/aws/app1/secret-keyprod/gcp/app1/service-account-key
Or store a single structured secret:
{
"access_key_id": "...",
"secret_access_key": "..."
}
Use versioning so apps can:
- read the “current” version
- roll forward safely
- fall back if needed
5) Use automation for rotation
A good automated rotation workflow:
- Generate new credential
- Store new value in secret manager as a new version
- Notify/reload the app or restart it
- Validate usage with health checks
- Revoke old credential after a delay
- Alert on failed rotation
Tooling that helps
- Terraform for provisioning secrets and policies
- CI/CD jobs to update secrets
- AWS Lambda / Cloud Functions / Cloud Run jobs for rotation logic
- Vault dynamic secrets if you want true lease-based rotation
6) Protect access to the secrets themselves
Apply least privilege:
- Only the workload that needs the secret can read it
- Humans should use SSO/federation rather than direct secret access
- Enable MFA for admins
- Use audit logging:
- AWS CloudTrail
- GCP Audit Logs
Encrypt secrets at rest with KMS:
- AWS KMS for AWS Secrets Manager / Parameter Store
- Cloud KMS for GCP Secret Manager
7) Practical architecture examples
Option A: Cloud-native per provider
- AWS apps use AWS Secrets Manager
- GCP apps use GCP Secret Manager
- Rotation is handled natively in each cloud
Good if:
- teams are cloud-separated
- you want the least operational overhead
Option B: Central Vault
- Vault stores AWS and GCP credentials
- Vault policies control access
- Rotation is centralized
Good if:
- you want one place for both clouds
- you need advanced secret lifecycle controls
- you run hybrid/multi-cloud workloads
Option C: Eliminate static keys
- Use AWS roles + federation
- Use GCP Workload Identity Federation / impersonation
- No stored cloud access keys at all
Best option if feasible.
8) Recommended rotation frequency
A common policy:
- 30–90 days for static access keys
- Faster for production/high-risk environments
- Immediate rotation if exposed or suspected compromised
Also:
- Alert on unused keys
- Delete keys not used in 30–45 days
- Review permissions regularly
9) Simple rule of thumb
- Humans: use SSO/federation, not keys
- Apps in same cloud: use native identities/roles
- Apps across clouds: use federation or Vault
- Static keys only when unavoidable: store in secrets manager and rotate automatically
If you want, I can give you:
- a reference architecture for AWS + GCP,
- Terraform examples for secrets + rotation,
- or a step-by-step rotation runbook for each cloud.