我正在尝试将 keycloak-gatekeeper 设置为 docker 容器前的反向代理,以便为容器提供身份验证和授权。我正在使用 FusionAuth 作为 OIDC 兼容的身份提供者,并且已经设法让 keycloak-getekeeper 使用它,使用授权流程。当我尝试根据他们的角色或组成员身份限制哪些用户可以访问资源时,问题就出现了。
目前,所有请求都被拒绝。当我查看服务器上的日志时,我可以看到以下消息:
1.5548202388823931e+09 info keycloak-gatekeeper/middleware.go:90 client request {"latency": 0.039427852, "status": 403, "bytes": 0, "client_ip": "127.0.0.1:40866", "method": "GET", "path": "/"}
1.5548202614442139e+09 error keycloak-gatekeeper/middleware.go:108 no session found in request, redirecting for authorization {"error": "authentication session not found"}
1.5548202614443152e+09 info keycloak-gatekeeper/middleware.go:90 client request {"latency": 0.000108426, "status": 307, "bytes": 95, "client_ip": "127.0.0.1:40866", "method": "GET", "path": "/"}
1.5548202614823494e+09 debug keycloak-gatekeeper/handlers.go:88 incoming authorization request from client address {"access_type": "", "auth_url": "https://identity.***********.io/oauth2/authorize?client_id=********&redirect_uri=https%3A%2F%2F********.io%2Foauth%2Fcallback&response_type=code&scope=openid+email+profile&state=********", "client_ip": "127.0.0.1:40866"}
1.554820261482426e+09 info keycloak-gatekeeper/middleware.go:90 client request {"latency": 0.000132558, "status": 307, "bytes": 298, "client_ip": "127.0.0.1:40866", "method": "GET", "path": "/oauth/authorize"}
1.5548203051960323e+09 info keycloak-gatekeeper/handlers.go:167 issuing access token for user {"email": "someuser@domain.com", "expires": "2019-04-09T15:31:45Z", "duration": "59m59.803970144s"}
1.5548203051961453e+09 info keycloak-gatekeeper/middleware.go:90 client request {"latency": 0.099124835, "status": 307, "bytes": 37, "client_ip": "127.0.0.1:40866", "method": "GET", "path": "/oauth/callback"}
1.5548203052413428e+09 debug keycloak-gatekeeper/session.go:51 found the user identity {"id": "5f165d68-9350-47e6-9152-d76260cabd7c", "name": "someuser@domain.com", "email": "someuser@domain.com", "roles": "", "groups": ""}
1.5548203052417035e+09 warn keycloak-gatekeeper/middleware.go:307 access denied, invalid roles {"access": "denied", "email": "someuser@domain.com", "resource": "/*", "roles": "role-1,role-3"}
1.5548203052417736e+09 info keycloak-gatekeeper/middleware.go:90 client request {"latency": 0.000509757, "status": 403, "bytes": 0, "client_ip": "127.0.0.1:40866", "method": "GET", "path": "/"}
据我所知,我拒绝的原因是没有填充角色。我还运行了一个客户端来为用户获取一个 JWT(通过隐式流),它看起来像这样:
{
"aud": "************************",
"exp": 1554822076,
"iat": 1554818476,
"iss": "https://identity.*******.io",
"sub": "****************",
"authenticationType": "PASSWORD",
"email": "someuser@domain.com",
"email_verified": true,
"applicationId": "*****************",
"roles": [
"role-1",
"role-3"
]
}
由此,我可以看到用户处于正确的角色中。
目前,我对问题出在哪里,或者如何更详细地调试 keycloak-gatekeeper 实例有点不知所措