Video in progress
How should internal services authenticate each other: mTLS, OAuth2 client credentials, or passing the user's token along?
Each one answers a different question: mTLS says "which service is connecting" (transport), client credentials says "the service's own permissions", and token propagation or token exchange says "on whose behalf". They are usually used together.
📖 Answer
The "the internal network is trusted, no authentication needed" approach ends with the first compromised pod. The zero trust principle: every call identifies itself.
mTLS. Every service has a certificate, and during the connection both sides verify each other. In Kubernetes a service mesh (Istio, Linkerd) usually does this without touching application code and rotates the certificates automatically. Encryption and service identity come for free, but mTLS knows nothing about the user and it is hard to express fine-grained permissions.
OAuth2 client credentials. The service gets a token from the IdP in its own name (scope=inventory.read). It is right for background jobs, batch, and the service's own work. In Spring:
@Bean
RestClient inventoryClient(RestClient.Builder b, OAuth2AuthorizedClientManager m) {
var interceptor = new OAuth2ClientHttpRequestInterceptor(m);
interceptor.setClientRegistrationIdResolver(req -> "inventory");
return b.baseUrl("http://inventory").requestInterceptor(interceptor).build();
}
(OAuth2ClientHttpRequestInterceptor exists in Spring Security 6.4+.) The token is cached and refreshed before it expires.
Passing the user's token along. Service A forwards the user's token to B, so B also knows "who is asking". It's simple, but the token's audience has to be broad, and if A is compromised it can reach everything on the user's behalf. Better is token exchange (RFC 8693): A presents its own token and the user's, and gets back a new, narrowly scoped token for B only.
My usual scheme:
- Transport: mTLS everywhere through the mesh.
- User request chain: the token is passed along, every service checks
audandscope; token exchange in sensitive spots. - Background jobs: client credentials.
- The authorization decision is made in each service; the gateway is only the first filter.
The most important organizational part: the list of service permissions (who calls whom and why) should be visible in code or configuration and go through review.
Sign up to mark studied questions and save your progress.