본문 바로가기
클라우드/Azure

[ApplicationGateway] 종단 간 TLS 통신 구성

by worldcenter 2025. 1. 23.

 

Internet ——> Azure Firewall —HTTPS—> ApplicationGateway —HTTPS—> AKS POD로 접속 시 Azure Application Gateway Ingress Controller(이하 AGIC)에서 HTTS로 받아 백엔드에 HTTPS로 데이터를 던지는 구성을 테스트 합니다.

 

테스트 환경

  • Azure Application Gateway Standard_v2
  • Azure Kubernetes 1.27.3(kubenet)
  • AKS Pod(Nginx Reverse Proxy)

 

테스트 

1. Let’s Encrypt에서 와일드카드 도메인 인증서를 발급받은 후 .pem 확장자를 .pfx로 변환합니다.

openssl pkcs12 -export -out certificate.pfx -inkey privkey.pem -in cert.pem -certfile chain.pem

 

2. PFX에서 key와 certificate를 추출하는 명령어는 다음 링크를 참고해주세요

1) 인증서 추출

openssl pkcs12 -in <filename.pfx> -clcerts -nokeys -out <clientcert.crt> --password pass:<password>

 

2) 키 추출

openssl pkcs12 -in <filename.pfx> -nocerts -nodes -out <clientcert.key> --password pass:<password>

 

3. 해당 인증서에서 Client Key와 Client Certificate를 Kubernetes Secret으로 등록합니다.

kubectl create secret tls <guestbook-secret-name> --key <path-to-key> --cert <path-to-cert>

 

4. Secret 등록이 완료되면 Ingress를 생성합니다.

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: <IngressName>
spec:
  ingressClassName: azure-application-gateway
  tls:
    - secretName: <guestbook-secret-name>
  rules:
  - host: <HostName> # image.gaonnuri.site
    http:
      paths:
      - backend:
          serviceName: frontend
          servicePort: 80

 

5. 종단 간 TLS 통신은 브라우저(클라이언트) <———> AGIC(서버, 클라이언트) <———> AKS POD(서버) 역할을 하며 브라우저와 AGIC간 1차 TLS 터널링이 맺어지고 AGIC와 AKS POD간 2차 터널링이 맺어집니다.

그에 따라 Nginx Reverse Proxy 설정에도 SSL 프라이빗 키와 fullchain 인증서를 등록해주어야 합니다.

upstream spring {
    server spring.nuri.site:80;
}

server {
    listen 80;
    server_name image.gaonnuri.site;
    location ~* ^/mycontainer/.*\.jpg$ {
        proxy_pass https://image;
        proxy_redirect off;
        proxy_set_header Host kbhchicdevstgpublic.blob.core.windows.net;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Host kbhchicdevstgpublic.blob.core.windows.net;
    }

    location / {
        root /usr/share/nginx/html;
        index index.html;
    }
}

server {
    listen 443 ssl;
    server_name spring.gaonnuri.site;
    ssl_certificate /usr/share/ca-certificates/extra/fullchain.pem;
    ssl_certificate_key /usr/share/ca-certificates/extra/privatekey.pem;
    ssl_session_timeout 1m;

    location /hello {
        #add_header 'Access-Control-Allow-Origin' '*' always;
        #add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS' always;
        #add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range' always;
        #add_header 'Access-Control-Allow-Headers' 'Content-Type, Authorization';
        proxy_pass http://spring;
        proxy_redirect off;
        proxy_set_header Host spring.nuri.site;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Host spring.nuri.site;
    }

    location / {
        root /usr/share/nginx/html;
        index index.html;
    }


}

 

6. 참고로 AGIC는 Health Probe와 Backend Health 상태 값이 다를 수 있습니다. 그 이유는 Health Probe는 인증서 정상 여부와 상관없이 등록한 경로에 리소스가 존재하는지 여부에 따라 상태코드 200을 반환하기 때문입니다.

 

 

참고 링크

https://learn.microsoft.com/ko-kr/azure/application-gateway/ingress-controller-expose-service-over-http-https

 

Application Gateway를 사용하여 HTTP 또는 HTTPS를 통해 AKS 서비스 공개

이 문서에서는 Application Gateway를 사용하여 HTTP 또는 HTTPS를 통해 AKS 서비스를 노출하는 방법에 대한 정보를 제공합니다.

learn.microsoft.com

https://azure.github.io/application-gateway-kubernetes-ingress/annotations/#health-probe-path

 

Annotations - Application Gateway Ingress Controller

NOTE: Application Gateway for Containers has been released, which introduces numerous performance, resilience, and feature changes. Please consider leveraging Application Gateway for Containers for your next deployment. A list of corresponding translations

azure.github.io

https://learn.microsoft.com/en-us/azure/application-gateway/application-gateway-backend-health-troubleshooting

 

Troubleshoot backend health issues in Azure Application Gateway

Describes how to troubleshoot backend health issues for Azure Application Gateway

learn.microsoft.com

https://learn.microsoft.com/ko-kr/azure/application-gateway/self-signed-certificates

 

사용자 지정 루트 CA를 사용하여 자체 서명된 인증서 생성 - Azure Application Gateway

사용자 지정 루트 CA를 사용하여 Azure Application Gateway 자체 서명된 인증서를 생성하는 방법을 알아봅니다.

learn.microsoft.com