# Secrets Management

> Keep API keys, passwords and certificates out of code, store them in a vault, rotate them and detect leaks early. Free notes, key concepts, resources and a...

Canonical: https://www.internhack.in/roadmaps/tracks/cybersecurity/secrets-management
Last updated: 2026-11-28

Keep API keys, passwords and certificates out of code, store them in a vault, rotate them and detect leaks early.

Intermediate · about 4 hours · difficulty 2/5

Learn first: [Secure SDLC](https://www.internhack.in/roadmaps/tracks/cybersecurity/secure-sdlc), [IAM Operations and Privileged Access](https://www.internhack.in/roadmaps/tracks/cybersecurity/iam-operations)

**Secrets** are credentials that grant access: API keys, database passwords, tokens, private keys and certificates. Leaked secrets are one of the most common causes of cloud breaches, often because they were committed to a Git repository.

### Rules of thumb

- **Never hardcode secrets** in source code, container images or front-end bundles.
- Store them in a dedicated **secrets manager**: HashiCorp Vault, AWS Secrets Manager, Azure Key Vault, Google Secret Manager, or your CI platform's encrypted secrets.
- Inject at runtime via environment variables or mounted files, with access restricted to the service that needs each secret.
- Prefer **short-lived credentials** (cloud IAM roles, workload identity, OIDC federation from CI) over long-lived static keys.
- **Rotate** secrets on a schedule and immediately after any suspected exposure.

### Detecting leaks

- Run **secret scanning** in pre-commit hooks and CI with tools like Gitleaks or TruffleHog, and enable GitHub secret scanning and push protection.
- Remember Git history is permanent: deleting the file in a new commit does not remove the secret. **Revoke and rotate first**, then clean history if needed.

### Local development

Use a git-ignored `.env` file with a committed `.env.example` that holds only placeholder values.

### Pitfalls

- Logging full request headers that contain tokens.
- One shared admin key used by every service, so rotation breaks everything.

Good enough to move on: you can move a hardcoded key from a project into a secrets manager, add a secret scanner to CI and explain the right response to a leaked key.

## Key concepts

- **What counts as a secret**
- **Secrets managers and vaults**
- **Runtime injection**
- **Short-lived credentials and OIDC**
- **Rotation and revocation**
- **Secret scanning (Gitleaks, TruffleHog)**
- **Push protection**

## Mini project

Add Gitleaks as a pre-commit hook and CI step to a repository, move any secrets into your CI platform's encrypted secrets or a cloud secrets manager, and write a leaked-key response checklist.

## Check yourself

Why is deleting a leaked secret from the latest commit not enough, and what must you do first?

## Free resources

- [OWASP Secrets Management Cheat Sheet](https://cheatsheetseries.owasp.org/cheatsheets/Secrets_Management_Cheat_Sheet.html) (OWASP)
- [About secret scanning](https://docs.github.com/en/code-security/secret-scanning/introduction/about-secret-scanning) (GitHub Docs)
- [HashiCorp Vault documentation](https://developer.hashicorp.com/vault/docs) (HashiCorp)
- [Gitleaks](https://github.com/gitleaks/gitleaks) (Gitleaks)

Previous: [Dependency and Supply-Chain Hygiene](https://www.internhack.in/roadmaps/tracks/cybersecurity/supply-chain-security) · Next: [SAST and SCA in CI Pipelines](https://www.internhack.in/roadmaps/tracks/cybersecurity/sast-sca-ci)

## More in Secure Software Development

- [Secure SDLC](https://www.internhack.in/roadmaps/tracks/cybersecurity/secure-sdlc)
- [Threat Modelling with STRIDE](https://www.internhack.in/roadmaps/tracks/cybersecurity/threat-modeling-stride)
- [Secure Coding and Input Validation](https://www.internhack.in/roadmaps/tracks/cybersecurity/secure-coding)
- [Dependency and Supply-Chain Hygiene](https://www.internhack.in/roadmaps/tracks/cybersecurity/supply-chain-security)
- [Secrets Management](https://www.internhack.in/roadmaps/tracks/cybersecurity/secrets-management)
- [SAST and SCA in CI Pipelines](https://www.internhack.in/roadmaps/tracks/cybersecurity/sast-sca-ci)

## Related

- [Roadmaps](https://www.internhack.in/roadmaps)
- [Cybersecurity Roadmap](https://www.internhack.in/roadmaps/tracks/cybersecurity)
