Video in progress

How do you design authentication and authorization between services: passing the user's JWT, token exchange, or mTLS?

I separate two questions: "which service is calling" (workload identity, mTLS or client credentials) and "on whose behalf" (the user context). Instead of spreading the external JWT inward unchanged, it's better to issue a short-lived token with a limited audience at the gateway or through token exchange.

📖 Answer

The most common setup: the gateway verifies the user's JWT and passes that very same token to all the internal services. It works, but it has problems:

  • the token is valid for every service: if it's stolen from one weak service, it grants access everywhere;
  • aud (audience) becomes meaningless;
  • the service never verifies its caller's identity, so anything in the internal network can call it.

I split it into layers.

Workload identity. Every service has its own identity. Options: mTLS (the mesh gives it automatically, a SPIFFE ID), or OAuth2 client credentials (the service gets its own token from the auth server). A policy like "only order-service can call payment-service's /charge" is built on this identity.

User context. Two ways:

  • The gateway verifies the external token and builds a short-lived internal token (or a signed header) with only the claims needed.
  • OAuth2 Token Exchange (RFC 8693): the service hands the incoming token to the auth server and gets back a new token with a limited audience for the next service. The cleanest, but it adds load and latency on the auth server.

Where authorization happens. Coarse checks ("this endpoint needs ADMIN") at the gateway or at the service entrance. Fine-grained checks ("does this order belong to this user") only in the service that owns the data, because only it knows the data. Trying to check everything at the gateway means pulling business logic into the gateway.

In asynchronous flows (Kafka) the token usually doesn't travel, because it will have expired. The actorId and needed context go into the event, and the consumer trusts the event, because write access to the topic is itself controlled.

The practical meaning of zero trust: being "inside the network" gives no rights. Every call proves who it is and why it's calling.