Skip to main content

service_accounts

Creates, updates, deletes, gets or lists a service_accounts resource.

Overview

Nameservice_accounts
TypeResource
Idgoogle.iam.service_accounts

Fields

The following fields are returned by SELECT queries:

Successful response

NameDatatypeDescription
namestringThe resource name of the service account. Use one of the following formats: * projects/{PROJECT_ID}/serviceAccounts/{EMAIL_ADDRESS} * projects/{PROJECT_ID}/serviceAccounts/{UNIQUE_ID} As an alternative, you can use the - wildcard character instead of the project ID: * projects/-/serviceAccounts/{EMAIL_ADDRESS} * projects/-/serviceAccounts/{UNIQUE_ID} When possible, avoid using the - wildcard character, because it can cause response messages to contain misleading error codes. For example, if you try to access the service account projects/-/serviceAccounts/fake@example.com, which does not exist, the response contains an HTTP 403 Forbidden error instead of a 404 Not Found error.
descriptionstringOptional. A user-specified, human-readable description of the service account. The maximum length is 256 UTF-8 bytes.
disabledbooleanOutput only. Whether the service account is disabled.
displayNamestringOptional. A user-specified, human-readable name for the service account. The maximum length is 100 UTF-8 bytes.
emailstringOutput only. The email address of the service account.
etagstring (byte)Deprecated. Do not use.
oauth2ClientIdstringOutput only. The OAuth 2.0 client ID for the service account.
projectIdstringOutput only. The ID of the project that owns the service account.
uniqueIdstringOutput only. The unique, stable numeric ID for the service account. Each service account retains its unique ID even if you delete the service account. For example, if you delete a service account, then create a new service account with the same name, the new service account has a different unique ID than the deleted service account.

Methods

The following methods are available for this resource:

NameAccessible byRequired ParamsOptional ParamsDescription
getselectprojectsId, serviceAccountsIdGets a ServiceAccount.
listselectprojectsIdpageSize, pageTokenLists every ServiceAccount that belongs to a specific project.
createinsertprojectsIdCreates a ServiceAccount.
patchupdateprojectsId, serviceAccountsIdPatches a ServiceAccount.
updatereplaceprojectsId, serviceAccountsIdNote: We are in the process of deprecating this method. Use PatchServiceAccount instead. Updates a ServiceAccount. You can update only the display_name field.
deletedeleteprojectsId, serviceAccountsIdDeletes a ServiceAccount. Warning: After you delete a service account, you might not be able to undelete it. If you know that you need to re-enable the service account in the future, use DisableServiceAccount instead. If you delete a service account, IAM permanently removes the service account 30 days later. Google Cloud cannot recover the service account after it is permanently removed, even if you file a support request. To help avoid unplanned outages, we recommend that you disable the service account before you delete it. Use DisableServiceAccount to disable the service account, then wait at least 24 hours and watch for unintended consequences. If there are no unintended consequences, you can delete the service account.
undeleteexecprojectsId, serviceAccountsIdRestores a deleted ServiceAccount. Important: It is not always possible to restore a deleted service account. Use this method only as a last resort. After you delete a service account, IAM permanently removes the service account 30 days later. There is no way to restore a deleted service account that has been permanently removed.
enableexecprojectsId, serviceAccountsIdEnables a ServiceAccount that was disabled by DisableServiceAccount. If the service account is already enabled, then this method has no effect. If the service account was disabled by other means—for example, if Google disabled the service account because it was compromised—you cannot use this method to enable the service account.
disableexecprojectsId, serviceAccountsIdDisables a ServiceAccount immediately. If an application uses the service account to authenticate, that application can no longer call Google APIs or access Google Cloud resources. Existing access tokens for the service account are rejected, and requests for new access tokens will fail. To re-enable the service account, use EnableServiceAccount. After you re-enable the service account, its existing access tokens will be accepted, and you can request new access tokens. To help avoid unplanned outages, we recommend that you disable the service account before you delete it. Use this method to disable the service account, then wait at least 24 hours and watch for unintended consequences. If there are no unintended consequences, you can delete the service account with DeleteServiceAccount.
sign_blobexecprojectsId, serviceAccountsId Signs a blob using the system-managed private key for a ServiceAccount.
sign_jwtexecprojectsId, serviceAccountsId Signs a JSON Web Token (JWT) using the system-managed private key for a ServiceAccount.

Parameters

Parameters can be passed in the WHERE clause of a query. Check the Methods section to see which parameters are required or optional for each operation.

NameDatatypeDescription
projectsIdstring
serviceAccountsIdstring
pageSizeinteger (int32)
pageTokenstring

SELECT examples

Gets a ServiceAccount.

SELECT
name,
description,
disabled,
displayName,
email,
etag,
oauth2ClientId,
projectId,
uniqueId
FROM google.iam.service_accounts
WHERE projectsId = '{{ projectsId }}' -- required
AND serviceAccountsId = '{{ serviceAccountsId }}' -- required;

INSERT examples

Creates a ServiceAccount.

INSERT INTO google.iam.service_accounts (
data__accountId,
data__serviceAccount,
projectsId
)
SELECT
'{{ accountId }}',
'{{ serviceAccount }}',
'{{ projectsId }}'
RETURNING
name,
description,
disabled,
displayName,
email,
etag,
oauth2ClientId,
projectId,
uniqueId
;

UPDATE examples

Patches a ServiceAccount.

UPDATE google.iam.service_accounts
SET
data__serviceAccount = '{{ serviceAccount }}',
data__updateMask = '{{ updateMask }}'
WHERE
projectsId = '{{ projectsId }}' --required
AND serviceAccountsId = '{{ serviceAccountsId }}' --required
RETURNING
name,
description,
disabled,
displayName,
email,
etag,
oauth2ClientId,
projectId,
uniqueId;

REPLACE examples

Note: We are in the process of deprecating this method. Use PatchServiceAccount instead. Updates a ServiceAccount. You can update only the display_name field.

REPLACE google.iam.service_accounts
SET
data__name = '{{ name }}',
data__displayName = '{{ displayName }}',
data__etag = '{{ etag }}',
data__description = '{{ description }}'
WHERE
projectsId = '{{ projectsId }}' --required
AND serviceAccountsId = '{{ serviceAccountsId }}' --required
RETURNING
name,
description,
disabled,
displayName,
email,
etag,
oauth2ClientId,
projectId,
uniqueId;

DELETE examples

Deletes a ServiceAccount. Warning: After you delete a service account, you might not be able to undelete it. If you know that you need to re-enable the service account in the future, use DisableServiceAccount instead. If you delete a service account, IAM permanently removes the service account 30 days later. Google Cloud cannot recover the service account after it is permanently removed, even if you file a support request. To help avoid unplanned outages, we recommend that you disable the service account before you delete it. Use DisableServiceAccount to disable the service account, then wait at least 24 hours and watch for unintended consequences. If there are no unintended consequences, you can delete the service account.

DELETE FROM google.iam.service_accounts
WHERE projectsId = '{{ projectsId }}' --required
AND serviceAccountsId = '{{ serviceAccountsId }}' --required;

Lifecycle Methods

Restores a deleted ServiceAccount. Important: It is not always possible to restore a deleted service account. Use this method only as a last resort. After you delete a service account, IAM permanently removes the service account 30 days later. There is no way to restore a deleted service account that has been permanently removed.

EXEC google.iam.service_accounts.undelete 
@projectsId='{{ projectsId }}' --required,
@serviceAccountsId='{{ serviceAccountsId }}' --required;