Credentials for workloads
The printer's old shared secret has turned up in places nobody meant to put it. This lesson compares the credentials a workload can hold, shows why a short lifetime limits what a leaked copy is worth without anyone noticing the leak, and follows how a credential that changes every hour reaches the running software.
Where the key ended up
A week after the overnight burst of print jobs, the printer's code scanner raises two alerts. The shared print lab secret appears in an old layer of the render service's container image, and again in a debug log that printed the service's configuration when it started. Removing the line from today's image does not help, because a container image keeps every layer it was built from. Every earlier version still contains the secret, and anyone who ever downloaded one of them has a copy. The team rotates the secret, then asks which credentials a workload should hold at all, and how they should reach running software.
Static secrets spread because using them means copying them. An environment variable is visible to anything that can inspect the process, and it often appears in crash reports. A configuration file gets committed to a repository. A startup log prints the settings it loaded. A pipeline log echoes the variables a job used. A developer copies the file to a laptop to run the service locally.
Every copy is as powerful as the original, and lasts as long. Secret scanning finds some of those copies, and finding them is worthwhile, but the more durable fix is a credential that is not worth much once someone has copied it.
Kinds of workload credentials
Workload credentials fall into three broad families, which build on the comparison in Secrets and key pairs.
Bearer secrets are API keys, client secrets and long-lived static tokens. Presenting the value is the proof, so the workload sends it with its requests, and anyone who sees it can use it.
Key pairs let the workload prove possession of a private keyThe half of a key pair that its owner keeps to themselves and uses to create signatures or decrypt data. Anyone who obtains it can act as its owner. by signing something, such as a client assertion or a TLSTransport Layer Security, the protection behind HTTPS. It encrypts traffic between two connected systems, detects changes on the way, and uses certificates so the client can confirm which server it reached. handshake, without sending the key itself, as Secrets and signed assertions showed for a tokenA piece of data issued by a trusted service that a client presents as a credential, for example to call an API or to report a sign-in. Some tokens carry readable claims; others are random strings that only the issuer can interpret. request. A captured request does not reveal the key. A captured client assertion that has not been used yet could still be presented once during its short validity, and replay tracking refuses only the later uses, so it cannot tell whether the first presenter was the real workload. The key file itself can still be copied if it is stored carelessly, the risk Storing and using keys addressed.
Issued short-lived credentials come from the workload's identity system after attestationA signed statement about a device or running process from a party the verifier already trusts, rather than from the thing itself. In WebAuthn, an authenticator's maker vouches for its model when a passkey is registered; for workloads, a cloud platform or orchestrator vouches for a running process before it receives a credential. and are renewed automatically. Two forms are common. The first is a certificateA signed statement that a public key belongs to a name, such as a website's hostname, for stated purposes and a limited period. A certificate authority signs it, so software that trusts the authority can connect the key to the name. whose subject alternative name holds the workload's identity, used for mutual TLS, where each side of a connection presents a certificate. SPIFFEAn open standard for workload identity. It names each workload with a URI under a trust domain, such as spiffe://printer.example/prod/render, and defines short-lived identity documents as X.509 certificates or JWTs. calls this an X.509-SVID, for SPIFFE Verifiable Identity Document. Its private key is generated on the workload's own machine and never leaves it. The certificate itself is public, so holding a copy proves nothing: the workload proves it is the holder by signing a fresh random value with that private key, its holder key, and anyone can check the signatureA value made with a private key that lets anyone holding the matching public key check that a message came from the key's holder and has not been changed. It proves origin and integrity; it does not hide the message. against the public keyThe half of a key pair that can be shared freely. It checks signatures made with the matching private key and can encrypt data that only that private key can decrypt. the certificate names. The second is a signed JWTA JSON Web Token: a compact token made of Base64url-encoded parts that carries claims and is usually signed. Anyone holding it can decode and read the claims, so the signature shows who issued it but hides nothing. carrying the same identity, which SPIFFE calls a JWT-SVID, for presenting to an API. Decoded, the render service's token for the storage service looks like this:
{
"sub": "spiffe://printer.example/prod/render",
"aud": ["https://storage.printer.example"],
"iat": 1790000600,
"exp": 1790000900
}All domains, credentials, and tokens in these examples are fictional. The token is signed with a key that belongs to the printer.example trust domain. Its subject is the workload's identity, it is meant only for the storage service, and it expires five minutes after it was issued. It is still a bearer tokenA token that works for whoever presents it: the API checks that the token is genuine and current, not who is holding it. That is why bearer tokens must be kept from being copied.: anyone holding a copy could present it to the storage service until it expires, which is why the audience and the lifetime are kept so tight.
The table compares the four credentials a workload is most likely to hold. Read the last column as the question the code scanner's alerts raised: if a copy of this credential leaks today, what does it give whoever finds it?
| Credential | Typical lifetime | What travels with a request | What a leaked copy gives an attacker |
|---|---|---|---|
| API key or client secret | Months or years, until someone rotates it | The secret itself | Full use until someone notices and replaces it |
| Private key for signed assertions | Months or years | A short-lived signed assertion | An unused captured assertion can authenticate once before it expires; a used one should be refused. A copied key can make fresh assertions until its registration is removed |
| Short-lived certificate | Minutes to hours, renewed automatically | The certificate and a signature in the TLS handshake | A copied private key works only until the certificate expires |
| Short-lived signed token | Minutes, renewed automatically | The token | Use at the token's one audience until it expires |
Short-lived by default
A lifetime is a control that works without anyone noticing a problem. If the render service's certificate lasts one hour, a snapshot of that certificate and its key stops authenticating within the hour. The old shared secret would have kept working for years.
That limit holds for a copy taken once. It assumes whoever took the copy cannot also renew it or obtain the next credential, so renewal must use fresh key material that stays protected. Someone who keeps control of the running workload, or of the local API that hands it credentials, can collect each new credential as it arrives, and that is a different incident to contain.
Short lifetimes also change what rotation means. Replacing a static key is a project: find every place it is used, update them in the right order, and hope nothing was missed. A credential issued automatically is replaced dozens of times a day, so renewal is exercised constantly and a broken renewal shows up at once rather than on the day a key must be replaced in a hurry.
Renewal should start well before expiry, often around halfway through the lifetime. If the identity server is briefly unavailable, workloads keep using credentials that are still valid, and the outage does not spread to every service. Verifiers should also allow a little clock difference between machines when they check issue and expiry times.
RevocationCancelling a credential, token, certificate, or authenticator before it would expire, so that it is no longer accepted. Whether every copy stops working at once depends on how services check it. matters less as well. Rather than maintaining lists of revoked certificates, the printer can usually wait for a credential to expire. In an emergency it removes the registration entry, so no new credential is issued, and the last one runs out shortly afterwards.
Delivering credentials to a running workload
A credential that changes every hour has to reach the workload without anyone copying it by hand. There are a few common routes.
A local workload API, like the node agent in Attesting a workload, gives the workload its credential on request and pushes a replacement before each one expires. The orchestrator can also mount the credential as a file and replace it in place, provided the workload reads the file again when it changes.
Cloud platforms offer a metadata endpoint at a special address that only the machine itself can reach. A workload asks it for short-lived credentials for the role assigned to its machine, and the platform answers. This is convenient, and it has one well-known weakness: an endpoint that is not protected well enough answers any request made from that machine, including one a vulnerable workload was tricked into making. If a web service on the machine has a server-side request forgery bug, which lets an attacker make the service fetch a URL of the attacker's choosing, the attacker can make it fetch the machine's credentials and then use the service's identity from anywhere.
Platforms defend against this by requiring a session token first, obtained with a kind of request a simple forgery cannot make, and by limiting how many network hops the credential response may travel, which makes it harder to relay. These controls narrow the risk without removing it, because their effect depends on which requests the vulnerable service can be made to construct. Each platform documents its own metadata settings and their defaults differ, so check what the platform actually enforces. Applications should also refuse to fetch internal addresses, and the link-local range the metadata endpoint usually sits in, on a user's behalf.
Secret managers fit into this picture once the first-secret problem is solved. The render service authenticates to the secret manager with its workload identity, and some secret managers then issue dynamic secrets, such as a database password created for one service on request and deleted when its lease ends.
When a static secret remains
Not every service can accept a short-lived credential. The shipping company the printer uses for international orders accepts only an API key. That key will exist for months, so the printer limits what it can do and who can reach it.
The key lives in the secret manager, not in configuration or an image, and only the batch job's identity may read it. The batch job loads it into memory when it needs it and never writes it to a log. The team rotates it on a schedule and immediately whenever it might have been exposed, following Rotating client credentials. Its use is monitored, so a request from anywhere other than the batch job is noticed. And the team keeps asking the shipping company for a better option, because every one of those controls depends on someone noticing, which a lifetime never does.
Check your understanding
Try these questions before moving on. If an answer isn't right, use the feedback and try again.
Try it in the Lab
- Deliver, renew and expire a workload's short-lived credentialDeliver a short-lived certificate and signed assertion to a hosted workload, see a replay refused and the credential renewed by itself, then watch a leaked copy expire without revocation.