简体   繁体   English

Kubernetes nginx 入口 controller 坏网关

[英]Kubernetes nginx ingress controller bad gateway

I'm facing a strange issue in my K8S cluster我在我的 K8S 集群中遇到了一个奇怪的问题

Basically I have 2 application:基本上我有2个应用程序:

  • identity manager (WSO2 IS based but the issue is not related to WSO2)身份管理器(基于 WSO2,但问题与 WSO2 无关)
  • external SAML2 IDP that will manage X509 authentication将管理 X509 身份验证的外部 SAML2 IDP

I configured WSO2 in order to use this external SAML2 IDP我配置了 WSO2 以便使用这个外部 SAML2 IDP

When I try to login by X509, WSO2 shows me the login page, i click on smartcard and a redirect is done to the external SAML IDP.当我尝试通过 X509 登录时,WSO2 显示登录页面,我单击智能卡并重定向到外部 SAML IDP。

In this case the nginx ingress gives to me 502 bad gateway.在这种情况下,nginx 入口给我 502 bad gateway。 If I copy the URL, close the browser and try again to access directly to the X509 IDP, all works pretty good.如果我复制 URL,关闭浏览器并再次尝试直接访问 X509 IDP,一切正常。

Note that I'm using another external SAML IDP and in this case the redirect is working pretty good请注意,我正在使用另一个外部 SAML IDP,在这种情况下,重定向工作得很好

The difference between the 2 external IDP is that I configured the ingress controller of X509 SAML IDP in pass-through because I need that X509 certificare is consumed by my Java application 2个外部IDP之间的区别在于我在直通中配置了X509 SAML IDP的入口controller,因为我需要我的Java应用程序使用X509证书

May, anybody, tell me why I'm having this strange behaviour?可以,任何人,告诉我为什么我有这种奇怪的行为?

Thank you谢谢

Angelo安杰洛

UPDATE Here you can find my nginx.conf https://raw.githubusercontent.com/angeloimm/nginx_configuration/main/nginx.conf更新在这里你可以找到我的nginx.conf https://raw.githubusercontent.com/angeloimm/nginx_configuration/main/nginx.conf

This is my ingress.yaml这是我的ingress.yaml

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: eid-tls-ingress
  annotations:
    kubernetes.io/ingress.class: "nginx"
    nginx.ingress.kubernetes.io/backend-protocol: "HTTPS"
    nginx.ingress.kubernetes.io/rewrite-target: /eid-tsl/
    nginx.ingress.kubernetes.io/ssl-passthrough: "true"
    nginx.ingress.kubernetes.io/ssl-redirect: "true"
spec:
  tls:
    - hosts:
        - login-cns-test.it
  rules:
  - host: login-cns-test.it
    http:
      paths:
      - path: /
        backend:
          serviceName: eid-tls-service
          servicePort: 443

UPDATE 2更新 2

This is my scenario:这是我的场景: 在此处输入图像描述

As you can see all http/s requests from internet are intercepted by my customer balancer ( Balancer cloud vmware nsx ) this balancer routes the requests to the worker nodes.正如您所见,来自 Internet 的所有 http/s 请求都被我的客户平衡器( Balancer cloud vmware nsx )拦截,此平衡器将请求路由到工作节点。

On worker nodes I have my eid-tls-service;在工作节点上,我有我的 eid-tls-service; it's a default type service (clusterIP type) so I need the ingress controller in order to handle request.这是一个默认类型的服务(clusterIP 类型),所以我需要入口 controller 来处理请求。

The only important thing (at least I think) is that I need a passthrough configuration.唯一重要的事情(至少我认为)是我需要一个直通配置。 So I confogured my K8S and my nginx controller by using passthrough.所以我通过使用直通配置了我的 K8S 和我的 nginx controller。 No configuration has been done on Balancer cloud vmware nsx Balancer cloud vmware nsx上没有做任何配置

In fact I need that the X509 certficate is not consumed by Ingress Controller but it must arrive directly to my application (to my service).事实上,我需要 Ingress Controller 不使用 X509 证书,但它必须直接到达我的应用程序(到我的服务)。

I have just 1 replica of my service.我的服务只有 1 个副本。

This is my service yaml config:这是我的服务 yaml 配置:

kind: Service
apiVersion: v1
metadata:
  name: eid-tls-service
spec:
  selector:
    app: eid-tls
  ports:
  - protocol: TCP
    name: https-port
    port: 443
    targetPort: 443

From kubectl this is my eid-tls-service describe:从 kubectl 这是我的 eid-tls-service 描述:

Name: eid-tls-service
Namespace: eid-tls-idp-ns
Labels: <none>
Annotations: Selector: app=eid-tls
Type: ClusterIP
IP: xx.ss.z.ttt
Port: https-port 443/TCP
TargetPort: 443/TCP
Endpoints: xx.yy.z.www:443
Session Affinity: None
Events: <none>

This is my ingress controller log error:这是我的入口 controller 日志错误:

2021/01/28 11:24:06 [error] 3210#3210: *78115978 SSL_do_handshake() failed (SSL: error:14094412:SSL routines:ssl3_read_bytes:sslv3 alert bad certificate:SSL alert number 42) while SSL handshaking to upstream, client: 127.0.0.1, server:

What I really can't understand is why if I copy the URL, close the browser (by cleaning all cookies and files) and I paste the copied URL all works good (certificate is consumed by my java application) What I really can't understand is why if I copy the URL, close the browser (by cleaning all cookies and files) and I paste the copied URL all works good (certificate is consumed by my java application)

I guess I found the reason for this behaviour.我想我找到了这种行为的原因。 Basically it's happening the following:基本上它正在发生以下情况:

  • a HTTP request is handled by my IAM by using SSL connection HTTP 请求由我的 IAM 使用 SSL 连接处理
  • a redirect is made from my IAM to my X509 IAM living inside the saml K8S cluster.从我的 IAM 重定向到位于 saml K8S 集群内的 X509 IAM。

My X509 IAM ingress controller is configured in pass-through.我的 X509 IAM 入口 controller 配置为直通。 On step 2 the SSL connection is terminated and handled by my pod, K8S ingress controller tries to use SSL connection during the redirect and so the flow is compromised.在第 2 步中,SSL 连接终止并由我的 pod 处理,K8S 入口 controller 尝试在重定向期间使用 SSL 连接,因此流量受到损害。

If I copy and paste the URL, I don't start a SSL connection on my IAM but I directly go to the X509 IAM so no redirect is done.如果我复制并粘贴 URL,我不会在我的 IAM 上启动 SSL 连接,但我直接将 go 重定向到 X509 IAM。

Basically I think I can't follow my approach so what I did is change the ingress.yaml definition in this way:基本上我认为我无法遵循我的方法,所以我所做的就是以这种方式更改ingress.yaml定义:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: eid-tls-ingress
  annotations:
    kubernetes.io/ingress.class: "nginx"
    nginx.ingress.kubernetes.io/backend-protocol: "HTTPS"
    nginx.ingress.kubernetes.io/rewrite-target: /
    nginx.ingress.kubernetes.io/configuration-snippet: "proxy_set_header X-SSL-CERT $ssl_client_escaped_cert;"
    nginx.ingress.kubernetes.io/server-snippet: "ssl_verify_client optional_no_ca;"
    nginx.ingress.kubernetes.io/ssl-redirect: "true"
spec:
  tls:
    - hosts:
        - login-cns-test.it
  rules:
  - host: login-cns-test.it
    http:
      paths:
      - path: /
        backend:
          serviceName: eid-tls-service
          servicePort: 443

I configured the ingress controller in way that the cetificate is passed to the backend application in a HTTP request header.我配置了入口 controller,使证书在 HTTP 请求 header 中传递到后端应用程序。 Now it seems to be all pretty working.现在似乎一切都很好。

Thank to all you谢谢大家

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

相关问题 用于Azure Kubernetes Service 502错误网关的Nginx入口控制器 - nginx-ingress controller for Azure Kubernetes Service 502 Bad Gateway Nginx 入口在 Kubernetes 上返回 502 Bad Gateway - Nginx Ingress returns 502 Bad Gateway on Kubernetes 使用带有 Ingress 控制器的 Kubernetes 的 502 错误网关 - 502 bad gateway using Kubernetes with Ingress controller 从 Kubernetes NGINX 入口 controller 暴露服务总是返回 502 Bad Gateway - Exposing service from Kubernetes NGINX Ingress controller always return 502 Bad Gateway Kubernetes Ingress-nginx出现502错误(错误的网关) - Kubernetes ingress-nginx gives 502 error (Bad Gateway) Kubernetes Nginx 入口返回 502 Bad Gateway 使用主机文件 - Kubernetes Nginx Ingress returning 502 Bad Gateway using hosts file webpack react ingress-nginx kubernetes 显示网关错误 - webpack react ingress-nginx kubernetes shows Bad Gateway Azure 应用网关如何连接 kubernetes 入口 controller (nginx) - Azure application gateway how to connect with kubernetes ingress controller (nginx) kubernetes 入口 502 错误网关 - kubernetes ingress 502 bad gateway 用于大文件上传的 Nginx Ingress 控制器 502 错误网关 - Nginx Ingress controller 502 bad gateway for large file uploads
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM