Skip to content

Commit 8bcb3ca

Browse files
authored
Merge pull request #114098 from danielsollondon/patch-22
May security reqs update
2 parents a821842 + c7cd4ed commit 8bcb3ca

File tree

1 file changed

+47
-11
lines changed

1 file changed

+47
-11
lines changed

articles/virtual-machines/linux/image-builder-gallery.md

Lines changed: 47 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: Use Azure Image Builder with an image gallery for Linux VMs (preview)
33
description: Create Linux VM images with Azure Image Builder and Shared Image Gallery.
44
author: cynthn
55
ms.author: cynthn
6-
ms.date: 04/20/2019
6+
ms.date: 05/05/2019
77
ms.topic: how-to
88
ms.service: virtual-machines-linux
99
ms.subservice: imaging
@@ -40,15 +40,17 @@ Check your registration.
4040

4141
```azurecli-interactive
4242
az provider show -n Microsoft.VirtualMachineImages | grep registrationState
43-
43+
az provider show -n Microsoft.KeyVault | grep registrationState
44+
az provider show -n Microsoft.Compute | grep registrationState
4445
az provider show -n Microsoft.Storage | grep registrationState
4546
```
4647

4748
If they do not say registered, run the following:
4849

4950
```azurecli-interactive
5051
az provider register -n Microsoft.VirtualMachineImages
51-
52+
az provider register -n Microsoft.Compute
53+
az provider register -n Microsoft.KeyVault
5254
az provider register -n Microsoft.Storage
5355
```
5456

@@ -85,18 +87,39 @@ Create the resource group.
8587
az group create -n $sigResourceGroup -l $location
8688
```
8789

90+
## Create a user-assigned identity and set permissions on the resource group
91+
Image Builder will use the [user-identity](https://docs.microsoft.com/azure/active-directory/managed-identities-azure-resources/qs-configure-cli-windows-vm#user-assigned-managed-identity) provided to inject the image into the Azure Shared Image Gallery (SIG). In this example, you will create an Azure role definition that has the granular actions to perform distributing the image to the SIG. The role definition will then be assigned to the user-identity.
8892

89-
Give Azure Image Builder permission to create resources in that resource group. The `--assignee` value is the app registration ID for the Image Builder service.
93+
```bash
94+
# create user assigned identity for image builder to access the storage account where the script is located
95+
idenityName=aibBuiUserId$(date +'%s')
96+
az identity create -g $sigResourceGroup -n $idenityName
9097

91-
```azurecli-interactive
92-
az role assignment create \
93-
--assignee cf32a0cc-373c-47c9-9156-0db11f6a6dfc \
94-
--role Contributor \
95-
--scope /subscriptions/$subscriptionID/resourceGroups/$sigResourceGroup
96-
```
98+
# get identity id
99+
imgBuilderCliId=$(az identity show -g $sigResourceGroup -n $idenityName | grep "clientId" | cut -c16- | tr -d '",')
100+
101+
# get the user identity URI, needed for the template
102+
imgBuilderId=/subscriptions/$subscriptionID/resourcegroups/$sigResourceGroup/providers/Microsoft.ManagedIdentity/userAssignedIdentities/$idenityName
103+
104+
# this command will download a Azure Role Definition template, and update the template with the parameters specified earlier.
105+
curl https://raw.githubusercontent.com/danielsollondon/azvmimagebuilder/master/solutions/12_Creating_AIB_Security_Roles/aibRoleImageCreation.json -o aibRoleImageCreation.json
106+
107+
imageRoleDefName="Azure Image Builder Image Def"$(date +'%s')
97108

109+
# update the definition
110+
sed -i -e "s/<subscriptionID>/$subscriptionID/g" aibRoleImageCreation.json
111+
sed -i -e "s/<rgName>/$sigResourceGroup/g" aibRoleImageCreation.json
112+
sed -i -e "s/Azure Image Builder Service Image Creation Role/$imageRoleDefName/g" aibRoleImageCreation.json
98113

114+
# create role definitions
115+
az role definition create --role-definition ./aibRoleImageCreation.json
99116

117+
# grant role definition to the user assigned identity
118+
az role assignment create \
119+
--assignee $imgBuilderCliId \
120+
--role $imageRoleDefName \
121+
--scope /subscriptions/$subscriptionID/resourceGroups/$sigResourceGroup
122+
```
100123

101124

102125
## Create an image definition and gallery
@@ -138,6 +161,7 @@ sed -i -e "s/<sharedImageGalName>/$sigName/g" helloImageTemplateforSIG.json
138161
sed -i -e "s/<region1>/$location/g" helloImageTemplateforSIG.json
139162
sed -i -e "s/<region2>/$additionalregion/g" helloImageTemplateforSIG.json
140163
sed -i -e "s/<runOutputName>/$runOutputName/g" helloImageTemplateforSIG.json
164+
sed -i -e "s%<imgBuilderId>%$imgBuilderId%g" helloImageTemplateforSIG.json
141165
```
142166

143167
## Create the image version
@@ -216,6 +240,18 @@ az resource delete \
216240
-n helloImageTemplateforSIG01
217241
```
218242

243+
Delete permissions asssignments, roles and identity
244+
```azurecli-interactive
245+
az role assignment delete \
246+
--assignee $imgBuilderCliId \
247+
--role "$imageRoleDefName" \
248+
--scope /subscriptions/$subscriptionID/resourceGroups/$sigResourceGroup
249+
250+
az role definition delete --name "$imageRoleDefName"
251+
252+
az identity delete --ids $imgBuilderId
253+
```
254+
219255
Get the image version created by image builder, this always starts with `0.`, and then delete the image version
220256

221257
```azurecli-interactive
@@ -257,4 +293,4 @@ az group delete -n $sigResourceGroup -y
257293

258294
## Next steps
259295

260-
Learn more about [Azure Shared Image Galleries](shared-image-galleries.md).
296+
Learn more about [Azure Shared Image Galleries](shared-image-galleries.md).

0 commit comments

Comments
 (0)