共用方式為


教學課程:使用媒體服務受控識別存取記憶體

媒體服務標誌 v3


警告

Azure 媒體服務將於 2024 年 6 月 30 日淘汰。 如需詳細資訊,請參閱 AMS 淘汰指南

注意

受控識別僅適用於使用 v3 API 建立的媒體服務帳戶。 如果您使用 v2 API 並想要使用受控識別,請從 v2 移轉至 v3 從媒體服務 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
  • 位置

注意

上述連字元僅用於分隔指引字組。 由於 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-nameyour-storage-account-nameyour-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"
}

授與媒體服務受控識別對記憶體帳戶的存取權

授與媒體服務受控識別對記憶體帳戶的存取權。 有三個命令:

取得 (show) 媒體服務帳戶的受控識別

下列第一個命令顯示媒體服務帳戶的受控識別,這是命令所傳回 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-nameyour-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-nameyour-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>

取得說明和支援

您可以連絡媒體服務,詢問問題,或遵循下列其中一種方法來追蹤我們的更新: