100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace
DevSecOps & Security Automation
30 minadvanced

Secrets management — Vault, AWS Secrets Manager and rotation

Secrets are the credentials that let systems authenticate to one another: database passwords, API keys, signing certificates, and cloud access tokens. Because a single leaked secret can unlock production data, managing them safely is a core DevSecOps discipline. This lesson covers why secrets must never live in source code, how dedicated secret stores such as HashiCorp Vault and AWS Secrets Manager centralise control, and why automatic rotation dramatically shrinks the value of any secret an attacker manages to steal.

Analogy🏏Cricket
💰 Think of it like finance: a bank PIN or account password is worthless paper until it unlocks real money, at which point protecting it becomes everything, because a single leaked code can drain the account. Secrets in software are exactly this kind of key — database passwords, API keys, and cloud tokens that let systems authenticate to one another, and one exposed value can unlock production data. Dedicated stores like Vault and AWS Secrets Manager centralise control, while automatic rotation regularly cancels old credentials. This reveals that a secret's danger scales with what it unlocks, so guarding and expiring it quickly is non-negotiable.

The cardinal rule is that secrets never belong in Git. Once committed, a secret persists in the repository's history forever, replicated to every clone and fork, even after the file is later deleted. Hard-coded credentials also get copied into logs, screenshots, and support tickets. Centralised secret managers solve this by storing values encrypted at rest, handing them to applications at runtime through short-lived tokens, and keeping source control entirely free of sensitive material.

Analogy🏏Cricket
🎵 Think of it like music: once a song is released and copied across streaming platforms, fan uploads, and downloads, you can never truly recall it — deleting the original file changes nothing, because countless copies persist everywhere. A secret committed to Git behaves identically: it lives in the repository's history forever, replicated to every clone and fork even after the file is deleted, and it leaks into logs and screenshots. Centralised managers instead store values encrypted at rest and hand them out as short-lived tokens at runtime. This reveals that the only reliable secret is one that never enters version history at all.

Under the hood, a modern secret store does far more than encrypt a value. Vault, for instance, can generate dynamic database credentials on demand that expire after minutes, issue short-lived cloud tokens, and record a detailed audit trail of every access. AWS Secrets Manager integrates rotation with native services, invoking a function on a schedule to change the underlying credential and update the stored value atomically, so consumers always retrieve a current, working secret.

Analogy🏏Cricket
🎮 Think of it like gaming: a well-designed game does not hand players one permanent master password; it issues single-use session tokens that expire when you log out and logs every action for anti-cheat review. A modern secret store works far beyond simple encryption in the same spirit. Vault can generate dynamic database credentials that self-destruct after minutes, mint short-lived cloud tokens, and record a detailed audit trail of every access, while AWS Secrets Manager rotates a credential on schedule and updates the stored value atomically. This reveals that expiring, traceable access beats a single static key that never changes.
bash
# Retrieve a secret at runtime instead of hard-coding it
# AWS Secrets Manager
aws secretsmanager get-secret-value \
  --secret-id prod/db/credentials --query SecretString --output text

# HashiCorp Vault: request a short-lived dynamic DB credential
vault read database/creds/app-role
#   -> username and password valid for e.g. 15 minutes, then auto-revoked
Analogy🏏Cricket
🏏 Think of it like cricket: a single ball used through an entire innings grows scuffed and predictable, until every batsman has learned its swing and it becomes both useless and unsafe to keep in play. That is why the umpire changes the ball at fixed intervals, denying either side a familiar advantage for long. A leaked static secret ages the same way — the longer it lives, the more exposed and exploitable it becomes. Rotation swaps it out on schedule, and dynamic short-lived credentials go further, offering a fresh ball almost every over. This reveals that freshness itself is a defence, because nothing stays exploitable for long.

Best practice combines centralisation, least privilege, and rotation. Store every secret in a managed vault, grant each application access only to the specific secrets it needs, and rotate credentials automatically on a schedule so a stolen value expires quickly. Prefer dynamic, short-lived credentials over long-lived static keys wherever a service supports them, and continuously scan repositories and CI logs so that any secret which slips through is detected and revoked within minutes, not months.

Analogy🏏Cricket
💪 Think of it like fitness: lasting results come from stacking several habits together — balanced diet, regular training, and enough recovery — because any one alone leaves a gap the others must cover. Secrets discipline layers defences the same way. Store every secret in a managed vault, grant each application access only to the specific values it needs, rotate credentials automatically so a stolen one expires fast, prefer dynamic short-lived keys, and continuously scan repositories and CI logs so anything that slips through is revoked in minutes. This reveals that no single control is enough; combined habits are what keep the system strong.

In the real world, a team might replace a hard-coded database password embedded across a dozen services with a single Vault role that issues fifteen-minute credentials on request. If an attacker later captures one of those credentials from memory, it is already worthless by the time they try to reuse it. The audit trail also shows precisely which service accessed which secret and when, turning a murky incident into a traceable timeline.

Analogy🏏Cricket
📷 Think of it like photography: a time-stamped, watermarked photo pass that expires at the end of an event is far safer than a permanent laminated badge — even if someone photographs or steals the pass, it is worthless the next morning, and the log shows exactly who entered and when. Replacing a hard-coded database password spread across a dozen services with a Vault role that issues fifteen-minute credentials works the same way. A credential captured from memory is already expired by reuse, and the audit trail records which service accessed which secret. This reveals that short-lived, logged access turns a murky breach into a traceable timeline.
  • Secrets are high-value credentials; a single leak can expose production.
  • Never commit secrets to Git — history preserves them permanently across every clone.
  • Vault and AWS Secrets Manager centralise, encrypt, and audit secret access.
  • Rotation shrinks a stolen secret's useful lifespan; dynamic credentials shrink it further.
  • Combine centralisation, least privilege, rotation, and continuous secret scanning.
Lesson 4 of 35
0% complete