当前位置: 首页 > 知识库问答 >
问题:

无法SSL通过入口Nginx控制器

归俊杰
2023-03-14

我有一个JavaSpring Boot Application,我已经将服务器配置为在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

我已经为我的域创建了一个证书*。kahootali.com从LetsEncrypt证书,并通过运行为keystore创建了一个p12文件

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

我想用Ingress Nginx控制器在Kubernetes上公开它,所以我创建了一个秘密

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

我已经部署了应用程序,可以看到部署文件,当我将本地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/

它运行良好,并且可以返回

* 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":"/"}

但当我为它创建一个入口并通过它的ssl时

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

它在浏览器和应用程序调试级别日志中给出了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

共有1个答案

盖雪峰
2023-03-14

我发表评论是为了提高知名度:

根据文档,默认情况下禁用SSL直通功能。为了启用它,您需要使用--启用ssl passthrough标志启动nginx入口控制器。确保你没有忘记这件事。

您还可以查看此故障排除步骤,以验证nginx入口控制器的配置。

如果有帮助,请告诉我。

 类似资料:
  • 我已经安装并配置了AWS ALB入口控制器(https://github.com/kubernetes-sigs/aws-alb-ingress-controller),它可以通过HTTP正常工作。但是,它不能通过HTTPS解析。 入口资源如下: 我还按照此处的说明添加了自签名SSL证书: https://kubernetes.github.io/ingress-nginx/user-guide/

  • 操作系统:RHEL7|k8s版本:1.12/13|kubes祈祷|裸机 我部署了一个标准的kubespray裸机集群,我正在尝试了解部署nginx ingress controller的最简单推荐方法是什么,它将允许我部署简单的服务。没有提供负载平衡器。我希望我的主公共IP作为我的服务的endpoint。 Github k8s ingress nginx建议将节点端口服务作为“强制”步骤,这似乎不

  • 我在RedHat EC2实例上安装了Minikube v1.3.1以进行一些测试。 由于nginx-ingress-控制器默认使用的端口已经在使用中,我正在尝试在部署中更改它们,但没有结果。有人能建议如何做吗? 如何知道端口已在使用? 当我使用命令kubectl-n kube system get deployment | grep nginx列出系统吊舱时,我得到: nginx入口控制器0/1

  • 我的目标是通过GCE入口过滤nginx提供服务的Kubernetes引擎上部署的angular应用程序的IP地址的访问。 但是在我的nginx上remote_addr不对。 $LB_IP是此处定义的IP:kubernetes。io/入口。全局静态ip名称:app angular 我在nginx上使用set_real_ip_from来设置X-Forwarded-For的ip 原始ip在X-Forwa

  • 我试图创建一个入口控制器,它指向我通过Nodeport公开的服务。 以下是入口控制器的yaml文件(摘自https://kubernetes.io/docs/tasks/access-application-cluster/ingress-minikube/):

  • 我正在AWS EKS上设置NGINX入口控制器。 我浏览了k8s入口资源,它非常有助于理解我们将LB端口映射到k8s服务端口,例如file Def。我安装了nginx控制器,直到必要的步骤。然后教程指示我创建一个入口资源。 我错过了什么?