简体   繁体   English

启用 nginx 入口 controller 后面的 tls 时,keycloak 停止工作

[英]keycloak stops working when enabling tls behind nginx ingress controller

I need advice on how to configure nginx ingress controller and keycloak on eks kubernetes with TLS.我需要有关如何在 eks kubernetes 上使用 TLS 配置 nginx 入口 controller 和 keycloak 的建议。

My first attempt was to get keycloak working without TLS.我的第一次尝试是让 keycloak 在没有 TLS 的情况下工作。 This works fine.这工作正常。 But when I add TLS to the ingress definition, keycloak gives a Invalid parameter: redirect_uri error.但是当我将 TLS 添加到入口定义时,keycloak 给出了一个无效参数:redirect_uri错误。

This is the working sample:这是工作样本:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: keycloak-tls-test
  namespace: keycloak-tls-test
spec:
  rules:
  - host: keycloak.test.myhops.com
    http:
      paths:
      - backend:
          serviceName: keycloak
          servicePort: 80

When I add the tls part, I get the aforementioned error.当我添加 tls 部分时,我得到了上述错误。 See yaml file below.请参阅下面的 yaml 文件。

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: keycloak-tls-test
  namespace: keycloak-tls-test
spec:
  tls:
  - hosts:
    - keycloak.test.myhops.com
    secretName: test-myhops-tls
  rules:
  - host: keycloak.test.myhops.com
    http:
      paths:
      - backend:
          serviceName: keycloak
          servicePort: 80

Any suggestions on how to solve this?关于如何解决这个问题的任何建议? One online suggestion was to add https://keycloak.test.myhops.com/ * to the Valid Redirect URL for the security-admin-console client in the master realm.一个在线建议是将https://keycloak.test.myhops.com/ * 添加到主 ZB94B7EF7F17D2394D6FBDF45 中的安全管理控制台客户端的有效重定向 URL 中。 This solved the invalid redirect_uri error, but then I only got blank pages.这解决了无效的 redirect_uri 错误,但后来我只有空白页。 I could not find hints in the keycloak logging.我在 keycloak 日志中找不到提示。

I figured out what caused the problem.我弄清楚是什么导致了这个问题。 It seems that when keycloak is used behind a reverse proxy that terminates the TLS, then keycloak needs proxy-address-forwarding to be set.似乎当在终止 TLS 的反向代理后面使用 keycloak 时,keycloak 需要设置代理地址转发。 For the docker container this means that the env var PROXY_ADDRESS_FORWARDING=true does the trick.对于 docker 容器,这意味着环境变量 PROXY_ADDRESS_FORWARDING=true 可以解决问题。 So Ingress was correct and the keycloak deployment needed an extra environment variable.所以 Ingress 是正确的,keycloak 部署需要一个额外的环境变量。

Please not that ingress-nginx already set the correct headers for this to work:请注意,ingress-nginx 已经为此设置了正确的标头:

  • X-Forwarded-For X-Forwarded-For
  • X-Forwarded-Proto X-Forwarded-Proto

Docker documentation [keycloak documentation 2 Docker 文档[keycloak 文档2

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM