Container の Application Gateway を使ったバックエンド MTLS - ゲートウェイ API

このドキュメントは、Gateway API から次のリソースを使用するアプリケーションの例を設定するのに役立ちます。 以下を行うための手順を示します。

  • HTTPS リスナーを 1 つ持つ Gateway リソースを作成します。
  • バックエンド サービスを参照する HTTPRoute リソースを作成します。
  • HTTPRoute で参照されるバックエンド サービスのクライアントと CA 証明書を持つ BackendTLSPolicy リソースを作成します。

背景

相互トランスポート層セキュリティ (MTLS) は、通信を暗号化し、サービスに対するクライアントを識別するために証明書に依存するプロセスです。 これにより、バックエンドのワークロードは、認証済みデバイスからの接続のみを信頼することで、セキュリティ体制を向上させることができます。

次の図を参照してください。

A diagram showing the Application Gateway for Containers backend MTLS process.

前提条件

  1. BYO デプロイ戦略に従う場合は、Application Gateway for Containers リソースと ALB コントローラーを設定していることを確認します。

  2. ALB マネージド デプロイ戦略に従う場合は、ALB コントローラーのプロビジョニングと、ApplicationLoadBalancer カスタム リソースを介した Application Gateway for Containers リソースのプロビジョニングが完了していることを確認します。

  3. サンプル HTTP アプリケーションをデプロイします。

    クラスターに次の deployment.yaml ファイルを適用し、サンプル Web アプリケーションを作成してバックエンド相互認証 (mTLS) のデモンストレーションを行うためのサンプル シークレットをデプロイします。

    kubectl apply -f https://trafficcontrollerdocs.blob.core.windows.net/examples/https-scenario/end-to-end-ssl-with-backend-mtls/deployment.yaml
    

    このコマンドによって、クラスターに次のものが作成されます。

    • test-infra という名前空間
    • test-infra 名前空間内の mtls-app という 1 つのサービス
    • test-infra 名前空間内の mtls-app という 1 つのデプロイ
    • test-infra 名前空間内の mtls-app-nginx-cm という 1 つの構成マップ
    • test-infra 名前空間内の backend.comfrontend.comgateway-client-certca.bundle という 4 つのシークレット

必要な Gateway 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: https-listener
    port: 443
    protocol: HTTPS
    allowedRoutes:
      namespaces:
        from: Same
    tls:
      mode: Terminate
      certificateRefs:
      - kind : Secret
        group: ""
        name: frontend.com
EOF

Note

ALB コントローラーは、ARM で Application Gateway for Containers リソースを作成するときに、フロントエンド リソースに対して次の名前付け規則を使用します。fe-<ランダムに生成された 8 文字>

Azure で作成されたフロントエンドの名前を変更したい場合は、BYO デプロイ戦略に従うことを検討してください。

ゲートウェイ リソースが作成されたら、状態が有効であること、リスナーが [プログラム済み] であること、ゲートウェイにアドレスが割り当てられていることを確認します。

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: mtls-app
      port: 443
EOF

HTTPRoute リソースが作成されたら、ルートが [承認済み] になり、Application Gateway for Containers リソースが [プログラム済み] になっていることを確認します。

kubectl get httproute https-route -n test-infra -o yaml

Application Gateway for Containers リソースの状態が正常に更新されたことを確認します。

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

BackendTLSPolicy の作成

kubectl apply -f - <<EOF
apiVersion: alb.networking.azure.io/v1
kind: BackendTLSPolicy
metadata:
  name: mtls-app-tls-policy
  namespace: test-infra
spec:
  targetRef:
    group: ""
    kind: Service
    name: mtls-app
    namespace: test-infra
  default:
    sni: backend.com
    ports:
    - port: 443
    clientCertificateRef:
      name: gateway-client-cert
      group: ""
      kind: Secret
    verify:
      caCertificateRef:
        name: ca.bundle
        group: ""
        kind: Secret
      subjectAltName: backend.com
EOF

BackendTLSPolicy オブジェクトが作成されたら、オブジェクトの状態を確認し、ポリシーが有効であることを確認します。

kubectl get backendtlspolicy -n test-infra mtls-app-tls-policy -o yaml

有効な BackendTLSPolicy オブジェクト作成の出力例。

status:
  conditions:
  - lastTransitionTime: "2023-06-29T16:54:42Z"
    message: Valid BackendTLSPolicy
    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 を実行すると、HTTPRoute で構成されているバックエンドから応答が返されます。

curl --insecure https://$fqdn/

これで、ALB コントローラーをインストールし、バックエンド アプリケーションをデプロイして、Application Gateway for Containers のイングレス経由でアプリケーションにトラフィックをルーティングすることができました。