ssl - ssl-passthrough 是在主机级别配置的,kubernetes ingress

标签 ssl kubernetes kubernetes-ingress

我在kubernetes中有2个服务,一个是mtls,另一个是tls。
我正在尝试为他们配置入口。
我想为 mtls 服务配置 ssl passthrough,但不使用 ssl-passthrough 离开 tls 服务,它不需要客户端证书。
我用两个不同的 yaml 文件在同一个主机名上配置了 2 个入口。
一个有直通,另一个没有直通。
当前的行为是,如果我首先创建 mtls 入口,则 tls 将不起作用,我发送给 tls 的 https 请求将始终路由到 mtls 服务。然后返回 404。
但是,如果我先配置 tls ingress,然后再配置 mtls。然后 tls 将工作,但 mtls 将因证书问题而失败。
我不确定是否在主机级别配置了 ssl passthrough 注释?或者我可以让它在每个路径级别上工作吗?
mtls 入口。

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  annotations:
    ingress.kubernetes.io/ssl-passthrough: "true"
    nginx.ingress.kubernetes.io/ssl-passthrough: "true"
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/backend-protocol: HTTPS
    nginx.ingress.kubernetes.io/ssl-redirect: "false"
  name: mtls-ingress
spec:
  rules:
  - host: app.abc.com
    http:
      paths:
      - backend:
          service:
            name: mtls-service
            port:
              number: 8081
        path: /mtls-api
        pathType: Prefix
  tls:
  - hosts:
    - app.abc.com
    secretName: tls-nginx-mtls
然后 tls 入口:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/backend-protocol: HTTPS
    nginx.ingress.kubernetes.io/ssl-redirect: "false"
  name: tls-ingress
spec:
  rules:
  - host: app.abc.com
    http:
      paths:
      - backend:
          service:
            name: tls-service
            port:
              number: 8080
        path: /tls-api
        pathType: Prefix
  tls:
  - hosts:
    - app.abc.com
    secretName: tls-nginx-tls
这就像两个入口相互覆盖,只有第一个注释有效。看起来为主机配置了直通,但没有为入口或路径配置。
不知道。请帮忙。谢谢。

最佳答案

您想在同一主机上使用带有注释 nginx.ingress.kubernetes.io/ssl-passthrough: "true" 的 2 个服务为其中之一。
这将不起作用,因为使用 SSL Passthrough 代理不知道路由流量的路径。
来自 the NGINX Ingress Controller User Guide :

The annotation nginx.ingress.kubernetes.io/ssl-passthrough instructs the controller to send TLS connections directly to the backend instead of letting NGINX decrypt the communication.

Because SSL Passthrough works on layer 4 of the OSI model (TCP) and not on the layer 7 (HTTP), using SSL Passthrough invalidates all the other annotations set on an Ingress object.


解决方案是为您的服务使用子域,而不是路径。
此外,来自 GitHub 的一些关于此问题的链接:
Multiple Ingress backends ignored when SSL Passthrough is enabled
Ignoring SSL Passthrough for location "/*" in server "example.com"
Path based routing only works with base path
来自 serverfault关于 SSL Passthrough 的 NginX 工作流程。

关于ssl - ssl-passthrough 是在主机级别配置的,kubernetes ingress,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70785851/

相关文章:

java - 如何使用在命令行上启动的 Spring Boot 自动重定向到 https

android - 如何在 Android 上使用 .p12 证书?

ssl - Weblogic 应用程序在通过 https 安全登录后切换回 http

kubernetes - 尽管服务帐户具有权限 "Error from server (Forbidden): ...",但无法获取 Pod

kubernetes - 在 Kubernetes 中,使用复制 Controller 时如何设置 Pod 的名称?

kubernetes - 应用程序网关入口 Controller 仅适用于根路径/

Python 生成错误 : failed to build modules _ssl and _hashlib

docker - kubernetes 是否支持日志保留?

deployment - Kubernetes Ingress 白名单源范围 允许所有 IP

kubernetes - 在 Kubernetes Ingress 中从 v1beta1 切换到 v1 时,在 io.k8s.api.networking.v1.IngressBackend"中出现错误 "unknown field "serviceName"