教學課程:使用媒體服務受控識別的儲存體
警告
Azure 媒體服務將於 2024 年 6 月 30 日淘汰。 如需詳細資訊,請參閱 AMS淘汰指南。
注意
受控識別僅適用於使用 v3 API 建立的媒體服務帳戶。 如果您使用 v2 API 且想要使用受控識別,請從 v2 移轉至 v3 從 v2 媒體服務 v2 移轉至 v3 簡介。
儲存體帳戶設為封鎖來自未知 IP 位址的要求時,如果您要存取儲存體帳戶,請授與將媒體服務帳戶存取儲存體帳戶的權限。 請遵循下列步驟,建立媒體服務帳戶的受控識別,並使用媒體服務 CLI,授與此身分識別存取儲存體的權限。
本教學課程使用 2020-05-01 媒體服務 API。
概觀
警告
您無法將 JobInputHTTP 或 SAS URL 與未與媒體服務帳戶相關聯的記憶體帳戶使用。 這些是方便客戶使用 HTTP (S) 存取 的現有內容 ,例如,如果您有公開伺服器上的媒體檔案,或與其他雲端提供者一起儲存。 如果您要建置新的解決方案,請使用資產作為作業輸入。
若要保護媒體服務所使用記憶體帳戶的存取:
- 將記憶體帳戶設定為拒絕 (的所有IP位址,或只允許客戶網路中IP位址)
- 設定記憶體帳戶以允許存取 “AzureServices”
- 設定媒體服務以使用受控識別存取記憶體帳戶
- 將媒體內容上傳至媒體服務資產
- 建立使用媒體服務資產做為作業輸入的編碼作業。 請勿 使用 SAS URLS 或 JobInputHTTP。
登入 Azure
若要使用本文中的任何命令,請先登入要使用的訂閱。
登入 Azure。 當您使用此命令時,系統會提示您輸入要使用的訂閱。
az login
設定訂用帳戶
使用此命令設定要使用的訂閱。
使用 CLI 設定 Azure 訂用帳戶
在下列命令中,提供您要用於媒體服務帳戶的 Azure 訂用帳戶識別碼。
az account set --subscription <subscriptionName>
資源名稱
開始前,請決定您要建立的資源名稱。 這些名稱應該可以輕鬆識別為集合,尤其當您不打算在完成測試後使用這些名稱。 許多資源類型的命名規則都不同,因此最好保持全部小寫。 例如,「mediatest1rg」用於資源群組名稱,而「mediatest1stor」用於儲存體帳戶名稱。 針對本文中每個步驟使用相同的名稱。
您會在下列命令中看到這些參考的名稱。 您需要的資源名稱如下:
- myRG
- myStorageAccount
- myAmsAccount
- location
注意
上方連字號僅用於分隔指引字組。 由於 Azure 服務中的命名資源不一致,命名資源時請勿使用連字號。 此外,您不會建立區域名稱。 區域名稱是由 Azure 決定。
列出 Azure 區域
如果您不確定要使用的實際區域名稱,請使用此命令取得清單:
使用此命令列出帳戶的可用區域。
az account list-locations --query "[].{DisplayName:displayName, Name:name}" -o table
順序
下方每個步驟會以特定順序完成,因為序列中的下一個步驟會使用來自 JSON 回應的一或多個值。
建立儲存體帳戶
您要建立的媒體服務帳戶必須有相關的儲存體帳戶。 請先建立媒體服務帳戶的儲存體帳戶。 您將使用取代後續步驟的 myStorageAccount
記憶體帳戶名稱。
使用 CLI 建立 Azure 記憶體帳戶
使用下列命令來建立 Azure 記憶體帳戶。
若要建立記憶體帳戶,您必須先在位置內建立資源群組。
若要列出可用的位置,請使用下列命令:
使用 CLI 列出可用的位置
若要列出可用的位置,請使用下列命令:
az account list-locations
使用 CLI 建立資源群組
若要建立資源群組,請使用下列命令:
az group create -n <resourceGroupName> --location chooseLocation
選擇 SKU
您也需要選擇記憶體帳戶的 SKU。 您可以列出記憶體帳戶。
從下列清單中選擇 SKU:Standard_LRS、Standard_GRS、Standard_RAGRS、Standard_ZRS、Premium_LRS、Premium_ZRS、Standard_GZRS Standard_RAGZRS。
- 變更
myStorageAccount
為長度少於 24 個字元的唯一名稱。 - 變更
chooseLocation
為您想要在其中工作的區域。 - 變更
chooseSKU
為您慣用的 SKU。
az storage account create -n <myStorageAccount> -g <resourceGroup> --location <chooseLocation> --sku <chooseSKU>
建立包含服務主體 (受控識別) 的媒體服務帳戶
接著建立包含服務主體 (或稱為受控識別) 的媒體服務帳戶。
重要
請務必記得在命令中使用 --mi 旗標。 否則後續步驟時,您將無法找到 principalId
。
以下 Azure CLI 命令會建立新的媒體服務帳戶。 以您要使用的名稱取代下列值:your-media-services-account-name
、your-storage-account-name
和 your-resource-group-name
。 此命令假設您已建立資源群組與儲存體帳戶。
命令會為媒體服務帳戶提供具有 --mi-system-assigned
旗標的系統指派受控識別。
az ams account create --name <your-media-services-account-name> --resource-group <your-resource-group-name> --mi-system-assigned --storage-account <your-storage-account-name>
範例 JSON 回應:
{
"encryption": {
"keyVaultProperties": null,
"type": "SystemKey"
},
"id": "/subscriptions/00000000-0000-0000-0000-00000000/resourceGroups/your-resource-group/providers/Microsoft.Media/mediaservices/your-media-services-account-name",
"identity": {
"principalId": "00000000-0000-0000-0000-00000000",
"tenantId": "00000000-0000-0000-0000-00000000",
"type": "SystemAssigned"
},
"location": "your-region",
"mediaServiceId": "00000000-0000-0000-0000-00000000",
"name": "your-media-services-account-name",
"resourceGroup": "your-resource-group",
"storageAccounts": [
{
"id": "/subscriptions/00000000-0000-0000-0000-00000000/resourceGroups/mediatest1rg/providers/Microsoft.Storage/storageAccounts/your-storage-account-name",
"resourceGroup": "your-resource-group",
"type": "Primary"
}
],
"storageAuthentication": "System",
"systemData": {
"createdAt": "2021-05-14T21:25:12.3492071Z",
"createdBy": "you@example.com",
"createdByType": "User",
"lastModifiedAt": "2021-05-14T21:25:12.3492071Z",
"lastModifiedBy": "you@example.com",
"lastModifiedByType": "User"
},
"tags": null,
"type": "Microsoft.Media/mediaservices"
}
授與媒體服務受控識別存取儲存體帳戶的權限
授與媒體服務受控識別存取儲存體帳戶的權限。 有三個命令:
取得 (顯示) 媒體服務帳戶的受控識別
下方第一個命令顯示媒體服務帳戶的受控識別,即命令傳回 JSON 中列出的 principalId
。
此命令會顯示媒體服務帳戶的所有屬性。
az ams account show --name <your-media-services-account-name> --resource-group <your-resource-group>
注意
如果您已指派存取角色給媒體服務帳戶,這一行會傳回 "storageAuthentication": "ManagedIdentity"
。
範例 JSON 回應:
{
"encryption": {
"keyVaultProperties": null,
"type": "SystemKey"
},
"id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/your-resource-group-name/providers/Microsoft.Media/mediaservices/your-media-services-account",
"identity": {
"principalId": "00000000-0000-0000-0000-000000000000",
"tenantId": "00000000-0000-0000-0000-000000000000",
"type": "SystemAssigned" //Type will show "Managed Identity" if you have assigned a role to the Media Services account.
},
"location": "your-region",
"mediaServiceId": "00000000-0000-0000-0000-000000000000",
"name": "your-media-services-account",
"resourceGroup": "your-resource-group-name",
"storageAccounts": [
{
"id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/your-resource-group-name/providers/Microsoft.Storage/storageAccounts/your-storage-account-name",
"resourceGroup": "your-resource-group-name",
"type": "Primary"
}
],
"storageAuthentication": "System", //If you have assigned access roles to the account, this line will return storageAuthentication": "ManagedIdentity"
"systemData": {
"createdAt": "2021-05-14T21:25:12.3492071Z",
"createdBy": "you@example.com",
"createdByType": "User",
"lastModifiedAt": "2021-05-14T21:25:12.3492071Z",
"lastModifiedBy": "you@example.com",
"lastModifiedByType": "User"
},
"tags": null,
"type": "Microsoft.Media/mediaservices"
}
建立儲存體 Blob 參與者角色指派
下列命令會建立儲存體 Blob 參與者角色。
將 assignee
變更為 principalId
. 此命令假設您已建立資源群組與儲存體帳戶。 使用 your-resource-group-name
和 your-storage-account-name
作為 scope
值的一部分,如下列命令所示:
az role assignment create --assignee 00000000-0000-0000-000000000000 --role "Storage Blob Data Contributor" --scope "/subscriptions/00000000-0000-0000-000000000000/resourceGroups/<your-resource-group-name>/providers/Microsoft.Storage/storageAccounts/<your-storage-account-name>"
範例 JSON 回應:
{
"canDelegate": null,
"condition": null,
"conditionVersion": null,
"description": null,
"id": "/subscriptions/00000000-0000-0000-000000000000/resourceGroups/your-resource-group-name/providers/Microsoft.Storage/storageAccounts/your-storage-account-name/providers/Microsoft.Authorization/roleAssignments/00000000-0000-0000-000000000000",
"name": "00000000-0000-0000-000000000000",
"principalId": "00000000-0000-0000-000000000000",
"principalType": "ServicePrincipal",
"resourceGroup": "your-resource-group-name",
"roleDefinitionId": "/subscriptions/00000000-0000-0000-000000000000/providers/Microsoft.Authorization/roleDefinitions/00000000-0000-0000-000000000000",
"scope": "/subscriptions/00000000-0000-0000-000000000000/resourceGroups/your-resource-group-name/providers/Microsoft.Storage/storageAccounts/your-storage-account-name",
"type": "Microsoft.Authorization/roleAssignments"
}
建立讀者角色指派
下列命令會建立讀者角色。
將 assignee
變更為 principalId
. 此命令假設您已建立資源群組與儲存體帳戶。 使用 your-resource-group-name
和 your-storage-account-name
作為 scope
值的一部分,如下列命令所示:
az role assignment create --assignee 00000000-0000-0000-000000000000 --role "Reader" --scope "/subscriptions/00000000-0000-0000-000000000000/resourceGroups/your-resource-group-name/providers/Microsoft.Storage/storageAccounts/your-storage-account-name"
範例 JSON 回應:
{
"canDelegate": null,
"condition": null,
"conditionVersion": null,
"description": null,
"id": "/subscriptions/00000000-0000-0000-000000000000/resourceGroups/your-resource-group-name/providers/Microsoft.Storage/storageAccounts/your-storage-account-name/providers/Microsoft.Authorization/roleAssignments/00000000-0000-0000-000000000000",
"name": "00000000-0000-0000-000000000000",
"principalId": "00000000-0000-0000-000000000000",
"principalType": "Reader",
"resourceGroup": "your-resource-group-name",
"roleDefinitionId": "/subscriptions/00000000-0000-0000-000000000000/providers/Microsoft.Authorization/roleDefinitions/00000000-0000-0000-000000000000",
"scope": "/subscriptions/00000000-0000-0000-000000000000/resourceGroups/your-resource-group-name/providers/Microsoft.Storage/storageAccounts/your-storage-account-name",
"type": "Microsoft.Authorization/roleAssignments"
}
使用受控識別存取儲存體帳戶
下列命令提供媒體服務受控識別存取儲存體帳戶的權限。
在下列命令中,將 your-resource-group-name
變更為資源群組名稱,而 your-media-services-account-name
變更為您要使用的媒體服務帳戶名稱:
az ams account storage set-authentication --storage-auth ManagedIdentity --resource-group <your-resource-group_name> --account-name <your-media-services-account-name>
範例 JSON 回應:
{
"encryption": {
"keyVaultProperties": null,
"type": "SystemKey"
},
"id": "/subscriptions/00000000-0000-0000-00000000/resourceGroups/your-resource-group-name/providers/Microsoft.Media/mediaservices/your-storage-account-name",
"identity": null,
"location": "West US 2",
"mediaServiceId": "00000000-0000-0000-00000000",
"name": "your-media-services-account",
"resourceGroup": "your-resource-group-name",
"storageAccounts": [
{
"id": "/subscriptions/2b461b25-f7b4-4a22-90cc-d640a14b5471/resourceGroups/your-resource-group-name/providers/Microsoft.Storage/storageAccounts/your-storage-account-name",
"resourceGroup": "your-resource-group-name",
"type": "Primary"
}
],
"storageAuthentication": "ManagedIdentity",
"systemData": {
"createdAt": "2021-05-17T19:15:00.8850297Z",
"createdBy": "you@example.com",
"createdByType": "User",
"lastModifiedAt": "2021-05-17T21:23:11.3863627Z",
"lastModifiedBy": "you@example.com",
"lastModifiedByType": "User"
},
"tags": null,
"type": "Microsoft.Media/mediaservices"
}
驗證
若要使用客戶自控金鑰確認帳戶已加密,請檢視帳戶加密屬性:
此命令會顯示媒體服務帳戶的所有屬性。
az ams account show --name <your-media-services-account-name> --resource-group <your-resource-group>
注意
如果您已指派存取角色給媒體服務帳戶,這一行會傳回 "storageAuthentication": "ManagedIdentity"
。
範例 JSON 回應:
{
"encryption": {
"keyVaultProperties": null,
"type": "SystemKey"
},
"id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/your-resource-group-name/providers/Microsoft.Media/mediaservices/your-media-services-account",
"identity": {
"principalId": "00000000-0000-0000-0000-000000000000",
"tenantId": "00000000-0000-0000-0000-000000000000",
"type": "SystemAssigned" //Type will show "Managed Identity" if you have assigned a role to the Media Services account.
},
"location": "your-region",
"mediaServiceId": "00000000-0000-0000-0000-000000000000",
"name": "your-media-services-account",
"resourceGroup": "your-resource-group-name",
"storageAccounts": [
{
"id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/your-resource-group-name/providers/Microsoft.Storage/storageAccounts/your-storage-account-name",
"resourceGroup": "your-resource-group-name",
"type": "Primary"
}
],
"storageAuthentication": "System", //If you have assigned access roles to the account, this line will return storageAuthentication": "ManagedIdentity"
"systemData": {
"createdAt": "2021-05-14T21:25:12.3492071Z",
"createdBy": "you@example.com",
"createdByType": "User",
"lastModifiedAt": "2021-05-14T21:25:12.3492071Z",
"lastModifiedBy": "you@example.com",
"lastModifiedByType": "User"
},
"tags": null,
"type": "Microsoft.Media/mediaservices"
}
屬性 storageAuthentication
應顯示「ManagedIdentity」。
如需其他驗證,請檢查 Azure 儲存體記錄,並查看每個要求使用的驗證方法。
清除資源
如果您不打算使用所建立的資源,請刪除資源群組。
使用 CLI 刪除資源群組
az group delete --name <your-resource-group-name>
取得說明及支援
您可以連絡媒體服務並詢問問題,或依照下列其中一種方法追蹤我們的更新:
- 問與答
- Stack Overflow。 使用
azure-media-services
標記問題。 - @MSFTAzureMedia 或使用 @AzureSupport 來要求支援。
- 透過 Azure 入口網站 開啟支援票證。