Kong 背后的 Keycloak 和奇怪的重定向
Keycloak behind Kong and strange redirect
设置:
- minikube 版本:v0.27.0
- Kong (helm install stable/kong) / 版本 1.0.2
- Keycloak (helm install stable/keycloak) / 版本 4.8.3.Final
我的 "hello.local".
有一个自签名的 SSL 证书
我需要实现的目标:Kong 后面的 Keycloak 在“https://hello.local/”。
我的步数:
1) 新鲜的 minikube
2) 使用 helm 安装 Keycloak,遵循 values.yaml:
keycloak:
basepath: ""
replicas: 1
...
extraEnv: |
- name: PROXY_ADDRESS_FORWARDING
value: "true"
(这将创建服务 auth-keycloak-http
)
3) 使用 helm 安装 Kong,遵循 values.yaml:
replicaCount: 1
admin:
ingress:
enabled: true
hosts: ['hello.local']
proxy:
type: LoadBalancer
ingress:
enabled: true
hosts: ['hello.local']
tls:
- hosts:
- hello.local
secretName: tls-certificate
annotations:
kubernetes.io/ingress.class: "nginx"
nginx.ingress.kubernetes.io/rewrite-target: /
nginx.ingress.kubernetes.io/ssl-passthrough: "true"
tls:
enabled: true
postgresql:
...
4) 我为 Kong
设置服务和路由
服务:
Protocol: http
Host: auth-keycloak-http
Port: 80
路线:
Hosts: hello.local
之后我可以在我的浏览器中打开“https://hello.local" and can see welcome page from Keycloak where I can click Administration Console and after that I have redirect to "https://hello.local:8443/admin/master/console/”。所以此时我们不应该使用另一个端口进行重定向。
如果 PROXY_ADDRESS_FORWARDING
是 true
,则使用 2 docker 个图像(Keycloak + Kong)的设置正在运行。
如何在没有重定向的情况下使 Keycloak(helm chart)在 kubernetes 集群中按预期在 Kong(helm chart)后面工作?
这正在 github issue 1, github issue 2 and github issue 3. Also, Similar questions
中讨论
原回答:
看来,有必要在 keycloak helm chart 的 values.yaml 中设置以下环境变量:
...
extraEnv: |
- name: KEYCLOAK_HTTP_PORT
value: "80"
- name: KEYCLOAK_HTTPS_PORT
value: "443"
- name: KEYCLOAK_HOSTNAME
value: example.com
...
所有这些都是必需的,之后,重定向将正常工作。
2021 年 9 月添加:
问题 weird behavior with redirect to port 8443 执行某些操作(例如使用管理控制台右上角的 link 转到帐户管理)。
实际上我们不需要设置任何KEYCLOAK_HTTP_PORT
或KEYCLOAK_HTTPS_PORT
。
需要在代理端进行一些更改。在代理上,我们需要将此路由的 x-forwarded-port
设置为 443
。
在我的例子中,我们使用 Kong:
在暴露Keycloak的路线上,我们需要添加(这个对我有用):
serverless
> post function
内容如下:
ngx.var.upstream_x_forwarded_port=443
设置:
- minikube 版本:v0.27.0
- Kong (helm install stable/kong) / 版本 1.0.2
- Keycloak (helm install stable/keycloak) / 版本 4.8.3.Final
我的 "hello.local".
有一个自签名的 SSL 证书我需要实现的目标:Kong 后面的 Keycloak 在“https://hello.local/”。
我的步数:
1) 新鲜的 minikube
2) 使用 helm 安装 Keycloak,遵循 values.yaml:
keycloak:
basepath: ""
replicas: 1
...
extraEnv: |
- name: PROXY_ADDRESS_FORWARDING
value: "true"
(这将创建服务 auth-keycloak-http
)
3) 使用 helm 安装 Kong,遵循 values.yaml:
replicaCount: 1
admin:
ingress:
enabled: true
hosts: ['hello.local']
proxy:
type: LoadBalancer
ingress:
enabled: true
hosts: ['hello.local']
tls:
- hosts:
- hello.local
secretName: tls-certificate
annotations:
kubernetes.io/ingress.class: "nginx"
nginx.ingress.kubernetes.io/rewrite-target: /
nginx.ingress.kubernetes.io/ssl-passthrough: "true"
tls:
enabled: true
postgresql:
...
4) 我为 Kong
设置服务和路由服务:
Protocol: http
Host: auth-keycloak-http
Port: 80
路线:
Hosts: hello.local
之后我可以在我的浏览器中打开“https://hello.local" and can see welcome page from Keycloak where I can click Administration Console and after that I have redirect to "https://hello.local:8443/admin/master/console/”。所以此时我们不应该使用另一个端口进行重定向。
如果 PROXY_ADDRESS_FORWARDING
是 true
,则使用 2 docker 个图像(Keycloak + Kong)的设置正在运行。
如何在没有重定向的情况下使 Keycloak(helm chart)在 kubernetes 集群中按预期在 Kong(helm chart)后面工作?
这正在 github issue 1, github issue 2 and github issue 3. Also, Similar questions
原回答:
看来,有必要在 keycloak helm chart 的 values.yaml 中设置以下环境变量:
...
extraEnv: |
- name: KEYCLOAK_HTTP_PORT
value: "80"
- name: KEYCLOAK_HTTPS_PORT
value: "443"
- name: KEYCLOAK_HOSTNAME
value: example.com
...
所有这些都是必需的,之后,重定向将正常工作。
2021 年 9 月添加:
问题 weird behavior with redirect to port 8443 执行某些操作(例如使用管理控制台右上角的 link 转到帐户管理)。
实际上我们不需要设置任何KEYCLOAK_HTTP_PORT
或KEYCLOAK_HTTPS_PORT
。
需要在代理端进行一些更改。在代理上,我们需要将此路由的 x-forwarded-port
设置为 443
。
在我的例子中,我们使用 Kong:
在暴露Keycloak的路线上,我们需要添加(这个对我有用):
serverless
> post function
内容如下:
ngx.var.upstream_x_forwarded_port=443