Skip to content

Lesson 4 of 13 · 18m

Secrets: where they actually live in AWS

Why env vars, user data, and .env files leak through the management plane — and when Secrets Manager beats Parameter Store.

The average AWS secret does not get stolen by a sophisticated attack. It gets committed to a git repo, pasted into a CI log during debugging, or read out of a Lambda environment variable by anyone holding lambda:GetFunctionConfiguration. Where you store a secret determines who can read it — and on AWS, "who can read it" is the whole game.

The wrong mental model

"Environment variables are private." They are not. Lambda environment variables are returned by GetFunctionConfiguration and rendered in the console for any principal with that read permission — the management plane is the leak. EC2 user data is the same shape: readable by describe-instance-attribute for anyone with read access, and readable from inside the instance by any process. .env files on the box are one cat away from any RCE or path traversal bug. And a secret committed to git is in the history forever — force-push does not help; the pack file remembers.

The evidence is old and keeps repeating: Uber's 2016 breach started with AWS keys sitting in a private GitHub repo. GitGuardian's annual reports count millions of secrets committed to public GitHub every year. AWS itself scrapes public repositories for AKIA-format keys and quarantines what it finds — the pattern is that reliable.

Secrets Manager: pay for rotation, not storage

secretsmanager stores versioned secrets at $0.40 per secret per month plus $0.05 per 10,000 API calls. The headline feature is not the storage — it is managed rotation for RDS, Redshift, and DocumentDB: Secrets Manager runs a four-step rotation (create new credentials, set them on the service, test them, flip the AWSCURRENT staging label) on a schedule, driven by a Lambda it manages for you.

aws secretsmanager create-secret \
  --name prod/db/app \
  --secret-string '{"user":"app","pass":"..."}'

aws secretsmanager get-secret-value --secret-id prod/db/app

In code: fetch at boot or lazily, cache in memory with a TTL, never log the payload. Rotation is not magic — your app must tolerate AWSCURRENT flipping mid-process, which means short cache lifetimes and a retry-with-refetch on authentication failure. A pinned client plus rotation equals a self-inflicted outage; that pattern has produced real ones.

IAM-wise, scope secretsmanager:GetSecretValue to exact secret ARNs — secretsmanager:* on * is "read every secret in the account," which is worse than the .env file you replaced. Add the secretsmanager:ResourceTag or path-prefix convention (prod/* vs dev/*) to keep environments separated.

SSM Parameter Store: the free tier that stays free

Parameter Store SecureString parameters cost nothing at the standard tier, are KMS-encrypted, and support hierarchical paths (/prod/db/pass) that map cleanly onto IAM resource scoping. What they lack is native rotation — you wire it yourself with EventBridge plus Lambda if you need it. Reach for it for low-value config secrets and feature flags; reach for Secrets Manager when rotation or cross-account sharing matters.

The secrets that should not exist

Machine-to-AWS authentication does not need a stored secret at all. EC2 instance profiles, ECS task roles, Lambda execution roles, EKS IRSA, and GitHub Actions OIDC all vend temporary credentials automatically. The correct count of AWS access keys in your CI secrets, laptops, and .env files is zero — the OIDC trust policy from the identity module is the replacement, and the keys that remain are the ones to hunt.

For third-party API keys — Stripe, Slack, a partner webhook — Secrets Manager is the answer: scoped GetSecretValue per ARN, CloudTrail on every read, rotation if the vendor supports it.

Exercise

Take an app that currently reads a database password from an environment variable. Move the secret to Secrets Manager, grant the execution role secretsmanager:GetSecretValue on that ARN only, and fetch at boot with a five-minute cache. Then rotate the secret and verify the app survives the label flip — fix it if it does not, because the next rotation happens without you watching.

Field notes

  • CloudTrail logs every GetSecretValue. Alert on a principal reading secrets it has never read before — that is a cheap anomaly signal.
  • git-secrets, gitleaks, or trufflehog in pre-commit and CI catch the leak before the push. After the push, treat the secret as burned even if you delete the commit.
  • Secrets Manager replicates secrets across regions for DR. Parameter Store does not — copy deliberately if you need it.
  • Never put the secret value in the Description field. It sounds absurd; it happens; descriptions are not encrypted.

Was this lesson helpful?

Sign in to rate

Keep reading

Related articles from the SudoSecurity blog.