This page explains how to disable and enable service accounts using the Identity and Access Management (IAM) API, the Trusted Cloud console, and the gcloud CLI.
Before you begin
Enable the IAM API.
Set up authentication.
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
Install the Google Cloud CLI, and then sign in to the gcloud CLI with your federated identity. After signing in, initialize the Google Cloud CLI by running the following command:
gcloud init
C#
To use the .NET samples on this page in a local development environment, install and initialize the gcloud CLI, and then set up Application Default Credentials with your user credentials.
Install the Google Cloud CLI, and then sign in to the gcloud CLI with your federated identity.
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.
For more information, see Set up ADC for a local development environment in the Trusted Cloud authentication documentation.
C++
To use the C++ samples on this page in a local development environment, install and initialize the gcloud CLI, and then set up Application Default Credentials with your user credentials.
Install the Google Cloud CLI, and then sign in to the gcloud CLI with your federated identity.
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.
For more information, see Set up ADC for a local development environment in the Trusted Cloud authentication documentation.
Go
To use the Go samples on this page in a local development environment, install and initialize the gcloud CLI, and then set up Application Default Credentials with your user credentials.
Install the Google Cloud CLI, and then sign in to the gcloud CLI with your federated identity.
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.
For more information, see Set up ADC for a local development environment in the Trusted Cloud authentication documentation.
Java
To use the Java samples on this page in a local development environment, install and initialize the gcloud CLI, and then set up Application Default Credentials with your user credentials.
Install the Google Cloud CLI, and then sign in to the gcloud CLI with your federated identity.
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.
For more information, see Set up ADC for a local development environment in the Trusted Cloud authentication documentation.
Python
To use the Python samples on this page in a local development environment, install and initialize the gcloud CLI, and then set up Application Default Credentials with your user credentials.
Install the Google Cloud CLI, and then sign in to the gcloud CLI with your federated identity.
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.
For more information, see Set up ADC for a local development environment in the Trusted Cloud authentication documentation.
REST
To use the REST API samples on this page in a local development environment, you use the credentials you provide to the gcloud CLI.
Install the Google Cloud CLI, and then sign in to the gcloud CLI with your federated identity.
For more information, see Authenticate for using REST in the Trusted Cloud authentication documentation.
Understand IAM service accounts
Required roles
To get the permissions that
you need to manage service accounts,
ask your administrator to grant you the
Service Account Admin (roles/iam.serviceAccountAdmin
)
IAM role on the project.
For more information about granting roles, see Manage access to projects, folders, and organizations.
You might also be able to get the required permissions through custom roles or other predefined roles.
To learn more about this role, see Service Accounts roles.
IAM basic roles also contain permissions to manage service accounts. You should not grant basic roles in a production environment, but you can grant them in a development or test environment.
Disable a service account
Similar to deleting a service account, when you disable a service account, applications will no longer have access to Trusted Cloud resources through that service account. If you disable the default Compute Engine service account, the instances will no longer have access to resources in the project. If you attempt to disable an already disabled service account, it will have no effect.
Unlike deleting a service account, disabled service accounts can easily be re-enabled as necessary. We recommend disabling a service account before deleting it to make sure no critical applications are using the service account.
Console
In the Trusted Cloud console, go to the Service accounts page.
Select a project.
Click the name of the service account that you want to disable.
Under Service account status, click Disable service account, then click Disable to confirm the change.
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.
-
Execute the
gcloud iam service-accounts disable
command to disable a service account.Command:
gcloud iam service-accounts disable SA_NAME@PROJECT_ID.s3ns-system.iam.gserviceaccount.com
Output:
Disabled service account SA_NAME@PROJECT_ID.s3ns-system.iam.gserviceaccount.com
C++
To learn how to install and use the client library for IAM, see IAM client libraries. For more information, see the IAM C++ API reference documentation.
To authenticate to IAM, set up Application Default Credentials. For more information, see Before you begin.
Before running code samples, set the GOOGLE_CLOUD_UNIVERSE_DOMAIN
environment
variable to s3nsapis.fr
.
C#
To learn how to install and use the client library for IAM, see IAM client libraries. For more information, see the IAM C# API reference documentation.
To authenticate to IAM, set up Application Default Credentials. For more information, see Before you begin.
Before running code samples, set the GOOGLE_CLOUD_UNIVERSE_DOMAIN
environment
variable to s3nsapis.fr
.
Go
To learn how to install and use the client library for IAM, see IAM client libraries. For more information, see the IAM Go API reference documentation.
To authenticate to IAM, set up Application Default Credentials. For more information, see Before you begin.
Before running code samples, set the GOOGLE_CLOUD_UNIVERSE_DOMAIN
environment
variable to s3nsapis.fr
.
Java
To learn how to install and use the client library for IAM, see IAM client libraries. For more information, see the IAM Java API reference documentation.
To authenticate to IAM, set up Application Default Credentials. For more information, see Before you begin.
Before running code samples, set the GOOGLE_CLOUD_UNIVERSE_DOMAIN
environment
variable to s3nsapis.fr
.
Python
To learn how to install and use the client library for IAM, see IAM client libraries. For more information, see the IAM Python API reference documentation.
To authenticate to IAM, set up Application Default Credentials. For more information, see Before you begin.
Before running code samples, set the GOOGLE_CLOUD_UNIVERSE_DOMAIN
environment
variable to s3nsapis.fr
.
REST
The
serviceAccounts.disable
method immediately disables a service account.
Before using any of the request data, make the following replacements:
PROJECT_ID
: Your Trusted Cloud project ID. Project IDs are alphanumeric strings, likemy-project
.SA_ID
: The ID of your service account. This can either be the service account's email address in the formSA_NAME@PROJECT_ID.s3ns-system.iam.gserviceaccount.com
, or the service account's unique numeric ID.
HTTP method and URL:
POST https://iam.googleapis.com/v1/projects/PROJECT_ID/serviceAccounts/SA_ID:disable
To send your request, expand one of these options:
If successful, the response body will be empty.
Enable a service account
After enabling a disabled service account, applications will regain access to Trusted Cloud resources through that service account.
You can enable a disabled service account whenever you need to. If you attempt to enable an already enabled service account, it will have no effect.
Console
In the Trusted Cloud console, go to the Service accounts page.
Select a project.
Click the name of the service account that you want to enable.
Under Service account status, click Enable service account, then click Enable to confirm the change.
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.
-
Execute the
gcloud iam service-accounts enable
command to enable a service account.Command:
gcloud iam service-accounts enable SA_NAME@PROJECT_ID.s3ns-system.iam.gserviceaccount.com
Output:
Enabled service account SA_NAME@PROJECT_ID.s3ns-system.iam.gserviceaccount.com
C++
To learn how to install and use the client library for IAM, see IAM client libraries. For more information, see the IAM C++ API reference documentation.
To authenticate to IAM, set up Application Default Credentials. For more information, see Before you begin.
Before running code samples, set the GOOGLE_CLOUD_UNIVERSE_DOMAIN
environment
variable to s3nsapis.fr
.
C#
To learn how to install and use the client library for IAM, see IAM client libraries. For more information, see the IAM C# API reference documentation.
To authenticate to IAM, set up Application Default Credentials. For more information, see Before you begin.
Before running code samples, set the GOOGLE_CLOUD_UNIVERSE_DOMAIN
environment
variable to s3nsapis.fr
.
Go
To learn how to install and use the client library for IAM, see IAM client libraries. For more information, see the IAM Go API reference documentation.
To authenticate to IAM, set up Application Default Credentials. For more information, see Before you begin.
Before running code samples, set the GOOGLE_CLOUD_UNIVERSE_DOMAIN
environment
variable to s3nsapis.fr
.
Java
To learn how to install and use the client library for IAM, see IAM client libraries. For more information, see the IAM Java API reference documentation.
To authenticate to IAM, set up Application Default Credentials. For more information, see Before you begin.
Before running code samples, set the GOOGLE_CLOUD_UNIVERSE_DOMAIN
environment
variable to s3nsapis.fr
.
Python
To learn how to install and use the client library for IAM, see IAM client libraries. For more information, see the IAM Python API reference documentation.
To authenticate to IAM, set up Application Default Credentials. For more information, see Before you begin.
Before running code samples, set the GOOGLE_CLOUD_UNIVERSE_DOMAIN
environment
variable to s3nsapis.fr
.
REST
The
serviceAccounts.enable
method enables a previously disabled service account.
Before using any of the request data, make the following replacements:
PROJECT_ID
: Your Trusted Cloud project ID. Project IDs are alphanumeric strings, likemy-project
.SA_ID
: The ID of your service account. This can either be the service account's email address in the formSA_NAME@PROJECT_ID.s3ns-system.iam.gserviceaccount.com
, or the service account's unique numeric ID.
HTTP method and URL:
POST https://iam.googleapis.com/v1/projects/PROJECT_ID/serviceAccounts/SA_ID:enable
To send your request, expand one of these options:
If successful, the response body will be empty.
What's next
- Learn how to delete and undelete service accounts.
- Review the process for granting IAM roles to all types of principals, including service accounts.
- Understand how to attach service accounts to resources.