Skip to main content

service_account_keys

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

Overview

Nameservice_account_keys
TypeResource
Idgoogle.iam.service_account_keys

Fields

The following fields are returned by SELECT queries:

Successful response

NameDatatypeDescription
namestringThe resource name of the service account key in the following format projects/{PROJECT_ID}/serviceAccounts/{ACCOUNT}/keys/{key}.
disableReasonstringOutput only. optional. If the key is disabled, it may have a DisableReason describing why it was disabled.
disabledbooleanThe key status.
extendedStatusarrayOutput only. Extended Status provides permanent information about a service account key. For example, if this key was detected as exposed or compromised, that information will remain for the lifetime of the key in the extended_status.
keyAlgorithmstringSpecifies the algorithm (and possibly key size) for the key.
keyOriginstringThe key origin.
keyTypestringThe key type.
privateKeyDatastring (byte)The private key data. Only provided in CreateServiceAccountKey responses. Make sure to keep the private key data secure because it allows for the assertion of the service account identity. When base64 decoded, the private key data can be used to authenticate with Google API client libraries and with gcloud auth activate-service-account.
privateKeyTypestringThe output format for the private key. Only provided in CreateServiceAccountKey responses, not in GetServiceAccountKey or ListServiceAccountKey responses. Google never exposes system-managed private keys, and never retains user-managed private keys.
publicKeyDatastring (byte)The public key data. Only provided in GetServiceAccountKey responses.
validAfterTimestring (google-datetime)The key can be used after this timestamp.
validBeforeTimestring (google-datetime)The key can be used before this timestamp. For system-managed key pairs, this timestamp is the end time for the private key signing operation. The public key could still be used for verification for a few hours after this time.

Methods

The following methods are available for this resource:

NameAccessible byRequired ParamsOptional ParamsDescription
getselectprojectsId, serviceAccountsId, keysIdpublicKeyTypeGets a ServiceAccountKey.
listselectprojectsId, serviceAccountsIdkeyTypesLists every ServiceAccountKey for a service account.
createinsertprojectsId, serviceAccountsIdCreates a ServiceAccountKey.
deletedeleteprojectsId, serviceAccountsId, keysIdDeletes a ServiceAccountKey. Deleting a service account key does not revoke short-lived credentials that have been issued based on the service account key.
uploadexecprojectsId, serviceAccountsIdUploads the public key portion of a key pair that you manage, and associates the public key with a ServiceAccount. After you upload the public key, you can use the private key from the key pair as a service account key.
disableexecprojectsId, serviceAccountsId, keysIdDisable a ServiceAccountKey. A disabled service account key can be re-enabled with EnableServiceAccountKey.
enableexecprojectsId, serviceAccountsId, keysIdEnable a ServiceAccountKey.

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
keysIdstring
projectsIdstring
serviceAccountsIdstring
keyTypesstring
publicKeyTypestring

SELECT examples

Gets a ServiceAccountKey.

SELECT
name,
disableReason,
disabled,
extendedStatus,
keyAlgorithm,
keyOrigin,
keyType,
privateKeyData,
privateKeyType,
publicKeyData,
validAfterTime,
validBeforeTime
FROM google.iam.service_account_keys
WHERE projectsId = '{{ projectsId }}' -- required
AND serviceAccountsId = '{{ serviceAccountsId }}' -- required
AND keysId = '{{ keysId }}' -- required
AND publicKeyType = '{{ publicKeyType }}';

INSERT examples

Creates a ServiceAccountKey.

INSERT INTO google.iam.service_account_keys (
data__privateKeyType,
data__keyAlgorithm,
projectsId,
serviceAccountsId
)
SELECT
'{{ privateKeyType }}',
'{{ keyAlgorithm }}',
'{{ projectsId }}',
'{{ serviceAccountsId }}'
RETURNING
name,
disableReason,
disabled,
extendedStatus,
keyAlgorithm,
keyOrigin,
keyType,
privateKeyData,
privateKeyType,
publicKeyData,
validAfterTime,
validBeforeTime
;

DELETE examples

Deletes a ServiceAccountKey. Deleting a service account key does not revoke short-lived credentials that have been issued based on the service account key.

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

Lifecycle Methods

Uploads the public key portion of a key pair that you manage, and associates the public key with a ServiceAccount. After you upload the public key, you can use the private key from the key pair as a service account key.

EXEC google.iam.service_account_keys.upload 
@projectsId='{{ projectsId }}' --required,
@serviceAccountsId='{{ serviceAccountsId }}' --required
@@json=
'{
"publicKeyData": "{{ publicKeyData }}"
}';