首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >不要在Kubernetes的入口级终止SSL

不要在Kubernetes的入口级终止SSL
EN

Stack Overflow用户
提问于 2021-03-24 00:52:15
回答 2查看 898关注 0票数 0

我有一个在tomcat服务器内部运行的Java应用程序(它在一个pod内),它被配置为使用https。我正在使用nginx入口。问题是,nginx入口正在终止SSL,并且只将纯http转发到tomcat服务器(实际上是转发到pod )。由于tomcat服务器被配置为仅使用HTTPS,因此它不接受流量。

以下内容不起作用:

代码语言:javascript
复制
nginx.ingress.kubernetes.io/ssl-passthrough: "true"
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2021-03-24 00:54:19

我终于找到了答案:

我必须添加以下两行:

代码语言:javascript
复制
nginx.ingress.kubernetes.io/backend-protocol: "HTTPS"
nginx.ingress.kubernetes.io/force-ssl-redirect: "true"

所以入口是这样的(我也添加了一些注释来描述和展示我尝试过的和不起作用的选项,这样你就不会浪费时间了):

代码语言:javascript
复制
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: ingress-resource-staging
  namespace: staging-space
  annotations:
    kubernetes.io/ingress.class: nginx #You may deploy any number of ingress controllers within a cluster. When you create an ingress, you should annotate each ingress with the appropriate ingress.class to indicate which ingress controller should be used if more than one exists within your cluster.
    #If you do not define a class, your cloud provider may use a default ingress controller.
    #nginx.ingress.kubernetes.io/ssl-passthrough: "true"
    ##Following 2 lines are important, otherwise the SSL is terminated at the ingress level and the
    ## traffic sent to the service is plain http and then tomcat complains that the host and port combination
    ## needs https connection (in the tomcat server we have enabled the HTTPS internally)
    ## We want to forward the HTTPS traffic to the pods
    nginx.ingress.kubernetes.io/backend-protocol: "HTTPS"
    nginx.ingress.kubernetes.io/force-ssl-redirect: "true"

spec:
  #tls:
  #  - hosts:
  #      - yourhost.com
  rules:
    - host: yourhost.com
      http:
        paths:
          - pathType: Prefix
            path: /
            backend:
              service:
                name: my-app-service
                port:
                  #number: 8080
                  number: 8443
票数 1
EN

Stack Overflow用户

发布于 2021-03-24 01:34:52

请参阅文档https://kubernetes.github.io/ingress-nginx/user-guide/nginx-configuration/annotations/#ssl-passthrough

默认情况下,SSL Passthrough处于禁用状态,需要使用--enable-ssl-passthrough标志启动控制器。

因此,如果要使用注释nginx.ingress.kubernetes.io/ssl-passthrough,则需要使用--enable-ssl-passthrough标志启动Nginx Ingress Controller

此外,由于SSL Passthrough在OSI模型(TCP)的第4层上工作,而不是在第7层(HTTP)上工作,因此使用SSL Passthrough会使Ingress对象上设置的所有其他注释无效。

编辑:

如果您使用入口注释nginx.ingress.kubernetes.io/ SSL -passthrough和--enable-ssl-passthrough=true标志作为入口控制器,那么SSL终止发生在您的Tomcat Server Pod上。因此,客户端浏览器收到的SSL服务器证书就是Tomcat SSL服务器证书。在这种情况下,您的客户端浏览器必须信任Tomcat SSL Server证书。此SSL通过发生在第4层TCP上,因此NGINX Ingress Controller不会解密来自客户端浏览器的SSL流量,而只是将其传递到Tomcat Server Pod。

如果只使用注释nginx.ingress.kubernetes.io/backend-protocol:"HTTPS",那么第一个SSL终止发生在入口控制器上。因此,您的客户端浏览器收到的SSL服务器证书就是您的Nginx Ingress Controller SSL服务器证书,您的客户端浏览器必须信任它。然后,从Nginx入口控制器到Tomcat Pod的通信使用另一种SSL加密。在这种情况下,您的Nginx Ingress Controller将必须信任Tomcat SSL Server证书,并且您具有双重SSL加密和解密。

如果您使用注释https "true“,那么您所有的nginx.ingress.kubernetes.io/force-ssl-redirect:请求都将使用308重定向http代码重定向到https。您是在呼叫http://还是https://?

以下是代码和文档链接

https://github.com/kubernetes/ingress-nginx/blob/master/rootfs/etc/nginx/lua/lua_ingress.lua

https://github.com/openresty/lua-nginx-module

http://nginx.org/en/docs/http/ngx_http_proxy_module.html

在ingress资源中进行更改时,检查/etc/ nginx /nginx.conf在nginx控制器pod中的更改情况

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66767660

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档