Container Image Sign and Verify with notation tool
nerdctl >= 1.3.0 | |
---|---|
Notation は、レジストリ エコシステムに署名を標準項目として追加し、これらの署名に署名および検証するための一連の簡単なツールを構築するプロジェクトです。
コンテナーの署名と検証の機能は、notation
を使用して nerdctl
のpush
コマンドとpull
コマンドで有効にできます
内部的には、--sign
フラグを利用してコンテナイメージをプッシュしたり、 --verify
を指定してコンテナイメージをプルしたりします。
- notationの実行コマンドが
$PATH
にあることを確認してください。 - notationは、次のページからインストールできます: https://notaryproject.dev/docs/user-guides/installation/cli/
- Notation はOCI仕様v1.1.0のRCに従います。指示に従って、テスト目的でコンプライアンスを備えたローカルレジストリを設定します。
環境準備
# Create a sample Dockerfile
$ cat <<EOF | tee Dockerfile.dummy
FROM alpine:latest
CMD [ "echo", "Hello World" ]
EOF
ベースイメージ (この場合は
alpine:latest
) は、ビルドされたコンテナーイメージの検証は行われません。 コンテナー イメージ自体は、署名後にのみ検証します。
# Build the image
$ nerdctl build -t localhost:5000/my-test -f Dockerfile.dummy .
# Generate a key-pair in notation's key store and trust store
$ notation cert generate-test --default "test"
# Confirm the signing key is correctly configured. 接頭辞 * が付いたキー名がデフォルトのキーです。
$notation key ls
#証明書が信頼ストアに保存されていることを確認します。
$ notation cert ls
プッシュ中にコンテナー イメージに署名します。
# Sign the image and store the signature in the registry
$ nerdctl push --sign=notation --notation-key-name test localhost:5000/my-test
プル中にコンテナー イメージを確認します。
注意:
--verify
フラグを渡した場合、信頼ポリシーの証明書と一致する署名がない場合、イメージはプルされません。
# Create `trustpolicy.json` under $XDG_CONFIG_HOME/notation (XDG_CONFIG_HOME is ~/.config below)
cat <<EOF | tee ~/.config/notation/trustpolicy.json
{
"version": "1.0",
"trustPolicies": [
{
"name": "test-images",
"registryScopes": [ "*" ],
"signatureVerification": {
"level" : "strict"
},
"trustStores": [ "ca:test" ],
"trustedIdentities": [
"*"
]
}
]
}
EOF
# Verify the image
$ nerdctl pull --verify=notation localhost:5000/my-test
# You can not verify the image if it is not signed by the cert in the trust policy
$ nerdctl pull --verify=notation localhost:5000/my-test-bad