Spring + Keycloak: Gateway Docker контейнер возвращает 404
Важно: все запросы отлично работают на localhost. Эта проблема возникает только тогда, когда я использую docker-compose конфигурацию.
Мой application-docker.yml для Gateway:
security:
oauth2:
client:
provider:
keycloak:
token-uri: http://keycloak:8080/realms/taxi-realm/protocol/openid-connect/token
authorization-uri: http://keycloak:8080/realms/taxi-realm/protocol/openid-connect/auth
user-name-attribute: preferred_username
user-info-uri: http://keycloak:8080/realms/taxi-realm/protocol/openid-connect/userinfo
jwk-set-uri: http://keycloak:8080/realms/taxi-realm/protocol/openid-connect/certs
user-info-authentication-method: header
registration:
keycloak:
provider: keycloak
client-id: taxi-realm
client-secret: DqTwdhwq0yYPt0qClZBWhJq6PNnxulxE
authorization-grant-type: authorization_code
redirect-uri: "{baseUrl}/login/oauth2/code/keycloak"
scope: openid
resourceserver:
jwt:
jwk-set-uri: http://keycloak:8080/realms/taxi-realm/protocol/openid-connect/certs
Моя docker-compose конфигурация для keycloak и gateway
api-gateway:
image: api-gateway:latest
container_name: api-gateway
ports:
- "8080:8080"
expose:
- "8080"
environment:
- SPRING_PROFILES_ACTIVE=docker
- LOGGING_LEVEL_ORG_SPRINGFRAMEWORK_SECURITY=TRACE
- MANAGEMENT_ZIPKIN_TRACING_ENDPOINT=http://zipkin:9411/api/v2/spans
- SPRING_SECURITY_OAUTH2_CLIENT_PROVIDER_KEYCLOAK_ISSUER_URI=http://keycloak:8080/realms/taxi-realm
depends_on:
- discovery-server
- broker
- keycloak
restart: always
keycloak:
image: quay.io/keycloak/keycloak:18.0.2
container_name: keycloak
environment:
- KEYCLOAK_ADMIN=admin
- KEYCLOAK_ADMIN_PASSWORD=admin
volumes:
- ./keycloak/themes:/opt/keycloak/themes/custom/login
command:
- start-dev
ports:
- "8181:8080"
Моя Keycloak-Client конфигурация:
И логи изGateway:
2024-03-19 22:40:38 2024-03-19T19:40:38.469Z DEBUG 1 --- [API-GATEWAY] [parallel-3] [] o.s.s.w.s.u.m.OrServerWebExchangeMatcher : Trying to match using PathMatcherServerWebExchangeMatcher{pattern='/logout', method=POST}
2024-03-19 22:40:38 2024-03-19T19:40:38.470Z DEBUG 1 --- [API-GATEWAY] [parallel-3] [] athPatternParserServerWebExchangeMatcher : Request 'GET /api/v1/passengers' doesn't match 'POST /logout'
2024-03-19 22:40:38 2024-03-19T19:40:38.471Z DEBUG 1 --- [API-GATEWAY] [parallel-3] [] o.s.s.w.s.u.m.OrServerWebExchangeMatcher : No matches found
2024-03-19 22:40:38 2024-03-19T19:40:38.473Z DEBUG 1 --- [API-GATEWAY] [parallel-3] [] o.s.s.w.s.u.m.OrServerWebExchangeMatcher : Trying to match using PathMatcherServerWebExchangeMatcher{pattern='/actuator/**', method=GET}
2024-03-19 22:40:38 2024-03-19T19:40:38.474Z DEBUG 1 --- [API-GATEWAY] [ parallel-3] [] athPatternParserServerWebExchangeMatcher : Request 'GET /api/v1/passengers' doesn't match 'GET /actuator/**'
2024-03-19 22:40:38 2024-03-19T19:40:38.475Z DEBUG 1 --- [API-GATEWAY] [ parallel-3] [] o.s.s.w.s.u.m.OrServerWebExchangeMatcher : No matches found
2024-03-19 22:40:38 2024-03-19T19:40:38.476Z DEBUG 1 --- [API-GATEWAY] [ parallel-3] [] a.DelegatingReactiveAuthorizationManager : Checking authorization on '/api/v1/passengers' using org.springframework.security.authorization.AuthenticatedReactiveAuthorizationManager@4a7f5d63
2024-03-19 22:40:38 2024-03-19T19:40:38.478Z DEBUG 1 --- [API-GATEWAY] [ parallel-3] [] o.s.s.w.s.a.AuthorizationWebFilter : Authorization successful
Важно: Если я делаю запрос с неправильным токеном, возвращается 401 (=> авторизация работает)