本頁說明如何使用 Identity and Access Management (IAM) API、 Trusted Cloud 控制台和 gcloud CLI 停用及啟用服務帳戶。
事前準備
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 服務帳戶
必要的角色
如要取得管理服務帳戶所需的權限,請要求管理員授予您專案的「服務帳戶管理員」 (
roles/iam.serviceAccountAdmin
) IAM 角色。如要進一步瞭解如何授予角色,請參閱「管理專案、資料夾和機構的存取權」。如要進一步瞭解這個角色,請參閱服務帳戶角色。
身分與存取權管理基本角色也包含管理服務帳戶的權限。您不應在正式版環境中授予基本角色,但可以在開發或測試環境中授予。
停用服務帳戶
就像刪除服務帳戶一樣,若您停用服務帳戶,應用程式就無法再透過該服務帳戶存取 Trusted Cloud 資源。如果您停用預設的 Compute Engine 服務帳戶,執行個體將無法再存取專案中的資源。若您嘗試停用已經停用的服務帳戶,將不會產生任何作用。
與刪除服務帳戶不同的地方,就是停用的服務帳戶可於必要時輕鬆重新啟用。我們建議您在刪除服務帳戶之前先將其停用,確認沒有重要應用程式使用該服務帳戶。
控制台
前往 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 disable
指令,停用服務帳戶。指令:
gcloud iam service-accounts disable SA_NAME@PROJECT_ID.s3ns-system.iam.gserviceaccount.com
輸出:
Disabled service account 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。
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.disable
方法會立即停用服務帳戶。使用任何要求資料之前,請先替換以下項目:
HTTP 方法和網址:
POST https://iam.googleapis.com/v1/projects/PROJECT_ID/serviceAccounts/SA_ID:disable
如要傳送要求,請展開以下其中一個選項:
如果成功,回應主體會留白。
啟用服務帳戶
啟用已停用的服務帳戶後,應用程式將能再次透過該服務帳戶存取Trusted Cloud 資源。
您可於需要時隨時啟用已停用的服務帳戶。若您嘗試啟用已經啟用的服務帳戶,將不會產生任何作用。
控制台
前往 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 enable
指令以啟用服務帳戶。指令:
gcloud iam service-accounts enable SA_NAME@PROJECT_ID.s3ns-system.iam.gserviceaccount.com
輸出:
Enabled service account 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。
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.enable
方法可啟用先前停用的服務帳戶。使用任何要求資料之前,請先替換以下項目:
HTTP 方法和網址:
POST https://iam.googleapis.com/v1/projects/PROJECT_ID/serviceAccounts/SA_ID:enable
如要傳送要求,請展開以下其中一個選項:
如果成功,回應主體會留白。
後續步驟
- 瞭解如何刪除及取消刪除服務帳戶。
- 請參閱將 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 guide demonstrates how to disable and enable service accounts within Google Cloud using the IAM API, Google Cloud console, and the gcloud CLI."],["Before managing service accounts, you must enable the IAM API and properly set up authentication, which varies depending on whether you're using the console, gcloud CLI, or a client library in languages like C#, C++, Go, Java, or Python."],["Disabling a service account immediately revokes its access to Google Cloud resources, and it is recommended to disable an account before deletion as a precaution."],["Enabling a disabled service account restores its access to Google Cloud resources and can be done at any time."],["To manage service accounts, ensure that your administrator grants you the Service Account Admin role on the project."]]],[]]