在针对外部OIDC提供程序进行身份验证时,Keycloak-Gatekeeper不会填充角色或组

问题描述 投票:1回答:1

我正在尝试将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": "[email protected]", "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": "[email protected]", "email": "[email protected]", "roles": "", "groups": ""}
1.5548203052417035e+09  warn    keycloak-gatekeeper/middleware.go:307   access denied, invalid roles    {"access": "denied", "email": "[email protected]", "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": "[email protected]",
  "email_verified": true,
  "applicationId": "*****************",
  "roles": [
    "role-1",
    "role-3"
  ]
}

从这里,我可以看到用户处于正确的角色。

目前我对问题所在,或者如何更详细地调试keycloak-gatekeeper实例感到有点失落

oidc keycloak-gatekeeper fusionauth
1个回答
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))
                }
            }
        }
    }

它可以解释为什么我的令牌中的声明没有出现

© www.soinside.com 2019 - 2024. All rights reserved.