securing our multiple micro-services. The major concern is that the JWT token provided to us will expire before the call is finished.
Consider using an API Gateway to validate the lifetime of the JWT for external requests, and internal microservices (receiving requests from API Gateway & other internal microservices, i.e. internal requests) should not perform the validation (for clarity, other forms of validation remain e.g. signature, iss
, aud
etc). Validating lifetime of internal requests is not required because:
- There's no benefit.
- There seems to be no guides online explaining how to rightly do so in a non-trivial manner, thus indicating that this could be a non-question.
- In some of the guides talking about using JWT for internal microservices, there's no mention about doing so, for example:
- OWASP Cheat Sheet Series on Microservices Security.
- Netflix has a slightly complex solution, whereby the API Gateway converts the incoming JWT to a
Passport
which contains user context (e.g. user ID, user roles/groups). There's no mention of Passport
having an expiration time, so there's no lifetime to be validated (which isn't a security concern because Passport
is only used for internal communications and never exposed to the external world. Passport
is not persisted by any of the internal microservices, so it is effectively "scoped to the life of the request [chain]").
The 2nd point of your suggestions
If JWT expires, use refresh token to get new one and place on response headers via token provider.
does not work because Token Refresh also requires supplying the Client Id (and Client Secret) of the Client that obtained the JWT, which internal microservices should not have.