Skip to content

Commit 80cd4b1

Browse files
committed
update per Zack's comments
Signed-off-by: Yi Zha <[email protected]>
1 parent 5f21067 commit 80cd4b1

File tree

1 file changed

+26
-21
lines changed

1 file changed

+26
-21
lines changed

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

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ ms.date: 4/23/2023
1111

1212
# Sign container images with Notation and Azure Key Vault using a self-signed certificate (Preview)
1313

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 tampered with. [Notation](https://github.com/notaryproject/notation) is an open source supply chain tool developed by [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 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 and discover these signatures to container images.
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.
1515

1616
> [!IMPORTANT]
1717
> 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).
@@ -21,7 +21,7 @@ In this tutorial:
2121
> [!div class="checklist"]
2222
> * Install Notation CLI and AKV plugin
2323
> * Create a self-signed certificate in AKV
24-
> * Build and push a container image with ACR task
24+
> * Build and push a container image with [ACR Tasks](container-registry-tasks-overview.md)
2525
> * Sign a container image with Notation CLI and AKV plugin
2626
> * Validate a container image against the signature with Notation CLI
2727
@@ -108,7 +108,13 @@ To learn more about Azure CLI and how to sign in with it, see [Sign in with Azur
108108

109109
## Assign access policy in AKV (Azure CLI)
110110

111-
To create a self-signed certificate and sign a container image in AKV, you must assign proper access policy to a principal. The permissions that you grant for a principal should include at least certificate permissions `Create` and `Get` for creating and getting certificates, and key permissions `Sign` for signing. A principal can be user principal, service principal or managed identity. 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).
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).
112118

113119
### Set the subscription that contains the AKV resource
114120

@@ -123,16 +129,16 @@ USER_ID=$(az ad signed-in-user show --query id -o tsv)
123129
az keyvault set-policy -n $AKV_NAME --certificate-permissions create get --key-permissions sign --object-id $USER_ID
124130
```
125131

126-
> [!NOTE]
127-
> The permissions granted are necessary for creating a certificate and signing a container image. Depending on your requirements, you may need to grant additional permissions.
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.
128134

129135
## Create a self-signed certificate in AKV (Azure CLI)
130136

131137
The following steps show how to create a self-signed certificate for testing purpose.
132138

133139
1. Create a certificate policy file.
134140

135-
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 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.
136142
137143
```bash
138144
cat <<EOF > ./my_policy.json
@@ -169,31 +175,29 @@ The following steps show how to create a self-signed certificate for testing pur
169175
170176
## Sign a container image with Notation CLI and AKV plugin
171177
172-
1. Build and push a new image with ACR Tasks. Always use digest to identify the image for signing, because tags are mutable and and can be overwritten.
178+
1. Authenticate to your ACR by using your individual Azure identity.
173179
174180
```bash
175-
DIGEST=$(az acr build -r $ACR_NAME -t $REGISTRY/${REPO}:$TAG $IMAGE_SOURCE --no-logs --query "outputImages[0].digest" -o tsv)
176-
IMAGE=$REGISTRY/${REPO}@$DIGEST
181+
az acr login --name $ACR_NAME
177182
```
178183
179-
2. Authenticate with your individual Azure AD identity to use an ACR token.
184+
> [!IMPORTANT]
185+
> 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/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 and can be overwritten.
180188
181189
```bash
182-
USER_NAME="00000000-0000-0000-0000-000000000000"
183-
PASSWORD=$(az acr login --name $ACR_NAME --expose-token --output tsv --query accessToken)
184-
notation login -u $USER_NAME -p $PASSWORD $REGISTRY
190+
DIGEST=$(az acr build -r $ACR_NAME -t $REGISTRY/${REPO}:$TAG $IMAGE_SOURCE --no-logs --query "outputImages[0].digest" -o tsv)
191+
IMAGE=$REGISTRY/${REPO}@$DIGEST
185192
```
186193
187-
> [!NOTE]
188-
> If notation login is failing, you may need to configure a credentials store. Alternatively in development and testing environments, you can use environment variables to authenticate to an OCI-compliant registry. See guide [Authenticate with OCI-compliant registries](https://notaryproject.dev/docs/how-to/registry-authentication/) for details.
189-
190-
3. Get the Key ID of the signing key. A certificate in AKV can have multiple versions, the following command get the Key Id of the latest version.
194+
3. Get the Key ID of the signing key. A certificate in AKV can have multiple versions, the following command gets the Key Id of the latest version.
191195
192196
```bash
193197
KEY_ID=$(az keyvault certificate show -n $CERT_NAME --vault-name $AKV_NAME --query 'kid' -o tsv)
194198
```
195199
196-
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 pass a plugin configuration `self_signed=true` in the command line.
200+
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`.
197201
198202
```bash
199203
notation sign --signature-format cose --id $KEY_ID --plugin azure-kv --plugin-config self_signed=true $IMAGE
@@ -207,7 +211,7 @@ The following steps show how to create a self-signed certificate for testing pur
207211
208212
## Verify a container image with Notation CLI
209213
210-
To verify the container image, you need to add the root certificate that signs the certificate to a trust store and create trust policies for verification. For a self-signed certificate used in this tutorial, the root certificate is the self-signed certificate itself.
214+
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.
211215
212216
1. Download public certificate.
213217
@@ -231,7 +235,7 @@ To verify the container image, you need to add the root certificate that signs t
231235
232236
4. Configure trust policy before verification.
233237
234-
Trust policies allow users to specify fine-tuned verification policies. 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`. Assuming that the user trusts a specific identity with the X.509 subject `$CERT_SUBJECT`, which is used for the certificate. The named trust store `$STORE_NAME` of type `$STORE_TYPE` contains the root certificates. See [Trust store and trust policy specification](https://github.com/notaryproject/notaryproject/blob/v1.0.0/specs/trust-store-trust-policy.md) for details.
238+
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).
235239
236240
```bash
237241
cat <<EOF > ./trustpolicy.json
@@ -261,11 +265,12 @@ To verify the container image, you need to add the root certificate that signs t
261265
notation policy show
262266
```
263267
264-
6. 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.
268+
6. Use `notation verify` to verify the container image hasn't been altered since build time.
265269

266270
```bash
267271
notation verify $IMAGE
268272
```
273+
269274
Upon successful verification of the image using the trust policy, the sha256 digest of the verified image is returned in a successful output message.
270275

271276
## Next steps

0 commit comments

Comments
 (0)