エージェントが独自の権限を使用して ServiceNow や Salesforce などの外部ツールに対して認証できるようにするには、Agent Identity Auth Manager で 2-Legged OAuth(クライアント認証情報)認証プロバイダを使用してアウトバウンド認証を構成します。
認証情報とトークンを管理することで、2-legged OAuth 認証プロバイダは認証フローを処理するためのカスタムコードを不要にします。
2-legged OAuth ワークフロー
2 レッグ OAuth 認証プロバイダはエージェントの ID を使用し、ユーザーの同意を必要としません。クライアント認証情報の保存は Google が管理します。Agent Development Kit(ADK)を使用すると、結果のアクセス トークンが自動的に取得され、ツール呼び出しヘッダーに挿入されます。
始める前に
- 正しい認証方法を選択していることを確認します。
Agent Identity API を有効にします。
API を有効にするために必要なロール
API を有効にするには、
serviceusage.services.enable権限が必要です。プロジェクトを作成した場合は、オーナーロール(roles/owner)を介してこの権限がすでに付与されている可能性があります。それ以外の場合は、Service Usage 管理者ロール(roles/serviceusage.serviceUsageAdmin)を介してこの権限を取得できます。ロールを付与する方法をご覧ください。接続するサードパーティ アプリケーションからクライアント ID とクライアント シークレットを取得します。
必要なロール
2 レッグ Agent Identity 認証プロバイダの作成と使用に必要な権限を取得するには、プロジェクトに対する次の IAM ロールを付与するよう管理者に依頼してください。
-
認証プロバイダを作成するには:
- エージェント ID 管理者 (
roles/agentidentity.admin) - エージェント ID 編集者 (
roles/agentidentity.editor)
- エージェント ID 管理者 (
-
認証プロバイダを使用するには:
- Agent Identity ユーザー (
roles/agentidentity.user) - エージェントのデフォルト アクセス (
roles/aiplatform.agentDefaultAccess) - エージェント コンテキスト編集者 (
roles/aiplatform.agentContextEditor) - Vertex AI ユーザー (
roles/aiplatform.user) - Service Usage コンシューマー (
roles/serviceusage.serviceUsageConsumer)
- Agent Identity ユーザー (
ロールの付与については、プロジェクト、フォルダ、組織へのアクセス権の管理をご覧ください。
これらの事前定義ロールには、2 レッグ Agent Identity 認証プロバイダの作成と使用に必要な権限が含まれています。必要とされる正確な権限については、「必要な権限」セクションを開いてご確認ください。
必要な権限
2 レッグ Agent Identity 認証プロバイダを作成して使用するには、次の権限が必要です。
-
認証プロバイダを作成するには:
agentidentity.authProviders.create -
認証プロバイダを使用するには:
-
agentidentity.authProviders.retrieveCredentials -
aiplatform.endpoints.predict -
aiplatform.sessions.create
-
カスタムロールや他の事前定義ロールを使用して、これらの権限を取得することもできます。
2 レッグ認証プロバイダを作成する
認証プロバイダを作成して、サードパーティ アプリケーションの構成と認証情報を定義します。
2 レッグ認証プロバイダを作成するには、 Google Cloud コンソールまたは Google Cloud CLI を使用します。
コンソール
- Google Cloud コンソールで、[エージェント レジストリ] ページに移動します。
- 認証プロバイダを作成するエージェントの名前をクリックします。
- [ID] をクリックします。
- [認証プロバイダ] セクションで、[ 認証プロバイダを追加] をクリックします。
-
[認証プロバイダを追加] ペインで、名前と説明を入力します。
名前に使用できるのは、英小文字、数字、ハイフンに限られます。末尾をハイフンにすることはできず、先頭は英小文字にする必要があります。
- [OAuth Type] リストから、[OAuth (2 legged)] を選択します。
- [作成して続行] をクリックします。
- 認証プロバイダを使用する権限をエージェント ID に付与するには、[アクセス権を付与] をクリックします。
このプロセスでは、認証プロバイダ リソースの Agent Identity に Agent Identity User(
roles/agentidentity.user)ロールが自動的に割り当てられます。 - [認証プロバイダの認証情報] セクションに、次の情報を入力します。
- クライアント ID
- クライアント シークレット
- トークン URL
- [プロバイダ設定を追加] をクリックします。
新しく作成された認証プロバイダが [認証プロバイダ] リストに表示されます。
gcloud CLI
-
認証プロバイダを作成します。
gcloud agent-identity auth-providers create
AUTH_PROVIDER_NAME\ --location="LOCATION" \ --two-legged-oauth-client-id="CLIENT_ID" \ --two-legged-oauth-client-secret="CLIENT_SECRET" \ --two-legged-oauth-token-url="TOKEN_URL" - 認証プロバイダがリストに表示され、その状態が
ENABLEDであることを確認します。gcloud agent-identity auth-providers list \ --project="
PROJECT_ID" \ --location="LOCATION" -
エージェントとローカル開発環境が認証プロバイダから認証情報を取得できるように、アクセス権を付与します。デプロイされたエージェントと個人用ユーザー アカウントが認証プロバイダにアクセスできるようにするには、認証プロバイダ リソースに対するAgent Identity User(
roles/agentidentity.user)ロールを付与します。-
デプロイされたエージェントの SPIFFE ID(Agent Identity)へのアクセス権を付与します。
gcloud agent-identity auth-providers add-iam-policy-binding
AUTH_PROVIDER_NAME\ --project="PROJECT_ID" \ --location="LOCATION" \ --role="roles/agentidentity.user" \ --member="principal://agents.global.org-ORGANIZATION_ID.system.id.goog/resources/aiplatform/projects/PROJECT_NUMBER/locations/LOCATION/reasoningEngines/ENGINE_ID" -
ローカルでの開発とテスト用に個人用ユーザー アカウントへのアクセス権を付与します(
adk web)。gcloud agent-identity auth-providers add-iam-policy-binding
AUTH_PROVIDER_NAME\ --project="PROJECT_ID" \ --location="LOCATION" \ --role="roles/agentidentity.user" \ --member="user:USER_EMAIL"
-
次のように置き換えます。
PROJECT_ID: 実際の Google Cloud プロジェクト ID。LOCATION: 認証プロバイダとエージェントがデプロイされているロケーション(例:us-west1)。AUTH_PROVIDER_NAME: 認証プロバイダの名前(jira-mcp-2lo-authproviderなど)。CLIENT_ID: サードパーティ サービスから生成した OAuth クライアント ID。CLIENT_SECRET: サードパーティ サービスから生成した OAuth クライアント シークレット。TOKEN_URL: トークン サーバーの URL(例:https://oauth2.googleapis.com/token)。ORGANIZATION_ID: Google Cloud 組織 ID。PROJECT_NUMBER: Google Cloud プロジェクトの番号。ENGINE_ID: デプロイされた Reasoning Engine エージェントの ID。USER_EMAIL: 個人のユーザー アカウントのメールアドレス。
エージェント コードで認証する
エージェントを認証するには、ADK を使用します。
ADK
ADK の MCP ツールセットを使用して、エージェントのコードで認証プロバイダを参照します。
from google.adk.agents import Agent from google.adk.auth.credential_manager import CredentialManager from google.adk.integrations.agent_identity import GcpAuthProvider, GcpAuthProviderScheme from google.adk.tools.mcp_tool.mcp_session_manager import StreamableHTTPConnectionParams from google.adk.tools.mcp_tool.mcp_toolset import McpToolset from google.adk.auth.auth_tool import AuthConfig # Register the Google Cloud Auth Provider so the CredentialManager can use it. CredentialManager.register_auth_provider(GcpAuthProvider()) # Create the Google Cloud Auth Provider scheme # Note: If using the legacy V1 API, the resource name uses 'connectors' # instead of 'authProviders': projects/.../connectors/... auth_scheme = GcpAuthProviderScheme( name="projects/PROJECT_ID/locations/LOCATION/authProviders/AUTH_PROVIDER_NAME" ) # Configure an MCP tool with the authentication scheme. toolset = McpToolset( connection_params=StreamableHTTPConnectionParams(url="https://YOUR_MCP_SERVER_URL"), auth_scheme=auth_scheme, ) # Initialize the agent with the authenticated tools. agent = Agent( name="AGENT_NAME", model="gemini-2.5-flash", instruction="AGENT_INSTRUCTIONS", tools=[toolset], )
ADK
ADK の認証済み関数ツールを使用して、エージェントのコードで認証プロバイダを参照します。
import httpx from google.adk.agents import Agent from google.adk.auth.credential_manager import CredentialManager from google.adk.integrations.agent_identity import GcpAuthProvider from google.adk.integrations.agent_identity import GcpAuthProviderScheme from google.adk.apps import App from google.adk.auth.auth_credential import AuthCredential from google.adk.auth.auth_tool import AuthConfig from google.adk.tools.authenticated_function_tool import AuthenticatedFunctionTool from vertexai import agent_engines # First, register Google Cloud auth provider CredentialManager.register_auth_provider(GcpAuthProvider()) # Create Auth Config # Note: If using the legacy V1 API, the resource name uses 'connectors' # instead of 'authProviders': projects/.../connectors/... spotify_auth_config = AuthConfig( auth_scheme=GcpAuthProviderScheme( name=( "projects/PROJECT_ID/locations/" "LOCATION/authProviders/" "AUTH_PROVIDER_NAME" ) ) ) # Use the Auth Config in Authenticated Function Tool spotify_search_track_tool = AuthenticatedFunctionTool( func=spotify_search_track, auth_config=spotify_auth_config ) # Sample function tool async def spotify_search_track(credential: AuthCredential, query: str) -> str | list: token = None if credential.http and credential.http.credentials: token = credential.http.credentials.token if not token: return "Error: No authentication token available." async with httpx.AsyncClient() as client: response = await client.get( "https://api.spotify.com/v1/search", headers={"Authorization": f"Bearer {token}"}, params={"q": query, "type": "track", "limit": 1}, ) # Add your own logic here agent = Agent( name="AGENT_NAME", model="MODEL_NAME", instruction="AGENT_INSTRUCTIONS", tools=[spotify_search_track_tool], ) app = App( name="APP_NAME", root_agent=agent, ) vertex_app = agent_engines.AdkApp(app_name=app)
ADK
ADK の Agent Registry MCP ツールセットを使用して、エージェントのコードで認証プロバイダを参照します。
このフローの認証スキームは構築しません。MCP サーバーのアウトバウンド バインディングには、使用する認証プロバイダがすでに記録されています。
from google.adk.agents import Agent from google.adk.auth.credential_manager import CredentialManager from google.adk.integrations.agent_identity import GcpAuthProvider from google.adk.integrations.agent_registry import AgentRegistry # First, register Google Cloud auth provider CredentialManager.register_auth_provider(GcpAuthProvider()) # Set Agent Registry. LOCATION must be the same region as the auth provider. registry = AgentRegistry(project_id="PROJECT_ID", location="LOCATION") # The auth provider is resolved from the MCP server's outbound binding. toolset = registry.get_mcp_toolset( mcp_server_name=( "projects/PROJECT_ID/locations/" "LOCATION/mcpServers/" "agentregistry-00000000-0000-0000-0000-000000000000" ), ) agent = Agent( name="AGENT_NAME", model="MODEL_NAME", instruction="AGENT_INSTRUCTIONS", tools=[toolset], )
ローカルテスト用の依存関係をインストールする
仮想環境でエージェントをローカルでテストするには、次の必要な依存関係をインストールします。
- 仮想環境を作成して有効にします。
python3 -m venv env source env/bin/activate
- 必要なパッケージをインストールします。
pip install google-cloud-aiplatform[agent_engines,adk] google-adk[agent-identity]
エージェントをデプロイする
エージェントを Google Cloudにデプロイするときは、エージェント ID が有効になっていることを確認してください。
エージェント CLI
Agent Development Kit(ADK)と Agents CLI を使用している場合は、次の手順で Agent Identity を有効にしてエージェントをデプロイします。
-
エージェント アプリケーション フォルダに、
.agent_engine_config.jsonという名前の構成ファイルを作成して、Agent Identity を有効にします。echo '{ "identity_type": "AGENT_IDENTITY" }' >
AGENT_NAME/.agent_engine_config.json -
Gemini Enterprise Agent Platform の Agent Runtime にエージェントをデプロイします。
uv run adk deploy agent_engine
AGENT_NAME\ --project="PROJECT_ID" \ --region="LOCATION"次のように置き換えます。
AGENT_NAME: エージェント アプリケーション フォルダの名前(maps_agentなど)。PROJECT_ID: 実際の Google Cloudプロジェクト ID。LOCATION: エージェントをデプロイするサポート対象の地域(例:us-west1)。
Python SDK
Vertex AI Python SDK を使用してプログラムでデプロイする場合は、identity_type=AGENT_IDENTITY フラグを使用します。
import vertexai from vertexai import types from vertexai.agent_engines import AdkApp from google.adk.auth.credential_manager import CredentialManager from google.adk.integrations.agent_identity import GcpAuthProvider # Initialize the Vertex AI client with v1beta1 API for Agent Identity support client = vertexai.Client( project="PROJECT_ID", location="LOCATION", http_options=dict(api_version="v1beta1") ) # Register the auth provider in set_up() so that it runs in the deployed # container. Use the proper wrapper class for your Agent Framework (for example, AdkApp). class AuthenticatedAdkApp(AdkApp): def set_up(self): CredentialManager.register_auth_provider(GcpAuthProvider()) super().set_up() app = AuthenticatedAdkApp(agent=agent) # Deploy the agent with Agent Identity enabled remote_app = client.agent_engines.create( agent=app, config={ "identity_type": types.IdentityType.AGENT_IDENTITY, "requirements": [ "google-cloud-aiplatform[agent_engines,adk]", "google-adk[agent-identity,mcp]>=2.7.1", ], }, )
次のように置き換えます。
PROJECT_ID: 実際の Google Cloud プロジェクト ID。LOCATION: エージェントをデプロイするサポート対象の地域(例:us-west1)。
次のステップ
- エージェント ID の概要
- 認証マネージャーで 3-legged OAuth を使用して認証する
- 認証マネージャーで API キーを使用して認証する
- エージェント ID 認証プロバイダを管理する
- Agent Identity Auth Manager のトラブルシューティング