Video in progress

Strong Junior 🧩 Microservices

If the API Gateway validates the JWT, can internal services accept requests with no checks at all?

That's risky. If it's possible to bypass the gateway and send requests straight from the internal network, forging any header is easy. Internal services should also validate the token (or at least the identity that comes with mTLS) and do authorization themselves.

📖 Answer

A common setup: the gateway validates the JWT and passes an X-User-Id: 42 header inward. The internal service blindly trusts that header.

The problems:

  • anyone who gets into the internal network (another compromised service, a misconfigured ingress, a developer who did a port-forward) can write X-User-Id: 1 and become an admin;
  • paths that bypass the gateway (an internal cron job, a call from another service) are left completely unchecked;
  • authorization ("can this user see this specific order?") is still the service's job; the gateway doesn't know that business rule.

A practical approach:

  • the gateway is a coarse filter: is there a token, has it expired, rate limiting;
  • the service validates the token itself (a Spring Security resource server; checking the signature with a public key is cheap) and checks permissions at the resource level;
  • for service-to-service calls, a separate identity: a client credentials token or mTLS.
spring.security.oauth2.resourceserver.jwt.issuer-uri=https://auth.example.uz/realms/shop

This is the "zero trust" idea: being inside the network is no reason to trust.