无法访问 Kubernetes 中的 Keycloak 帐户控制台 (403)

发布于 2025-01-11 11:52:26 字数 990 浏览 0 评论 0原文

当部署在 Kubernetes 中时,我发现 Keycloak 有一个奇怪的行为,我无法理解。

使用案例:

  • 以 admin:admin 身份登录(默认创建)
  • ,单击管理帐户

(管理帐户对话框屏幕截图< /a>)

我比较了(相同)映像 (quay.io/keycloak/keycloak:17.0.0) 在 Docker 或 Kubernetes (K3S) 中运行时的行为。

如果我从 Docker 运行它,则会加载帐户控制台。换句话说,我的请求

GET /realms/master/protocol/openid-connect/login-status-iframe.html/init?client_id=account- 获得成功 (204)控制台

从部署在 Kubernetes 中的同一映像中,相同的请求失败并出现错误 403。但是,在同一个应用程序上,我的请求

GET /realms/master/protocol/openid-connect/login-status-iframe.html/init?client_id 获得成功 (204) =security-admin-console

由于我可以调用 security-admin-console,因此这看起来不像 Kubernetes Ingress 网关的问题,也不像与路由相关的任何问题。

然后我考虑了 Keycloak 访问控制配置问题,但在这两种情况下我都使用默认图像而不进行任何更改。我反复检查以确保管理员用户和帐户控制台客户端在 docker 和 k8s 应用程序中的配置方式完全相同。

我不知道可能是什么问题,你有什么建议吗?

I have found a strange behavior in Keycloak when deployed in Kubernetes, that I can't wrap my head around.

Use-case:

  • login as admin:admin (created by default)
  • click on Manage account

(manage account dialog screenshot)

I have compared how the (same) image (quay.io/keycloak/keycloak:17.0.0) behaves if it runs on Docker or in Kubernetes (K3S).

If I run it from Docker, the account console loads. In other terms, I get a success (204) for the request

GET /realms/master/protocol/openid-connect/login-status-iframe.html/init?client_id=account-console

From the same image deployed in Kubernetes, the same request fails with error 403. However, on this same application, I get a success (204) for the request

GET /realms/master/protocol/openid-connect/login-status-iframe.html/init?client_id=security-admin-console

Since I can call security-admin-console, this does not look like an issue with the Kubernetes Ingress gateway nor with anything related to routing.

I've then thought about a Keycloak access-control configuration issue, but in both cases I use the default image without any change. I cross-checked to be sure, it appears that the admin user and the account-console client are configured exactly in the same way in both the docker and k8s applications.

I have no more idea about what could be the problem, do you have any suggestion?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

拒绝两难 2025-01-18 11:52:26

尝试将 Keycloak 数据库中 realm 表中的 ssl_required = NONE 设置为您的领域(主)

Try to set ssl_required = NONE in realm table in Keycloak database to your realm (master)

疯狂的代价 2025-01-18 11:52:26

我可以使用以下环境变量解决问题,我的 Keycloak 版本是 23.0.4:

        - name: KC_HOSTNAME
          value: subdomain.domain.com
        - name: KC_HOSTNAME_ADMIN_URL
          value: https://subdomain.domain-name.com/
        - name: KC_HTTP_ENABLED
          value: 'false'
        - name: KC_HOSTNAME_STRICT
          value: 'true'
        - name: KC_HOSTNAME_STRICT_HTTPS
          value: 'true'
        - name: KC_PROXY
          value: edge

I am able to resolve the issue with the following environment variables my Keycloak version is 23.0.4:

        - name: KC_HOSTNAME
          value: subdomain.domain.com
        - name: KC_HOSTNAME_ADMIN_URL
          value: https://subdomain.domain-name.com/
        - name: KC_HTTP_ENABLED
          value: 'false'
        - name: KC_HOSTNAME_STRICT
          value: 'true'
        - name: KC_HOSTNAME_STRICT_HTTPS
          value: 'true'
        - name: KC_PROXY
          value: edge
深居我梦 2025-01-18 11:52:26

所以我们发现是 nginx 入口控制器导致了很多问题。虽然我们能够通过 X-Forwarded-Proto 等使其与 nginx 一起工作,但它有点复杂和令人费解。改用 haproxy 反而解决了这个问题。另外,请确保您通过 https 与入口控制器进行交互,否则可能会导致 keycloak 出现问题。

  annotations:
        kubernetes.io/ingress.class: haproxy
  ...

So we found that it was the nginx ingress controller causing a lot of issues. While we were able to get it working with nginx, via X-Forwarded-Proto etc., but it was a bit complicated and convoluted. Moving to haproxy instead resolved this problem. As well, make sure you are interfacing with the ingress controller over https or that may cause issues with keycloak.

  annotations:
        kubernetes.io/ingress.class: haproxy
  ...
一袭水袖舞倾城 2025-01-18 11:52:26

我遇到了类似的问题,并使用 Nginx 作为 HTTPS 代理。
管理 Web 控制台因 403 加载而卡住:
/realms/master/protocol/openid-connect/login-status-iframe.html/init

我通过添加这些用于 KeyCloak 位置配置的 Nginx 行来修复它。

    proxy_set_header X-Forwarded-Host   $host;
    proxy_set_header X-Forwarded-Server $host;
    proxy_set_header X-Forwarded-Port   $server_port;
    proxy_set_header X-Forwarded-Proto  $scheme;

I had similar issue and was using Nginx as proxy for HTTPS.
The admin web console got stuck with 403 loading:
/realms/master/protocol/openid-connect/login-status-iframe.html/init

I fixed it by adding these Nginx lines for KeyCloak location configuration.

    proxy_set_header X-Forwarded-Host   $host;
    proxy_set_header X-Forwarded-Server $host;
    proxy_set_header X-Forwarded-Port   $server_port;
    proxy_set_header X-Forwarded-Proto  $scheme;
故事和酒 2025-01-18 11:52:26

我遇到了同样的问题,并通过将正确的来源添加到 keycloak UI 中的帐户控制台客户端来解决它。
客户->帐户控制台 ->网络起源

I had the same issue, and solved it by adding the correct origin to the account-console client in the keycloak UI.
Clients -> account-console -> Web origins

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文