Passing user information between Kubernetes/Spring Boot services

3/13/2020

Situation is as follows:
I have a RestController in service 1.
As part of a function (a standard method) in service 1, information is needed from service 2 which is also a RestController but in a completely separate Kubernetes process.
I call service 2 using a RestTemplate, a standard HTTP GET.
The fetching of information in service 2 should be logged for auditing reasons.
This is where my headache starts.
I need to get hold of the logged in user name in service 1 and currently, as a low budget solution, I pull the user name in service 1 and pass it as a request parameter.
Service 2 is also new and implemented by me and intended to be a general purpose component in the future for other services as well.
I would therefore prefer to have the user information pulled out of whatever Sprint Boot has internally to enforce this, to avoid that other developers pass in some rubbish text.

The entire setup is secured using OAuth2, jwt and @PreAuthorize.

What options would I have besides my current low-budget setup?

-- Anders Persson
kubernetes
spring-boot
spring-security

0 Answers