Skip to content

Commit d6f2165

Browse files
committed
update RBAC for signing with CA issued certificates
Signed-off-by: Yi Zha <[email protected]>
1 parent 3b955df commit d6f2165

File tree

1 file changed

+86
-27
lines changed

1 file changed

+86
-27
lines changed

articles/container-registry/container-registry-tutorial-sign-trusted-ca.md

Lines changed: 86 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,11 @@ In this article:
7373
> [!NOTE]
7474
> This guide uses environment variables for convenience when configuring the AKV and ACR. Update the values of these environment variables for your specific resources.
7575
76-
1. Configure AKV resource names.
76+
1. Configure environment variables for AKV and certificates
7777
7878
```bash
79-
# Name of the existing Azure Key Vault used to store the signing keys
79+
AKV_SUB_ID=myAkvSubscriptionId
80+
AKV_RG=myAkvResourceGroup
8081
AKV_NAME=myakv
8182
8283
# Name of the certificate created or imported in AKV
@@ -86,9 +87,11 @@ In this article:
8687
CERT_SUBJECT="CN=wabbit-networks.io,O=Notation,L=Seattle,ST=WA,C=US"
8788
```
8889
89-
2. Configure ACR and image resource names.
90+
2. Configure environment variables for ACR and images.
9091
9192
```bash
93+
ACR_SUB_ID=myAcrSubscriptionId
94+
ACR_RG=myAcrResourceGroup
9295
# Name of the existing registry example: myregistry.azurecr.io
9396
ACR_NAME=myregistry
9497
# Existing full domain of the ACR
@@ -151,7 +154,28 @@ To import the certificate:
151154
> [!NOTE]
152155
> If the certificate does not contain a certificate chain after creation or importing, you can obtain the intermediate and root certificates from your CA vendor. You can ask your vendor to provide you with a PEM file that contains the intermediate certificates (if any) and root certificate. This file can then be used at step 5 of [signing container images](#sign-a-container-image-with-notation-cli-and-akv-plugin).
153156
154-
## Sign a container image with Notation CLI and AKV plugin
157+
## Sign a container image with Notation CLI and AKV plugin
158+
159+
When working with ACR and AKV, it’s essential to grant the appropriate permissions to ensure secure and controlled access. You can authorize access for different entities, such as user principals, service principals, or managed identities, depending on your specific scenarios. In this tutorial, the access are authorized to a signed-in Azure user.
160+
161+
### Authoring access to ACR
162+
163+
The `AcrPull` and `AcrPush` roles are required for building and signing container images in ACR.
164+
165+
1. Set the subscription that contains the ACR resource
166+
167+
```bash
168+
az account set --subscription $ACR_SUB_ID
169+
```
170+
171+
1. Assign the roles
172+
173+
```bash
174+
USER_ID=$(az ad signed-in-user show --query id -o tsv)
175+
az role assignment create --role "AcrPull" --role "AcrPush" --assignee $USER_ID --scope "/subscriptions/$ACR_SUB_ID/resourceGroups/$ACR_RG/providers/Microsoft.ContainerRegistry/registries/$ACR_NAME"
176+
```
177+
178+
### Build and push container images to ACR
155179
156180
1. Authenticate to your ACR by using your individual Azure identity.
157181
@@ -162,7 +186,7 @@ To import the certificate:
162186
> [!IMPORTANT]
163187
> 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/).
164188
165-
2. Build and push a new image with ACR Tasks. Always use `digest` to identify the image for signing, since tags are mutable and can be overwritten.
189+
1. Build and push a new image with ACR Tasks. Always use `digest` to identify the image for signing, since tags are mutable and can be overwritten.
166190
167191
```bash
168192
DIGEST=$(az acr build -r $ACR_NAME -t $REGISTRY/${REPO}:$TAG $IMAGE_SOURCE --no-logs --query "outputImages[0].digest" -o tsv)
@@ -175,37 +199,72 @@ To import the certificate:
175199
IMAGE=$REGISTRY/${REPO}@$TAG
176200
```
177201
178-
3. Assign access policy in AKV using the Azure CLI
202+
### Authoring access to AKV
179203
180-
To sign a container image with a certificate in AKV, a principal must have authorized access to AKV. The principal can be a user principal, service principal, or managed identity. In this tutorial, we assign an access policy to a signed-in user. To learn more about assigning policy to a principal, see [Assign Access Policy](/azure/key-vault/general/assign-access-policy).
181-
182-
To set the subscription that contains the AKV resources, run the following command:
204+
#### Use Azure RBAC (Recommended)
183205
184-
```bash
185-
az account set --subscription <your_subscription_id>
186-
```
187-
188-
If the certificate contains the entire certificate chain, the principal must be granted key permission `Sign`, secret permission `Get`, and certificate permissions `Get`. To grant these permissions to the principal:
206+
1. Set the subscription that contains the AKV resource
189207
190-
```bash
191-
USER_ID=$(az ad signed-in-user show --query id -o tsv)
192-
az keyvault set-policy -n $AKV_NAME --key-permissions sign --secret-permissions get --certificate-permissions get --object-id $USER_ID
193-
```
194-
195-
If the certificate doesn't contain the chain, the principal must be granted key permission `Sign`, and certificate permissions `Get`. To grant these permissions to the principal:
208+
```bash
209+
az account set --subscription $AKV_SUB_ID
210+
```
211+
212+
1. Assign the roles
213+
214+
If the certificate contains the entire certificate chain, the principal must be assigned with the following roles:
215+
- `Key Vault Secrets User` for reading secrets
216+
- `Key Vault Certificates User`for reading certificates
217+
- `Key Vault Crypto User` for signing operations
218+
219+
```bash
220+
USER_ID=$(az ad signed-in-user show --query id -o tsv)
221+
az role assignment create --role "Key Vault Secrets User" --role "Key Vault Certificates User" --role "Key Vault Crypto User" --assignee $USER_ID --scope "/subscriptions/$AKV_SUB_ID/resourceGroups/$AKV_RG/providers/Microsoft.KeyVault/vaults/$AKV_NAME"
222+
```
223+
224+
If the certificate doesn't contain the chain, the principal must be assigned with the following roles:
225+
- `Key Vault Certificates User`for reading certificates
226+
- `Key Vault Crypto User` for signing operations
227+
228+
```bash
229+
USER_ID=$(az ad signed-in-user show --query id -o tsv)
230+
az role assignment create --role "Key Vault Certificates User" --role "Key Vault Crypto User" --assignee $USER_ID --scope "/subscriptions/$AKV_SUB_ID/resourceGroups/$AKV_RG/providers/Microsoft.KeyVault/vaults/$AKV_NAME"
231+
```
232+
233+
To learn more about Key Vault access with Azure RBAC, see [Use an Azure RBAC for managing access](/azure/key-vault/general/rbac-guide).
234+
235+
#### Use access policy (Legacy)
196236

197-
```bash
198-
USER_ID=$(az ad signed-in-user show --query id -o tsv)
199-
az keyvault set-policy -n $AKV_NAME --key-permissions sign --certificate-permissions get --object-id $USER_ID
200-
```
237+
To set the subscription that contains the AKV resources, run the following command:
238+
239+
```bash
240+
az account set --subscription $AKV_SUB_ID
241+
```
242+
243+
If the certificate contains the entire certificate chain, the principal must be granted key permission `Sign`, secret permission `Get`, and certificate permissions `Get`. To grant these permissions to the principal:
244+
245+
```bash
246+
USER_ID=$(az ad signed-in-user show --query id -o tsv)
247+
az keyvault set-policy -n $AKV_NAME --key-permissions sign --secret-permissions get --certificate-permissions get --object-id $USER_ID
248+
```
249+
250+
If the certificate doesn't contain the chain, the principal must be granted key permission `Sign`, and certificate permissions `Get`. To grant these permissions to the principal:
251+
252+
```bash
253+
USER_ID=$(az ad signed-in-user show --query id -o tsv)
254+
az keyvault set-policy -n $AKV_NAME --key-permissions sign --certificate-permissions get --object-id $USER_ID
255+
```
256+
257+
To learn more about assigning policy to a principal, see [Assign Access Policy](/azure/key-vault/general/assign-access-policy).
258+
259+
### Sign container images using the certificate in AKV
201260
202-
4. Get the Key ID for a certificate. A certificate in AKV can have multiple versions, the following command gets the Key ID for the latest version of the `$CERT_NAME` certificate.
261+
1. Get the Key ID for a certificate. A certificate in AKV can have multiple versions, the following command gets the Key ID for the latest version of the `$CERT_NAME` certificate.
203262
204263
```bash
205264
KEY_ID=$(az keyvault certificate show -n $CERT_NAME --vault-name $AKV_NAME --query 'kid' -o tsv)
206265
```
207266
208-
5. Sign the container image with the COSE signature format using the Key ID.
267+
1. Sign the container image with the COSE signature format using the Key ID.
209268
210269
If the certificate contains the entire certificate chain, run the following command:
211270
@@ -241,7 +300,7 @@ To import the certificate:
241300
| Managed identity credential | `managedid` |
242301
| Azure CLI credential | `azurecli` |
243302
244-
6. View the graph of signed images and associated signatures.
303+
1. View the graph of signed images and associated signatures.
245304
246305
```bash
247306
notation ls $IMAGE

0 commit comments

Comments
 (0)