3

目标:当 nginx 入口具有活动的重写目标功能时,Keycloak 网关守卫部署。

Ingress 根据以下内容重写目标:

  • rewrite.bar.com/something/重写为rewrite.bar.com/
  • rewrite.bar.com/something/new重写为rewrite.bar.com/new

并添加以下标题:

X-Forwarded-Prefix: /something

Keycloak 网守配置:

#deployment.yaml:
...
- name: keycloak-gatekeeper
  image: quay.io/keycloak/keycloak-gatekeeper:9.0.2
  imagePullPolicy: IfNotPresent
  args:
    - --listen=0.0.0.0:3000
    - --discovery-url=https://auth.server.com/auth/realms/realm
    - --client-id={client_id}
    - --client-secret={client_secret}
    - --redirection-url=https://rewrite.bar.com/something/
    - --upstream-url=http://127.0.0.1:8080
    - --skip-upstream-tls-verify=false
    - --skip-openid-provider-tls-verify=false
    - --enable-default-deny=true

问题
关守将未经授权的请求重定向到,https://rewrite.bar.com/oauth/authorize?state=00191...但端点位于https://rewrite.bar.com/something/oauth/authorize。网守忽略 X-Forwarded-Prefix 标头。something/当通过添加到路径在浏览器中手动更正路径时,一切正常。正确重定向到身份验证服务器,回调也有效。

当通过在部署中设置基本 uri 来增加网守配置时:

    ...
    - --redirection-url=https://rewrite.bar.com/something/
    - --base-uri=/something
    ...

未经授权的请求被正确重定向到https://rewrite.bar.com/something/oauth/authorize由入口重写的https://rewrite.bar.com/oauth/authorize,这与网守中未受保护的授权端点 ( ) 不匹配something/oauth/authorize。它导致不断的重定向。

问题:有没有办法以添加/something到重定向请求但不期望它的方式配置网关(proxy-base-url)?

4

1 回答 1

1

您可以使用代理重定向注释来完成此操作:https ://kubernetes.github.io/ingress-nginx/user-guide/nginx-configuration/annotations/#proxy-redirect

它会将位置标题更改为您想要的。

nginx.ingress.kubernetes.io/proxy-redirect-from: /oauth
nginx.ingress.kubernetes.io/proxy-redirect-to: /something/oauth
于 2020-09-10T05:28:45.500 回答