我试图在docker容器前面将keycloak-gatekeeper设置为反向代理,以便针对该容器提供身份验证和授权。我使用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实例不知所措
答案 0 :(得分:1)
keycloak-gatekeeper似乎只能处理keycloak(https://github.com/keycloak/keycloak-gatekeeper/blob/master/user_context.go)提供的令牌中的领域和客户端角色
以下是有问题的代码,可从令牌中提取角色:
// @step: extract the realm roles
var roleList []string
if realmRoles, found := claims[claimRealmAccess].(map[string]interface{}); found {
if roles, found := realmRoles[claimResourceRoles]; found {
for _, r := range roles.([]interface{}) {
roleList = append(roleList, fmt.Sprintf("%s", r))
}
}
}
// @step: extract the client roles from the access token
if accesses, found := claims[claimResourceAccess].(map[string]interface{}); found {
for name, list := range accesses {
scopes := list.(map[string]interface{})
if roles, found := scopes[claimResourceRoles]; found {
for _, r := range roles.([]interface{}) {
roleList = append(roleList, fmt.Sprintf("%s:%s", name, r))
}
}
}
}
这将解释为什么我的令牌中的要求没有出现