Secrets management explained in plain terms starts with a leak that happens every week. A developer pastes an API key into a chat message, commits a database password to a public repository, or leaves a credential in a screenshot, and within minutes an automated scanner has found it and tried it. The central question is how teams keep the dozens of secrets a modern system needs without them ending up in the places secrets go to die, and the answer is a system built for the job: a secrets manager that stores, delivers, and rotates credentials, so humans never have to handle them directly.
A secret is any credential a system needs to prove itself: an API key, a database password, a signing key, a token, or a certificate. A modern application can easily hold fifty, spread across laptops, servers, pipelines, and cloud accounts, each one a key to something valuable.
Secrets management is the discipline, and the tooling, that keeps those keys safe through their whole life: creation, delivery, use, rotation, and retirement. This article explains the eight mistakes that leak secrets, and what good practice looks like instead.
Key takeaways
- Secrets are API keys, passwords, tokens, and certificates a system needs to prove itself.
- Store them in a dedicated secrets manager, never in code, chat, or email.
- Deliver secrets to applications at run time, not baked into images or files.
- Rotate secrets regularly and automatically, so a leak has a short life.
- Scope every secret narrowly, audit every use, and revoke fast when one leaks.
Mistake 1: secrets in source code
The most common leak is also the oldest: a credential written directly into the code. It feels harmless in the moment, a key pasted into a config file so the feature can ship, but code travels further than anyone expects, into forks, contractors’ laptops, and public repositories, and a secret in code is a secret published.
Scanners watch public code hosting around the clock, and a newly committed key is typically tried within minutes by bots testing it against cloud providers and databases. A stolen cloud key can run up a bill of thousands before anyone notices.
The fix is to keep secrets out of the repository entirely. Code should read its secrets from the environment or from a secrets manager at run time, and the repository should be scanned on every commit for anything that looks like a key. The scan is a safety net, not a strategy, but it catches the mistakes that the strategy misses.
Mistake 2: secrets shared by chat and email
Chat messages and emails are where secrets go to be forgotten. A password pasted into a channel stays in the history, is copied into search indexes, and is visible to everyone who joins the channel later, including people who should never have seen it.
The right answer is that humans should rarely handle secrets at all. A developer who needs access should receive a short-lived credential from the secrets manager, scoped to the job, which expires on its own. If a secret must be shared between people, a password manager with secure sharing is the least bad option, and even then the secret should be rotated afterwards.
Mistake 3: one secret everywhere
A single API key used by every service, in every environment, is a single point of failure. When it leaks, everything it touches is exposed, and when it must be rotated, every service breaks at once, which is why teams put off rotating it, which is why the leak lasts longer.
Each service and environment should have its own secret, scoped to exactly what it needs: a development key should not work in production, and a read-only key should not delete data. Our guide to zero trust explains the principle behind this: never trust a credential more than its narrowest job requires.
Scoping also makes the blast radius visible. When a secret is found in the wild, the team can see exactly what it could reach, revoke it, and move on, instead of guessing at the damage.
Mistake 4: never rotating secrets
A secret that never changes is a secret that is useful forever, which is exactly what an attacker wants. Keys created years ago, by people who have long since left, are still sitting in old servers, old backups, and old laptops, waiting to be found.
Rotation should be automatic and boring: passwords change on a schedule, keys expire, and the rotation is tested so it does not break the service at three in the morning. The best rotations are the ones nobody notices.
Rotation also bounds the damage of an undiscovered leak. A key that lives for thirty days can only be abused for thirty days, while a key that lives forever is a permanent back door.

Mistake 5: secrets baked into images and files
A secret baked into a container image or a configuration file travels with the image everywhere it goes: into registries, into caches, into the laptops of everyone who pulls it, and into the layers of the image, where it survives even if the file is later deleted.
The fix is to inject secrets at run time. The application starts with no credentials, asks the secrets manager or the orchestrator for them, and holds them only in memory. The image itself contains nothing worth stealing, which means it can be shared, cached, and scanned without worry.
The same rule applies to virtual machine snapshots, backups, and Terraform state files, all of which are notorious for carrying secrets far beyond their intended audience. Every artefact a team produces should be assumed public, and built as if it were.
Mistake 6: no audit trail
A secret that is used without a record is a secret whose abuse cannot be detected. If nobody logs who read a credential, when, and from where, then a stolen key can be used for months before anyone notices, and the investigation afterwards has nothing to work with.
A good secrets manager logs every access, and monitoring flags unusual patterns: a key used from a new country, at an odd hour, or far more often than usual. Our guide to rate limiting explains a related control that slows down abuse once it is detected, and the two work best together.
Audit also covers the human side. Who can grant access to a secret, who approved it, and when does it expire are questions the system should answer without a meeting, because the answers matter most during an incident.
Mistake 7: hard-coded credentials in pipelines
Build and deployment pipelines hold some of the most powerful secrets in a company: the credentials that deploy to production, publish releases, and push images. Hard-coding them into pipeline scripts, or storing them in plain text in the pipeline tool, hands the keys to anyone who can read the pipeline.
Modern pipeline tools offer identity-based access instead: the pipeline proves who it is to the cloud provider, and receives a short-lived token for exactly the job it is running. There is no long-lived credential to steal, and the token expires when the job ends.
Mistake 8: no plan for a leak
The final mistake is assuming it will not happen to you. Secrets leak, and the teams that survive a leak are the ones that rehearsed it: they know which secret it is, what it can reach, how to revoke it, and how to tell the people affected.
The response should be fast and mechanical: revoke the secret, issue a replacement, check the audit logs for abuse, and tell those affected plainly. A leak handled well costs a day; one discovered months later costs a reputation.
Prevention helps, but detection is what saves you. Secret scanning in repositories, alerts on unusual use, and canary tokens, fake secrets planted where only an attacker would find them, all turn a silent leak into a noisy one. Our guide to threat modelling explains how to plan for the failures you know are coming, rather than hoping they do not.
Comparing secrets management options
Teams can manage secrets in several ways, from environment variables to dedicated vaults, and the right choice depends on scale. Environment variables are simple and suit a single small application, but they spread secrets across servers and are easy to leak through logs and error messages.
A dedicated vault adds encryption, access control, audit, and rotation in one place. It is more work to set up, but it is the only option that scales past a handful of services without becoming a liability.
The table below compares the main approaches.
| Aspect | Dedicated secrets manager | Environment variables | Secrets in code |
|---|---|---|---|
| Storage | Encrypted, access-controlled | Plain text on the server | Plain text in the repo |
| Rotation | Automatic and audited | Manual, often forgotten | Manual, breaks deploys |
| Audit trail | Every access logged | None | None |
| Leak risk | Low, scoped and short-lived | Medium, spreads widely | High, published by accident |
| Best for | Any team past a few services | One small app | Nothing, never do this |
The honest summary is that environment variables are a starting point, not a destination. Any team with more than a few services, or any secret that matters, should be using a dedicated manager.
Secrets management checklist
- Store every secret in a dedicated manager, never in code, chat, or email.
- Give each service and environment its own secret, scoped to its narrowest job.
- Deliver secrets at run time and hold them only in memory.
- Rotate secrets automatically and test that rotation does not break anything.
- Use short-lived credentials and identity-based access in pipelines.
- Log every access and alert on unusual patterns.
- Scan repositories on every commit for anything that looks like a key.
- Rehearse the leak response, so revocation is fast and mechanical.
- Remove secrets from leavers’ machines and revoke their access the same day.
Frequently asked questions
What is secrets management?
It is the practice of storing, delivering, rotating, and retiring credentials such as API keys and passwords through a dedicated system, so they never appear in code, chat, or files.
Why can I not just use environment variables?
You can, for one small application, but they spread plain-text secrets across servers, leak through logs, and are hard to rotate. A dedicated manager adds encryption, audit, and automatic rotation.
How quickly are leaked keys abused?
Often within minutes. Automated scanners watch public code hosting continuously, and a fresh key is typically tested against cloud and database services almost immediately.
What should I do if a secret leaks?
Revoke it at once, issue a replacement, check the audit logs for abuse, and tell anyone affected. Speed matters more than anything else, so rehearse the steps before you need them.
What is a canary token?
It is a fake secret planted where only an attacker would find it, such as in a document or a repository, which triggers an alert the moment someone tries to use it.
Do small teams need a secrets manager?
Yes, if they have more than a handful of secrets or anything that matters. Cloud secrets managers are cheap and simple, and the cost of a leak dwarfs the cost of setting one up.
The bottom line
Secrets management explained in one line is this: keep credentials in one guarded place, hand them out briefly and narrowly, and replace them before a leak can do lasting harm.
Secrets will leak, because people are human and systems are complicated. The teams that survive are the ones whose leaks are short, narrow, and noisy, rather than permanent, broad, and silent.
This article is general information about how secrets management works, not advice about securing a particular organisation.







