このページでは、Identity and Access Management(IAM)API、 Google Cloud コンソール、gcloud
コマンドライン ツールを使用して、サービス アカウントの一覧を取得して編集する方法について説明します。
始める前に
Enable the IAM API.
認証を設定する。
Select the tab for how you plan to use the samples on this page:
Console
When you use the Google Cloud console to access Google Cloud services and APIs, you don't need to set up authentication.
gcloud
-
Install the Google Cloud CLI.
-
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
-
To initialize the gcloud CLI, run the following command:
gcloud init
-
If you're using a local shell, then create local authentication credentials for your user account:
gcloud auth application-default login
You don't need to do this if you're using Cloud Shell.
If an authentication error is returned, and you are using an external identity provider (IdP), confirm that you have signed in to the gcloud CLI with your federated identity.
-
Install the Google Cloud CLI.
-
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
-
To initialize the gcloud CLI, run the following command:
gcloud init
-
If you're using a local shell, then create local authentication credentials for your user account:
gcloud auth application-default login
You don't need to do this if you're using Cloud Shell.
If an authentication error is returned, and you are using an external identity provider (IdP), confirm that you have signed in to the gcloud CLI with your federated identity.
-
Install the Google Cloud CLI.
-
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
-
To initialize the gcloud CLI, run the following command:
gcloud init
-
If you're using a local shell, then create local authentication credentials for your user account:
gcloud auth application-default login
You don't need to do this if you're using Cloud Shell.
If an authentication error is returned, and you are using an external identity provider (IdP), confirm that you have signed in to the gcloud CLI with your federated identity.
-
Install the Google Cloud CLI.
-
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
-
To initialize the gcloud CLI, run the following command:
gcloud init
-
If you're using a local shell, then create local authentication credentials for your user account:
gcloud auth application-default login
You don't need to do this if you're using Cloud Shell.
If an authentication error is returned, and you are using an external identity provider (IdP), confirm that you have signed in to the gcloud CLI with your federated identity.
-
Install the Google Cloud CLI.
-
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
-
To initialize the gcloud CLI, run the following command:
gcloud init
-
If you're using a local shell, then create local authentication credentials for your user account:
gcloud auth application-default login
You don't need to do this if you're using Cloud Shell.
If an authentication error is returned, and you are using an external identity provider (IdP), confirm that you have signed in to the gcloud CLI with your federated identity.
IAM サービス アカウントを理解する
-
サービス アカウントを確認する: サービス アカウントの表示(
roles/iam.serviceAccountViewer
) - サービス アカウントを編集する: サービス アカウント管理者(
roles/iam.serviceAccountAdmin
) Google Cloud コンソールで、[サービス アカウント] ページに移動します。
プロジェクトを選択します。
[サービス アカウント] ページに、選択したプロジェクトのユーザーが管理するサービス アカウントがすべて一覧表示されます。
-
In the Google Cloud console, activate Cloud Shell.
At the bottom of the Google Cloud console, a Cloud Shell session starts and displays a command-line prompt. Cloud Shell is a shell environment with the Google Cloud CLI already installed and with values already set for your current project. It can take a few seconds for the session to initialize.
-
gcloud iam service-accounts list
コマンドを実行して、プロジェクト内のすべてのサービス アカウントを一覧表示します。コマンド:
gcloud iam service-accounts list
プロジェクト内にあるユーザー管理のサービス アカウントが一覧表示されます。
NAME EMAIL SA_DISPLAY_NAME_1 SA_NAME_1@PROJECT_ID.iam.gserviceaccount.com SA_DISPLAY_NAME_2 SA_NAME_2@PROJECT_ID.iam.gserviceaccount.com
PROJECT_ID
: 実際の Google Cloud プロジェクト ID。プロジェクト ID は英数字からなる文字列です(例:my-project
)。Google Cloud コンソールで、[サービス アカウント] ページに移動します。
プロジェクトを選択します。
名前を変更するサービス アカウントのメールアドレスをクリックします。
[名前] ボックスに新しい名前を入力して、[保存] をクリックします。
-
In the Google Cloud console, activate Cloud Shell.
At the bottom of the Google Cloud console, a Cloud Shell session starts and displays a command-line prompt. Cloud Shell is a shell environment with the Google Cloud CLI already installed and with values already set for your current project. It can take a few seconds for the session to initialize.
-
gcloud iam service-accounts update
コマンドを実行して、サービス アカウントを更新します。コマンド:
gcloud iam service-accounts update
SA_NAME@PROJECT_ID.iam.gserviceaccount.com
--description="UPDATED_SA_DESCRIPTION"
--display-name="UPDATED_DISPLAY_NAME"出力は名前が変更されたサービス アカウントです。
description: UPDATED_SA_DESCRIPTION displayName: UPDATED_DISPLAY_NAME name: projects/PROJECT_ID/serviceAccounts/SA_NAME@PROJECT_ID.iam.gserviceaccount.com
PROJECT_ID
: 実際の Google Cloud プロジェクト ID。プロジェクト ID は英数字からなる文字列です(例:my-project
)。SA_ID
: サービス アカウントの ID。これは、サービス アカウントのメールアドレス(SA_NAME@PROJECT_ID.iam.gserviceaccount.com
の形式)、またはサービス アカウントの一意の数値 ID のいずれかです。SA_NAME
: サービス アカウントの英数字 ID。この名前は 6~30 文字で指定する必要があり、小文字の英数字とダッシュを含めることができます。- 次のうち少なくとも 1 つを置き換えます。
UPDATED_DISPLAY_NAME
: サービス アカウントの新しい表示名。UPDATED_DESCRIPTION
: サービス アカウントの新しい説明。- サービス アカウントを無効または有効にする方法を確認する。
- サービス アカウントを含むすべてのタイプのプリンシパルに IAM のロールを付与するプロセスを確認する。
- ロールの推奨事項を使用して、すべてのプリンシパル(サービス アカウントを含む)の権限の範囲を制限する方法を確認する。
- サービス アカウントをリソースに関連付ける方法を理解する。
In the Google Cloud console, activate Cloud Shell.
At the bottom of the Google Cloud console, a Cloud Shell session starts and displays a command-line prompt. Cloud Shell is a shell environment with the Google Cloud CLI already installed and with values already set for your current project. It can take a few seconds for the session to initialize.
C#
ローカル開発環境でこのページの .NET サンプルを使用するには、gcloud CLI をインストールして初期化し、ユーザー認証情報を使用してアプリケーションのデフォルト認証情報を設定します。
詳細については、 Google Cloud 認証ドキュメントのローカル開発環境の ADC の設定をご覧ください。
C++
ローカル開発環境でこのページの C++ サンプルを使用するには、gcloud CLI をインストールして初期化し、ユーザー認証情報を使用してアプリケーションのデフォルト認証情報を設定します。
詳細については、 Google Cloud 認証ドキュメントのローカル開発環境の ADC の設定をご覧ください。
Go
ローカル開発環境でこのページの Go サンプルを使用するには、gcloud CLI をインストールして初期化し、ユーザー認証情報を使用してアプリケーションのデフォルト認証情報を設定します。
詳細については、 Google Cloud 認証ドキュメントのローカル開発環境の ADC の設定をご覧ください。
Java
ローカル開発環境でこのページの Java サンプルを使用するには、gcloud CLI をインストールして初期化し、ユーザー認証情報を使用してアプリケーションのデフォルト認証情報を設定します。
詳細については、 Google Cloud 認証ドキュメントのローカル開発環境の ADC の設定をご覧ください。
Python
ローカル開発環境でこのページの Python サンプルを使用するには、gcloud CLI をインストールして初期化し、ユーザー認証情報を使用してアプリケーションのデフォルト認証情報を設定します。
詳細については、 Google Cloud 認証ドキュメントのローカル開発環境の ADC の設定をご覧ください。
REST
このページの REST API サンプルをローカル開発環境で使用するには、gcloud CLI に指定した認証情報を使用します。
After installing the Google Cloud CLI, initialize it by running the following command:
gcloud init
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
詳細については、 Google Cloud 認証ドキュメントの REST を使用して認証するをご覧ください。
必要なロール
サービス アカウントの管理に必要な権限を取得するため、プロジェクトに対する次の IAM ロールを付与するよう管理者に依頼します。
ロールの付与については、プロジェクト、フォルダ、組織へのアクセスを管理するをご覧ください。
必要な権限は、カスタムロールや他の事前定義ロールから取得することもできます。
これらのロールの詳細については、サービス アカウントのロールをご覧ください。
IAM の基本ロールには、サービス アカウントを管理する権限も含まれています。本番環境では基本ロールを付与すべきではありません。基本ロールは、開発環境またはテスト環境で付与してください。
サービス アカウントの一覧取得
サービス アカウントとキーの監査を行う際に、プロジェクトのユーザー管理のサービス アカウントを一覧表示できます。また、サービス アカウントを管理するカスタムツールでこの操作を行うこともできます。
プロジェクトの許可ポリシーと監査ログに表示されるサービス エージェントを一覧表示することはできません。サービス エージェントはプロジェクトに定義されていないため、直接アクセスすることはできません。
コンソール
gcloud
C++
IAM のクライアント ライブラリをインストールして使用する方法については、IAM クライアント ライブラリをご覧ください。詳細については、IAM C++ API のリファレンス ドキュメントをご覧ください。
IAM で認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、始める前にをご覧ください。
C#
IAM のクライアント ライブラリをインストールして使用する方法については、IAM クライアント ライブラリをご覧ください。詳細については、IAM C# API のリファレンス ドキュメントをご覧ください。
IAM で認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、始める前にをご覧ください。
Go
IAM のクライアント ライブラリをインストールして使用する方法については、IAM クライアント ライブラリをご覧ください。詳細については、IAM Go API のリファレンス ドキュメントをご覧ください。
IAM で認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、始める前にをご覧ください。
Java
IAM のクライアント ライブラリをインストールして使用する方法については、IAM クライアント ライブラリをご覧ください。詳細については、IAM Java API のリファレンス ドキュメントをご覧ください。
IAM で認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、始める前にをご覧ください。
Python
IAM のクライアント ライブラリをインストールして使用する方法については、IAM クライアント ライブラリをご覧ください。詳細については、IAM Python API のリファレンス ドキュメントをご覧ください。
IAM で認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、始める前にをご覧ください。
REST
serviceAccounts.list
メソッドは、プロジェクト内のユーザー管理のサービス アカウントを一覧表示します。リクエストのデータを使用する前に、次のように置き換えます。
HTTP メソッドと URL:
GET https://iam.googleapis.com/v1/projects/PROJECT_ID/serviceAccounts
リクエストを送信するには、次のいずれかのオプションを展開します。
次のような JSON レスポンスが返されます。
{ "accounts": [ { "name": "projects/my-project/serviceAccounts/sa-1@my-project.iam.gserviceaccount.com", "projectId": "my-project", "uniqueId": "123456789012345678901", "email": "sa-1@my-project.iam.gserviceaccount.com", "description": "My first service account", "displayName": "Service account 1", "etag": "BwUpTsLVUkQ=", "oauth2ClientId": "987654321098765432109" }, { "name": "projects/my-project/serviceAccounts/sa-2@my-project.iam.gserviceaccount.com", "projectId": "my-project", "uniqueId": "234567890123456789012", "email": "sa-2@my-project.iam.gserviceaccount.com", "description": "My second service account", "displayName": "Service account 2", "etag": "UkQpTwBVUsL=", "oauth2ClientId": "876543210987654321098" } ] }
サービス アカウントを編集する
サービス アカウントの表示名(わかりやすい名前)や説明は、サービス アカウントの目的やアカウントの担当者など、サービス アカウントに関する追加情報を取得するためによく使用されます。
コンソール
gcloud
C++
IAM のクライアント ライブラリをインストールして使用する方法については、IAM クライアント ライブラリをご覧ください。詳細については、IAM C++ API のリファレンス ドキュメントをご覧ください。
IAM で認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、始める前にをご覧ください。
C#
IAM のクライアント ライブラリをインストールして使用する方法については、IAM クライアント ライブラリをご覧ください。詳細については、IAM C# API のリファレンス ドキュメントをご覧ください。
IAM で認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、始める前にをご覧ください。
Go
IAM のクライアント ライブラリをインストールして使用する方法については、IAM クライアント ライブラリをご覧ください。詳細については、IAM Go API のリファレンス ドキュメントをご覧ください。
IAM で認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、始める前にをご覧ください。
Java
IAM のクライアント ライブラリをインストールして使用する方法については、IAM クライアント ライブラリをご覧ください。詳細については、IAM Java API のリファレンス ドキュメントをご覧ください。
IAM で認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、始める前にをご覧ください。
Python
IAM のクライアント ライブラリをインストールして使用する方法については、IAM クライアント ライブラリをご覧ください。詳細については、IAM Python API のリファレンス ドキュメントをご覧ください。
IAM で認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、始める前にをご覧ください。
REST
serviceAccounts.patch
メソッドを使用して、サービス アカウントを更新します。リクエストのデータを使用する前に、次のように置き換えます。
HTTP メソッドと URL:
PATCH https://iam.googleapis.com/v1/projects/PROJECT_ID/serviceAccounts/SA_ID
リクエストの本文(JSON):
{ "serviceAccount": { "email": "SA_NAME@PROJECT_ID.iam.gserviceaccount.com", "displayName": "UPDATED_DISPLAY_NAME", "description": "UPDATED_DESCRIPTION" }, "updateMask": "displayName,description" }
リクエストを送信するには、次のいずれかのオプションを展開します。
次のような JSON レスポンスが返されます。
{ "name": "projects/my-project/serviceAccounts/my-service-account@my-project.iam.gserviceaccount.com", "displayName": "My updated service account", "description": "An updated description of my service account" }
次のステップ
使ってみる
Google Cloudを初めて使用する場合は、アカウントを作成して、実際のシナリオでの Google プロダクトのパフォーマンスを評価してください。新規のお客様には、ワークロードの実行、テスト、デプロイができる無料クレジット $300 分を差し上げます。
無料で開始特に記載のない限り、このページのコンテンツはクリエイティブ・コモンズの表示 4.0 ライセンスにより使用許諾されます。コードサンプルは Apache 2.0 ライセンスにより使用許諾されます。詳しくは、Google Developers サイトのポリシーをご覧ください。Java は Oracle および関連会社の登録商標です。
最終更新日 2025-07-14 UTC。
-