이 문서는 게이트웨이 API에서 다음 리소스를 사용하는 예제 애플리케이션을 설정하는 데 도움이 됩니다. 다음 단계가 제공됩니다.
- 하나의 HTTPS 수신기를 사용하여 게이트웨이 리소스를 만듭니다.
- 백 엔드 서비스를 참조하는 HTTPRoute 리소스를 만듭니다.
- CA 인증서가 있는 FrontendTLSPolicy 리소스를 만듭니다.
배경
MTLS(상호 전송 계층 보안)는 인증서를 사용하여 통신을 암호화하고 서비스에 대한 클라이언트를 식별하는 프로세스입니다. 이를 통해 Application Gateway for Containers는 인증된 디바이스의 연결만 신뢰하여 보안 태세를 더욱 강화할 수 있습니다.
다음 그림을 참조하세요.
유효한 클라이언트 인증서 흐름은 컨테이너용 Application Gateway의 프런트 엔드에 인증서를 표시하는 클라이언트를 보여줍니다. 컨테이너용 Application Gateway는 인증서가 유효하다고 판단하고 백 엔드 대상에 요청을 프록시합니다. 응답은 궁극적으로 클라이언트에 반환됩니다.
해지된 클라이언트 인증서 흐름은 해지된 인증서를 컨테이너용 Application Gateway의 프런트 엔드에 표시하는 클라이언트를 보여 줍니다. 컨테이너용 Application Gateway는 인증서가 유효하지 않다고 판단하고 요청이 클라이언트에 프록시되지 않도록 합니다. 클라이언트는 HTTP 400 잘못된 요청 및 해당 이유를 받게 됩니다.
필수 구성 요소
BYO 배포 전략을 따르는 경우 컨테이너용 Application Gateway 리소스 및 ALB 컨트롤러를 설정했는지 확인합니다.
ALB 관리된 배포 전략을 따르는 경우 ALB 컨트롤러를 프로비전하고 ApplicationLoadBalancer 사용자 지정 리소스를 통해 컨테이너용 Application Gateway 리소스를 프로비전해야 합니다.
샘플 HTTP 애플리케이션을 배포합니다.
클러스터에 다음 deployment.yaml 파일을 적용하여 샘플 웹 애플리케이션을 만들고 샘플 비밀을 배포하여 mTLS(프런트 엔드 상호 인증)를 보여 줍니다.
kubectl apply -f https://raw.githubusercontent.com/MicrosoftDocs/azure-docs/refs/heads/main/articles/application-gateway/for-containers/examples/https-scenario/ssl-termination/deployment.yaml이 명령은 클러스터에 다음을 만듭니다.
-
test-infra라는 네임스페이스 -
echo네임스페이스에서test-infra(이)라는 하나의 서비스 -
echo네임스페이스에서test-infra(이)라는 하나의 배포 -
listener-tls-secret네임스페이스에서test-infra(이)라는 하나의 비밀
-
인증서 생성
이 예제에서는 루트 인증서를 만들고 루트에서 클라이언트 인증서를 발급합니다. 루트 인증서 및 클라이언트 인증서가 이미 있는 경우 다음 단계를 건너뛸 수 있습니다.
루트 인증서에 대한 프라이빗 키 생성
openssl genrsa -out root.key 2048
루트 인증서 생성
openssl req -x509 -new -nodes -key root.key -sha256 -days 1024 -out root.crt -subj "/C=US/ST=North Dakota/L=Fargo/O=Contoso/CN=contoso-root"
클라이언트 인증서에 대한 프라이빗 키 생성
openssl genrsa -out client.key 2048
클라이언트 인증서에 대한 인증서 서명 요청 만들기
openssl req -new -key client.key -out client.csr -subj "/C=US/ST=North Dakota/L=Fargo/O=Contoso/CN=contoso-client"
루트 인증서로 서명된 클라이언트 인증서 생성
openssl x509 -req -in client.csr -CA root.crt -CAkey root.key -CAcreateserial -out client.crt -days 1024 -sha256
필수 게이트웨이 API 리소스 배포
게이트웨이 만들기
kubectl apply -f - <<EOF
apiVersion: gateway.networking.k8s.io/v1
kind: Gateway
metadata:
name: gateway-01
namespace: test-infra
annotations:
alb.networking.azure.io/alb-namespace: alb-test-infra
alb.networking.azure.io/alb-name: alb-test
spec:
gatewayClassName: azure-alb-external
listeners:
- name: mtls-listener
port: 443
protocol: HTTPS
allowedRoutes:
namespaces:
from: Same
tls:
mode: Terminate
certificateRefs:
- kind : Secret
group: ""
name: listener-tls-secret
EOF
참고
ALB 컨트롤러는 Azure Resource Manager에서 컨테이너용 Application Gateway 리소스를 만들 때 프런트 엔드 리소스 fe-<eight randomly generated characters>에 대해 다음 명명 규칙을 사용합니다.
Azure에서 만든 프런트 엔드 리소스의 이름을 변경하려면 사용자 고유의 배포 전략을 따르는 것이 좋습니다.
게이트웨이 리소스가 만들어지면 상태가 유효한지, 수신기가 프로그래밍되어 있는지, 주소가 게이트웨이에 할당되어 있는지 확인합니다.
kubectl get gateway gateway-01 -n test-infra -o yaml
성공적인 게이트웨이 만들기의 예제 출력:
status:
addresses:
- type: IPAddress
value: xxxx.yyyy.alb.azure.com
conditions:
- lastTransitionTime: "2023-06-19T21:04:55Z"
message: Valid Gateway
observedGeneration: 1
reason: Accepted
status: "True"
type: Accepted
- lastTransitionTime: "2023-06-19T21:04:55Z"
message: Application Gateway For Containers resource has been successfully updated.
observedGeneration: 1
reason: Programmed
status: "True"
type: Programmed
listeners:
- attachedRoutes: 0
conditions:
- lastTransitionTime: "2023-06-19T21:04:55Z"
message: ""
observedGeneration: 1
reason: ResolvedRefs
status: "True"
type: ResolvedRefs
- lastTransitionTime: "2023-06-19T21:04:55Z"
message: Listener is accepted
observedGeneration: 1
reason: Accepted
status: "True"
type: Accepted
- lastTransitionTime: "2023-06-19T21:04:55Z"
message: Application Gateway For Containers resource has been successfully updated.
observedGeneration: 1
reason: Programmed
status: "True"
type: Programmed
name: https-listener
supportedKinds:
- group: gateway.networking.k8s.io
kind: HTTPRoute
게이트웨이가 만들어지면 HTTPRoute 리소스를 만듭니다.
kubectl apply -f - <<EOF
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
name: https-route
namespace: test-infra
spec:
parentRefs:
- name: gateway-01
rules:
- backendRefs:
- name: echo
port: 80
EOF
HTTPRoute 리소스가 만들어지면 경로가 수락됨 상태이고 컨테이너용 Application Gateway 리소스가 프로그래밍됨 상태인지 확인합니다.
kubectl get httproute https-route -n test-infra -o yaml
컨테이너용 Application Gateway 리소스의 상태가 성공적으로 업데이트되었는지 확인합니다.
status:
parents:
- conditions:
- lastTransitionTime: "2023-06-19T22:18:23Z"
message: ""
observedGeneration: 1
reason: ResolvedRefs
status: "True"
type: ResolvedRefs
- lastTransitionTime: "2023-06-19T22:18:23Z"
message: Route is Accepted
observedGeneration: 1
reason: Accepted
status: "True"
type: Accepted
- lastTransitionTime: "2023-06-19T22:18:23Z"
message: Application Gateway For Containers resource has been successfully updated.
observedGeneration: 1
reason: Programmed
status: "True"
type: Programmed
controllerName: alb.networking.azure.io/alb-controller
parentRef:
group: gateway.networking.k8s.io
kind: Gateway
name: gateway-01
namespace: test-infra
클라이언트 인증서에 대한 인증서 체인이 포함된 kubectl을 사용하여 Kubernetes 비밀을 만듭니다.
kubectl create secret generic ca.bundle -n test-infra --from-file=ca.crt=root.crt
FrontendTLSPolicy 만들기
kubectl apply -f - <<EOF
apiVersion: alb.networking.azure.io/v1
kind: FrontendTLSPolicy
metadata:
name: mtls-policy
namespace: test-infra
spec:
targetRef:
group: gateway.networking.k8s.io
kind: Gateway
name: gateway-01
namespace: test-infra
sectionNames:
- mtls-listener
default:
verify:
caCertificateRef:
name: ca.bundle
group: ""
kind: Secret
namespace: test-infra
EOF
FrontendTLSPolicy 개체가 만들어지면 개체의 상태를 확인하여 정책이 유효한지 확인합니다.
kubectl get frontendtlspolicy mtls-policy -n test-infra -o yaml
유효한 FrontendTLSPolicy 개체 만들기의 예제 출력:
status:
conditions:
- lastTransitionTime: "2023-06-29T16:54:42Z"
message: Valid FrontendTLSPolicy
observedGeneration: 1
reason: Accepted
status: "True"
type: Accepted
애플리케이션에 대한 액세스 테스트
이제 프런트 엔드에 할당된 FQDN을 통해 샘플 애플리케이션에 일부 트래픽을 전송할 준비가 되었습니다. 다음 명령을 실행하여 FQDN을 가져옵니다.
fqdn=$(kubectl get gateway gateway-01 -n test-infra -o jsonpath='{.status.addresses[0].value}')
클라이언트 인증서 없이 프런트 엔드의 FQDN을 컬링합니다.
curl --insecure https://$fqdn/
인증서가 필요하다는 응답 경고가 표시됩니다.
curl: (56) OpenSSL SSL_read: OpenSSL/1.1.1k: error:1409445C:SSL routines:ssl3_read_bytes:tlsv13 alert certificate required, errno 0
생성된 클라이언트 인증서를 표시하는 FQDN을 curl합니다.
curl --cert client.crt --key client.key --insecure https://$fqdn/
응답은 Application Gateway for Containers 뒤에 있는 백 엔드 서비스에서 제공됩니다.
축하합니다. ALB 컨트롤러를 설치하고, 백 엔드 애플리케이션을 배포하고, 클라이언트 인증서를 통해 인증하고, 컨테이너용 Application Gateway를 통해 백 엔드 서비스에서 트래픽을 반환했습니다.