RHEL ベースの VKS クラスタで additionalTrustedCAs を使用して SSL/TLS 証明書を指定してもサーバが信頼されない
search cancel

RHEL ベースの VKS クラスタで additionalTrustedCAs を使用して SSL/TLS 証明書を指定してもサーバが信頼されない

book

Article ID: 448353

calendar_today

Updated On:

Products

VMware vSphere Kubernetes Service

Issue/Introduction

免責事項: これは英文の記事 SSL certificates specified in additionalTrustedCAs are not trusted in a RHEL-based VKS cluster. の日本語訳です。記事はベストエフォートで翻訳を進めているため、ローカライズコンテンツは最新情報ではない可能性があります。最新情報は英語版の記事を参照してください。


RHEL ベースの VKS クラスタでは、以下のように additionalTrustedCAs の下に SSL/TLS サーバー証明書を指定しても、実際のワーカーノードでは証明書が信頼されません。

$ kubectl get cluster ##CLUSTER_NAME## -o yaml
...
- name: osConfiguration
      value:
        trust:
          additionalTrustedCAs:
          - caCert:
              secretRef:
                key: sample-ssl
                name: sample-ssl-secret
...

Pod イメージにプライベートレジストリを使用している場合、イメージのプル時に "certificate signed by unknown authority" (証明書は不明な認証局により署名されています) というエラーが発生し、Pod のデプロイが失敗します。

Events:
  Type     Reason     Age                    From                 Message
  ----     ------     ----                    ----                 -------
Normal   Scheduled  21m                    default-scheduler    Successfully assigned default/sample-deployment-######## to ########
Normal   Pulling    18m (x5 over 21m)     kubelet              Pulling image "registry.example.com/library/sample:v1"
Warning  Failed     18m (x5 over 21m)     kubelet              Failed to pull image "registry.example.com/library/sample:v1": failed to pull and unpack image "registry.example.com/library/sample:v1": failed to resolve image: failed to do request: Head "https://registry.example.com/v2/library/sample/manifests/v1": tls: failed to verify certificate: x509: certificate signed by unknown authority
Warning  Failed     18m (x5 over 21m)     kubelet              Error: ErrImagePull

さらに、ワーカーノード上で curl コマンドを実行してその SSL 証明書を使用するサーバにアクセスすると、次のエラーが発生します。

$ curl -I https://registry.example.com
curl: (60) SSL certificate problem: unable to get local issuer certificate
More details here: https://curl.se/docs/sslcerts.html

curl failed to verify the legitimacy of the server and therefore could not
establish a secure connection to it. To learn more about this situation and
how to fix it, please visit the web page mentioned above.

Cause

この問題は、RHEL の証明書インストールプロセスがサーバ (リーフ) 証明書をスキップするために発生します。

additionalTrustedCAs で証明書を定義すると、VKS クラスタはそれらを RHEL ベースのワーカーノードの /etc/pki/ca-trust/source/anchors/machine-agent.crt に配置し update-ca-trust コマンドを実行することで、システム全体で CA 証明書を信頼するようになります。証明書の Basic Constraints に CA:TRUE が含まれていない場合、RHEL はそれを信頼された証明書ストアに追加しないため、サーバー証明書は信頼されません。

 

Resolution

この問題を解決するには、additionalTrustedCAs が参照する Secret に、サーバー証明書ではなく CA 証明書を指定します。

  1. 次のコマンドを使用して、CA 証明書を base64 で 2 回エンコードします。
    base64 -w 0 CA.crt | base64 -w 0
  2. 二重エンコードされた文字列を含む YAML ファイルを作成し、名前空間に適用します。
    apiVersion: v1
    data:
      ##KEY_NAME##: |
      <ステップ 1. で生成された文字列をここに貼付します。>
    kind: Secret
    metadata:
      name: ##SECRET_NAME##
      namespace: ##NAMESPACE##
    type: Opaque
  3. kubectl edit cluster <cluster name> を使用してクラスタを編集し、spec.topology.variables の配下に証明書の Secret の参照を定義します。
        - name: osConfiguration
          value:
            trust:
              additionalTrustedCAs:
              - caCert:
                  secretRef:
                    key: ##KEY_NAME##
                    name: ##SECRET_NAME##
  4. ワーカーノードにログインし、目的のサーバが信頼されていることを確認します。
    curl -I https://server.example.com