Azure CLI를 사용하여 Azure VM Image Builder 권한 구성

적용 대상: ✔️ Linux VM ✔️ 유연한 확장 집합

Azure VM Image Builder에 등록하면 구독을 통해 VM Image Builder SPN(서비스 사용자 이름)에 액세스할 수 있습니다. 등록은 스테이징 리소스 그룹을 만들고, 관리하고, 삭제할 수 있는 권한을 서비스에 부여합니다. 이미지 빌드 프로세스의 경우 스테이징 리소스 그룹에서도 참가자 역할 할당이 필요합니다.

VM Image Builder에서 이미지를 배포하려면 이미지를 읽고 쓸 수 있는 권한이 있는 Azure에서 사용자 할당 ID를 만들어야 합니다. 예를 들어 관리되는 이미지나 Azure Compute Gallery에 이미지를 배포할 수 있습니다. Azure Storage에 액세스하는 경우 만드는 사용자 할당 ID에는 프라이빗 또는 공용 컨테이너를 읽을 수 있는 권한이 필요합니다.

이미지를 빌드하기 전에 사용 권한과 권한을 설정해야 합니다. 다음 섹션에서는 Azure CLI를 사용하여 가능한 시나리오를 구성하는 방법을 자세히 설명합니다.

필수 조건

사용자 할당 관리 ID 만들기

VM Image Builder를 사용하려면 Azure 사용자 할당 관리 ID를 만들어야 합니다. VM Image Builder는 이 ID를 사용하여 이미지를 읽고, 이미지를 쓰고, Azure Storage 계정에 액세스합니다. 구독에서 특정 작업을 수행할 수 있는 권한을 해당 ID에 부여합니다.

참고 항목

사용자 할당 관리 ID는 이미지 리소스 그룹에 권한을 부여하는 올바른 방법입니다. 이를 위해 SPN은 더 이상 사용되지 않습니다.

다음 예제에서는 Azure 사용자 할당 관리 ID를 만드는 방법을 보여 줍니다. 자리 표시자 설정을 대체하여 변수를 설정합니다.

설정 설명
<리소스 그룹> 사용자 할당 관리 ID를 만들려는 리소스 그룹입니다.
identityName="aibIdentity"
imageResourceGroup=<Resource group>

az identity create \
    --resource-group $imageResourceGroup \
    --name $identityName

자세한 내용은 Azure 사용자 할당 관리 ID를 참조하세요.

VM Image Builder에서 이미지 배포 허용

VM Image Builder에서 이미지를 배포하려면 서비스에서 리소스 그룹에 이미지를 삽입할 수 있어야 합니다. 필요한 권한을 부여하려면 사용자 할당 관리 ID를 만들고 이미지가 빌드된 리소스 그룹에 대한 권한을 부여합니다. VM Image Builder에는 구독의 다른 리소스 그룹에 있는 리소스에 액세스할 수 있는 권한이 없습니다. 빌드 실패를 방지하려면 액세스를 허용하는 명시적 작업을 수행해야 합니다.

이미지를 배포하기 위해 리소스 그룹에 대한 사용자 할당 관리 ID 참가자 권한을 부여하지 않아도 됩니다. 그러나 사용자 할당 관리 ID의 경우 배포 리소스 그룹에 다음 Azure Actions 권한이 필요합니다.

Microsoft.Compute/images/write
Microsoft.Compute/images/read
Microsoft.Compute/images/delete

Azure Compute Gallery에 배포하려면 다음도 필요합니다.

Microsoft.Compute/galleries/read
Microsoft.Compute/galleries/images/read
Microsoft.Compute/galleries/images/versions/read
Microsoft.Compute/galleries/images/versions/write

기존 이미지를 사용자 지정하기 위한 권한

VM Image Builder가 원본 사용자 지정 이미지에서 이미지를 빌드하려면 서비스에서 이러한 리소스 그룹으로 이미지를 읽을 수 있어야 합니다. 필요한 권한을 부여하려면 사용자 할당 관리 ID를 만들고 이미지가 있는 리소스 그룹에 대한 권한을 부여합니다.

기존 사용자 지정 이미지에서 빌드하는 방법은 다음과 같습니다.

Microsoft.Compute/images/read

기존 Azure Compute Gallery 버전에서 빌드하는 방법은 다음과 같습니다.

Microsoft.Compute/galleries/read
Microsoft.Compute/galleries/images/read
Microsoft.Compute/galleries/images/versions/read

가상 네트워크에서 이미지를 사용자 지정할 수 있는 권한

VM Image Builder에는 구독에서 기존 가상 네트워크를 배포하고 사용할 수 있는 기능이 있으므로 연결된 리소스에 대한 사용자 지정 액세스를 허용합니다.

VM을 기존 가상 네트워크에 배포하기 위해 리소스 그룹에 대한 사용자 할당 관리 ID 참가자 권한을 부여하지 않아도 됩니다. 그러나 사용자 할당 관리 ID에는 가상 네트워크 리소스 그룹에 대한 다음 Azure Actions 권한이 필요합니다.

Microsoft.Network/virtualNetworks/read
Microsoft.Network/virtualNetworks/subnets/join/action

Azure 역할 정의 만들기

다음 예제에서는 이전 섹션에서 설명한 작업에서 Azure 역할 정의를 만듭니다. 예제는 리소스 그룹 수준에서 적용됩니다. 사용자 요구 사항에 따라 예제가 충분히 세분화되어 있는지 평가하고 테스트합니다.

이미지 작업은 읽기 및 쓰기를 허용합니다. 사용자 환경에 적합한 항목을 결정합니다. 예를 들어, VM Image Builder가 리소스 그룹 ‘example-rg-1’에서 이미지를 읽고 리소스 그룹 ‘example-rg-2’에 이미지를 쓰도록 허용하는 역할을 만듭니다.

사용자 지정 이미지 Azure 역할 예제

다음 예제에서는 원본 사용자 지정 이미지를 사용하고 배포하는 Azure 역할을 만듭니다. 그런 다음 VM Image Builder에 대한 사용자 지정 관리 ID에 사용자 지정 역할을 부여합니다.

예제의 값을 간단하게 바꾸기 위해 먼저 다음 변수를 설정합니다. 자리 표시자 설정을 대체하여 변수를 설정합니다.

설정 설명
<구독 ID> Azure 구독 ID.
<리소스 그룹> 사용자 지정 이미지에 대한 리소스 그룹입니다.
# Subscription ID - You can get this using `az account show | grep id` or from the Azure portal.
subscriptionID=$(az account show --query id --output tsv)
# Resource group - image builder will only support creating custom images in the same Resource Group as the source managed image.
imageResourceGroup=<Resource group>
identityName="aibIdentity"

# Use *cURL* to download the a sample JSON description 
curl https://raw.githubusercontent.com/azure/azvmimagebuilder/master/solutions/12_Creating_AIB_Security_Roles/aibRoleImageCreation.json -o aibRoleImageCreation.json

# Create a unique role name to avoid clashes in the same Azure Active Directory domain
imageRoleDefName="Azure Image Builder Image Def"$(date +'%s')

# Update the JSON definition using stream editor
sed -i -e "s/<subscriptionID>/$subscriptionID/g" aibRoleImageCreation.json
sed -i -e "s/<rgName>/$imageResourceGroup/g" aibRoleImageCreation.json
sed -i -e "s/Azure Image Builder Service Image Creation Role/$imageRoleDefName/g" aibRoleImageCreation.json

# Create a custom role from the sample aibRoleImageCreation.json description file.
az role definition create --role-definition ./aibRoleImageCreation.json

# Get the user-assigned managed identity id
imgBuilderCliId=$(az identity show -g $imageResourceGroup -n $identityName --query clientId -o tsv)

# Grant the custom role to the user-assigned managed identity for Azure Image Builder.
az role assignment create \
    --assignee $imgBuilderCliId \
    --role $imageRoleDefName \
    --scope /subscriptions/$subscriptionID/resourceGroups/$imageResourceGroup

기존 가상 네트워크 Azure 역할 예

다음 예에서는 기존 가상 네트워크 이미지를 사용하고 배포하기 위한 Azure 역할을 만듭니다. 그런 다음 VM Image Builder에 대한 사용자 지정 관리 ID에 사용자 지정 역할을 부여합니다.

예제의 값을 간단하게 바꾸기 위해 먼저 다음 변수를 설정합니다. 자리 표시자 설정을 대체하여 변수를 설정합니다.

설정 설명
<구독 ID> Azure 구독 ID.
<리소스 그룹> 가상 네트워크 리소스 그룹
# Subscription ID - You can get this using `az account show | grep id` or from the Azure portal.
subscriptionID=$(az account show --query id --output tsv)
VnetResourceGroup=<Resource group>
identityName="aibIdentity"

# Use *cURL* to download the a sample JSON description 
curl https://raw.githubusercontent.com/azure/azvmimagebuilder/master/solutions/12_Creating_AIB_Security_Roles/aibRoleNetworking.json -o aibRoleNetworking.json

# Create a unique role name to avoid clashes in the same domain
netRoleDefName="Azure Image Builder Network Def"$(date +'%s')

# Update the JSON definition using stream editor
sed -i -e "s/<subscriptionID>/$subscriptionID/g" aibRoleNetworking.json
sed -i -e "s/<vnetRgName>/$VnetResourceGroup/g" aibRoleNetworking.json
sed -i -e "s/Azure Image Builder Service Networking Role/$netRoleDefName/g" aibRoleNetworking.json

# Create a custom role from the aibRoleNetworking.json description file.
az role definition create --role-definition ./aibRoleNetworking.json

# Get the user-assigned managed identity id
imgBuilderCliId=$(az identity show -g $imageResourceGroup -n $identityName --query clientId -o tsv)

# Grant the custom role to the user-assigned managed identity for Azure Image Builder.
az role assignment create \
    --assignee $imgBuilderCliId \
    --role $netRoleDefName \
    --scope /subscriptions/$subscriptionID/resourceGroups/$VnetResourceGroup

Azure Storage 액세스에 관리 ID 사용

Azure Storage로 인증하고 프라이빗 컨테이너를 사용하려면 VM Image Builder에 사용자 할당 관리 ID가 필요합니다. VM Image Builder는 해당 ID를 사용하여 Azure Storage에서 인증을 받습니다.

참고 항목

VM Image Builder는 이미지 템플릿을 제출할 때만 ID를 사용합니다. 빌드 VM은 이미지 빌드 중에 ID에 액세스할 수 없습니다.

Azure CLI를 사용하여 사용자 할당 관리 ID를 만듭니다.

az role assignment create \
    --assignee <Image Builder client ID> \
    --role "Storage Blob Data Reader" \
    --scope /subscriptions/<Subscription ID>/resourceGroups/<Resource group>/providers/Microsoft.Storage/storageAccounts/$scriptStorageAcc/blobServices/default/containers/<Storage account container>

VM Image Builder 템플릿에서 사용자 할당 관리 ID를 제공합니다.

    "type": "Microsoft.VirtualMachineImages/imageTemplates",
    "apiVersion": "2020-02-14",
    "location": "<Region>",
    ..
    "identity": {
    "type": "UserAssigned",
          "userAssignedIdentities": {
            "<Image Builder ID>": {}     
        }

다음 자리 표시자 설정을 바꿉니다.

설정 설명
<지역> 템플릿 지역
<리소스 그룹> Resource group
<스토리지 계정 컨테이너> 스토리지 계정 컨테이너 이름
<구독 ID> Azure 구독

자세한 내용은 이미지 만들기 및 사용자 할당 관리 ID를 사용하여 Azure Storage의 파일 액세스를 참조하세요. 스토리지 계정에 액세스하기 위해 사용자 할당 관리 ID를 만들고 구성하는 방법을 알아봅니다.

다음 단계

Azure VM Image Builder 개요