Workload identity federation
The printer's deployment pipeline still reaches the cloud with a stored access key. This lesson removes it: the cloud trusts the pipeline platform's signed statement about each job, exchanges it for a short-lived credential, and admits only the jobs its trust conditions name, which is where most of the care goes.
A pipeline with a stored key
Apart from the shipping company's key, one stored credential is left. The deployment pipeline no longer uses an engineer's 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.: it has its own cloud identity with permission to deploy and nothing else. But that identity still authenticates with a long-lived access key, stored in the pipeline platform's secret settings.
The printer's code lives on a hosted pipeline platform. The code sits in a repository, which keeps every file and its history. Changes are made on branches, named lines of work such as main or new-layout, and a pull request proposes merging one branch into another so someone can review it first. A workflow file in the repository tells the platform which jobs to run, and the platform runs those build and deployment jobs on its own machines.
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. from Attesting a workload works for software running inside the printer's cloud account, where the cloud platform can vouch for each machine. The pipeline's jobs run somewhere the cloud knows nothing about, so the team created an access key for the deploy identity and pasted it into the pipeline's settings.
That key has all the problems of a static secret, and a few of its own. It lasts for months. Any job in the repository can read it, not only the main-branch deployment. And anyone who can change a workflow file can make a job print the key or send it somewhere: that includes anyone who can push a branch and, in some configurations, contributors whose pull requests run in the repository's context.
Trusting another issuer
The pipeline platform knows exactly which job is running: which repository it belongs to, which branch or environment it deploys, and which workflow started it. An environment here is a named deployment target, such as production, that the platform can protect with rules like a required reviewer. Many pipeline platforms can put all of this into a signed token issued to each job. Decoded, a token from the printer's fictional pipeline platform looks like this:
{
"iss": "https://token.pipelines.example",
"aud": "https://sts.cloud.example",
"sub": "repo:printer/print-services:environment:production",
"repository": "printer/print-services",
"repository_id": "48213",
"ref": "refs/heads/main",
"environment": "production",
"workflow": "deploy.yml",
"iat": 1790000600,
"exp": 1790000900
}All domains, credentials, and tokens in these examples are fictional. The platform signs these tokens with keys it publishes at a key setA JSON document, published at a fixed HTTPS address, that lists an issuer's current public keys so others can verify its signatures. It never contains private keys. URLA web address, such as https://photos.example/api/albums/42?limit=10. It names how to connect (https), the domain, the path to a particular page or resource, and any extra parameters after the question mark. listed in its discovery documentA JSON document that an OpenID Provider publishes at a well-known address under its issuer, listing its endpoints, where to find its signing keys, and its supported features so clients can configure themselves from one value., the way an OpenID provider publishes its signing keys. The cloud platform can be configured to trust that issuerThe party that creates and signs a token, assertion, or certificate, named in a token's iss claim. A recipient must check that the issuer is exactly the one it expected and trusts.: it fetches the published keys and checks each job token's 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 them.
This is the federation idea from Trust across systems, applied to software. Instead of checking a secret the job holds, the cloud relies on a statement about which job is asking, made by a party it has chosen to trust. This arrangement is called workload identity federation.
Exchanging the token
When the deploy job starts, it asks the pipeline platform for a token whose audience is the cloud's token service. Then it exchanges that token for a short-lived cloud credential:
POST /token HTTP/1.1
Host: sts.cloud.example
Content-Type: application/x-www-form-urlencoded
grant_type=urn:ietf:params:oauth:grant-type:token-exchange
&subject_token=demo-pipeline-job-token
&subject_token_type=urn:ietf:params:oauth:token-type:jwt
&audience=https://cloud.example/roles/printer-deployThis is the OAuthA framework that lets a person give an application limited access to their resources at another service, using tokens instead of sharing their password. OAuth is about access; OpenID Connect adds sign-in. token exchangeAn OAuth grant, RFC 8693, in which a client trades a token it holds for a new one, usually for another audience, with narrower access, or acting for someone. It lets a service call the next service without passing the original token along. from Following a token exchange. Other cloud platforms offer an APIAn application programming interface: a defined way for software to interact with a service. A web API offers endpoints where other programs send HTTP requests. of their own, or accept the job token in place of a client secretA shared secret that a confidential client uses to prove itself to the authorization server, much like a password for an application. It belongs on a backend, never in code sent to browsers or phones., as a signed client assertion like the one in Secrets and signed assertions. The shape is the same in every case, and the same as in JWT and SAML assertion grants: a signed statement from a trusted issuer goes in, and a short-lived credential comes out.
Before answering, the cloud's token service checks the job token's signature with the pipeline platform's published keys. It confirms that the issuer is one it trusts, that the audience is the token service itself, and that the token has not expired. Then it checks the token's claims against the trust conditions for the deploy role, and only then issues a credential for that role, valid for an hour:
The deployment runs, and the credential expires soon after the job ends. No long-lived deployment key is stored in the pipeline any more. The short-lived credential is still sensitive while it lasts, so it stays out of job logs.
Writing the trust conditions
A valid signature proves only that the pipeline platform issued the token, and the platform issues tokens to every job of every customer it has. Without further conditions, any job anywhere on the platform could obtain the printer's deploy role. The trust conditions decide which jobs the printer actually means:
Trusted issuer: https://token.pipelines.example
Audience: https://sts.cloud.example
Subject equals: repo:printer/print-services:environment:production
Repository ID: 48213Each line closes a door. The subject names one repository and one environment, and the production environment on the pipeline platform requires a reviewer's approval before any job can use it. The audience check matters because the same pipeline platform issues tokens for many services: without it, a token a job requested for some other service could be replayed here.
The mistakes in trust conditions tend to look reasonable at a glance:
- Matching only the organization. A condition that the subject starts with
repo:printer/admits every repository the printer owns, including a test repository with no review rules. - Wildcards in the subject.
repo:printer/print-services:*admits every branch and every pull request. A contributor's pull request may run its workflow in the repository's context, so the deploy role becomes available to whoever can open one. - Values a contributor controls. Anyone who can push can choose a branch name, so a condition on
refs/heads/release-*admits anyone who creates a branch calledrelease-anything. Prefer claims tied to protections the platform enforces, such as an environment that requires approval. - Names instead of stable IDs. If
print-servicesis renamed or deleted, someone else may be able to create a repository with that name. The numericrepository_idstays with the original repository.
Each pipeline platform defines its own subject format and claims, and those formats can change. Write conditions against the platform's current documented subject and claims, including how it treats renamed and transferred repositories and protected environments. Then test the exact issuer, audience and repository ID against jobs that should be admitted and jobs that must be refused, as the cases below do; a subject that looks right is not enough.
Try it: test a trust condition
Simulation. These job tokens and conditions are made up. Each token's signature is assumed to be valid for the issuer it names. Checking an answer happens in your browser and sends nothing.
Federation between trust domains
The same idea works between any two systems that issue workload identities. The print lab could trust the printer's identity server directly. The batch job would then authenticate to the print lab with its own short-lived signed token, and the print lab would accept it only from the printer's issuer and only with the subject spiffe://printer.example/prod/print-batch. The client secret from Client credentials would no longer exist.
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 federation between trust domains. Two trust domains exchange trust bundles, the certificates and public keys each uses to sign its workloads' credentials, so each can verify the other's workloads. The bundles are fetched again regularly from a published endpoint, so either side can rotate its keys without breaking the other.
In every form, the rule is the same. Trust a specific issuer for specific names, and never everything an issuer signs, because a large issuer signs for a great many workloads that are not yours.
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
- Trust a pipeline's job tokens instead of a stored keyTrust a pipeline for one repository, branch and environment; exchange its job token, see another branch, a recreated repository, a preview job and a replay refused, then read only this case's inventory.