# Best Practices for Secrets Management: The Order We Fix Things In

URL: https://donedeploy.com/secrets-management-best-practices/
Published: 2026-11-20

Most lists of secrets management best practices are correct and not very useful. “Use a vault, rotate often, apply least privilege” is true, and almost every team we meet already agrees with it. What they lack is not the list but the order: which step to take first, which one removes the most risk, and which one quietly depends on another being done.

We covered the basics in [Keeping Secrets Safe](https://donedeploy.com/secret-management-guide/). This post is the practitioner’s version: the sequence we follow when we take over a client’s infrastructure, and why each step comes where it does.

## 1. Find out what you have

You cannot protect secrets you do not know about. Before any tool is chosen, we build an inventory:

- Every credential an application, pipeline or person uses, and where its value lives today.
- Who or what can read it, and who can change it.
- What it unlocks: one table, one bucket, or the whole cloud account.
- When it was last changed, if anyone knows.

The inventory is usually the most uncomfortable document in the project. It turns up the cloud access key created years ago by someone who has since left, the database password shared by six services, and the token pasted into a CI variable “temporarily”. That is the point. Every later step works from this list.

## 2. Stop new leaks before cleaning old ones

Cleaning up is slow. Leaks are fast. So the second step is to stop the bleeding:

- **Scan on every commit.** Run a scanner such as gitleaks or TruffleHog in a pre-commit hook and again in CI, so a secret is caught before it reaches the main branch.
- **Turn on provider protection.** GitHub push protection and GitLab secret detection block known token formats at push time.
- **Scan the history once.** A secret deleted in a later commit is still in Git history. Anything the scan finds there counts as leaked and goes on the rotation list.

Do not rewrite Git history and call it fixed. Once a secret has been pushed, assume it has been copied. The fix is rotation, not deletion.

## 3. One place for every secret

With leaks under control, move values into a single managed store: HashiCorp Vault or OpenBao, AWS Secrets Manager, Google Secret Manager or Azure Key Vault. Which one matters less than having exactly one source of truth per environment.

Where secrets live today Where they should end up `.env` files on laptops and servers The secret store, fetched at runtime or at deploy CI/CD variables copied by hand Short-lived credentials, or a reference to the store Kubernetes manifests in Git An external secret resource that points to the store Terraform variables and state The store, with state encrypted and access restricted Chat messages and wikis Nowhere. Rotate and remove

Terraform deserves a note of its own. State files can contain secret values in plain text, including generated passwords. Keep state in an encrypted remote backend, limit who can read it as strictly as the secrets themselves, and prefer resources that let the cloud provider generate and hold the password rather than passing it through Terraform.

## 4. Replace long-lived keys with short-lived credentials

This is the step that removes the most risk, and the one most teams skip. A static key is dangerous because it works for anyone, from anywhere, until someone remembers to revoke it. A credential that expires in an hour is far less valuable to an attacker.

- **CI/CD:** use OIDC federation. GitHub Actions, GitLab CI and other platforms can exchange a signed identity token for temporary cloud credentials in AWS, Google Cloud and Azure. No cloud key is stored in the pipeline at all.
- **Workloads:** use the platform’s workload identity, such as IAM roles for service accounts on EKS or Workload Identity on GKE, so pods receive credentials tied to their service account.
- **Databases:** where it fits, let Vault’s database secrets engine issue a username and password per service that expire on their own.
- **People:** single sign-on to the cloud console and CLI with short sessions, not personal access keys.

Every static secret that disappears is one less thing to rotate, scan for and worry about.

## 5. Deliver secrets to Kubernetes properly

A Kubernetes Secret is base64 encoded, which is not encryption. Anyone who can read Secrets in a namespace can read the values, and unless encryption at rest is configured, they sit in etcd as readable data. So:

- **Keep values out of Git.** Use the External Secrets Operator or the Secrets Store CSI Driver to sync from your store. If you must keep encrypted values in Git for GitOps, SOPS or Sealed Secrets make that safe.
- **Enable encryption at rest** for Secrets, using a KMS provider on managed clusters where it is offered.
- **Lock down RBAC.** `get` and `list` on Secrets is effectively read access to every credential in that namespace. Grant it rarely.
- **Prefer files to environment variables.** Mounted files can be updated without a restart and are less likely to appear in crash dumps and debug output.

## 6. Rotate, and prove you can

Rotation on paper is not rotation. For every remaining static secret, write down how it is rotated, then do it once on purpose, during working hours, while watching what breaks. The first rotation almost always finds a service that had the value copied somewhere nobody listed.

After that, automate what you can. Most cloud secret stores can rotate database credentials on a schedule. For the rest, set a review date in the inventory and treat an overdue one like an overdue certificate.

## 7. Practise the leak response

Sooner or later a secret will leak: in a log, a screenshot, a public repository or a support ticket. The difference between a bad afternoon and a breach is whether the response is already written down:

1. **Revoke or rotate first**, investigate second.
2. **Check the access logs** of whatever the secret unlocked, for the whole period it was exposed.
3. **Find the path** it took to leak and close it, whether that is a scanner rule, a log filter or a permission.
4. **Update the inventory**, so the next person knows what changed.

Run this once as an exercise with a harmless secret. Teams that have practised it move noticeably faster when it is real.

## Audit what reads your secrets

Every read from the secret store should be logged with who, what and when, and those logs should go somewhere the people being audited cannot edit. Alert on the unusual: a secret read from a new place, a burst of reads, or access to a production value from a developer machine. These logs are also how you answer the most important question after a leak: was it used?

## Where to start this week

If this list feels long, do three things now:

- Run a secret scanner across all your repositories, including history.
- Replace the cloud keys in your CI/CD pipelines with OIDC.
- Start the inventory, even as a spreadsheet, with an owner for every row.

Secrets management is not a tool you install once. It is a habit of knowing what credentials exist, keeping them short-lived, and being ready for the day one escapes. If you want a second pair of eyes on how your team handles secrets, [book a free call](https://donedeploy.com/lets-talk/) and we will go through it with you.
