このドキュメントでは、gcloud functions、REST API、Terraform などで Cloud Functions v2 API を使用して作成された関数を呼び出す方法について補足情報を提供します。詳細情報と例については、Cloud Run ガイドのリクエストの認証をご覧ください。Cloud Run ガイドで説明されているトピックは、Cloud Functions v2 API を使用して作成された関数にも適用されます。これは、v2 関数も Cloud Run 起動元ロール(roles/run.invoker)を使用するためです。
認証された関数を呼び出すには、基盤となるプリンシパルが次の要件を満たしている必要があります。
関数を呼び出す権限を持っている。
関数を呼び出すときに ID トークンを提供する。
Cloud Run functions は、次の 2 種類の ID をサポートしています。これらはプリンシパルとも呼ばれます。
サービス アカウント: 関数、アプリケーション、VM など、人以外の ID として機能する特別なアカウントです。これにより、人以外の認証を行うことができます。
ユーザー アカウント: 個々の Google アカウント所有者、または Google グループのような Google が管理するエンティティの一員など、人を表します。
イベント ドリブン関数を呼び出すことができるのは、関数が登録されているイベントソースだけです。ただし、HTTP 関数は、関数をテストするデベロッパーや関数を使用する別のサービスなど、さまざまな場所で発生するさまざまな ID タイプによって呼び出すことができます。ID は認証用の ID トークンを提供する必要があります。また、使用するアカウントに適切な権限が付与されている必要があります。
[[["わかりやすい","easyToUnderstand","thumb-up"],["問題の解決に役立った","solvedMyProblem","thumb-up"],["その他","otherUp","thumb-up"]],[["わかりにくい","hardToUnderstand","thumb-down"],["情報またはサンプルコードが不正確","incorrectInformationOrSampleCode","thumb-down"],["必要な情報 / サンプルがない","missingTheInformationSamplesINeed","thumb-down"],["翻訳に関する問題","translationIssue","thumb-down"],["その他","otherDown","thumb-down"]],["最終更新日 2025-08-14 UTC。"],[[["To invoke an authenticated Cloud Run function, the principal must have the `run.routes.invoke` permission, typically through the Cloud Run Invoker role, and provide an ID token."],["Principals can be service accounts (for non-persons like functions or applications) or user accounts (for individual Google Account holders or groups), both requiring appropriate permissions to invoke functions."],["Developers can test functions by assigning the Cloud Run Invoker role to their user account, using the Google Cloud CLI to generate ID tokens for requests, and allocating the minimum required permissions to operate."],["For function-to-function calls, grant the calling function's service account the Cloud Run Invoker role on the receiving function's service, ensuring the calling function provides a Google-signed ID token."],["ID tokens can be generated programmatically using authentication libraries or manually by using the Compute metadata server or exchanging a self-signed JWT for a Google-signed ID token, with the latter two methods being more complex."]]],[]]