マネージド ID による認証

適用対象: すべての API Management レベル

authentication-managed-identity ポリシーを使用して、マネージド ID を利用するバックエンド サービスで認証します。 このポリシーでは、基本的にマネージド ID を使用して、指定されたリソースにアクセスするためのアクセス トークンをMicrosoft Entra IDから取得します。 トークンが正常に取得されると、ポリシーは、Authorization スキームを使用してトークンの値を Bearer ヘッダーに設定します。 API Management は、有効期限が切れるまでトークンをキャッシュします。

システムによって割り当てられた ID と、ユーザーが割り当てた複数の ID のいずれかの、どちらを使用してもトークンを要求できます。 client-id が指定されていない場合、システムによって割り当てられた ID が指定されたと見なされます。 client-id 変数が指定されている場合は、Microsoft Entra IDからそのユーザー割り当て ID に対してトークンが要求されます。

ポリシーの要素と子要素を、ポリシー ステートメントで指定された順序で設定します。 API Management ポリシーを設定または編集する方法について説明します。

注意事項

セキュリティに関する考慮事項: API Management ポリシーを編集するアクセス許可を持つユーザーは、このポリシーを使用してサービスのマネージド ID として認証できます。 ただし、最初に API Management インスタンスにマネージド ID を割り当てなければ、リソースに直接アクセスすることはできません。 マネージド ID が割り当てられると、ポリシーを変更できるユーザーは、認証トークンを流出させたり、バックエンドに伝達したり、後で使用するためにログに記録したりすることができます。 詳細なセキュリティ ガイダンスと軽減戦略については、マネージド ID の概要の マネージド ID のセキュリティに関する考慮事項 を参照してください。

ポリシー ステートメント

<authentication-managed-identity resource="resource" client-id="clientid of user-assigned identity" output-token-variable-name="token-variable" ignore-error="true|false"/>  

属性

属性 説明 必要 既定値
リソース 文字列 をオンにします。 Microsoft Entra ID内のターゲット Web API (セキュリティで保護されたリソース) のアプリケーション ID。 ポリシー式を使用できます。 はい 該当なし
クライアントID 文字列 をオンにします。 Microsoft Entra IDのユーザー割り当て ID のクライアント ID。 ポリシー式は使用できません。 いいえ 該当なし。 属性が存在しない場合は、システム割り当て ID が使用されます。
output-token-variable-name 文字列 をオンにします。 string 型のオブジェクトとしてトークン値を受け取るコンテキスト変数の名前。 ポリシー式は使用できません。 いいえ 該当なし
ignore-error Boolean です。 true に設定された場合、アクセス トークンが取得されなかったとしても、ポリシー パイプラインは引き続き実行されます。 いいえ false

使用法

マネージド ID を使用してバックエンド サービスで認証する

<authentication-managed-identity resource="https://graph.microsoft.com"/> 
<authentication-managed-identity resource="https://cognitiveservices.azure.com"/> <!--Azure OpenAI-->
<authentication-managed-identity resource="https://management.azure.com/"/> <!--Azure Resource Manager-->
<authentication-managed-identity resource="https://vault.azure.net"/> <!--Azure Key Vault-->
<authentication-managed-identity resource="https://servicebus.azure.net/"/> <!--Azure Service Bus-->
<authentication-managed-identity resource="https://eventhubs.azure.net/"/> <!--Azure Event Hub-->
<authentication-managed-identity resource="https://storage.azure.com/"/> <!--Azure Blob Storage-->
<authentication-managed-identity resource="https://database.windows.net/"/> <!--Azure SQL-->
<authentication-managed-identity resource="https://signalr.azure.com"/> <!--Azure SignalR-->
<authentication-managed-identity resource="AD_application_id"/> <!--Application (client) ID of your own Azure AD Application-->

マネージド ID を使用し、ヘッダーを手動で設定する

<authentication-managed-identity resource="AD_application_id"
   output-token-variable-name="msi-access-token" ignore-error="false" /> <!--Application (client) ID of your own Azure AD Application-->
<set-header name="Authorization" exists-action="override">
   <value>@("Bearer " + (string)context.Variables["msi-access-token"])</value>
</set-header>

send-request ポリシーでマネージド ID を使用する

<send-request mode="new" timeout="20" ignore-error="false">
    <set-url>https://example.com/</set-url>
    <set-method>GET</set-method>
    <authentication-managed-identity resource="ResourceID"/>
</send-request>

ポリシーに対する処理の詳細については、次のトピックを参照してください。