0%
Security Engineering for Software Teams
Thinking About Security
Cryptography You Will Actually Use
Identity
Vulnerability Classes
Detection and Response
Secrets Management
A secret is any value that grants access: a database password, an API key, a cloud access key, a signing key, a TLS private key, an OAuth client secret or a webhook signing token. Whoever holds the value can act as the system it belongs to. Secrets management is the practice of creating, storing, distributing, using, rotating and revoking these values so that they reach only the workloads that need them, for only as long as they need them. This section explains why secrets leak and what the costs are when they do.
What counts as a secret
The boundary is wider than passwords. Session signing keys let anyone forge logins. Webhook secrets let anyone send fake events. Encryption keys protect data at rest, so losing them exposes every backup. Deploy keys and CI tokens let attackers change code. Personal access tokens carry a developer full permissions. Connection strings embed credentials inside a URL that looks like configuration. A useful test is to ask what an attacker could do with the value. If the answer is anything other than nothing, it is a secret.
How secrets leak
Secrets leak through a small number of recurring paths. They are committed to source control, pasted into chat or tickets, printed in logs and error messages, baked into container images, left in environment variables visible to debugging tools, stored in CI variables that every pipeline can read, copied onto laptops and shared through spreadsheets or wikis. Each path is ordinary, which is why leaks are so common. Most leaked secrets were never stolen by a sophisticated attacker. They were simply placed somewhere readable.
Source control is the largest path
Committing a secret is easy: a developer hard codes a key while testing, adds a configuration file that holds a password or commits a .env file by accident. Deleting the line in a later commit does not remove it, because the value remains in history and in every clone and fork. Public repositories are scanned by attackers within minutes of a push, and private repositories become public, are cloned by contractors or are exposed when a developer account is compromised.
Why speed matters
Automated scanners watch public code hosts, package registries and paste sites continuously. Studies of exposed cloud keys have found them used within minutes of exposure, usually to start resources for cryptocurrency mining or to copy data. This means that rotating a leaked secret next week is far too slow. The response to a leak must be measured in minutes, which in turn requires that rotation is easy and practised before it is needed.
Long lived credentials
Many organisations rely on static credentials that never expire: an access key created years ago, a database password shared by every service or an API token with no expiry. Long lived credentials accumulate risk. They are copied to more places over time, their owners leave, nobody knows what still uses them and rotating them risks an outage. The longer a credential lives, the more likely it has leaked somewhere and the harder it is to replace.
Shared credentials
A credential shared by many services or people removes accountability and makes rotation hard. Logs show only that the shared identity acted, not which service or person did. Revoking it breaks everything at once. Shared admin passwords for databases or cloud accounts are especially dangerous because they also survive the departure of every person who knew them. Each workload and person should have their own identity so that access can be traced and removed individually.
Secret sprawl
Secret sprawl describes the state where copies of the same secrets exist in many places: configuration files, CI settings, developer laptops, wiki pages, password managers and multiple vaults. Sprawl makes it impossible to answer basic questions such as where is this key used and who can read it. Reducing sprawl means choosing one system of record for each secret and making every consumer fetch from it rather than holding a copy.
The cost of a leaked secret
The impact of a leak depends on what the secret grants. A leaked read only key for a public dataset is minor. A leaked cloud key with administrator rights can lead to data theft, destroyed infrastructure and large bills. A leaked signing key can let attackers forge sessions or software updates until every relying party trusts a new key. Scoping each secret narrowly limits this cost before any leak happens.
Machine identities outnumber people
In modern systems, machine identities such as services, functions, jobs and pipelines far outnumber human users, and each needs credentials. Human accounts usually get single sign on, multi factor authentication and offboarding processes. Machine credentials often get none of these. Treating machine identities as first class, with owners, inventories, short lifetimes and automated rotation, closes the largest part of the credential estate.
Secrets in third party systems
Secrets are also held by vendors and integrations: tokens stored in a monitoring tool, keys given to a CI provider or OAuth grants held by a SaaS app. A breach at one of these vendors exposes the secrets they hold. Inventories should include which third parties hold which credentials, with scopes as narrow as possible and a plan for rotating them quickly when a vendor reports a breach.
Goals of a secrets programme
A good programme aims for a few clear outcomes. Secrets are never in source code, images or logs. Each workload has its own identity and fetches credentials at runtime from one system of record. Credentials are short lived or rotated automatically. Every secret has an owner and a known set of consumers. Leaks are detected quickly and rotation takes minutes. The rest of this lesson describes how to reach each of these outcomes.
Starting from an inventory
Most teams begin without knowing how many secrets they have. Scanning repositories, CI settings, cloud accounts and configuration stores produces a first inventory, typically with many unknown or orphaned entries. Recording each secret owner, purpose, consumers, scope and age turns the inventory into a plan: remove unused secrets, replace shared ones with per workload identities and move the rest into a managed store.
Time to exploitation
The gap between exposure and abuse is the number that shapes every design choice in this lesson. In controlled tests where organisations deliberately pushed canary cloud keys to public repositories, the first unauthorised use usually came within minutes, and nearly every key was tried within a day. Keys pushed to private repositories, chat or logs are found more slowly, but by insiders, contractors or attackers who already hold some access.
Why people hard code secrets
Hard coded secrets are rarely a matter of ignorance. Developers hard code values because the secure path is slower: requesting access to a vault takes a ticket, local development has no easy way to fetch credentials or a deadline makes a shortcut tempting. Understanding this changes the response. Telling people not to commit secrets helps little, while making the secure path faster than the shortcut removes the reason to take it.
Secrets in client side code
Any value shipped to a browser or mobile app is readable by its users, however it is obfuscated. API keys embedded in front end code or app binaries should be treated as public identifiers, scoped to the actions a public client may perform and protected by rate limits or domain restrictions. Operations that need real secrets belong on a backend that the client calls, never in code delivered to devices.
Secrets include keys, tokens, passwords, signing keys and connection strings. They leak through code, logs, CI, images, chat and laptops, and exposed keys are used within minutes. Long lived and shared credentials accumulate risk, so aim for per workload identities, one system of record, short lifetimes and fast rotation.