# Secrets Management Fundamentals

> What counts as a secret, why it must never live in Git or images, and the patterns for storing, delivering and rotating credentials. Free notes, key concepts,...

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

What counts as a secret, why it must never live in Git or images, and the patterns for storing, delivering and rotating credentials.

Intermediate · about 3 hours · difficulty 2/5

Learn first: [Configuration, Secrets, Storage and RBAC](https://www.internhack.in/roadmaps/tracks/devops/k8s-config-storage)

A **secret** is anything that grants access: passwords, API keys, tokens, private keys, database URLs with credentials, signing keys. Leaked secrets are one of the most common causes of breaches, and they usually leak through Git history, container images, CI logs or chat.

### Rules to live by

- Never commit secrets, even to private repos. If one is committed, **rotate it**; deleting the commit is not enough.
- Never bake secrets into images or pass them as build arguments.
- Mask secrets in CI logs and avoid `set -x` around them.
- Give each workload its **own** credentials with the least privilege it needs.
- Prefer **short-lived, dynamic credentials** over long-lived static ones.

### Where secrets live

- **Cloud secret managers**: AWS Secrets Manager and Parameter Store, Azure Key Vault, Google Secret Manager.
- **Dedicated vaults** such as HashiCorp Vault or OpenBao.
- **Encrypted files in Git** with SOPS or Sealed Secrets, decrypted only at deploy time.
- **Kubernetes Secrets** are only base64 encoded; enable encryption at rest and restrict RBAC.

### Getting secrets to apps

Environment variables are simple but leak into crash dumps and child processes; mounted files are slightly safer and can be refreshed. Identity-based access (cloud IAM roles, workload identity) lets apps fetch secrets without a bootstrap secret at all.

### Detection

Run scanners such as **gitleaks** or **trufflehog** in pre-commit hooks and CI, and enable push protection on your Git host.

**Good enough to move on:** you can explain why rotating beats deleting, list three storage options with trade-offs, and add secret scanning to a repository.

## Key concepts

- **What counts as a secret**
- **Leak paths: Git, images, logs**
- **Cloud secret managers**
- **Env vars vs mounted files**
- **Rotation and short-lived credentials**
- **Kubernetes Secret encryption at rest**
- **Secret scanning with gitleaks**

## Mini project

Add gitleaks to a pre-commit hook and CI for one of your repositories, move an app's database password into a cloud secret manager, and have the app read it through its IAM role.

## Check yourself

A developer pushed an API key and force-pushed to remove the commit a minute later. Is the key safe? What do you do?

## Free resources

- [OWASP Secrets Management Cheat Sheet](https://cheatsheetseries.owasp.org/cheatsheets/Secrets_Management_Cheat_Sheet.html) (OWASP)
- [Kubernetes Secrets](https://kubernetes.io/docs/concepts/configuration/secret/) (kubernetes.io)
- [AWS Secrets Manager user guide](https://docs.aws.amazon.com/secretsmanager/latest/userguide/) (AWS)

Previous: [Flux](https://www.internhack.in/roadmaps/tracks/devops/flux) · Next: [HashiCorp Vault](https://www.internhack.in/roadmaps/tracks/devops/vault)

## More in GitOps and Secrets Management

- [GitOps Principles](https://www.internhack.in/roadmaps/tracks/devops/gitops-principles)
- [Argo CD](https://www.internhack.in/roadmaps/tracks/devops/argo-cd)
- [Flux](https://www.internhack.in/roadmaps/tracks/devops/flux)
- [Secrets Management Fundamentals](https://www.internhack.in/roadmaps/tracks/devops/secrets-management)
- [HashiCorp Vault](https://www.internhack.in/roadmaps/tracks/devops/vault)
- [SOPS, Sealed Secrets and External Secrets](https://www.internhack.in/roadmaps/tracks/devops/sops-external-secrets)

## Related

- [Roadmaps](https://www.internhack.in/roadmaps)
- [DevOps Engineer Roadmap](https://www.internhack.in/roadmaps/tracks/devops)
