RGoogle Cloud playbook · Identity and access
Leaked service account key used to change permissions
An attacker authenticates with a leaked user-managed service account key, then grants roles and creates new keys or service accounts to keep access. Every Admin Activity entry made with that key carries the key's name. Disable the key and the service account first, then remove what the attacker added.
Look here
| Log | Search for |
|---|---|
| Admin Activity audit log | Calls made with the key: gcloud logging read 'protoPayload.authenticationInfo.serviceAccountKeyName:"<key-id>"' --project=<project> --freshness=30d |
| Admin Activity audit log | Role grants. SetIamPolicy on projects, folders and the organization grants roles. On service accounts, this method grants rights to impersonate them: google.iam.admin.v1.SetIAMPolicy |
| Admin Activity audit log | New keys and service accounts, and disabled ones turned back on: google.iam.admin.v1.CreateServiceAccountKey, google.iam.admin.v1.UploadServiceAccountKey, google.iam.admin.v1.CreateServiceAccount, google.iam.admin.v1.EnableServiceAccountKey, google.iam.admin.v1.EnableServiceAccount |
| Data Access audit log for iamcredentials.googleapis.com (only if enabled) | Tokens the service account minted for other service accounts, where the caller is the service account: protoPayload.serviceName="iamcredentials.googleapis.com" AND protoPayload.methodName=("GenerateAccessToken" OR "SignJwt" OR "SignBlob" OR "GenerateIdToken") |
| Any audit log entry made through impersonation | The principal at the start of an impersonation chain: protoPayload.authenticationInfo.serviceAccountDelegationInfo.firstPartyPrincipal.principalEmail |
| Security Command Center | Key and grant findings: Initial Access: Leaked Service Account Key Used Account has leaked credentials, Persistence: IAM Anomalous Grant, Persistence: Service Account Key Created Discovery: Service Account Self-Investigation |
Contain
| # | Item |
|---|---|
| 1 | Disable the leaked key: gcloud iam service-accounts keys disable <key-id> --iam-account=<sa-email> |
| 2 | Disable the service account to block tokens already minted from the key. Workloads using it stop: gcloud iam service-accounts disable <sa-email> |
| 3 | List user-managed keys on each affected account, and disable the ones created in the window: gcloud iam service-accounts keys list --iam-account=<sa-email> --managed-by=user |
| 4 | Disable service accounts the attacker created with gcloud iam service-accounts disable |
| 5 | Remove bindings the attacker added: gcloud projects remove-iam-policy-binding <project> --member='<type>:<member>' --role=<role> --all |
Eradicate and recover
| # | Item |
|---|---|
| 1 | Deploy a new credential for the workload, record the evidence, then delete the leaked key destructive: gcloud iam service-accounts keys delete <key-id> --iam-account=<sa-email> |
| 2 | Re-enable the service account at least 60 minutes after disabling it: gcloud iam service-accounts enable <sa-email> |
| 3 | Compare organization, folder and project IAM policies against baseline and restore the previous version |
| 4 | Block new service account keys wherever keys are not required. The legacy form of this constraint is iam.disableServiceAccountKeyCreation: iam.managed.disableServiceAccountKeyCreation |
| 5 | Confirm iam.serviceAccountKeyExposureResponse is not set to WAIT_FOR_ABUSE. DISABLE_KEY, which disables keys Google finds exposed, has been the default since June 2024 |
Watch out
- Disabling a key leaves short-lived tokens issued from it valid until they expire: 60 minutes by default, up to 12 hours with an extended token lifetime policy. Disable the service account or apply an IAM deny policy to stop them.
- Reads made with the key appear only for services with Data Access audit logs enabled. Treat data the service account could read as exposed where those logs were off.