Beta

Create a tenant

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

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 token: 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.

Attestation 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 set URL listed in its discovery document, the way an OpenID provider publishes its signing keys. The cloud platform can be configured to trust that issuer: it fetches the published keys and checks each job token's signature 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-deploy

This is the OAuth token exchange from Following a token exchange. Other cloud platforms offer an API of their own, or accept the job token in place of a client secret, 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 pipeline platform vouches for the job, and the cloud exchanges that statement for a credential that lasts about as long as the deployment. A job the trust conditions do not name gets nothing, however valid its signature.

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:   48213

Each 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 called release-anything. Prefer claims tied to protections the platform enforces, such as an environment that requires approval.
  • Names instead of stable IDs. If print-services is renamed or deleted, someone else may be able to create a repository with that name. The numeric repository_id stays 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.

The approved production deployment of print-services asks for the deploy role. Will the cloud accept this token? 1 of 5
Conditions for the deploy role:
Trusted issuer:  https://token.pipelines.example
Audience:        https://sts.cloud.example
Subject equals:  repo:printer/print-services:environment:production
Repository ID:   48213

Job token claims:
iss:           https://token.pipelines.example
aud:           https://sts.cloud.example
sub:           repo:printer/print-services:environment:production
repository_id: 48213
ref:           refs/heads/main

Enable JavaScript to check an answer here, or open the explanation below.

Show the answer and why

Yes. Every condition matches. The issuer, audience, subject and repository ID all match. The branch is not one of the conditions: the condition relies on the production environment, which requires a reviewer's approval.

With the same conditions, a job on a feature branch of the same repository asks for the deploy role. Will the cloud accept this token? 2 of 5
Job token claims:
iss:           https://token.pipelines.example
aud:           https://sts.cloud.example
sub:           repo:printer/print-services:ref:refs/heads/new-layout
repository_id: 48213
ref:           refs/heads/new-layout

Enable JavaScript to check an answer here, or open the explanation below.

Show the answer and why

No. The subject names a branch, not the production environment. Anyone who can push can create a branch, so the condition asks for the protected environment instead. This job never passed that approval.

With the same conditions, a workflow runs for a pull request to print-services and asks for the deploy role. Will the cloud accept this token? 3 of 5
Job token claims:
iss:           https://token.pipelines.example
aud:           https://sts.cloud.example
sub:           repo:printer/print-services:pull_request
repository_id: 48213
ref:           refs/pull/212/merge

Enable JavaScript to check an answer here, or open the explanation below.

Show the answer and why

No. The subject names a pull request, not the environment. A pull request can run its workflow before anyone reviews the change. Only the protected production environment, which needs an approval, matches the condition.

Someone runs their own token issuer and signs a token with the same claims as the approved production job. Will the cloud accept it? 4 of 5
Job token claims:
iss:           https://ci.lookalike.example
aud:           https://sts.cloud.example
sub:           repo:printer/print-services:environment:production
repository_id: 48213
ref:           refs/heads/main

Enable JavaScript to check an answer here, or open the explanation below.

Show the answer and why

No. Its issuer is not the one the cloud trusts. The cloud checks the signature with the published keys of the issuer it trusts. Anyone can copy the claims, but only the trusted pipeline platform can sign tokens that verify against those keys.

With the same conditions: the print-services repository was renamed last month, and someone created a new repository with the old name. A job there asks for the deploy role. Will the cloud accept this token? 5 of 5
Job token claims:
iss:           https://token.pipelines.example
aud:           https://sts.cloud.example
sub:           repo:printer/print-services:environment:production
repository_id: 61002
ref:           refs/heads/main

Enable JavaScript to check an answer here, or open the explanation below.

Show the answer and why

No. Its repository ID does not match. A stable ID stays with the original repository after a rename. Checking it stops a newcomer who takes over the old name.

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.

SPIFFE 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.

A trust condition for the deploy role checks the issuer and that sub starts with repo:printer/. What is wrong with it? 1 of 3

Choose one answer.

The pipeline platform issues job tokens for many different services. Why must the cloud's token service check the aud claim? 2 of 3

Choose one answer.

The print-services repository is renamed, and someone else creates a new repository with the old name. Which trust condition stops that repository's jobs from getting the deploy role? 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