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
Copy file name to clipboardExpand all lines: articles/container-registry/container-registry-tutorial-sign-build-push.md
+65-15Lines changed: 65 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -64,6 +64,8 @@ In this tutorial:
64
64
1. Configure AKV resource names.
65
65
66
66
```bash
67
+
AKV_SUB_ID=myAkvSubscriptionId
68
+
AKV_RG=myAkvResourceGroup
67
69
# Name of the existing AKV used to store the signing keys
68
70
AKV_NAME=myakv
69
71
# Name of the certificate created in AKV
@@ -75,6 +77,8 @@ In this tutorial:
75
77
2. Configure ACR and image resource names.
76
78
77
79
```bash
80
+
ACR_SUB_ID=myAcrSubscriptionId
81
+
ACR_RG=myAcrResourceGroup
78
82
# Name of the existing registry example: myregistry.azurecr.io
79
83
ACR_NAME=myregistry
80
84
# Existing full domain of the ACR
@@ -95,28 +99,74 @@ az login
95
99
96
100
To learn more about Azure CLI and how to sign in with it, see [Sign in with Azure CLI](/cli/azure/authenticate-azure-cli).
97
101
98
-
## Assign access policy in AKV (Azure CLI)
102
+
## Secure access permissions to ACR and AKV
99
103
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.
101
105
102
-
- `Create` permissions for certificates
103
-
- `Get` permissions for certificates
104
-
- `Sign` permissions for keys
106
+
### Authorize access to ACR
105
107
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.
107
109
108
-
### Set the subscription that contains the AKV resource
110
+
1. Set the subscription that contains the ACR resource
109
111
110
-
```bash
111
-
az account set --subscription <your_subscription_id>
112
-
```
112
+
```bash
113
+
az account set --subscription $ACR_SUB_ID
114
+
```
113
115
114
-
### Set the access policy in AKV
116
+
2. Assign the roles
115
117
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
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
+
```
120
170
121
171
> [!IMPORTANT]
122
172
> 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.
Copy file name to clipboardExpand all lines: articles/container-registry/container-registry-tutorial-sign-trusted-ca.md
+88-30Lines changed: 88 additions & 30 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -73,10 +73,11 @@ In this article:
73
73
> [!NOTE]
74
74
> This guide uses environment variables for convenience when configuring the AKV and ACR. Update the values of these environment variables for your specific resources.
75
75
76
-
1. Configure AKV resource names.
76
+
1. Configure environment variables for AKV and certificates
77
77
78
78
```bash
79
-
# Name of the existing Azure Key Vault used to store the signing keys
79
+
AKV_SUB_ID=myAkvSubscriptionId
80
+
AKV_RG=myAkvResourceGroup
80
81
AKV_NAME=myakv
81
82
82
83
# Name of the certificate created or imported in AKV
2. Configure environment variables for ACR and images.
90
91
91
92
```bash
93
+
ACR_SUB_ID=myAcrSubscriptionId
94
+
ACR_RG=myAcrResourceGroup
92
95
# Name of the existing registry example: myregistry.azurecr.io
93
96
ACR_NAME=myregistry
94
97
# Existing full domain of the ACR
@@ -151,7 +154,28 @@ To import the certificate:
151
154
> [!NOTE]
152
155
> 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).
153
156
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
155
179
156
180
1. Authenticate to your ACR by using your individual Azure identity.
157
181
@@ -162,50 +186,85 @@ To import the certificate:
162
186
> [!IMPORTANT]
163
187
> 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/).
164
188
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.
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
173
207
174
208
```bash
175
-
IMAGE=$REGISTRY/${REPO}@$TAG
209
+
az account set --subscription $AKV_SUB_ID
176
210
```
177
211
178
-
3. Assign access policy in AKV using the Azure CLI
212
+
1. Assign the roles
179
213
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:
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)
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:
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)
196
236
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
201
260
202
-
4. Get the Key ID fora certificate. A certificatein 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.
0 commit comments