チュートリアル: Media Services マネージド ID を使用してストレージにアクセスする

Media Services ロゴ v3


警告

Azure Media Services は、2024 年 6 月 30 日に廃止されます。 詳細については、AMS 提供終了ガイドを参照してください。

手記

マネージド ID は、v3 API を使用して作成された Media Services アカウントでのみ使用できます。 v2 API を使用していて、マネージド ID を使用する場合は、v2 から v3 に移行 Media Services v2 から v3 への移行の概要

ストレージ アカウントが不明な IP アドレスからの要求をブロックするように構成されているときにストレージ アカウントにアクセスする場合は、Media Services アカウントにストレージ アカウントへのアクセスを許可する必要があります。 Media Services アカウントのマネージド ID を作成し、Media Services CLI を使用してこの ID にストレージへのアクセス権を付与するには、次の手順に従います。

Media Services アカウント マネージド ID を使用してストレージ にアクセスする

このチュートリアルでは、2020-05-01 Media Services API を使用します。

概要

警告

Media Services アカウントに関連付けられていないストレージ アカウントでは、JobInputHTTP または SAS URL を使用できません。 これらは、HTTP(S) を使用してアクセスできる既存のコンテンツ を しているお客様にとって便利です。たとえば、公開サーバー上にメディア ファイルがある場合や、別のクラウド プロバイダーと一緒に保存されている場合などです。 新しいソリューションを構築する場合は、ジョブ入力に資産を使用します。

Media Services で使用されるストレージ アカウントへのアクセスをセキュリティで保護するには:

  • すべての IP アドレスを拒否するようにストレージ アカウントを構成する (または、顧客のネットワーク内の IP アドレスのみを許可する)
  • "AzureServices" へのアクセスを許可するようにストレージ アカウントを構成する
  • マネージド ID を使用してストレージ アカウントにアクセスするように Media Services を構成する
  • メディア コンテンツを Media Services アセットにアップロードする
  • Media Services アセットをジョブ入力として使用するエンコード ジョブを作成します。 SAS URL または JobInputHTTP を使用

Azure にサインインする

この記事のコマンドのいずれかを使用するには、まず、使用するサブスクリプションにサインインする必要があります。

Azure にサインインします。 このコマンドを使用すると、使用するサブスクリプションの入力を求められます。

az login

サブスクリプションの設定

このコマンドを使用して、使用するサブスクリプションを設定します。

CLI を使用して Azure サブスクリプションを設定する

次のコマンドで、Media Services アカウントに使用する Azure サブスクリプション ID を指定します。

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 応答の 1 つ以上の値がシーケンスの次の手順で使用されるため、以下の各手順は特定の順序で実行されます。

ストレージ アカウントを作成する

作成する Media Services アカウントには、ストレージ アカウントが関連付けられている必要があります。 まず、Media Services アカウントのストレージ アカウントを作成します。 以降の手順では、myStorageAccount を置き換えるストレージ アカウント名を使用します。

CLI を使用して Azure Storage アカウントを作成する

次のコマンドを使用して、Azure Storage アカウントを作成します。

ストレージ アカウントを作成するには、最初に場所内にリソース グループを作成する必要があります。

使用可能な場所を一覧表示するには、次のコマンドを使用します。

CLI を使用して使用可能な場所を一覧表示する

使用可能な場所を一覧表示するには、次のコマンドを使用します。

az account list-locations

CLI を使用してリソース グループを作成する

リソース グループを作成するには、次のコマンドを使用します。

az group create -n <resourceGroupName> --location chooseLocation

SKU を選択する

また、ストレージ アカウントの SKU を選択する必要もあります。 ストレージ アカウントを一覧表示できます。

Standard_LRS、Standard_GRS、Standard_RAGRS、Standard_ZRS、Premium_LRS、Premium_ZRS、Standard_GZRS、Standard_RAGZRSの一覧から SKU を選択します。

  • myStorageAccount の長さが 24 文字未満の一意の名前に変更します。
  • chooseLocation を、作業するリージョンに変更します。
  • chooseSKU を希望の SKU に変更します。
az storage account create -n <myStorageAccount> -g <resourceGroup>  --location <chooseLocation> --sku <chooseSKU>

サービス プリンシパル (マネージド ID) を使用して Media Services アカウントを作成する

次に、サービス プリンシパル (マネージド ID とも呼ばれます) を使用して Media Services アカウントを作成します。

大事な

コマンドで --mi フラグを忘れずに使用することが重要です。 それ以外の場合は、後の手順で principalId を見つけることができません。

次の Azure CLI コマンドは、新しい Media Services アカウントを作成します。 your-media-services-account-name your-storage-account-nameyour-resource-group-name の値を使用する名前に置き換えます。 このコマンドは、リソース グループとストレージ アカウントが既に作成されていることを前提としています。

Media Services アカウントに、--mi-system-assigned フラグを持つシステム割り当てマネージド ID が付与されます。


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"
}

Media Services マネージド ID にストレージ アカウントへのアクセス権を付与する

Media Services マネージド ID にストレージ アカウントへのアクセス権を付与します。 次の 3 つのコマンドがあります。

Media Services アカウントのマネージド ID を取得 (表示) する

次の最初のコマンドは、Media Services アカウントのマネージド ID を示しています。これは、コマンドによって返される JSON に記載されている principalId です。

このコマンドは、Media Services アカウントのすべてのプロパティを表示します。

az ams account show --name <your-media-services-account-name> --resource-group <your-resource-group>

手記

Media Services アカウントにアクセス ロールを割り当てた場合、この行は "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 共同作成者ロールを作成します。

assigneeprincipalIdに変更します。 このコマンドは、リソース グループとストレージ アカウントが既に作成されていることを前提としています。 次のコマンドに示すように、scope 値の一部として your-resource-group-nameyour-storage-account-name を使用します。

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"
}

閲覧者ロールの割り当てを作成する

次のコマンドは、閲覧者ロールを作成します。

assigneeprincipalIdに変更します。 このコマンドは、リソース グループとストレージ アカウントが既に作成されていることを前提としています。 次のコマンドに示すように、scope 値の一部として your-resource-group-nameyour-storage-account-name を使用します。

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"
}

マネージド ID を使用してストレージ アカウントにアクセスする

次のコマンドは、Media Services マネージド ID にストレージ アカウントへのアクセス権を付与します。

次のコマンドで、your-resource-group-name をリソース グループ名に変更し、操作する Media Services アカウント名に 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"
}

検証

カスタマー マネージド キーを使用してアカウントが暗号化されていることを確認するには、アカウントの暗号化プロパティを表示します。

このコマンドは、Media Services アカウントのすべてのプロパティを表示します。

az ams account show --name <your-media-services-account-name> --resource-group <your-resource-group>

手記

Media Services アカウントにアクセス ロールを割り当てた場合、この行は "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 Storage ログを確認して、要求ごとに使用される認証方法を確認できます。

リソースのクリーンアップ

作成したリソースを使用する予定がない場合は、リソース グループを削除します。

CLI を使用してリソース グループを削除する

az group delete --name <your-resource-group-name>

ヘルプとサポートを受ける

Media Services に質問がある場合は、次のいずれかの方法で更新プログラムに従ってください。