nginx - GKE Nginx 入口 - 设置主机导致 400 不需要 SSL 证书
问题描述
我在 GKE 1.16.13-gke.401 中使用 nginx 入口。
我的配置
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: api-ingress
namespace: development
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /$1
nginx.ingress.kubernetes.io/backend-protocol: "HTTPS"
kubernetes.io/ingress.class: "nginx"
# Enable client certificate authentication
nginx.ingress.kubernetes.io/auth-tls-verify-client: "on"
# Create the secret containing the trusted ca certificates
nginx.ingress.kubernetes.io/auth-tls-secret: "development/client-cert-api-ingress"
# Specify the verification depth in the client certificates chain
nginx.ingress.kubernetes.io/auth-tls-verify-depth: "1"
# Automatically redirect http to https
nginx.ingress.kubernetes.io/force-ssl-redirect: "true"
# Use regex in paths
nginx.ingress.kubernetes.io/use-regex: "true"
# For notifications we add the proxy headers
nginx.ingress.kubernetes.io/configuration-snippet: |
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
spec:
tls:
- hosts:
- example.com
secretName: api-tls-certificate
rules:
- host: example.com
http:
paths:
- path: /(.*)
backend:
serviceName: v2-api-frontend
servicePort: 443
Nginx 控制器配置:
kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingressnginx/controller-v0.40.2/deploy/static/provider/cloud/deploy.yaml
问题
指定时调用curl -k --cert my-cert.pem --key my-cert.key https://MY_IP/ --header "Host: example.com"
不起作用rules.host
。
如果我指定rules.host
服务器响应
400 Bad Request 未发送所需的 SSL 证书
如果我没有指定rules.host
curl 工作正常。
我怎样才能解决这个问题?
编辑1:
我签发的自签名客户端证书似乎导致了问题。
使用以下脚本创建:
#!/bin/bash
# USE: ./build-client-cert.sh <CERTNAME> <EXPR_DAYS>
# How to generate client certificate
# based on https://www.makethenmakeinstall.com/2014/05/ssl-client-authentication-step-by-step/
openssl genrsa -out client.key 4096
openssl req -new -key client.key -out client.req
openssl x509 -req -in client.req -CA rootCA.crt -CAkey rootCA.key -set_serial 101 -extensions client -days $2 -outform PEM -out client.cer
openssl pkcs12 -export -inkey client.key -in client.cer -out $1.p12
rm client.key client.cer client.req
使用 cloudflare 时,服务器会正确响应,只有在通过 curl 使用我的证书时才会发生这种情况。
编辑 2
使用以下脚本创建 CA:
#!/bin/bash
# https://gist.github.com/fntlnz/cf14feb5a46b2eda428e000157447309
openssl genrsa -des3 -out rootCA.key 4096
openssl req -x509 -new -nodes -key rootCA.key -sha256 -days 1024 -out rootCA.crt
解决方案
推荐阅读
- kubernetes - k8s 入口控制器中的 Traefik 前向身份验证
- javascript - 让用户在暗模式和亮模式之间进行选择(保存每个页面的设置,cookie?)
- django - Django,如何在views.py上获取模板标签渲染数据?
- server - 在加速器上找不到 - Apache Traffic Server
- c# - Winform - 双显示器 - 无边框窗口 - 仅最大化到主屏幕尺寸
- angular - 无法将我的 Angular2 前端与我的 Springboot JAX-RS 后端连接起来
- boost - 找不到以下静态 Boost 库:boost_thread
- python - 谁能向我解释以下python代码是什么?
- xml - cakephp http 如何发回响应
- python - 在linkedin API中获取授权代码错误