Secrets Management Explained: Keeping Passwords and Keys Out of the Wrong Hands

Secrets management explained in plain terms is the practice of storing, controlling and delivering the sensitive credentials that software needs, such as passwords, API keys and certificates, so that only the right systems can use them, and only for as long as they need them. The central question is why secrets keep leaking even in well-run teams, and the short answer is that secrets are copied into code, configuration files, chat messages and screenshots faster than anyone tracks, so the fix is a single controlled store with strict access rules and automatic rotation, rather than discipline alone.

Almost every system needs secrets. An application needs a database password, a key to call a payment provider, and a certificate to prove its identity. A build pipeline needs tokens to deploy code. A person needs credentials to sign in. Each of these is a secret, and each one is valuable to an attacker, because a stolen secret works exactly like a legitimate one. The history of security breaches is full of secrets found in places they should never have been: in public code repositories, in log files, in old backups, and in configuration files shared between teams. Our guide to identity and access management explains how the identities that use these secrets are organised.

Key takeaways

  • Secrets management is the controlled storage, delivery and rotation of passwords, API keys, tokens and certificates.
  • A stolen secret works exactly like a legitimate one, which is why secrets are a favourite target for attackers.
  • Secrets leak through code, configuration, logs, chat and screenshots, not only through direct attacks.
  • A dedicated secrets store, with strict access rules and automatic rotation, replaces scattered copies with one controlled source.
  • Short-lived, automatically delivered secrets are safer than long-lived keys that people copy by hand.

What a secret is

A secret is any credential that proves identity or grants access. Passwords are the best-known kind, but most secrets in modern systems are not typed by people at all. API keys let one service call another. Tokens let a pipeline deploy code or a device connect to a network. Private keys and certificates prove that a server is who it claims to be, and encryption keys protect data at rest. Each type has its own lifetime and its own way of being used, but they all share one property: anyone who holds one can act as its owner.

That property is what makes secrets different from other configuration. A wrong database address breaks an application, but a leaked database password gives an attacker the data. Secrets therefore need stronger handling than ordinary settings: they must be stored encrypted, delivered only to the systems that need them, logged when accessed, and replaced regularly so that a leaked secret stops working quickly.

How secrets leak

Secrets leak in ordinary, everyday ways. A developer pastes a key into a code file to get something working and forgets to remove it. A configuration file containing a password is committed to a shared repository. An error message logs a full request, including the token in it. A screenshot of a dashboard shows a key in a corner. A chat message shares a password that is never changed afterwards. None of these involve an attacker breaking in; they involve a secret being put somewhere it can be found.

Secrets also leak through systems that copy them. Backups contain configuration files. Container images contain the environment variables they were built with. Log aggregators collect everything an application prints. Each copy is another place a secret lives, and each one is a place that must be cleaned up when the secret is changed. Teams that do not know where their secrets are cannot protect them, which is why the first step in secrets management is usually a painful discovery: finding all the places secrets already live.

What a secrets store does

A secrets store is a dedicated system for keeping secrets, and it does four things. It stores secrets encrypted, so that even someone who can read the storage cannot read the secrets. It controls access, so that only named identities can read a given secret, and every access is logged. It delivers secrets to workloads at runtime, so applications receive them when they start rather than carrying them in code or configuration. And it rotates secrets, replacing them on a schedule so that any leaked copy stops working.

Rotation is the feature that matters most over time. A password that never changes is useful to an attacker forever, once stolen. A password that changes every month is useful for at most a month, and if the system that uses it fetches the new value automatically, the change costs nobody any work. Some secrets can be made dynamic, generated fresh for a single use and expiring within minutes, so there is nothing long-lived to steal at all.

A photograph of a locked server cabinet in a dark room, a small green status light glowing beside the handle
A secrets store keeps credentials encrypted, controls who can read them, and replaces them on a schedule.

Comparing ways of handling secrets

Approach How it works Main risk Best for
Hard-coded in code Secret written in source files Leaks through repositories and copies Nothing, never do this
Environment variables Secret passed when a process starts Visible in logs, images and process lists Local development only
Configuration files Secret stored in a file on disk Spreads through backups and sharing Small systems with strict file control
Dedicated secrets store Encrypted store, runtime delivery Needs correct access rules Production systems of any size
Dynamic short-lived secrets Generated fresh, expire in minutes More complex to set up High-value access and automation

Secrets in the delivery pipeline

The delivery pipeline deserves special attention, because it touches everything. Build and deployment systems need credentials to fetch code, push images and apply changes, and those credentials are powerful: a stolen deployment token can change what runs in production. Pipeline secrets should be scoped as narrowly as possible, so a token can only do the one job it was made for, and they should be short-lived where the pipeline supports it.

Secrets must also be kept out of build outputs. A container image built with a secret in an environment variable carries that secret forever, in every copy of the image, including copies stored in registries and on laptops. Build systems should inject secrets at runtime, after the image is built, and scans should check images for anything that looks like a key or a token before they are allowed to run. Our guide to access control explains how permissions limit what a stolen credential can do, and our guide to cloud security covers how cloud services store and deliver secrets.

Rotation, revocation and incident response

Rotation is the routine replacement of secrets on a schedule. It should be automatic, because manual rotation is skipped under pressure and forgotten during holidays. Automatic rotation needs applications that fetch secrets at runtime, so they pick up the new value without a restart or a code change. Where automatic rotation is not possible, the secret’s lifetime should still be limited, and its expiry date should be tracked like any other deadline.

Revocation is the emergency version of rotation: when a secret is known to be leaked, it must be disabled immediately, and every system that used it must receive the replacement. This only works if the team knows where the secret was used, which is another reason a single store beats scattered copies. After a leak, the team should also check the logs for use of the old secret, to learn whether it was actually used by anyone other than its owner.

What good practice looks like

Good practice starts with a single rule: no secret ever appears in code, in a chat message, or in a document. Secrets live in the store, and applications receive them at runtime. The second rule is least privilege: each secret grants only the access its owner needs, and each identity can read only the secrets it needs, so a leak in one place does not open every door.

Good practice also means watching the store itself. Access logs are reviewed, unusual reads are investigated, and secrets that have not been rotated are flagged. Teams run scans that search code, images and logs for patterns that look like keys and tokens, and they treat a finding as a leak to be revoked, not as a warning to be ignored. Finally, good practice means planning for the day a secret leaks, with a runbook that says who revokes it, who replaces it, and how the team checks whether it was used.

Secrets management checklist

  • Store every secret in a dedicated, encrypted secrets store, never in code, chat or documents.
  • Deliver secrets to workloads at runtime, so they never appear in images or configuration files.
  • Give each identity access only to the secrets it needs, and log every read.
  • Rotate secrets automatically on a schedule, and use short-lived or dynamic secrets where possible.
  • Scope pipeline and deployment tokens narrowly, so each one can only do its own job.
  • Scan code, images and logs for patterns that look like keys or tokens before they reach production.
  • Keep secrets out of error messages, screenshots and shared configuration.
  • Track expiry dates for certificates and long-lived keys, and renew them before they lapse.
  • Keep a leak runbook: who revokes, who replaces, and how to check whether a leaked secret was used.

Frequently asked questions

What is secrets management?

Secrets management is the practice of storing, controlling and delivering sensitive credentials, such as passwords, API keys, tokens and certificates, through a dedicated store. The store encrypts secrets, controls who can read them, delivers them to workloads at runtime, and rotates them on a schedule so leaked copies stop working.

What counts as a secret?

Any credential that proves identity or grants access counts: passwords, API keys, access tokens, private keys, certificates and encryption keys. Most secrets in modern systems are used by software, not people, and anyone who holds one can act as its owner, which is why they need stronger handling than ordinary settings.

Why should secrets not be stored in code?

Because code is copied, shared, backed up and reviewed, and every copy carries the secret with it. A key committed to a repository can spread to laptops, registries and public hosting before anyone notices, and changing it means finding every copy. Secrets should live in one controlled store and be delivered at runtime.

What is secret rotation?

Rotation is the routine replacement of a secret with a new one, on a schedule. It limits the damage from a leak, because a stolen secret stops working when it is replaced. Rotation should be automatic where possible, with applications fetching the new value at runtime so the change costs nobody any work.

What is a dynamic secret?

A dynamic secret is generated fresh for a single use or a short period, often expiring within minutes, and then discarded. Because there is no long-lived credential to steal, dynamic secrets are the safest option for high-value access, such as database credentials for automated jobs.

What should I do if a secret leaks?

Revoke it immediately, replace it everywhere it was used, and check the access logs to see whether it was used by anyone other than its owner. Treat the leak as an incident even if nothing looks wrong yet, and record what happened so the team can fix the process that allowed the secret to escape.

The bottom line

Secrets management explained in one line is this: secrets are powerful because anyone who holds one can act as its owner, so they belong in one encrypted store with strict access and automatic rotation, delivered at runtime, and never in code, chat or configuration, because discipline alone cannot keep track of every copy.

Latest articles

Scroll to Top