I am deploying Keycloak and a Spring Boot application in two different docker containers, and Keycloak is securing the application.
The problem is that the user logs in via the browser, and so they see the Keycloak server on an address like localhost:8080
, while the Spring Boot application is running on a docker container next to it and so sees the service on a host like keycloak_service
.
The Spring Boot application receives a token from the user that Keycloak gave him and sees that it's signed by localhost:8080
but it was expecting it to be signed by keycloak_service
. It then gives the error 15:29:12.062 [http-nio-29000-exec-8] ERROR o.k.a.r.AdapterRSATokenVerifier - Didn't find publicKey for kid: b4A5E3xbvc-ulr-w_u38p7aHRZIi9O36Na7I8r_L76M
So far I have been using a temporary fix of having the application use the host networking stack so that it can see keycloak at localhost:8080
. I will eventually need to change this though as I need other features of the docker bridge networks.
There are various other hacky solutions to the problem I could use, but I can't help but feel this shouldn't be a difficult problem. I can't be the only one running a spring boot app alongside a Keycloak instance in containers. I would have thought the natural solution would be to tell Spring Boot that it can talk to keycloak on keycloak_service
but that the same Keycloak instance is also known as localhost:8080
to some clients and it should accept tokens signed by that as well. Is this possible to do? If not, is there any other normal solution to this problem?