BBackend CourseLeroy Labs
0/0
Search the course

Secrets management, and what to do when one leaks

Where secrets should live, .gitignore and pre-commit scanning, SSM and Secrets Manager, least-privilege IAM, and a step-by-step leaked-secret response using real findings from your repos.

● intermediateSpring-Boot-StoreReport-Manager-2IR3D (Kontentt)Hostel-Web-AppSperoTek (in dev)

What counts as a secret

DB passwords, JWT signing keys, AES keys, API keys (Stripe, Paystack, Cloudinary, SES), OAuth client secrets, VAPID private keys, Apple .p8 keys, Firebase service-account JSON, CloudFront private keys, tunnel tokens.

Where secrets should live

Environment Store
Local dev .env (git-ignored) + .env.example with placeholder values
CI GitHub Actions encrypted secrets, or better, OIDC with no long-lived keys at all
Production AWS SSM Parameter Store (SecureString) / Secrets Manager / Vault / Render environment variables

In your projects (findings)

Spring-Boot-Storesrc/main/resources/application.yaml

⚠️ A hard-coded DB username and password in a public repo. Store PR #1 moved them to DB_URL, DB_USERNAME and DB_PASSWORD, but the old value is still in git history, so treat it as leaked and never reuse it.

Report-Manager-2backend/.env · frontend/.env · frontend/.env.production

⚠️ These files are tracked in git. .env.staging.example is the only file meant to be committed.

IR3D (Kontentt)*.p8 · backend/secrets/*.pem · firebase-service-account.json · backend/.env

⚠️ Key material sits in the working tree (Apple .p8 keys, a CloudFront private key, a Firebase service account). Make sure all of it is git-ignored, or better, keep it in SSM only. Production does the right thing: fetch-env.sh pulls from SSM under /kontentt/(env)/... using the instance’s IAM role.

Hostel-Web-Appinfrastructure-stack.ts · deploy.yml

Best practice:

  • The RDS password comes from Credentials.fromGeneratedSecret (in Secrets Manager; no human ever sees it).
  • App secrets are injected with ecs.Secret.fromSsmParameter.
  • GitHub Actions uses OIDC to assume Hostel-Github-Actions, so there are no AWS access keys stored in GitHub.
SperoTek (in dev)ProductionSecretsCheck · .env.example

The app fails fast if prod secrets are blank or dev defaults. A real .env exists locally, so confirm it’s ignored.

Leaked-secret response playbook

  1. Rotate first. Generate a new secret at the provider or DB and deploy it. Deleting the file doesn’t un-leak anything, and bots scrape GitHub for keys within minutes.
  2. Revoke the old secret.
  3. Check the logs for misuse (Stripe dashboard, AWS CloudTrail, DB logs).
  4. Remove it from git history with git filter-repo --path backend/.env --invert-paths, then force-push and have collaborators re-clone. This is cosmetic once rotated, but it reduces noise.
  5. Prevent it next time:
    • .gitignore: .env, *.pem, *.p8, secrets/.
    • Pre-commit scanning with gitleaks or trufflehog (you already use Husky in Hostel’s frontend, so add a hook).
    • Turn on GitHub secret scanning + push protection.
# quick audit
git ls-files | grep -Ei '\.env$|\.pem$|\.p8$|secret|credential'
gitleaks detect --source . -v
  • Least privilege. The IAM role reads only /kontentt/prod/*, and the DB user can’t DROP.
  • Short-lived credentials (OIDC, IAM roles, Vault dynamic DB users) beat long-lived keys.
  • Don’t log secrets. Sentry PII scrubbing (RM and IR3D BeforeSend), and mask Authorization headers in request logs.
  • Separate secrets per environment. A leaked staging key must not unlock production.

Check yourself

1. You committed a Stripe key and deleted it in the next commit. First action?
2. Hostel’s CI accesses AWS with…