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

Media Services ロゴ v3


警告

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

注意

マネージド ID は、v3 API を使用して作成された Media Services アカウントでのみ使用できます。 v2 API を使用していて、マネージド ID を使用する場合は、「Media Services v2 から v3 への移行の概要」の説明に従って、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" へのアクセスを許可するようにストレージ アカウントを構成する
  • Media Services が、マネージド ID を使用してストレージ アカウントにアクセスするように構成する
  • メディア コンテンツを 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
  • location

注意

上記のハイフンは、ガイダンス ワードを分離するためにのみ使用されています。 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 アカウントを作成します。

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

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

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>

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

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

重要

コマンドでは --mi フラグを必ず使用してください。 そうしないと、後の手順で principalId を見つけることができなくなります。

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

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


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>

Note

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 共同作成者ロールの割り当てを作成する

次のコマンドでは、Storage Blob の共同作成者ロールが作成されます。

assigneeprincipalId に変更します。 このコマンドは、リソース グループとストレージ アカウントが既に作成済みであることを前提としています。 次のコマンドに示すように、scope 値の一部として your-resource-group-name および your-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-name および your-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 をリソース グループ名に変更し、your-media-services-account-name を使用する Media Services アカウント名に変更します。

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>

Note

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 に質問がある場合は、次のいずれかの方法で更新プログラムに従ってください。

  • Q & A
  • Stack Overflow。 質問に タグを付け、 を使用します azure-media-services
  • @MSFTAzureMedia するか 、@AzureSupport を使用してサポートを要求します。
  • Azure portalからサポート チケットを開きます。