简体   繁体   English

Azure Kubernetes Nginx-Ingress客户端证书认证问题

[英]Azure Kubernetes Nginx-Ingress client certificate auth problem

I've been struggling with this all weekend, and I now on my knees hoping one of you geniuses can solve my problem.我整个周末都在为此苦苦挣扎,现在我跪下希望你们中的一个天才能够解决我的问题。

I short: I have an ingress-nginx controller (Image: nginx/nginx-ingress:1.5.8) with whom I'm trying to achieve a self-signed mutual authentication.我简短地说:我有一个 ingress-nginx controller(图片:nginx/nginx-ingress:1.5.8),我正在尝试与它实现自签名相互身份验证。

The https aspect works all fine, but the problem I'm having (I think) is that the ingress controller reroute the request with the default cert and the ingress validates with the default CA(because it can't find my CA). https 方面工作正常,但我遇到的问题(我认为)是入口 controller 使用默认证书重新路由请求,并且入口使用默认 CA 验证(因为它找不到我的 CA)。

So.. Help!所以..救命!

Steps I've gone through on this cluster-f*** of a journey (pun intended):我在这段旅程中经历的步骤(双关语):

I've tested it in a local Minikube-cluster and it all works like a charm.我已经在本地 Minikube 集群中对其进行了测试,这一切都像一个魅力。 When I exec -it into the ingress-controller-pod and cat the nginx.conf for both my clusters (Minikube and Azure) I did find large differences;当我 exec -it 进入 ingress-controller-pod 并为我的两个集群(Minikube 和 Azure)搜索 nginx.conf 时,我确实发现了很大的差异; hence I just found out that I'm working with apples and pears in terms of minikube- vs azure-k8s nginx-ingresses.因此,我刚刚发现我正在使用 minikube- 与 azure-k8s nginx-ingresses 方面的苹果和梨。

This is the ingress setup that worked as a charm for my minikube cluster (the ingress I'm using is more or less a duplicate of the file you'll find in the link): https://kubernetes.github.io/ingress-nginx/examples/auth/client-certs/这是我的 minikube 集群的魅力的入口设置(我使用的入口或多或少是您在链接中找到的文件的副本): https://kubernetes.github.io/ingress -nginx/examples/auth/client-certs/

In addition i found this which in a long way describes the problem that I'm having: https://success.docker.com/article/how-to-configure-a-default-tls-certificate-for-the-kubernetes-nginx-ingress-controller From the link above the solution is simple;此外,我发现这在很大程度上描述了我遇到的问题: https://success.docker.com/article/how-to-configure-a-default-tls-certificate-for-the-kubernetes -nginx-ingress-controller从上面的链接解决方案很简单; nuke the ingress from orbit and create a new one.核对轨道入口并创建一个新入口。 Well.. Here's the thing, this is a production cluster and my bosses would be all but pleased if I did that.嗯.. 事情是这样的,这是一个生产集群,如果我这样做,我的老板会非常高兴。

Another discovery that I made whilst "exec -it bash"-roaming around inside the Azure-ingress-controller is that there is no public root cert folder (/etc/ssl/) to be found.我在“exec -it bash”在 Azure-ingress-controller 内漫游时发现的另一个发现是找不到公共根证书文件夹 (/etc/ssl/)。 Do not know why, but though I'd mention it.不知道为什么,但我会提到它。

I've also discovered the param --default-ssl-certificate=default/foo-tls, but this is a default.我还发现了参数 --default-ssl-certificate=default/foo-tls,但这是默认值。 As there will be other needs for different client-auths later I have to be able to specify dynamic CA-certs for different ingresses.由于稍后对不同的客户端身份验证会有其他需求,我必须能够为不同的入口指定动态 CA 证书。

I'll past my nginx.conf that I think is the problem below.我将通过我认为是以下问题的 nginx.conf。 Hoping to hear back from some of you because at this point in time I'm thoroughly lost.希望收到你们中的一些人的回复,因为此时我完全迷路了。 Hit me up if additional information is needed.如果需要更多信息,请联系我。

user  nginx;
worker_processes  auto;
daemon off;

error_log  /var/log/nginx/error.log notice;
pid        /var/run/nginx.pid;

events {
    worker_connections  1024;
}

http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';


    access_log  /var/log/nginx/access.log  main;


    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout 65s;
    keepalive_requests 100;

    #gzip  on;

    server_names_hash_max_size 512;


    variables_hash_bucket_size 256;
    variables_hash_max_size 1024;

    map $http_upgrade $connection_upgrade {
        default upgrade;
        ''      close;
    }





    server {
        listen 80 default_server;
        listen 443 ssl default_server;

        ssl_certificate /etc/nginx/secrets/default;
        ssl_certificate_key /etc/nginx/secrets/default;

        server_name _;
        server_tokens "on";
        access_log off;



        location / {
           return 404;
        }
    }
    # stub_status
    server {
        listen 8080;

        allow 127.0.0.1;
        deny all;
        location /stub_status {
            stub_status;
        }
    }
    server {
        listen unix:/var/run/nginx-status.sock;
        access_log off;

        location /stub_status {
            stub_status;
        }
    }

    include /etc/nginx/config-version.conf;
    include /etc/nginx/conf.d/*.conf;

    server {
        listen unix:/var/run/nginx-502-server.sock;
        access_log off;

        location / {
            return 502;
        }
    }
}

stream {
    log_format  stream-main  '$remote_addr [$time_local] '
                      '$protocol $status $bytes_sent $bytes_received '
                      '$session_time';

    access_log  /var/log/nginx/stream-access.log  stream-main;

So the problem came down to the ingress-controller being old and outdated.所以问题归结为入口控制器过时和过时。 Didn't have the original helm-chart that is was deployed with so I was naturally worried about rollback options.没有部署的原始 helm-chart,所以我自然担心回滚选项。 Anyhoo -> took a leap of faith in the middle of the night local time and nuked the namespace; Anyhoo -> 在当地时间的半夜大吃一惊,对命名空间进行了核爆; recreated the namespace;重新创建了命名空间; helm install stable/nginx-ingress.掌舵安装稳定/nginx-ingress。

There was a minimum downtime -> 1 min at most, but beware to lock down the public IP that's attached to the load balancer before going all 3.rd world war on your services.最短停机时间 - > 最多 1 分钟,但请注意在您的服务进行所有第三次世界大战之前锁定连接到负载均衡器的公共 IP。

Had to add an argument to the standard azure helm install command to imperatively set the public IP for the resource;必须向标准 azure helm install 命令添加一个参数,以强制设置资源的公共 IP; pasting it below if any poor soul should find himself in the unfortunate situation with a new helm-cli and lost charts.如果任何可怜的灵魂发现自己处于不幸的境地,新的 helm-cli 和丢失的图表,请将其粘贴在下面。

That's it;而已; keep your services up to date and make sure to save your charts!让您的服务保持最新,并确保保存您的图表!

helm install nginx stable/nginx-ingress --namespace ingress-basic \
                                           --set controller.replicaCount=2 \
                                           --set controller.nodeSelector."beta\.kubernetes\.io/os"=linux \
                                           --set defaultBackend.nodeSelector."beta\.kubernetes\.io/os"=linux \
                                           --set controller.service.loadBalancerIP=*YourVeryPreciousPublicIP*

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

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