Pebellslearn by building
0%
RoadmapsMatrixCoursesSandboxSign in
Encryption and Secrets  ›  Capstone Project

Secrets Management

Key Management Service 15 minSecrets belong in a secrets manager backed by a key management service, injected at runtime to short-lived identities, rotated regularly, and caught by scanners if they ever reach code.

Secrets Management

Tiffin talks to a payment provider, a database, an email service and a container registry. Each one needs a password, token or key: a secret. Where those secrets live decides whether one mistake is a shrug or a breach. The answer is never "in the code".

The rule

Store secrets centrally, inject them late, rotate them often, scan for leaks.

  • Store centrally. Keep secrets in a secrets manager, such as HashiCorp Vault or your cloud's secrets service, not in code, config files, container images or chat. Every read is access-controlled and logged.
  • Protect the keys with a KMS. A key management service holds master keys that never leave it; you ask it to encrypt, decrypt or sign. Big data is protected by envelope encryption: a data key encrypts the data, and the KMS master key encrypts the data key.
  • Inject late. The app or pipeline job fetches the secret at runtime using its own identity. Many CI systems can swap a short-lived identity token (OIDC) for cloud credentials that expire within the hour, so there is no long-lived key to steal.
  • Rotate. Change secrets on a schedule and immediately after any suspected leak. Automated rotation makes this routine instead of scary.
  • Scan. Run a secret scanner as a pre-commit hook and in the pipeline, because someone will eventually paste a key.
deploy:
  permissions: { id-token: write }         # job gets a short-lived identity
  steps:
    - run: cloud-login --oidc --role tiffin-deploy
    - run: deploy --db-password-from secrets://tiffin/prod/db

The shortcut

Follow one secret's life and check each stop: where is it stored, who can read it, how long does it live, what if it leaks?

Tiffin's payment API keyStep 1 of 4
  1. Stored

    In the secrets manager at tiffin/prod/payments, encrypted under a KMS key. Not in config.py.

The biggest trap: deleting a leaked secret in a new commit and calling it fixed. Git keeps every earlier version. A secret that touched a repository is compromised; rotate it.

Drills

Answer fast — trust the rule.

quick drill

A token was committed and then removed in the next commit. What must happen first?

quick drill

What is a key management service mainly for?

quick drill

Tiffin's Dockerfile has ENV DB_PASSWORD=hunter2. Why is this a problem?

quick drill

Why is a short-lived OIDC credential for the deploy job better than a stored cloud key?

quick drill

In envelope encryption, what does the KMS master key encrypt?

Remember

  • Store centrally, inject late, rotate often, scan for leaks.
  • Trace a secret: stored where, read by whom, lives how long, what if it leaks?
  • A secret that touched Git is compromised; rotate it before anything else.

Practice — level up

0/1 solved

Write your answer, then compare it with a rubric and a model answer.

ExplainA key in the commit history

A developer committed Tiffin's payment API key in config.py, noticed an hour later, and pushed a second commit deleting it. Explain why the problem is not solved, what to do now, and how to stop it happening again.