本頁說明如何使用 Identity and Access Management (IAM) API、 Trusted 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 Trusted Cloud console to access Trusted Cloud by S3NS services and APIs, you don't need to set up authentication.
gcloud
安裝 Google Cloud CLI,然後 使用同盟身分登入 gcloud CLI。 登入後,執行下列指令初始化 Google Cloud CLI:
gcloud init
C#
如要在本機開發環境中使用本頁的 .NET 範例,請安裝並初始化 gcloud CLI,然後使用使用者憑證設定應用程式預設憑證。
安裝 Google Cloud CLI,然後 使用同盟身分登入 gcloud CLI。
Create local authentication credentials for your user account:
gcloud auth application-default login
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.
詳情請參閱 Trusted Cloud 驗證說明文件中的「 為本機開發環境設定 ADC」。
C++
如要在本機開發環境中使用本頁的 C++ 範例,請安裝並初始化 gcloud CLI,然後使用使用者憑證設定應用程式預設憑證。
安裝 Google Cloud CLI,然後 使用同盟身分登入 gcloud CLI。
Create local authentication credentials for your user account:
gcloud auth application-default login
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.
詳情請參閱 Trusted Cloud 驗證說明文件中的「 為本機開發環境設定 ADC」。
Go
如要在本機開發環境中使用本頁的 Go 範例,請安裝並初始化 gcloud CLI,然後使用使用者憑證設定應用程式預設憑證。
安裝 Google Cloud CLI,然後 使用同盟身分登入 gcloud CLI。
Create local authentication credentials for your user account:
gcloud auth application-default login
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.
詳情請參閱 Trusted Cloud 驗證說明文件中的「 為本機開發環境設定 ADC」。
Java
如要在本機開發環境中使用本頁的 Java 範例,請安裝並初始化 gcloud CLI,然後使用使用者憑證設定應用程式預設憑證。
安裝 Google Cloud CLI,然後 使用同盟身分登入 gcloud CLI。
Create local authentication credentials for your user account:
gcloud auth application-default login
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.
詳情請參閱 Trusted Cloud 驗證說明文件中的「 為本機開發環境設定 ADC」。
Python
如要在本機開發環境中使用本頁的 Python 範例,請安裝並初始化 gcloud CLI,然後使用使用者憑證設定應用程式預設憑證。
安裝 Google Cloud CLI,然後 使用同盟身分登入 gcloud CLI。
Create local authentication credentials for your user account:
gcloud auth application-default login
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.
詳情請參閱 Trusted Cloud 驗證說明文件中的「 為本機開發環境設定 ADC」。
REST
如要在本機開發環境中使用本頁的 REST API 範例,請使用您提供給 gcloud CLI 的憑證。
安裝 Google Cloud CLI,然後 使用同盟身分登入 gcloud CLI。
詳情請參閱 Trusted Cloud 驗證說明文件中的「Authenticate for using REST」。
瞭解 IAM 服務帳戶
必要的角色
如要取得管理服務帳戶所需的權限,請要求管理員在專案中授予下列 IAM 角色:
-
如要查看服務帳戶:
按一下「查看服務帳戶」 (
roles/iam.serviceAccountViewer
) -
如要編輯服務帳戶:
服務帳戶管理員 (
roles/iam.serviceAccountAdmin
)
如要進一步瞭解如何授予角色,請參閱「管理專案、資料夾和機構的存取權」。
如要進一步瞭解這些角色,請參閱「服務帳戶角色」。
身分與存取權管理基本角色也包含管理服務帳戶的權限。您不應在正式版環境中授予基本角色,但可以在開發或測試環境中授予。
列出服務帳戶
您可以列出專案中的使用者代管服務帳戶,以稽核服務帳戶和金鑰,或做為管理服務帳戶的自訂工具。
您無法列出可能出現在專案允許政策和稽核記錄中的服務代理程式。服務代理不在您的專案中,您無法直接存取。
控制台
前往 Trusted Cloud 控制台的「Service accounts」(服務帳戶) 頁面。
選取專案。
「Service accounts」(服務帳戶) 頁面會列出所選專案中的所有使用者管理服務帳戶。
gcloud
-
In the Trusted Cloud console, activate Cloud Shell.
At the bottom of the Trusted 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.s3ns-system.iam.gserviceaccount.com SA_DISPLAY_NAME_2 SA_NAME_2@PROJECT_ID.s3ns-system.iam.gserviceaccount.com
PROJECT_ID
:您的 Trusted Cloud 專案 ID。專案 ID 為英數字串,例如my-project
。
C++
如要瞭解如何安裝及使用 IAM 的用戶端程式庫,請參閱 IAM 用戶端程式庫。 詳情請參閱 IAM C++ API 參考說明文件。
如要向 IAM 進行驗證,請設定應用程式預設憑證。 詳情請參閱「事前準備」。
執行程式碼範例前,請將
GOOGLE_CLOUD_UNIVERSE_DOMAIN
環境變數設為s3nsapis.fr
。C#
如要瞭解如何安裝及使用 IAM 的用戶端程式庫,請參閱 IAM 用戶端程式庫。 詳情請參閱 IAM C# API 參考說明文件。
如要向 IAM 進行驗證,請設定應用程式預設憑證。 詳情請參閱「事前準備」。
執行程式碼範例前,請將
GOOGLE_CLOUD_UNIVERSE_DOMAIN
環境變數設為s3nsapis.fr
。Go
如要瞭解如何安裝及使用 IAM 的用戶端程式庫,請參閱 IAM 用戶端程式庫。 詳情請參閱 IAM Go API 參考說明文件。
如要向 IAM 進行驗證,請設定應用程式預設憑證。 詳情請參閱「事前準備」。
執行程式碼範例前,請將
GOOGLE_CLOUD_UNIVERSE_DOMAIN
環境變數設為s3nsapis.fr
。Java
如要瞭解如何安裝及使用 IAM 的用戶端程式庫,請參閱 IAM 用戶端程式庫。 詳情請參閱 IAM Java API 參考說明文件。
如要向 IAM 進行驗證,請設定應用程式預設憑證。 詳情請參閱「事前準備」。
執行程式碼範例前,請將
GOOGLE_CLOUD_UNIVERSE_DOMAIN
環境變數設為s3nsapis.fr
。Python
如要瞭解如何安裝及使用 IAM 的用戶端程式庫,請參閱 IAM 用戶端程式庫。 詳情請參閱 IAM Python API 參考說明文件。
如要向 IAM 進行驗證,請設定應用程式預設憑證。 詳情請參閱「事前準備」。
執行程式碼範例前,請將
GOOGLE_CLOUD_UNIVERSE_DOMAIN
環境變數設為s3nsapis.fr
。REST
serviceAccounts.list
方法會列出專案中的所有使用者管理服務帳戶。使用任何要求資料之前,請先替換以下項目:
HTTP 方法和網址:
GET https://iam.googleapis.com/v1/projects/PROJECT_ID/serviceAccounts
如要傳送要求,請展開以下其中一個選項:
您應該會收到如下的 JSON 回應:
{ "accounts": [ { "name": "projects/my-project/serviceAccounts/sa-1@my-project.s3ns-system.iam.gserviceaccount.com", "projectId": "my-project", "uniqueId": "123456789012345678901", "email": "sa-1@my-project.s3ns-system.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.s3ns-system.iam.gserviceaccount.com", "projectId": "my-project", "uniqueId": "234567890123456789012", "email": "sa-2@my-project.s3ns-system.iam.gserviceaccount.com", "description": "My second service account", "displayName": "Service account 2", "etag": "UkQpTwBVUsL=", "oauth2ClientId": "876543210987654321098" } ] }
編輯服務帳戶
服務帳戶的顯示名稱 (好記的名稱) 和說明通常用於擷取與服務帳戶有關的其他資訊,例如服務帳戶用途或帳戶聯絡人。
控制台
前往 Trusted Cloud 控制台的「Service accounts」(服務帳戶) 頁面。
選取專案。
按一下要重新命名的服務帳戶電子郵件地址。
在「名稱」方塊中輸入新名稱,然後按一下「儲存」。
gcloud
-
In the Trusted Cloud console, activate Cloud Shell.
At the bottom of the Trusted 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.s3ns-system.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.s3ns-system.iam.gserviceaccount.com
PROJECT_ID
:您的 Trusted Cloud 專案 ID。專案 ID 為英數字串,例如my-project
。SA_ID
:服務帳戶的 ID。 這可以是SA_NAME@PROJECT_ID.s3ns-system.iam.gserviceaccount.com
形式的服務帳戶電子郵件地址,也可以是服務帳戶的不重複數字 ID。SA_NAME
:服務帳戶的英數字元 ID。名稱長度必須介於 6 至 30 個字元之間,可以使用小寫英數字元和破折號。- 至少取代下列其中一項:
UPDATED_DISPLAY_NAME
:服務帳戶的新顯示名稱。UPDATED_DESCRIPTION
:服務帳戶的新說明。
C++
如要瞭解如何安裝及使用 IAM 的用戶端程式庫,請參閱 IAM 用戶端程式庫。 詳情請參閱 IAM C++ API 參考說明文件。
如要向 IAM 進行驗證,請設定應用程式預設憑證。 詳情請參閱「事前準備」。
執行程式碼範例前,請將
GOOGLE_CLOUD_UNIVERSE_DOMAIN
環境變數設為s3nsapis.fr
。C#
如要瞭解如何安裝及使用 IAM 的用戶端程式庫,請參閱 IAM 用戶端程式庫。 詳情請參閱 IAM C# API 參考說明文件。
如要向 IAM 進行驗證,請設定應用程式預設憑證。 詳情請參閱「事前準備」。
執行程式碼範例前,請將
GOOGLE_CLOUD_UNIVERSE_DOMAIN
環境變數設為s3nsapis.fr
。Go
如要瞭解如何安裝及使用 IAM 的用戶端程式庫,請參閱 IAM 用戶端程式庫。 詳情請參閱 IAM Go API 參考說明文件。
如要向 IAM 進行驗證,請設定應用程式預設憑證。 詳情請參閱「事前準備」。
執行程式碼範例前,請將
GOOGLE_CLOUD_UNIVERSE_DOMAIN
環境變數設為s3nsapis.fr
。Java
如要瞭解如何安裝及使用 IAM 的用戶端程式庫,請參閱 IAM 用戶端程式庫。 詳情請參閱 IAM Java API 參考說明文件。
如要向 IAM 進行驗證,請設定應用程式預設憑證。 詳情請參閱「事前準備」。
執行程式碼範例前,請將
GOOGLE_CLOUD_UNIVERSE_DOMAIN
環境變數設為s3nsapis.fr
。Python
如要瞭解如何安裝及使用 IAM 的用戶端程式庫,請參閱 IAM 用戶端程式庫。 詳情請參閱 IAM Python API 參考說明文件。
如要向 IAM 進行驗證,請設定應用程式預設憑證。 詳情請參閱「事前準備」。
執行程式碼範例前,請將
GOOGLE_CLOUD_UNIVERSE_DOMAIN
環境變數設為s3nsapis.fr
。REST
serviceAccounts.patch
方法會更新服務帳戶。使用任何要求資料之前,請先替換以下項目:
HTTP 方法和網址:
PATCH https://iam.googleapis.com/v1/projects/PROJECT_ID/serviceAccounts/SA_ID
JSON 要求主體:
{ "serviceAccount": { "email": "SA_NAME@PROJECT_ID.s3ns-system.iam.gserviceaccount.com", "displayName": "UPDATED_DISPLAY_NAME", "description": "UPDATED_DESCRIPTION" }, "updateMask": "displayName,description" }
如要傳送要求,請展開以下其中一個選項:
您應該會收到如下的 JSON 回應:
{ "name": "projects/my-project/serviceAccounts/my-service-account@my-project.s3ns-system.iam.gserviceaccount.com", "displayName": "My updated service account", "description": "An updated description of my service account" }
後續步驟
- 瞭解如何停用及啟用服務帳戶。
- 請參閱將 IAM 角色授予所有類型主體的程序,包括服務帳戶。
- 瞭解如何將服務帳戶附加至資源。
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-08-08 (世界標準時間)。
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["缺少我需要的資訊","missingTheInformationINeed","thumb-down"],["過於複雜/步驟過多","tooComplicatedTooManySteps","thumb-down"],["過時","outOfDate","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["示例/程式碼問題","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-08-08 (世界標準時間)。"],[[["This document outlines how to manage service accounts, specifically listing and editing them, using the IAM API, Google Cloud console, and the `gcloud` command-line tool."],["Before managing service accounts, users must enable the IAM API and set up authentication, which varies depending on whether they are using the console, `gcloud`, or a local development environment with various language-specific setups like C#, C++, Go, Java, or Python."],["Listing service accounts can be accomplished through the Google Cloud console's Service accounts page or via the `gcloud iam service-accounts list` command in Cloud Shell, displaying all user-managed service accounts within a selected project."],["Editing a service account, such as changing its display name or description, can be done through the Google Cloud console or with the `gcloud iam service-accounts update` command, using the specific email or ID of the account to be updated."],["The IAM roles of View Service Accounts (`roles/iam.serviceAccountViewer`) and Service Account Admin (`roles/iam.serviceAccountAdmin`) are required for viewing and editing service accounts, respectively, but other custom or predefined roles may also provide these permissions."]]],[]]