You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
title: Build, Sign and Verify a container image using notation and certificate in Azure Key Vault
3
-
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: feynmanzhou
5
-
ms.author: davete
2
+
title: Sign container images with Notation and Azure Key Vault using a self-signed certificate (Preview)
3
+
description: In this tutorial you'll learn to create a self-signed certificate in Azure Key Vault (AKV), build and sign a container image stored in Azure Container Registry (ACR) with notation and AKV, and then verify the container image with notation.
4
+
author: yizha1
5
+
ms.author: yizha1
6
6
ms.service: container-registry
7
7
ms.custom: devx-track-azurecli
8
8
ms.topic: how-to
9
9
ms.date: 4/23/2023
10
10
---
11
11
12
-
# Build, sign, and verify container images using Notary and Azure Key Vault (Preview)
12
+
# Sign container images with Notation and Azure Key Vault using a self-signed certificate (Preview)
13
13
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.
15
-
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.
14
+
Signing container images is a process that ensures their authenticity and integrity. This is achieved by adding a digital signature to the container image, which can be validated during deployment. The signature helps to verify that the image is from a trusted publisher and has not been modified. [Notation](https://github.com/notaryproject/notation) is an open source supply chain tool developed by the [Notary Project](https://notaryproject.dev/), which supports signing and verifying container images and other artifacts. The Azure Key Vault (AKV) is used to store certificates with signing keys that can be used 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 signatures to container images and other artifacts as well as view those signatures.
17
15
16
+
> [!IMPORTANT]
17
+
> This feature is currently in preview. Previews are made available to you on the condition that you agree to the [supplemental terms of use][terms-of-use]. Some aspects of this feature may change prior to general availability (GA).
18
18
19
19
In this tutorial:
20
20
21
21
> [!div class="checklist"]
22
-
> * Store a signing certificate in Azure Key Vault
23
-
> * Sign a container image with notation
24
-
> * Verify a container image signature with notation
22
+
> * Install Notation CLI and AKV plugin
23
+
> * Create a self-signed certificate in AKV
24
+
> * Build and push a container image with [ACR Tasks](container-registry-tasks-overview.md)
25
+
> * Sign a container image with Notation CLI and AKV plugin
26
+
> * Validate a container image against the signature with Notation CLI
25
27
26
28
## Prerequisites
27
29
28
-
> * Create and sign in ACR with OCI artifact enabled
29
-
> * Create or use an [Azure Key Vault](../key-vault/general/quick-create-cli.md)
30
-
>* This tutorial can be run in the [Azure Cloud Shell](https://portal.azure.com/#cloudshell/)
30
+
* Create or use an [Azure Container Registry](../container-registry/container-registry-get-started-azure-cli.md) for storing container images and signatures
31
+
* Create or use an [Azure Key Vault](../key-vault/general/quick-create-cli.md) for managing certificates
32
+
* Install and configure the latest [Azure CLI](/cli/azure/install-azure-cli), or Run commands in the [Azure Cloud Shell](https://portal.azure.com/#cloudshell/)
31
33
32
-
## Install the notation CLI and AKV plugin
34
+
## Install Notation CLI and AKV plugin
33
35
34
-
1. Install notation v1.0.0-rc.7 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/).
36
+
1. Install Notation v1.0.0 on a Linux amd64 environment. You can also download the package for other environments by following the [Notation installation guide](https://notaryproject.dev/docs/user-guides/installation/).
# Copy the notation cli to the desired bin directory in your PATH
43
+
# Copy the Notation binary to the desired bin directory in your $PATH, for example
42
44
cp ./notation /usr/local/bin
43
45
```
44
46
45
-
2. Install the notation Azure Key Vault plugin on a Linux environment for remote signing and verification. You can also download the package for other environments by following the [Notation AKV plugin installation guide](https://github.com/Azure/notation-azure-kv#installation-the-akv-plugin).
47
+
2. Install the Notation Azure Key Vault plugin on a Linux amd64 environment. You can also download the package for other environments by following the [Notation AKV plugin installation guide](https://github.com/Azure/notation-azure-kv#installation-the-akv-plugin).
46
48
47
49
> [!NOTE]
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.
50
+
> 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/user-guides/how-to/directory-structure/) for more information.
To learn more about Azure CLI and how to sign in with it, see [Sign in with Azure CLI](/cli/azure/authenticate-azure-cli).
108
+
109
+
## Assign access policy in AKV (Azure CLI)
110
+
111
+
A user principal with the correct access policy permissions is needed to create a self-signed certificate and sign artifacts. This principal can be a user principal, service principal, or managed identity. At a minimum, this principal needs the following permissions:
112
+
113
+
- `Create` permissions for certificates
114
+
- `Get` permissions for certificates
115
+
- `Sign` permissions for keys
116
+
117
+
In this tutorial, the access policy is assigned to a signed-in Azure user. To learn more about assigning policy to a principal, see [Assign Access Policy](/azure/key-vault/general/assign-access-policy).
100
118
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)
102
-
Otherwise create an x509 self-signed certificate storing it in AKV for remote signing using the steps below.
119
+
### Set the subscription that contains the AKV resource
103
120
104
-
### Create a self-signed certificate (Azure CLI)
121
+
```bash
122
+
az account set --subscription <your_subscription_id>
123
+
```
124
+
125
+
### Set the access policy in AKV
126
+
127
+
```bash
128
+
USER_ID=$(az ad signed-in-user show --query id -o tsv)
129
+
az keyvault set-policy -n $AKV_NAME --certificate-permissions create get --key-permissions sign --object-id $USER_ID
130
+
```
131
+
132
+
> [!IMPORTANT]
133
+
> This example shows the minimum permissions needed for creating a certificate and signing a container image. Depending on your requirements, you may need to grant additional permissions.
134
+
135
+
## Create a self-signed certificate in AKV (Azure CLI)
136
+
137
+
The following steps show how to create a self-signed certificate for testing purpose.
105
138
106
139
1. Create a certificate policy file.
107
140
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.
141
+
Once the certificate policy file is executed as below, it creates a valid certificate compatible with [Notary Project certificate requirement](https://github.com/notaryproject/specifications/blob/v1.0.0/specs/signature-specification.md#certificate-requirements) in AKV. The value for`ekus` 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.
109
142
110
143
```bash
111
144
cat <<EOF > ./my_policy.json
@@ -114,6 +147,12 @@ Otherwise create an x509 self-signed certificate storing it in AKV for remote si
114
147
"certificateTransparency": null,
115
148
"name": "Self"
116
149
},
150
+
"keyProperties": {
151
+
"exportable": false,
152
+
"keySize": 2048,
153
+
"keyType": "RSA",
154
+
"reuseKey": true
155
+
},
117
156
"x509CertificateProperties": {
118
157
"ekus": [
119
158
"1.3.6.1.5.5.7.3.3"
@@ -130,87 +169,79 @@ Otherwise create an x509 self-signed certificate storing it in AKV for remote si
130
169
131
170
2. Create the certificate.
132
171
133
-
```azure-cli
134
-
az keyvault certificate create -n $KEY_NAME --vault-name $AKV_NAME -p @my_policy.json
172
+
```bash
173
+
az keyvault certificate create -n $CERT_NAME --vault-name $AKV_NAME -p @my_policy.json
135
174
```
136
175
137
-
3. Get the Key ID for the certificate.
176
+
## Sign a container image with Notation CLI and AKV plugin
177
+
178
+
1. Authenticate to your ACR by using your individual Azure identity.
> If you have Docker installed on your system and used `az acr login` or `docker login` to authenticate to your ACR, your credentials are already stored and available to notation. In this case, you don’t need to run `notation login` again to authenticate to your ACR. To learn more about authentication options for notation, see [Authenticate with OCI-compliant registries](https://notaryproject.dev/docs/user-guides/how-to/registry-authentication/).
186
+
187
+
2. Build and push a new image with ACR Tasks. Always use the digest value to identify the image for signing since tags are mutable and can be overwritten.
7. Add the downloaded public certificateto named trust store for signature verification.
206
+
4. Sign the container image with the [COSE](https://datatracker.ietf.org/doc/html/rfc9052) signature format using the signing key ID. To sign with a self-signed certificate, you need to set the plugin configuration value `self_signed=true`.
5. View the graph of signed images and associated signatures.
171
213
172
214
```bash
173
-
notation cert ls
215
+
notation ls $IMAGE
174
216
```
175
217
176
-
## Build and sign a container image
177
-
178
-
1. Build and push a new image with ACR Tasks.
218
+
## Verify a container image with Notation CLI
179
219
180
-
```azure-cli
181
-
az acr build -r $ACR_NAME -t $IMAGE $IMAGE_SOURCE
182
-
```
220
+
To verify the container image, add the root certificate that signs the leaf certificate to the trust store and create trust policies for verification. For the self-signed certificate used in this tutorial, the root certificate is the self-signed certificate itself.
183
221
184
-
2. Authenticate with your individual Azure AD identity to use an ACR token.
az keyvault certificate download --name $CERT_NAME --vault-name $AKV_NAME --file $CERT_PATH
190
226
```
191
227
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/).
228
+
2. Add the downloaded public certificate to named trust store for signature verification.
194
229
195
-
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.
4. View the graph of signed images and associated signatures.
236
+
3. List the certificate to confirm.
202
237
203
238
```bash
204
-
notation ls $IMAGE
239
+
notation cert ls
205
240
```
241
+
242
+
4. Configure trust policy before verification.
206
243
207
-
## Verify the container image
208
-
209
-
1. Configure trust policy before verification.
210
-
211
-
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.
212
-
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://github.com/notaryproject/notaryproject/blob/main/specs/trust-store-trust-policy.md) for details.
244
+
Trust policies allow users to specify fine-tuned verification policies. The following example configures a trust policy named `wabbit-networks-images`, which applies to all artifacts in `$REGISTRY/$REPO` and uses the named trust store `$STORE_NAME` of type `$STORE_TYPE`. It also assumes that the user trusts a specific identity with the X.509 subject `$CERT_SUBJECT`. For more details, see [Trust store and trust policy specification](https://github.com/notaryproject/notaryproject/blob/v1.0.0/specs/trust-store-trust-policy.md).
214
245
215
246
```bash
216
247
cat <<EOF > ./trustpolicy.json
@@ -233,20 +264,23 @@ Otherwise create an x509 self-signed certificate storing it in AKV for remote si
233
264
EOF
234
265
```
235
266
236
-
3. Use `notation policy` to import the trust policy configuration from a JSON file that we created previously.
267
+
5. Use `notation policy` to import the trust policy configuration from a JSON file that we created previously.
237
268
238
269
```bash
239
270
notation policy import ./trustpolicy.json
240
271
notation policy show
241
272
```
242
273
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.
274
+
6. Use `notation verify` to verify the container image hasn't been altered since build time.
244
275
245
276
```bash
246
277
notation verify $IMAGE
247
278
```
279
+
248
280
Upon successful verification of the image using the trust policy, the sha256 digest of the verified image is returned in a successful output message.
249
281
250
282
## Next steps
251
283
252
284
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/quickstarts/ratify-on-azure.md).
0 commit comments