Skip to content

Commit f3e3184

Browse files
Merge pull request #275840 from yizha1/add_rabc
docs: add Azure RBAC for access control
2 parents 2aadfc0 + 71cedc9 commit f3e3184

File tree

2 files changed

+153
-45
lines changed

2 files changed

+153
-45
lines changed

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

Lines changed: 65 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ In this tutorial:
6464
1. Configure AKV resource names.
6565
6666
```bash
67+
AKV_SUB_ID=myAkvSubscriptionId
68+
AKV_RG=myAkvResourceGroup
6769
# Name of the existing AKV used to store the signing keys
6870
AKV_NAME=myakv
6971
# Name of the certificate created in AKV
@@ -75,6 +77,8 @@ In this tutorial:
7577
2. Configure ACR and image resource names.
7678
7779
```bash
80+
ACR_SUB_ID=myAcrSubscriptionId
81+
ACR_RG=myAcrResourceGroup
7882
# Name of the existing registry example: myregistry.azurecr.io
7983
ACR_NAME=myregistry
8084
# Existing full domain of the ACR
@@ -95,28 +99,74 @@ az login
9599
96100
To learn more about Azure CLI and how to sign in with it, see [Sign in with Azure CLI](/cli/azure/authenticate-azure-cli).
97101
98-
## Assign access policy in AKV (Azure CLI)
102+
## Secure access permissions to ACR and AKV
99103
100-
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:
104+
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 is authorized to a signed-in Azure user.
101105
102-
- `Create` permissions for certificates
103-
- `Get` permissions for certificates
104-
- `Sign` permissions for keys
106+
### Authorize access to ACR
105107
106-
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).
108+
The `AcrPull` and `AcrPush` roles are required for signing container images in ACR.
107109
108-
### Set the subscription that contains the AKV resource
110+
1. Set the subscription that contains the ACR resource
109111
110-
```bash
111-
az account set --subscription <your_subscription_id>
112-
```
112+
```bash
113+
az account set --subscription $ACR_SUB_ID
114+
```
113115
114-
### Set the access policy in AKV
116+
2. Assign the roles
115117
116-
```bash
117-
USER_ID=$(az ad signed-in-user show --query id -o tsv)
118-
az keyvault set-policy -n $AKV_NAME --certificate-permissions create get --key-permissions sign --object-id $USER_ID
119-
```
118+
```bash
119+
USER_ID=$(az ad signed-in-user show --query id -o tsv)
120+
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"
121+
```
122+
123+
### Authorize access to AKV
124+
125+
In this section, we’ll explore two options for authorizing access to AKV.
126+
127+
#### Use Azure RBAC (Recommended)
128+
129+
The following roles are required for signing using self-signed certificates:
130+
- `Key Vault Certificates Officer` for creating and reading certificates
131+
- `Key Vault Certificates User`for reading existing certificates
132+
- `Key Vault Crypto User` for signing operations
133+
134+
To learn more about Key Vault access with Azure RBAC, see [Use an Azure RBAC for managing access](/azure/key-vault/general/rbac-guide).
135+
136+
1. Set the subscription that contains the AKV resource
137+
138+
```bash
139+
az account set --subscription $AKV_SUB_ID
140+
```
141+
142+
2. Assign the roles
143+
144+
```bash
145+
USER_ID=$(az ad signed-in-user show --query id -o tsv)
146+
az role assignment create --role "Key Vault Certificates Officer" --role "Key Vault Crypto User" --assignee $USER_ID --scope "/subscriptions/$AKV_SUB_ID/resourceGroups/$AKV_RG/providers/Microsoft.KeyVault/vaults/$AKV_NAME"
147+
```
148+
149+
#### Assign access policy in AKV (legacy)
150+
151+
The following permissions are required for an identity:
152+
- `Create` permissions for creating a certificate
153+
- `Get` permissions for reading existing certificates
154+
- `Sign` permissions for signing operations
155+
156+
To learn more about assigning policy to a principal, see [Assign Access Policy](/azure/key-vault/general/assign-access-policy).
157+
158+
1. Set the subscription that contains the AKV resource:
159+
160+
```bash
161+
az account set --subscription $AKV_SUB_ID
162+
```
163+
164+
2. Set the access policy in AKV:
165+
166+
```bash
167+
USER_ID=$(az ad signed-in-user show --query id -o tsv)
168+
az keyvault set-policy -n $AKV_NAME --certificate-permissions create get --key-permissions sign --object-id $USER_ID
169+
```
120170
121171
> [!IMPORTANT]
122172
> 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.

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

Lines changed: 88 additions & 30 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,50 +186,85 @@ 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)
169193
IMAGE=$REGISTRY/${REPO}@$DIGEST
170194
```
171195
172-
In this tutorial, if the image has already been built and is stored in the registry, the tag serves as an identifier for that image for convenience.
196+
In this tutorial, if the image has already been built and is stored in the registry, the tag serves as an identifier for that image for convenience.
197+
198+
```bash
199+
IMAGE=$REGISTRY/${REPO}@$TAG
200+
```
201+
202+
### Authoring access to AKV
203+
204+
#### Use Azure RBAC (Recommended)
205+
206+
1. Set the subscription that contains the AKV resource
173207
174208
```bash
175-
IMAGE=$REGISTRY/${REPO}@$TAG
209+
az account set --subscription $AKV_SUB_ID
176210
```
177211
178-
3. Assign access policy in AKV using the Azure CLI
212+
1. Assign the roles
179213
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:
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
183218
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:
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+
```
189223
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:
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
@@ -220,7 +279,6 @@ To import the certificate:
220279
```
221280
222281
To authenticate with AKV, by default, the following credential types if enabled will be tried in order:
223-
224282
- [Environment credential](/dotnet/api/azure.identity.environmentcredential)
225283
- [Workload identity credential](/dotnet/api/azure.identity.workloadidentitycredential)
226284
- [Managed identity credential](/dotnet/api/azure.identity.managedidentitycredential)
@@ -241,7 +299,7 @@ To import the certificate:
241299
| Managed identity credential | `managedid` |
242300
| Azure CLI credential | `azurecli` |
243301
244-
6. View the graph of signed images and associated signatures.
302+
1. View the graph of signed images and associated signatures.
245303
246304
```bash
247305
notation ls $IMAGE

0 commit comments

Comments
 (0)