NGINX Gateway Fabric 인증서 추가를 통한 보안 강화

기본적으로, NGINX Gateway Fabric 은 자체 서명 인증서 를 설치하여 NGINX Gateway Fabric control plane pod와 NGINX Gateway Fabric data plane pod 사이의 연결을 보호합니다. 이러한 인증서는 NGINX Gateway Fabric이 최초로 설치될 때 cert-generator job을 통해 생성됩니다.

하지만 이 인증서는 자체 서명된 인증서고, 3년 뒤 만료되기 때문에, 프로덕션 환경에선선 cert-manager와 같은 솔루션을 통해 인증서를 생성하고 관리하는 것을 권장합니다.

이 가이드는 cert-manager를 설치하고 사용하여 연결을 보호하는 방법을 설명합니다.

사전 구성

이 가이드를 완수하기 위해 다음 전제 조건이 구성되어야 합니다.

  • Kubernetes 클러스터의 관리자 권한.
  • Helm,  kubectl 설치.

목차

1. cert-manager 설치
2. CA issuer 생성

3. NGINX Gateway Fabric 서버, 클라이언트 인증서 생성
4. NGINX Gateway Fabric 인증서 Secrets 생성 확인

1. cert-manager 설치

Helm 리포지토리를 추가합니다.

$ helm repo add jetstack https://charts.jetstack.io
$ helm repo update

cert-manager를 설치합니다.

$ helm install \
  cert-manager jetstack/cert-manager \
  --namespace cert-manager \
  --create-namespace \
  --set config.apiVersion="controller.config.cert-manager.io/v1alpha1" \
  --set config.kind="ControllerConfiguration" \
  --set config.enableGatewayAPI=true \
  --set crds.enabled=true

이 명령어는 워크로드 트래픽 보호에 유용한 cert-manager를 위한 Gateway API 기능도 활성화합니다.

2. CA Issuer 생성

가장 먼저 CA (certificate authority) issuer를 생성해야 합니다.

Note:

이 예제에서는 자체 서명 Issuer를 사용하며, 프로덕션 환경에서는 실제 CA issuer를 사용해야 합니다.

네임스페이스를 생성합니다.

$ kubectl create namespace nginx-gateway

CA Issuer를 생성합니다.

$ kubectl apply -f - <<EOF
apiVersion: cert-manager.io/v1
kind: Issuer
metadata:
  name: selfsigned-issuer
  namespace: nginx-gateway
spec:
  selfSigned: {}
---
apiVersion: cert-manager.io/v1
kind: Certificate
metadata:
  name: nginx-gateway-ca
  namespace: nginx-gateway
spec:
  isCA: true
  commonName: nginx-gateway
  secretName: nginx-gateway-ca
  privateKey:
    algorithm: RSA
    size: 2048
  issuerRef:
    name: selfsigned-issuer
    kind: Issuer
    group: cert-manager.io
---
apiVersion: cert-manager.io/v1
kind: Issuer
metadata:
  name: nginx-gateway-issuer
  namespace: nginx-gateway
spec:
  ca:
    secretName: nginx-gateway-ca
EOF

3. NGINX Gateway Fabric 서버, 클라이언트 인증서 생성

NGINX Gateway Fabric control plane(서버)와 NGINX agent(클라이언트)를 위한 인증서 리소스를 생성합니다.

서버 인증서의 dnsName 필드는 설치 이후에 NGINX Gateway Fabric control plane 서비스가 가질 이름을 나타냅니다. 이 이름은 설치 방법에 따라 달라집니다.

Helm

전체 service 이름은 다음 형식을 따릅니다.
<helm-release-name>-nginx-gateway-fabric.<namespace>.svc

설치 문서에서 사용하는 기본 Helm 릴리즈 이름은 ngf, 기본 네임스페이스는 nginx-gateway입니다. 따라서 dnsNamengf-nginx-gateway-fabric.nginx-gateway.svc가 되어야 합니다.

Manifests

전체 service 이름은 다음 형식을 따릅니다.

<service-name>.<namespace>.svc

기본적으로 기본 service 이름은 nginx-gateway, 기본 네임스페이스는 nginx-gateway입니다. 따라서 dnsNamenginx-gateway.nginx-gateway.svc가 되어야 합니다

$ kubectl apply -f - <<EOF
apiVersion: cert-manager.io/v1
kind: Certificate
metadata:
  name: nginx-gateway
  namespace: nginx-gateway
spec:
  secretName: server-tls
  usages:
  - digital signature
  - key encipherment
  dnsNames:
  - ngf-nginx-gateway-fabric.nginx-gateway.svc # 환경에 맞춰 변경
  issuerRef:
    name: nginx-gateway-issuer
EOF
$ kubectl apply -f - <<EOF
apiVersion: cert-manager.io/v1
kind: Certificate
metadata:
  name: nginx
  namespace: nginx-gateway
spec:
  secretName: agent-tls
  usages:
  - "digital signature"
  - "key encipherment"
  dnsNames:
  - "*.cluster.local"
  issuerRef:
    name: nginx-gateway-issuer
EOF

TLS Secret을 사용하는 각각의 Pod에 마운트되기 때문에, NGINX agent (클라이언트) Secret은 NGINX가 어떤 네임스페이스에 배포되던간에 NGINX Gateway Fabric control plane에 의해 중복됩니다. source Secret에 대한 모든 업데이트는 복사된 Secrets로 전파됩니다.

agent Secret의 이름은 명령줄을 통해 NGINX Gateway Fabric control plane로 제공됩니다. 기본 이름은  agent-tls 이며, 다른 이름을 사용하고 싶다면 NGINX Gateway Fabric 설치 시 설정할 수 있습니다.

  • Helm : Secret 이름을 certGenerator.agentTLSSecretName helm value에 명시합니다.
  • Manifests : Secret 이름을 agent-tls-secret command-line argument에 명시합니다.

4. NGINX Gateway Fabric 인증서 Secrets 생성 확인

nginx-gateway 네임스페이스에 생성된 secrete를 확인합니다.

$ kubectl -n nginx-gateway get secrets

agent-tls          kubernetes.io/tls   3      3s
nginx-gateway-ca   kubernetes.io/tls   3      15s
server-tls         kubernetes.io/tls   3      8s

이제 NGINX Gateway Fabric을 설치해도 좋습니다.