Skip to content

Commit cf87b2f

Browse files
authored
Merge pull request #235470 from FeynmanZhou/main
Update container-registry-tutorial-sign-build-push.md
2 parents 6b175c2 + 13dfcb6 commit cf87b2f

File tree

1 file changed

+30
-59
lines changed

1 file changed

+30
-59
lines changed

articles/container-registry/container-registry-tutorial-sign-build-push.md

Lines changed: 30 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
---
22
title: Build, Sign and Verify a container image using notation and certificate in Azure Key Vault
33
description: In this tutorial you'll learn to create a signing certificate, build a container image, remote sign image with notation and Azure Key Vault, and then verify the container image using the Azure Container Registry.
4-
author: dtzar
4+
author: feynmanzhou
55
ms.author: davete
66
ms.service: container-registry
77
ms.custom: devx-track-azurecli
88
ms.topic: how-to
9-
ms.date: 12/12/2022
9+
ms.date: 4/23/2023
1010
---
1111

1212
# Build, sign, and verify container images using Notary and Azure Key Vault (Preview)
1313

14-
The Azure Key Vault (AKV) is used to store a signing key that can be utilized by **notation** with the notation AKV plugin (azure-kv) to sign and verify container images and other artifacts. The Azure Container Registry (ACR) allows you to attach these signatures using the **az** or **oras** CLI commands.
14+
The Azure Key Vault (AKV) is used to store a signing key that can be utilized by [notation](http://notaryproject.dev/) with the notation AKV plugin (azure-kv) to sign and verify container images and other artifacts. The Azure Container Registry (ACR) allows you to attach these signatures using the **az** or **oras** CLI commands.
1515

16-
The signed containers enable users to assure deployments are built from a trusted entity and verify artifact hasn't been tampered with since their creation. The signed artifact ensures integrity and authenticity before the user pulls an artifact into any environment and avoid attacks.
16+
The signed image enables users to assure deployments are built from a trusted entity and verify artifact hasn't been tampered with since their creation. The signed artifact ensures integrity and authenticity before the user pulls an artifact into any environment and avoid attacks.
1717

1818

1919
In this tutorial:
@@ -31,11 +31,11 @@ In this tutorial:
3131
3232
## Install the notation CLI and AKV plugin
3333

34-
1. Install notation v1.0.0-rc.1 with plugin support on a Linux environment. You can also download the package for other environments from the [release page](https://github.com/notaryproject/notation/releases/tag/v1.0.0-rc.1).
34+
1. Install notation v1.0.0-rc.4 on a Linux environment. You can also download the package for other environments by following the [Notation installation guide](https://notaryproject.dev/docs/installation/cli/).
3535

3636
```bash
3737
# Download, extract and install
38-
curl -Lo notation.tar.gz https://github.com/notaryproject/notation/releases/download/v1.0.0-rc.1/notation_1.0.0-rc.1_linux_amd64.tar.gz
38+
curl -Lo notation.tar.gz https://github.com/notaryproject/notation/releases/download/v1.0.0-rc.4/notation_1.0.0-rc.4_linux_amd64.tar.gz
3939
tar xvzf notation.tar.gz
4040

4141
# Copy the notation cli to the desired bin directory in your PATH
@@ -45,22 +45,21 @@ In this tutorial:
4545
2. Install the notation Azure Key Vault plugin for remote signing and verification.
4646

4747
> [!NOTE]
48-
> The plugin directory varies depending upon the operating system being used. The directory path below assumes Ubuntu.
49-
> Please read the [notation config article](https://github.com/notaryproject/notaryproject.dev/blob/main/content/en/docs/how-to/directory-structure.md) for more information.
48+
> The plugin directory varies depending upon the operating system being used. The directory path below assumes Ubuntu. Please read the [Notation directory structure for system configuration](https://notaryproject.dev/docs/concepts/directory-structure/) for more information.
5049

5150
```bash
5251
# Create a directory for the plugin
5352
mkdir -p ~/.config/notation/plugins/azure-kv
5453
5554
# Download the plugin
5655
curl -Lo notation-azure-kv.tar.gz \
57-
https://github.com/Azure/notation-azure-kv/releases/download/v0.5.0-rc.1/notation-azure-kv_0.5.0-rc.1_Linux_amd64.tar.gz
56+
https://github.com/Azure/notation-azure-kv/releases/download/v0.6.0/notation-azure-kv_0.6.0_Linux_amd64.tar.gz
5857
5958
# Extract to the plugin directory
6059
tar xvzf notation-azure-kv.tar.gz -C ~/.config/notation/plugins/azure-kv notation-azure-kv
6160
```
6261

63-
3. List the available plugins and verify that the plugin is available.
62+
3. List the available plugins.
6463

6564
```bash
6665
notation plugin ls
@@ -99,14 +98,14 @@ In this tutorial:
9998

10099
## Store the signing certificate in AKV
101100

102-
If you have an existing certificate, upload it to AKV. For more information on how to use your own signing key, see the [signing certificate requirements.](https://github.com/notaryproject/notaryproject/blob/v1.0.0-rc.1/specs/signature-specification.md)
101+
If you have an existing certificate, upload it to AKV. For more information on how to use your own signing key, see the [signing certificate requirements.](https://github.com/Azure/notation-azure-kv/blob/release-0.6/docs/ca-signed-workflow.md)
103102
Otherwise create an x509 self-signed certificate storing it in AKV for remote signing using the steps below.
104103

105104
### Create a self-signed certificate (Azure CLI)
106105

107106
1. Create a certificate policy file.
108107

109-
Once the certificate policy file is executed as below, it creates a valid signing certificate compatible with **notation** in AKV. The EKU listed is for code-signing, but isn't required for notation to sign artifacts. The subject is used later as trust identity that user tursts during verification.
108+
Once the certificate policy file is executed as below, it creates a valid signing certificate compatible with **notation** in AKV. The EKU listed is for code-signing, but isn't required for notation to sign artifacts. The subject is used later as trust identity that user trust during verification.
110109
111110
```bash
112111
cat <<EOF > ./my_policy.json
@@ -148,7 +147,7 @@ Otherwise create an x509 self-signed certificate storing it in AKV for remote si
148147
az keyvault certificate download --file $CERT_PATH --id $CERT_ID --encoding PEM
149148
```
150149
151-
5. Add a signing key referencing the key id.
150+
5. Add a signing key referencing the key ID.
152151
153152
```bash
154153
notation key add $KEY_NAME --plugin azure-kv --id $KEY_ID
@@ -159,7 +158,7 @@ Otherwise create an x509 self-signed certificate storing it in AKV for remote si
159158
```bash
160159
notation key ls
161160
```
162-
161+
163162
7. Add the downloaded public certificate to named trust store for signature verification.
164163
165164
```bash
@@ -168,7 +167,7 @@ Otherwise create an x509 self-signed certificate storing it in AKV for remote si
168167
notation cert add --type $STORE_TYPE --store $STORE_NAME $CERT_PATH
169168
```
170169
171-
8. List the certificate to confirm
170+
8. List the certificate to confirm.
172171
173172
```bash
174173
notation cert ls
@@ -182,14 +181,17 @@ Otherwise create an x509 self-signed certificate storing it in AKV for remote si
182181
az acr build -r $ACR_NAME -t $IMAGE $IMAGE_SOURCE
183182
```
184183
185-
2. Authenticate with your individual Azure AD identity to use an ACR token.
184+
2. Authenticate with your individual Azure AD identity to use an ACR token.
186185
187186
```azure-cli
188187
export USER_NAME="00000000-0000-0000-0000-000000000000"
189188
export PASSWORD=$(az acr login --name $ACR_NAME --expose-token --output tsv --query accessToken)
190189
notation login -u $USER_NAME -p $PASSWORD $REGISTRY
191190
```
192191
192+
> [!NOTE]
193+
> Currently, `notation` relies on [Docker Credential Store](https://docs.docker.com/engine/reference/commandline/login/#credentials-store) for authentication. Notation requires additional configuration on Linux. If `notation login` is failing, you can configure the Docker Credential Store or Notation environment variables by following the guide [Authenticate with OCI-compliant registries](https://notaryproject.dev/docs/how-to/registry-authentication/).
194+
193195
3. Sign the container image with the [COSE](https://datatracker.ietf.org/doc/html/rfc8152) signature format using the signing key added in previous step.
194196
195197
```bash
@@ -202,54 +204,16 @@ Otherwise create an x509 self-signed certificate storing it in AKV for remote si
202204
notation ls $IMAGE
203205
```
204206
205-
## View the graph of artifacts with the ORAS CLI (optional)
206-
207-
ACR support for OCI artifacts enables a linked graph of supply chain artifacts that can be viewed through the ORAS CLI or the Azure CLI.
208-
209-
1. Signed images can be view with the ORAS CLI.
210-
211-
```bash
212-
oras login -u $USER_NAME -p $PASSWORD $REGISTRY
213-
oras discover -o tree $IMAGE
214-
```
215-
216-
## View the graph of artifacts with the Azure CLI (optional)
217-
218-
1. List the manifest details for the container image.
219-
220-
```azure-cli
221-
az acr manifest show-metadata $IMAGE -o jsonc
222-
```
223-
224-
2. Generates a result, showing the `digest` representing the notary v2 signature.
225-
226-
```json
227-
{
228-
"changeableAttributes": {
229-
"deleteEnabled": true,
230-
"listEnabled": true,
231-
"readEnabled": true,
232-
"writeEnabled": true
233-
},
234-
"createdTime": "2022-05-13T23:15:54.3478293Z",
235-
"digest": "sha256:effba96d9b7092a0de4fa6710f6e73bf8c838e4fbd536e95de94915777b18613",
236-
"lastUpdateTime": "2022-05-13T23:15:54.3478293Z",
237-
"name": "v1",
238-
"quarantineState": "Passed",
239-
"signed": false
240-
}
241-
```
242-
243207
## Verify the container image
244208
245209
1. Configure trust policy before verification.
246210
247211
The trust policy is a JSON document named `trustpolicy.json`, which is stored under the notation configuration directory. Users who verify signed artifacts from a registry use the trust policy to specify trusted identities that sign the artifacts, and the level of signature verification to use.
248212
249-
Use the following command to configure trust policy for this tutorial. Upon successful execution of the command, one trust policy named `wabbit-networks-images` is created. This trust policy applies to all the artifacts stored in repositories defined in `$REGISTRY/$REPO`. The trust identity that user trusts has the x509 subject `$CERT_SUBJECT` from previous step, and stored under trust store named `$STORE_NAME` of type `$STORE_TYPE`. See [Trust store and trust policy specification](https://notaryproject.dev/docs/concepts/trust-store-trust-policy-specification/) for details.
213+
Use the following command to configure trust policy. Upon successful execution of the command, one trust policy named `wabbit-networks-images` is created. This trust policy applies to all the artifacts stored in repositories defined in `$REGISTRY/$REPO`. The trust identity that user trusts has the x509 subject `$CERT_SUBJECT` from previous step, and stored under trust store named `$STORE_NAME` of type `$STORE_TYPE`. See [Trust store and trust policy specification](https://notaryproject.dev/docs/concepts/trust-store-trust-policy-specification/) for details.
250214
251215
```bash
252-
cat <<EOF > $HOME/.config/notation/trustpolicy.json
216+
cat <<EOF > ./trustpolicy.json
253217
{
254218
"version": "1.0",
255219
"trustPolicies": [
@@ -268,14 +232,21 @@ ACR support for OCI artifacts enables a linked graph of supply chain artifacts t
268232
}
269233
EOF
270234
```
235+
236+
3. Use `notation policy` to import the trust policy configuration from a JSON file that we created previously.
237+
238+
```bash
239+
notation policy import ./trustpolicy.json
240+
notation policy show
241+
```
271242
272-
2. The notation command can also help to ensure the container image hasn't been tampered with since build time by comparing the `sha` with what is in the registry.
243+
4. The notation command can also help to ensure the container image hasn't been tampered with since build time by comparing the `sha` with what is in the registry.
273244

274245
```bash
275246
notation verify $IMAGE
276247
```
277-
Upon successful verification of the image using the trust policy, the sha256 digest of the verified image is returned in a successful output messages.
248+
Upon successful verification of the image using the trust policy, the sha256 digest of the verified image is returned in a successful output message.
278249

279250
## Next steps
280251

281-
See [Enforce policy to only deploy signed container images to Azure Kubernetes Service (AKS) utilizing **ratify** and **gatekeeper**.](https://github.com/Azure/notation-azure-kv/blob/main/docs/nv2-sign-verify-aks.md)
252+
See [Ratify on Azure: Allow only signed images to be deployed on AKS with Notation and Ratify](https://github.com/deislabs/ratify/blob/main/docs/examples/ratify-verify-azure-cmd.md).

0 commit comments

Comments
 (0)