Secrets
Management
Learn why hardcoding passwords is dangerous, how secrets vaults protect sensitive data, and the principles behind keeping credentials safe at scale.
What Are Secrets?
In cyber security, a secret is any piece of sensitive information that grants access to a system, service, or dataset. Secrets must be kept confidential: if an attacker obtains one, they can impersonate a legitimate user or service.
Why Secrets Management Matters
A single leaked database password can compromise millions of records. Secrets management is the practice of storing, distributing, and rotating sensitive credentials so they never appear where attackers can find them.
The Lifecycle of a Secret
The Core Rule: Never Hardcode
Hardcoding means embedding a secret directly in source code, configuration files, or scripts that are checked into version control. Once committed, the secret lives in the repository's history: even if you delete the line, git remembers.
What Is a Secrets Vault?
A secrets vault is a dedicated, encrypted service designed to store, manage, and control access to secrets. Think of it as a digital safe: applications authenticate to the vault, request only the secrets they need, and receive them securely at runtime.
How a Vault Works
Hardcoded vs. Vault-Managed
| Hardcoded | Vault-Managed | |
|---|---|---|
| Storage | Plaintext in source code | Encrypted vault |
| Version control | Committed to git history | Never in repos |
| Rotation | Manual code change + deploy | Automated, zero-downtime |
| Access control | Anyone with repo access | Fine-grained policies |
| Audit trail | None | Full logging of every access |
| Breach impact | All secrets exposed at once | Scoped, revocable |
Principle of Least Privilege
Every service or user should receive only the specific secrets it needs to perform its function: nothing more. This limits the blast radius if any single service is compromised.
How to Apply Secrets Management
Example 1: Environment Variables
The simplest step away from hardcoding: store secrets in environment variables on the host machine, and read them at runtime.
Example 2: Vault API Integration
For production systems, use a dedicated vault. The application authenticates and fetches secrets dynamically: no environment files needed.
Example 3: Automatic Rotation
Rotation ensures that even if a secret is leaked, it becomes useless within a short window. Vaults can rotate database credentials automatically.
Common Mistakes to Avoid
Secrets Management Summary
| Concept | Key Idea | Best Practice |
|---|---|---|
| Hardcoding | Secrets in source code | Never do this |
| Env Variables | Runtime injection | Good first step |
| Secrets Vault | Centralized encrypted store | Production standard |
| Least Privilege | Minimum necessary access | Scope every policy |
| Rotation | Regular secret expiry | Automate with vault |
| Audit Logging | Track every access | Alert on anomalies |
Question 1 of 5
A developer writes API_KEY = "sk-abc123..." directly in their Python file and pushes it to GitHub. What is this practice called?
Question 2 of 5
Which of the following is the primary benefit of using a secrets vault over environment variables?
Question 3 of 5
Your company's Payment API only needs the Stripe secret key. Under the principle of least privilege, what should the vault policy allow?
Question 4 of 5
A secret was accidentally committed to a public GitHub repo 10 minutes ago. The developer immediately deletes the line and pushes a new commit. Is the secret still at risk?
Question 5 of 5
Which step in the secrets lifecycle limits the damage window if a credential is leaked?