I am using nginx ingress in GKE 1.16.13-gke.401.
My Configuration
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 controller config:
kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingressnginx/controller-v0.40.2/deploy/static/provider/cloud/deploy.yaml
The Problem
Calling curl -k --cert my-cert.pem --key my-cert.key https://MY_IP/ --header "Host: example.com" doesn't work when rules.host is specified.
If I am specifing rules.host server responding with
400 Bad Request No required SSL certificate was sent
If I am not specifying rules.host the curl works fine.
How can I fix this?
Edit 1:
It seems like the client certificate I issued which is self-signed caused the problem.
Created using the following script:
#!/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
When using cloudflare the server responds correctly, Only when using my certificate through curl this happens.
Edit 2
Created the CA using the following script:
#!/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