Notation と Artifact Signing を使用してコンテナー イメージに署名する

この記事は、コンテナー イメージとその他の Open Container Initiative (OCI) 成果物の整合性と信頼性を確保するためのシリーズの一部です。 全体像を把握するには、概要から始めて、署名が重要な理由を説明し、さまざまなシナリオを詳細にわたって説明します。

この記事では、Notary Project ツール、Notation、 Artifact Signing を使用した署名に焦点を当てます。

  • ここで学習する内容: Notation コマンド ライン インターフェイス (CLI) を使用して、アーティファクト署名を使用してアーティファクトに署名する方法について説明します。
  • 適合する場所: アーティファクト署名は、Azure Key Vault の代替手段です。 Key Vault を使用すると、組織は証明書のライフサイクル管理を完全に制御できますが、アーティファクト署名では、ゼロタッチ証明書ライフサイクル管理と有効期間の短い証明書を使用して、効率的な署名エクスペリエンスが提供されます。
  • 重要な理由: アーティファクト署名を使用すると、強力な ID 保証を提供しながら開発者エクスペリエンスが簡素化されます。 セキュリティを損なうことなく、チームが運用の複雑さを軽減するのに役立ちます。

[前提条件]

Notation と Artifact Signing を使用してコンテナー イメージに署名して検証する前に、必要な Azure リソースを設定し、必要なツールをインストールする必要があります。 このセクションでは、Azure Container Registry の準備、アーティファクト署名の構成、開発環境としての Azure CLI の設定について説明します。

Azure Container Registry でコンテナー イメージを準備する

  1. コンテナー レジストリを作成または使用して、コンテナー イメージ、OCI 成果物、署名を格納します。
  2. コンテナー レジストリでコンテナー イメージをプッシュまたは使用します。

成果物の署名を設定する

Azure サブスクリプションで アーティファクト署名アカウントと証明書プロファイル を設定します。

証明書プロファイルには、国/地域 (C)、都道府県 (ST または S)、および組織 (O) が証明書のサブジェクトに含まれている必要があります。 公証人プロジェクトの仕様では、これらのフィールドが必要です。

Azure CLI を設定する

Azure CLI をインストールするか、Azure Cloud Shell を使用します。

Notation CLI と Artifact Signing プラグインをインストールする

このガイドでは、Linux AMD64 と Windows でコマンドを例として実行します。

  1. Notation CLI v1.3.2 をインストールします。

    curl -Lo notation.tar.gz https://github.com/notaryproject/notation/releases/download/v1.3.2/notation_1.3.2_linux_amd64.tar.gz
    # Validate the checksum
    EXPECTED_SHA256SUM="e1a0f060308086bf8020b2d31defb7c5348f133ca0dba6a1a7820ef3cbb6dfe5"
    echo "$EXPECTED_SHA256SUM  notation.tar.gz" | sha256sum -c -
    # Continue if sha256sum matches
    tar xvzf notation.tar.gz
    cp ./notation /usr/local/bin
    

    その他のプラットフォームについては、 Notation インストール ガイドを参照してください。

  2. アーティファクト署名プラグインをインストールします。

    notation plugin install --url "https://github.com/Azure/artifact-signing-notation-plugin/releases/download/v1.0.0/notation-azure-artifactsigning_1.0.0_linux_amd64.tar.gz" --sha256sum 2f45891a14aa9c88c9bee3d11a887c1adbe9d2d24e50de4bc4b4fa3fe595292f
    

    リリース ページで最新のプラグイン URL とチェックサムを見つけます。

  3. プラグインのインストールを確認します。

    notation plugin ls
    

    出力例:

    NAME                    DESCRIPTION                                             VERSION   CAPABILITIES                ERROR
    azure-artifactsigning   Sign OCI artifacts using the Artifact Signing Service   1.0.0     [SIGNATURE_GENERATOR.RAW]   <nil>
    

環境変数を構成する

後続のコマンドで使用するために、次の環境変数を設定します。 プレースホルダーを実際の値に置き換えます。

必要な値は、Azure portal で確認できます。

  • アーティファクト署名アカウント情報については、自分のアカウントに移動し、[ 概要] を選択します。
  • 証明書プロファイル情報については、自分のアカウントに移動し、 オブジェクト>Certificate プロファイルを選択します。
# Artifact Signing environment variables
AS_SUB_ID="<subscription-id>"
AS_ACCT_RG=<ts-account-resource-group>
AS_ACCT_NAME=<ts-account-name>
AS_ACCT_URL=<ts-account-url>
AS_CERT_PROFILE=<ts-cert-profile>
AS_CERT_SUBJECT=<ts-cert-subject>
AS_SIGNING_ROOT_CERT="https://www.microsoft.com/pkiops/certs/Microsoft%20Enterprise%20Identity%20Verification%20Root%20Certificate%20Authority%202020.crt"
AS_TSA_URL="http://timestamp.acs.microsoft.com/"
AS_TSA_ROOT_CERT="http://www.microsoft.com/pkiops/certs/microsoft%20identity%20verification%20root%20certificate%20authority%202020.crt"

# Azure Container Registry and image environment variables
ACR_SUB_ID="<acr-subscription-id>"
ACR_RG=<acr-resource-group>
ACR_NAME=<registry-name>
ACR_LOGIN_SERVER=$ACR_NAME.azurecr.io
REPOSITORY=<repository>
TAG=<tag>
IMAGE=$ACR_LOGIN_SERVER/${REPOSITORY}:$TAG

Azure にサインインする

Azure CLI を使用してユーザー ID でサインインします。

az login
USER_ID=$(az ad signed-in-user show --query id -o tsv)

このガイドでは、ユーザー アカウントでサインインする方法について説明します。 マネージド ID など、その他の ID オプションについては、 Azure CLI を使用した Azure への認証に関するページを参照してください。

Azure Container Registry と Artifact Signing のアクセス許可を割り当てる

Container Registry にアクセスするために必要なロールを ID に付与します。

  • 属性ベースのアクセス制御 (ABAC) で有効になっているレジストリの場合は、次を割り当てます。
    • Container Registry Repository Reader
    • Container Registry Repository Writer
  • ABAC 以外のレジストリの場合は、次を割り当てます。
    • AcrPull
    • AcrPush
az role assignment create --role "Container Registry Repository Reader" --assignee $USER_ID --scope "/subscriptions/$ACR_SUB_ID/resourceGroups/$ACR_RG/providers/Microsoft.ContainerRegistry/registries/$ACR_NAME"
az role assignment create --role "Container Registry Repository Writer" --assignee $USER_ID --scope "/subscriptions/$ACR_SUB_ID/resourceGroups/$ACR_RG/providers/Microsoft.ContainerRegistry/registries/$ACR_NAME"

アーティファクト署名を使用して署名できるように、ID にロール Artifact Signing Certificate Profile Signer を割り当てます。

az role assignment create --assignee $USER_ID --role "Artifact Signing Certificate Profile Signer" --scope "/subscriptions/$AS_SUB_ID/resourceGroups/$AS_ACCT_RG/providers/Microsoft.CodeSigning/codeSigningAccounts/$AS_ACCT_NAME/certificateProfiles/$AS_CERT_PROFILE"

コンテナー イメージに署名する

# Authenticate to Azure Container Registry
az acr login --name $ACR_NAME

# Download the timestamping root certificate
curl -o msft-tsa-root-certificate-authority-2020.crt $AS_TSA_ROOT_CERT

# Sign the image
notation sign --signature-format cose --timestamp-url $AS_TSA_URL --timestamp-root-cert "msft-tsa-root-certificate-authority-2020.crt" --id $AS_CERT_PROFILE --plugin azure-artifactsigning --plugin-config accountName=$AS_ACCT_NAME --plugin-config baseUrl=$AS_ACCT_URL --plugin-config certProfile=$AS_CERT_PROFILE $IMAGE

キー フラグについて説明します。

  • --signature-format cose: 署名に CBOR オブジェクト署名と暗号化 (COSE) 形式を使用します。
  • --timestamp-url: アーティファクト署名でサポートされているタイムスタンプ サーバーを使用します。
  • --plugin-config: 成果物署名プラグインに構成を渡します。

署名されたイメージと署名を一覧表示します。

notation ls $IMAGE

出力例:

myregistry.azurecr.io/myrepo@sha256:5d0bf1e8f5a0c74a4c22d8c0f962a7cfa06a4f9d8423b196e482df8af23b5d55
└── application/vnd.cncf.notary.signature
    └── sha256:d3a4c9fbc17e27b19a0b28e7b6a33f2c0f541dbdf8d2e5e8d0d79a835e8a76f2a

コンテナー イメージを確認する

  1. ルート証明書をダウンロードして追加します。

    curl -o msft-root-certificate-authority-2020.crt $AS_SIGNING_ROOT_CERT
    SIGNING_TRUST_STORE="myRootCerts"
    notation cert add --type ca --store $SIGNING_TRUST_STORE msft-root-certificate-authority-2020.crt
    
    curl -o msft-tsa-root-certificate-authority-2020.crt $AS_TSA_ROOT_CERT
    TSA_TRUST_STORE="myTsaRootCerts"
    notation cert add -t tsa -s $TSA_TRUST_STORE msft-tsa-root-certificate-authority-2020.crt
    notation cert ls
    

  1. 信頼ポリシー JSON ファイルを作成します。

    cat <<EOF > trustpolicy.json
    {
        "version": "1.0",
        "trustPolicies": [
            {
                "name": "myPolicy",
                "registryScopes": [ "$ACR_LOGIN_SERVER/$REPOSITORY" ],
                "signatureVerification": {
                    "level" : "strict"
                },
                "trustStores": [ "ca:$SIGNING_TRUST_STORE", "tsa:$TSA_TRUST_STORE" ],
                "trustedIdentities": [
                    "x509.subject: $AS_CERT_SUBJECT"
                ]
            }
        ]
    }
    EOF
    

    ポリシーをインポートして確認します。

    notation policy import trustpolicy.json
    notation policy show
    

  1. イメージを確認します。

    notation verify $IMAGE
    

    出力例:

    Successfully verified signature for myregistry.azurecr.io/myrepo@sha256:5d0bf1e8f5a0c74a4c22d8c0f962a7cfa06a4f9d8423b196e482df8af23b5d55
    

    検証に失敗した場合は、信頼ポリシーと証明書が正しく構成されていることを確認します。