简体   繁体   English

无法 SSL 通过入口 Nginx Controller

[英]Unable to SSL Pass through Ingress Nginx Controller

I have a Java Spring Boot Application and I have configured the server to run on SSL and it is mandatory.我有一个 Java Spring 引导应用程序,我已将服务器配置为在 SSL 上运行,这是强制性的。

server:
  port: 8443
  ssl:
    enabled: true
    key-store-type: pkcs12
    key-store: ${KEYSTORE}
    key-password: ${KEYSTORE_PASSWORD}
    key-store-password: ${KEYSTORE_PASSWORD}
    client-auth: need

I have created a cert for my domain *.kahootali.com from LetsEncrypt certificate and created a p12 file for the keystore by running我从 LetsEncrypt 证书为我的域*.kahootali.com创建了一个证书,并通过运行为密钥库创建了一个 p12 文件

openssl pkcs12 -export -CAfile ca.crt -in cert.pem -inkey key.pem -certfile cert.pem -out kstore.p12

I want to expose it on Kubernetes using Ingress Nginx Controller, so I have created secret by我想使用 Ingress Nginx Controller 在 Kubernetes 上公开它,所以我创建了秘密

kubectl create secret generic store --from-file=kstore.p12

I have deployed application, can see the deployment files, and when I port-forward local 8443 to its service's 8443 and run我已经部署了应用程序,可以看到部署文件,当我将本地 8443 端口转发到其服务的 8443 并运行时

curl -iv --cacert ca.crt --cert mediator_cert.pem --key mediator_key.pem --resolve 'spring-app.kahootali.com:8443:127.0.0.1' https://spring-app.kahootali.com:8443/

It works fine and returns它工作正常并返回

* Added spring-app.kahootali.com:8444:127.0.0.1 to DNS cache
* Hostname spring-app.kahootali.com was found in DNS cache
*   Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to spring-app.kahootali.com (127.0.0.1) port 8444 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
* successfully set certificate verify locations:
*   CAfile: ca.crt
  CApath: /etc/ssl/certs
* TLSv1.3 (OUT), TLS handshake, Client hello (1):
* TLSv1.3 (IN), TLS handshake, Server hello (2):
* TLSv1.2 (IN), TLS handshake, Certificate (11):
* TLSv1.2 (IN), TLS handshake, Server key exchange (12):
* TLSv1.2 (IN), TLS handshake, Request CERT (13):
* TLSv1.2 (IN), TLS handshake, Server finished (14):
* TLSv1.2 (OUT), TLS handshake, Certificate (11):
* TLSv1.2 (OUT), TLS handshake, Client key exchange (16):
* TLSv1.2 (OUT), TLS handshake, CERT verify (15):
* TLSv1.2 (OUT), TLS change cipher, Client hello (1):
* TLSv1.2 (OUT), TLS handshake, Finished (20):
* TLSv1.2 (IN), TLS handshake, Finished (20):
* SSL connection using TLSv1.2 / ECDHE-RSA-AES256-GCM-SHA384
* ALPN, server did not agree to a protocol
* Server certificate:
*  subject: CN=*.kahootali.com
*  start date: Feb 11 10:27:47 2021 GMT
*  expire date: May 12 10:27:47 2021 GMT
*  subjectAltName: host "spring-app.kahootali.com" matched cert's "*.kahootali.com"
*  issuer: C=US; O=Let's Encrypt; CN=R3
*  SSL certificate verify ok.
> GET / HTTP/1.1
> Host: spring-app.kahootali.com:8444
> User-Agent: curl/7.58.0
> Accept: */*
> 
< HTTP/1.1 404 
HTTP/1.1 404 
< X-Application-Context: application:8443
X-Application-Context: application:8443
< Content-Type: application/json;charset=UTF-8
Content-Type: application/json;charset=UTF-8
< Transfer-Encoding: chunked
Transfer-Encoding: chunked
< Date: Sun, 14 Feb 2021 14:29:47 GMT
Date: Sun, 14 Feb 2021 14:29:47 GMT

< 
* Connection #0 to host spring-app.kahootali.com left intact
{"timestamp":1613312987350,"status":404,"error":"Not Found","message":"No message available","path":"/"}

But when I create an Ingress for it and ssl-passthrough it但是当我为它创建一个 Ingress 并 ssl-passthrough 它时

apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: spring-monitoring-app
  labels:
    app: spring-monitoring-app
  annotations:
    ingress.kubernetes.io/force-ssl-redirect: "true"
    ingress.kubernetes.io/rewrite-target: /
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/ssl-passthrough: "true"
spec:
  rules:
    - host: spring-app.kahootali.com
      http:
        paths:
          - path: /
            backend:
              serviceName: spring-monitoring-app
              servicePort: http
  tls:
    - hosts:
      - spring-app.kahootali.com
      secretName: tls-cert

It gives ERR_BAD_SSL_CLIENT_AUTH_CERT on browser and in app Debug level logs, it gives它在浏览器和应用程序调试级别日志中提供ERR_BAD_SSL_CLIENT_AUTH_CERT ,它提供

Error during SSL handshake
java.io.IOException: EOF during handshake.
The SNI host name extracted for this connection was [spring-app.kahootali.com]
Handshake failed during wrap
javax.net.ssl.SSLHandshakeException: Empty server certificate chain

I'm posting my comment as an answer for better visibility:我发布我的评论作为更好的可见性的答案:

As per the docs SSL Passthrough feature is disabled by default.根据文档SSL 默认情况下禁用直通功能。 In order to enable it you need to start your nginx-ingress controller with --enable-ssl-passthrough flag.为了启用它,您需要使用--enable-ssl-passthrough标志启动您的nginx-ingress controller Make sure you didn't forget about it.确保你没有忘记它。

You may also take a look at this troubleshooting steps to verify your nginx-ingress controller configuration.您还可以查看此故障排除步骤以验证您的nginx-ingress controller配置。

Please let me know if it helps.如果有帮助,请告诉我。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM