Beta

Create a tenant

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

Keeping context across services

Your photo book order passes through three of the printer's services, and each call now says which workload is calling. This lesson adds the other half: how each service learns whose request it is handling, why forwarding your token is the wrong answer, and how exchanging it for a narrower token at each hop keeps both you and the acting service visible.

Whose request is it?

When you order a photo book, you sign in at printer.example and the printer's web app sends your order to the order service with your access token. The order service asks the render service to build the book. The render service needs the copies of your photos that the printer imported earlier, so it asks the storage service for them. Service-to-service access met this question behind the photo API; inside the printer it comes up at every hop.

Each of those calls carries the caller's workload identity, so the storage service knows the render service is calling. It does not know whose photos the render service should be reading. Every hop involves two identities: the workload making the call, and the person the request is for. If storage relies only on the render service's identity, the rule can say "the render service may read customers' files" and no more. That rule may be limited to certain folders, but it cannot say which customer asked for this particular order, so a bug in the render service, or an attacker who controls one copy of it, can read everyone's photos.

If the storage service knows both identities, the rule can be "the render service may read a customer's files while it is working on that customer's order." The question is how to tell the storage service whose request this is in a way it can rely on. The quickest answer is a header:

GET /files/cust-1182/lisbon-trip/page-01.jpg HTTP/1.1
Host: storage.printer.example
X-User-Id: cust-1182

All domains, credentials, and tokens in these examples are fictional. Here cust-1182 is your customer ID at the printer. Nothing about that header comes from you: the storage service would be trusting the render service's word, and any caller, or any bug that builds the wrong header, could name any customer.

Forwarding the original token

The next idea is to pass your own access token along the chain, so the storage service can see it was issued to you. That is safer than an unsigned header, but it causes three problems.

The first is the audience. Your token was issued for the order service, with aud set to https://orders.printer.example. If the storage service accepts it anyway, it accepts tokens meant for other services, and a token leaked from any service in the chain works at the storage service too.

The second is breadth. Your token carries everything you allowed the printer's web app to do, such as placing orders and reading your account details, while the render service needs to read one album.

The third is spread. Every service that handles your token can present it anywhere it is accepted until it expires, so the more hops it travels, the more places it can leak from.

There is a related danger in the other direction. Suppose the render service fetched files using its own broad identity, based on an album name in the order. A customer could put someone else's album in their order, and the render service would fetch it with authority the customer never had. A program that holds authority of its own and is tricked into using it on someone else's behalf is called a confused deputy. Tying each request to the authority of the person it is for, rather than to the service's own, is what prevents it.

Exchanging for a narrower token

The printer's authorization server can issue a new token for each hop, with the token exchange from Following a token exchange. The order service authenticates with its workload certificate over mutual TLS and asks the authorization server to exchange your token for one meant for the render service:

POST /token HTTP/1.1
Host: auth.printer.example
Content-Type: application/x-www-form-urlencoded

grant_type=urn:ietf:params:oauth:grant-type:token-exchange
&subject_token=demo-your-access-token
&subject_token_type=urn:ietf:params:oauth:token-type:access_token
&audience=https://render.printer.example
&scope=books.render

The authorization server checks that your token is valid and that the order service may make this exchange. Its policy then says what your token may become: a token carrying orders.write may be translated into books.render for the render service, the narrower permission that rendering your order needs, and into nothing more. Then it issues the new token. Here are the two tokens side by side, decoded:

{
  "iss": "https://auth.printer.example",
  "sub": "cust-1182",
  "aud": "https://orders.printer.example",
  "client_id": "printer-web",
  "scope": "orders.write account.read",
  "exp": 1790001500
}
{
  "iss": "https://auth.printer.example",
  "sub": "cust-1182",
  "aud": "https://render.printer.example",
  "scope": "books.render",
  "act": { "sub": "spiffe://printer.example/prod/orders" },
  "exp": 1790000900
}

The subject is still you. The audience is now the render service, so the token is useless anywhere else. The scope covers only rendering, and the token expires sooner. A new claim, act, records that the order service is acting for you.

Two of those changes are separate decisions. An exchange can reduce the scopes and keep the same audience, and a token with fewer scopes is still a token for the order service, not one the render service should accept. Choosing the render service as the audience is a decision of its own. So is the translation from orders.write to books.render: the server allows it because its policy says rendering an order is part of what placing it authorized, not because the names look related.

The render service does the same when it needs your files. It exchanges the token it received for one whose audience is the storage service and whose scope is files.read. The storage service then checks three things: the token is meant for it, the files belong to the token's subject, and the actor is the render service. A forwarded token fails the first of those checks:

Each hop exchanges the token it received for a narrower one meant for the next service. The subject stays the same, the actor records who is calling, and a forwarded token is refused for its audience.

The same context helps when a reply goes missing. When the book is rendered, the render service exchanges its token again, this time for a storage token with scope files.write, and saves the finished file to the storage service as job rj-2207. Suppose storage saves it, but its answer is lost on the way back. The render service cannot tell whether the file exists, and uploading again under a fresh token could leave two copies of your book, or replace one that the next step has already read. So it treats the upload as unresolved and asks storage about the request it already made, by the same job identifier, for the same customer:

GET /uploads/rj-2207 HTTP/1.1
Host: storage.printer.example
Authorization: Bearer demo-storage-token

HTTP/1.1 200 OK
Content-Type: application/json

{"job": "rj-2207", "owner": "cust-1182", "status": "stored", "sha256": "demo-digest-of-the-book"}

The file is there, with the digest the render service computed before it sent it, so the render service carries on without a second upload. Storage checks the lookup exactly as it checks an upload: the token must be meant for storage, and its subject must own the job. Asking about a lost reply never becomes a way to read another customer's files.

Delegation and impersonation

The act claim is what makes this delegation: the token says the request is yours and that the order service is the one acting for you. Both identities stay visible, so the render service can require that only the order service starts renders for customers, and its records can show who did what.

The same exchange could instead produce a token that leaves out the actor and looks as though it had been issued to you directly. That is impersonation, and the receiving service cannot tell that another party was involved. Impersonation has uses, such as old services that cannot read an actor, but it gives up accountability, so where it matters who acted, prefer delegation. Delegation, impersonation, and actor tokens looked at when impersonation is justified and how to keep it narrow.

When the render service exchanges its token in turn, the storage service's token records both actors. The outer act names the render service, the current actor, and a nested act inside it names the order service, which acted before it:

"act": {
  "sub": "spiffe://printer.example/prod/render",
  "act": { "sub": "spiffe://printer.example/prod/orders" }
}

The storage service bases its decision on the token's subject and the current actor. The nested actors are a record of the path the request took, which is what an investigation reads when it needs to know how a request reached storage, not only who sent it last.

Context inside one trust domain

A round trip to the authorization server at every hop is fine for a chain of three services. Some systems handle a single request with dozens of internal calls, and exchanging tokens at each one adds cost and delay.

A common alternative is to create a signed record of the request's context once, where the request enters the system. The record says who the user is, what the request is for, and which service received it. It travels with every internal call, and every service verifies its signature before relying on it. No service along the way can change the record; it can only ask the issuer for a new one, and no internal service accepts a user's identity from an unsigned header.

Transaction Tokens (Txn-Tokens), defined in an OAuth working group draft that is not yet a standard, carry short-lived transaction context in a tctx claim inside one trust domain. A Transaction Token does not replace the caller's workload authentication, and it is not an OAuth access token. Calls that leave the trust domain, such as the batch job's requests to the print lab, still need access tokens issued for that outside audience.

Check your understanding

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

The order service exchanges your token, which has the scopes orders.write account.read and aud https://orders.printer.example. The new token has only orders.write and the same aud. Should the render service accept it? 1 of 3

Choose one answer.

The storage service receives a token with sub set to you and an act claim naming the render service. What does it learn that an impersonation token would hide? 2 of 3

Choose one answer.

The render service fetches album files with its own broad identity, using whatever album name the order contains. A customer orders a book naming someone else's album. What has gone wrong? 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