Beta

Create a tenant

A new tenant starts with its own users, OAuth settings, audit history and logs. You are its first Tenant Admin.

Managing secrets for software

Software has nobody to type a password, so it carries its proof with it, and anyone who copies that proof can act as the software. This lesson follows Cedar Inc.'s engineers through the service accounts on Quinn's list: keeping their secrets in a vault, making credentials that expire by themselves, finding the copies that escaped, changing a secret without an outage, and removing the stored secret altogether.

Secrets that software holds

A person proves who they are by typing a password or touching a key. Software has nobody to do that, so it carries its proof with it: an API key for the payroll provider, a client secret for Cedar's identity provider at login.cedar.example, a password for the finance database, a private key for signing. These are secrets, and anyone who copies one can act as the software that owns it, from anywhere, for as long as the secret lasts.

Service accounts were the fourth kind of privilege on Quinn's list in Privileged access management, the one its table left out. Cedar's engineers took stock of the secrets behind them one afternoon, starting with the nightly report job that reads the finance database, and found the same secrets in more places than they expected. The database password was in the configuration file of each service, in an environment variable on each server, in the deployment pipeline's settings, in a chat message from two years earlier when someone needed it in a hurry, and in an old commit of the repository, where it had been removed from the file but not from the history. Each copy was as powerful as the original. Nobody could say which systems would break if the password changed, so it never had.

Secrets management is the work of keeping that from happening: storing secrets in one place, handing them only to the software that needs them, making them short-lived where possible, finding copies that escaped, and changing them without an outage. Better than any of these is to stop needing a stored secret at all.

Keeping secrets in a vault

A secrets vault, or secret manager, is a service that stores secrets encrypted and gives each one out only to identities its policy allows. Cedar's payroll export may read the payroll provider key; the report job may read the finance database password; neither may read the other's. Every read is recorded with the identity that asked, so the question "who used this secret last week?" finally has an answer. Secrets are versioned, so a change can be rolled back, and the vault rather than a file is the one place to change them. It is the same idea as the credential vault Cedar uses for people's root passwords, applied to software.

The vault has a puzzle at its centre. To read the database password, the report job must authenticate to the vault, and if that needs another stored secret, the problem has moved rather than gone away. The answer is to authenticate the job by something its platform can vouch for: the cloud machine it runs on, the account the platform started it under, or a signed token from the deployment system. When software needs its own identity and the lessons after it explain how platforms vouch for workloads. With that in place, the only secret the job still holds is the one it fetched a moment ago, in memory.

Dynamic and short-lived secrets

A vault can do more than store a password someone typed in. With dynamic secrets, it creates a credential when it is asked for one. When the report job starts, it asks the vault for database access and receives a username and password that did not exist a second earlier, together with a lease:

json
{
  "lease_id": "database/creds/report-job/3f9c21",
  "lease_duration": 3600,
  "renewable": true,
  "data": {
    "username": "v-report-job-7Hq2Lm",
    "password": "demo-generated-password-not-real"
  }
}

All names, hosts and values in these examples are fictional.

The vault created that database user with exactly the rights the report job needs, and it will drop the user when the lease ends in an hour, unless the job renews it while it is still running. Every running copy of the job gets its own user, so the database's own logs say which copy ran which query, and a credential copied out of a crash report stops working by itself within the hour. Changing a credential is no longer a project, because every credential is replaced all the time.

Short-lived access tokens work the same way at a smaller scale. A service that authenticates once and receives a token valid for fifteen minutes holds something far less valuable than a static API key valid until someone remembers to change it.

Scanning for leaked secrets

Secrets escape anyway, most often into source code. Secret scanning looks for them where they land. A scanner recognizes secrets in two ways: by known shapes, such as a provider's key prefix or a private key's BEGIN PRIVATE KEY line, and by long strings of random-looking characters assigned to names like password or secret. Some scanners go on to test whether a found key is still valid, which separates a live leak from an old example.

Where the scanner runs decides what it can prevent. A check on the developer's machine before each commit stops a secret before it is shared. Push protection on the code host refuses a push that contains one. A scan of the whole history, including old commits and forks, finds the copies that already escaped, like Cedar's database password, which deleting the line from the current file had not removed.

Before each commit

Runs on
The developer's machine
The secret
Never committed
Who may have it
Only the developer

Stopped before it is shared

Push protection

Runs on
The code host
The secret
Push refused
Who may have it
Only the developer

Never reaches the shared repository

History scan

Runs on
Old commits and forks
The secret
Already escaped
Who may have it
Anyone with a copy

Treat it as stolen: replace it first

A found secret must be treated as stolen, because there is no way to know who else saw it.

The same leaked database password met by a scanner at three points. Only the first two keep it from being shared; a history scan finds a copy that must be treated as stolen.

A found secret must be treated as stolen, because there is no way to know who else saw it. The first step is to revoke or replace it, before investigating, and only then to remove it from the history and look for misuse. Rotating credentials and keys after exposure follows that response further.

Rotating without an outage

Rotation means replacing a secret with a new one. Done carelessly, it is an outage: the old password stops working before every service has the new one. The way to avoid that is an overlap, in which both secrets are valid for a while:

  1. Create the new secret alongside the old one, so both work.
  2. Put the new secret in the vault, and let each service pick it up.
  3. Watch until nothing uses the old secret any more.
  4. Revoke the old secret.

Rotating client credentials showed the same sequence for an OAuth client's secret and keys. Rotation that is automated and frequent becomes boring, and boring is the goal: a secret that is changed every month will be changed smoothly on the day it leaks, while one that has never been changed tends to be the one nobody dares touch.

Removing the stored secret

The strongest move is to stop needing the secret. Two changes take Cedar most of the way.

The first replaces shared secrets with key pairs. When the report job authenticates to Cedar's identity provider with a signed assertion, as Secrets and signed assertions described, the identity provider holds only the job's public key, so nothing it stores can be used to impersonate the job. The private key still has to be kept somewhere, ideally in hardware or a key service that signs without ever releasing the key.

The second removes the stored credential altogether. With workload identity federation, the platform a workload runs on issues it a short-lived signed token that says which workload it is, such as a deployment pipeline's token naming the repository, branch and job. The service it calls is configured to trust that platform's tokens under exact conditions, and exchanges each one for a short-lived credential of its own. Cedar's deployment pipeline used to hold a cloud access key in its settings; now each run proves which job it is with a token minted for that run, and there is no key to leak, scan for or rotate. Workload identity federation follows how the trust conditions are written and why they must be exact.

Cedar's service secrets, before and after
SecretBeforeAfter
Finance database passwordOne password in five places, never changedA dynamic user per running copy, leased for an hour
Report job's client secretShared secret in configurationA key pair; the identity provider holds only the public key
Cloud deployment keyA static key in the pipeline's settingsFederation: each run exchanges a token minted for that run
Payroll provider API keyIn configuration and an old commitRotated, kept in the vault, readable only by the payroll export

The payroll provider accepts nothing but an API key, so one static secret remains. It lives in the vault, only one identity may read it, its reads are recorded, and it is rotated on a schedule, which is the most care a secret the software cannot avoid can be given.

Check your understanding

Try these questions before moving on. If an answer isn't right, use the feedback and try again.

A history scan finds Cedar's finance database password in a commit from two years ago. What should happen first? 1 of 3

Choose one answer.

Cedar's deployment pipeline used to hold a static cloud key. With workload identity federation, what does each pipeline run present instead? 2 of 3

Choose one answer.

Cedar's report job gets database credentials from the vault as dynamic secrets, leased for an hour. A crash report leaks one copy's username and password. What limits the damage? 3 of 3

Choose one answer.

Try it in the Lab

We value your privacy

We use cookies and similar technologies to enhance your browsing experience, and analytics to understand our traffic. By clicking "Allow all", you consent to optional analytics. Cookie Policy

Learn identity