Dashboard
Courses
Problems
Badges
Theme
Sign inStart free
Courses/Architecture Leadership
Lesson 18 of 32

Secrets and key management

Store, distribute and rotate secrets and encryption keys so that a single leak is short-lived and contained.

15 min read

Where secrets leak

Secrets (API keys, database passwords, signing keys, OAuth client secrets) leak through predictable paths: committed to git, baked into container images, printed in logs, pasted into chat, or shared between environments. Public GitHub scanning shows leaked cloud keys are typically exploited within minutes. The architecture goal is that secrets never appear in code or images, live in one managed store, are delivered at runtime to only the workload that needs them, and are rotated regularly. Assume leaks will happen, and design so each leak is short-lived and limited in scope.

A secrets manager

Use a dedicated secrets manager (HashiCorp Vault, AWS Secrets Manager, GCP Secret Manager, Azure Key Vault) rather than environment files or config repos. Workloads authenticate with their platform identity and fetch only the secrets their policy allows.

  • Encrypt secrets at rest with keys held in a KMS or HSM
  • Grant access per workload identity, not per human
  • Log every read and every change to an append-only audit trail
  • Cache secrets in the client briefly to survive a manager outage, and refresh on rotation
  • Run secret scanning in CI and on the repository to catch accidents

Dynamic secrets and rotation

The best secret is one that expires quickly. Dynamic secrets are generated on demand: Vault can create a database user with a one-hour lease for each service instance and drop it afterwards. Where static secrets are unavoidable, rotate them on a schedule (90 days is a common baseline) and support two valid credentials at once so rotation does not cause downtime: create new, deploy consumers, verify, then revoke old. A rotation you have never rehearsed will fail during an incident.

Envelope encryption and KMS

Encrypting large amounts of data directly with a central key would make the KMS a bottleneck. Envelope encryption solves this: each object or record is encrypted with a data encryption key (DEK), and the DEK is itself encrypted with a key encryption key (KEK) that never leaves the KMS or HSM. Rotating the KEK only requires re-wrapping the small DEKs, not re-encrypting terabytes. Per-tenant KEKs also enable crypto-shredding: delete a tenant's key and all their data becomes unreadable. Restrict KMS decrypt permissions tightly, since they are the real key.

Key takeaways

  • Secrets must never live in code or images; deliver them at runtime from a managed store.
  • Grant access by workload identity and audit every read.
  • Prefer short-lived dynamic secrets; rotate static ones with an overlap window and rehearse it.
  • Envelope encryption with a KMS keeps keys central while making rotation and crypto-shredding cheap.

Sign in to track lessons and earn badges.

Identity: authentication, authorisation and SSOPrivacy and compliance

Challenge checkpoint

Course: 0/32 lessons · 0/10 challenges0%

Build it on the canvas, pass the review (70+) and mark it complete to count it toward the course badge.

  1. 4/10Design Single Sign-OnCentralise identity with SAML/OIDC, MFA and fast session revocation while protecting the signing keys.Medium
All 10 challenges →