Skip to content

Commit 87c7417

Browse files
authored
Merge pull request #102648 from yizha1/yizha1-sign
update to latest notation cli
2 parents 8c7d7eb + c774d6e commit 87c7417

File tree

1 file changed

+79
-58
lines changed

1 file changed

+79
-58
lines changed

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

Lines changed: 79 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ author: dtzar
55
ms.author: davete
66
ms.service: container-registry
77
ms.topic: how-to
8-
ms.date: 10/11/2022
8+
ms.date: 12/12/2022
99
---
1010

1111
# Build, sign, and verify container images using Notary and Azure Key Vault (Preview)
@@ -24,20 +24,17 @@ In this tutorial:
2424
2525
## Prerequisites
2626

27-
> * Install, create and sign in to [ORAS artifact enabled registry](./container-registry-oras-artifacts.md#create-oras-artifact-enabled-registry)
27+
> * Install, create and sign in to OCI artifact enabled registry ACR
2828
> * Create or use an [Azure Key Vault](../key-vault/general/quick-create-cli.md)
2929
>* This tutorial can be run in the [Azure Cloud Shell](https://portal.azure.com/#cloudshell/)
3030
3131
## Install the notation CLI and AKV plugin
3232

33-
> [!NOTE]
34-
> The tutorial uses early released versions of notation and notation plugins.
35-
36-
1. Install notation 0.11.0-alpha.4 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/v0.11.0-alpha.4).
33+
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).
3734

3835
```bash
3936
# Download, extract and install
40-
curl -Lo notation.tar.gz https://github.com/notaryproject/notation/releases/download/v0.11.0-alpha.4/notation_0.11.0-alpha.4_linux_amd64.tar.gz
37+
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
4138
tar xvzf notation.tar.gz
4239

4340
# Copy the notation cli to the desired bin directory in your PATH
@@ -48,15 +45,15 @@ In this tutorial:
4845

4946
> [!NOTE]
5047
> The plugin directory varies depending upon the operating system being used. The directory path below assumes Ubuntu.
51-
> Please read the [notation config article](https://github.com/notaryproject/notation/blob/main/specs/notation-config.md) for more information.
48+
> 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.
5249

5350
```bash
5451
# Create a directory for the plugin
5552
mkdir -p ~/.config/notation/plugins/azure-kv
5653
5754
# Download the plugin
5855
curl -Lo notation-azure-kv.tar.gz \
59-
https://github.com/Azure/notation-azure-kv/releases/download/v0.4.0-alpha.4/notation-azure-kv_0.4.0-alpha.4_Linux_amd64.tar.gz
56+
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
6057
6158
# Extract to the plugin directory
6259
tar xvzf notation-azure-kv.tar.gz -C ~/.config/notation/plugins/azure-kv notation-azure-kv
@@ -80,7 +77,7 @@ In this tutorial:
8077
AKV_NAME=<your-unique-keyvault-name>
8178
# New desired key name used to sign and verify
8279
KEY_NAME=wabbit-networks-io
83-
KEY_SUBJECT_NAME=wabbit-networks.io
80+
CERT_SUBJECT="CN=wabbit-networks.io,O=Notary,L=Seattle,ST=WA,C=US"
8481
CERT_PATH=./${KEY_NAME}.pem
8582
```
8683

@@ -101,14 +98,14 @@ In this tutorial:
10198

10299
## Store the signing certificate in AKV
103100

104-
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/main/specs/signature-specification.md#certificate-requirements)
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/notaryproject/notaryproject/blob/v1.0.0-rc.1/specs/signature-specification.md)
105102
Otherwise create an x509 self-signed certificate storing it in AKV for remote signing using the steps below.
106103

107104
### Create a self-signed certificate (Azure CLI)
108105

109106
1. Create a certificate policy file.
110107

111-
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.
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 tursts during verification.
112109
113110
```bash
114111
cat <<EOF > ./my_policy.json
@@ -121,44 +118,60 @@ Otherwise create an x509 self-signed certificate storing it in AKV for remote si
121118
"ekus": [
122119
"1.3.6.1.5.5.7.3.3"
123120
],
124-
"subject": "CN=${KEY_SUBJECT_NAME}",
121+
"keyUsage": [
122+
"digitalSignature"
123+
],
124+
"subject": "$CERT_SUBJECT",
125125
"validityInMonths": 12
126126
}
127127
}
128128
EOF
129129
```
130130
131-
1. Create the certificate.
131+
2. Create the certificate.
132132
133133
```azure-cli
134134
az keyvault certificate create -n $KEY_NAME --vault-name $AKV_NAME -p @my_policy.json
135135
```
136136
137-
1. Get the Key ID for the certificate.
137+
3. Get the Key ID for the certificate.
138138
139139
```bash
140140
KEY_ID=$(az keyvault certificate show -n $KEY_NAME --vault-name $AKV_NAME --query 'kid' -o tsv)
141141
```
142+
142143
4. Download public certificate.
143144
144145
```bash
145146
CERT_ID=$(az keyvault certificate show -n $KEY_NAME --vault-name $AKV_NAME --query 'id' -o tsv)
146147
az keyvault certificate download --file $CERT_PATH --id $CERT_ID --encoding PEM
147148
```
148149
149-
5. Add the Key ID to the keys and certs.
150+
5. Add a signing key referencing the key id.
150151
151152
```bash
152-
notation key add --name $KEY_NAME --plugin azure-kv --id $KEY_ID
153-
notation cert add --name $KEY_NAME $CERT_PATH
153+
notation key add $KEY_NAME --plugin azure-kv --id $KEY_ID
154154
```
155155
156-
6. List the keys and certs to confirm.
156+
6. List the keys to confirm.
157157
158-
```bash
159-
notation key ls
160-
notation cert ls
161-
```
158+
```bash
159+
notation key ls
160+
```
161+
162+
7. Add the downloaded public certificate to named trust store for signature verification.
163+
164+
```bash
165+
STORE_TYPE="ca"
166+
STORE_NAME="wabbit-networks.io"
167+
notation cert add --type $STORE_TYPE --store $STORE_NAME $CERT_PATH
168+
```
169+
170+
8. List the certificate to confirm
171+
172+
```bash
173+
notation cert ls
174+
```
162175
163176
## Build and sign a container image
164177
@@ -173,26 +186,24 @@ Otherwise create an x509 self-signed certificate storing it in AKV for remote si
173186
```azure-cli
174187
export USER_NAME="00000000-0000-0000-0000-000000000000"
175188
export PASSWORD=$(az acr login --name $ACR_NAME --expose-token --output tsv --query accessToken)
176-
export NOTATION_PASSWORD=$PASSWORD
189+
notation login -u $USER_NAME -p $PASSWORD $REGISTRY
177190
```
178191
179-
3. Choose [COSE](https://datatracker.ietf.org/doc/html/rfc8152) or JWS signature envelope to sign the container image.
180-
181-
- Sign the container image with the COSE signature envelope:
192+
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.
182193
183194
```bash
184-
notation sign --envelope-type cose --key $KEY_NAME $IMAGE
185-
```
186-
187-
- Sign the container image with the default JWS signature envelope:
188-
189-
```bash
190-
notation sign --key $KEY_NAME $IMAGE
195+
notation sign --signature-format cose --key $KEY_NAME $IMAGE
191196
```
192197
193-
## View the graph of artifacts with the ORAS CLI
198+
4. View the graph of signed images and associated signatures.
199+
200+
```bash
201+
notation ls $IMAGE
202+
```
194203
195-
ACR support for ORAS artifacts enables a linked graph of supply chain artifacts that can be viewed through the ORAS CLI or the Azure CLI.
204+
## [Option] View the graph of artifacts with the ORAS CLI
205+
206+
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.
196207
197208
1. Signed images can be view with the ORAS CLI.
198209
@@ -201,15 +212,15 @@ ACR support for ORAS artifacts enables a linked graph of supply chain artifacts
201212
oras discover -o tree $IMAGE
202213
```
203214
204-
## View the graph of artifacts with the Azure CLI
215+
## [Option] View the graph of artifacts with the Azure CLI
205216
206217
1. List the manifest details for the container image.
207218
208219
```azure-cli
209220
az acr manifest show-metadata $IMAGE -o jsonc
210221
```
211222
212-
2. Generates a result, showing the `digest` representing the notary v2 signature.
223+
2. Generates a result, showing the `digest` representing the notary v2 signature.
213224
214225
```json
215226
{
@@ -230,29 +241,39 @@ ACR support for ORAS artifacts enables a linked graph of supply chain artifacts
230241
231242
## Verify the container image
232243
233-
1. 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.
234-
235-
```bash
236-
notation verify $IMAGE
237-
sha256:effba96d9b7092a0de4fa6710f6e73bf8c838e4fbd536e95de94915777b18613
238-
```
239-
The sha256 result is a successful verification of the image using the trusted certificate.
244+
1. Configure trust policy before verification.
240245
241-
2. We can add a different local signing certificate to show how multiple certificates and verification failures work.
242-
243-
```bash
244-
notation cert generate-test -n localcert --trust true
245-
notation verify $IMAGE
246-
sha256:effba96d9b7092a0de4fa6710f6e73bf8c838e4fbd536e95de94915777b18613
247-
```
246+
The trust policy is a JSON document named `trustpolicy.jsoin`, which is stored under notation configuration directory. Users who verify signed artifact from a registry use the trust policy to specify trusted identities which sign the artifacts, and level of signature verification to use.
247+
248+
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 under repository `$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`.
248249
249-
We can see that verification still passes because `notation verify` will implicitly pass with _any_ certificate in its trust store. To get a verification failure, we'll remove the certificate utilized to sign the image.
250+
```bash
251+
cat <<EOF > $HOME/.config/notation/trustpolicy.json
252+
{
253+
"version": "1.0",
254+
"trustPolicies": [
255+
{
256+
"name": "wabbit-networks-images",
257+
"registryScopes": [ "$REGISTRY/$REPO" ],
258+
"signatureVerification": {
259+
"level" : "strict"
260+
},
261+
"trustStores": [ "$STORE_TYPE:$STORE_NAME" ],
262+
"trustedIdentities": [
263+
"x509.subject: $CERT_SUBJECT"
264+
]
265+
}
266+
]
267+
}
268+
EOF
269+
```
270+
271+
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.
250272

251-
```azure-cli
252-
notation cert rm $KEY_NAME
253-
notation verify $IMAGE
254-
2022/06/10 11:24:30 verification failure: x509: certificate signed by unknown authority
255-
```
273+
```bash
274+
notation verify $IMAGE
275+
```
276+
Upon successful verification of the image using the trust policy, the sha256 digest of the verified image is returned in a successful output messages.
256277

257278
## Next steps
258279

0 commit comments

Comments
 (0)