How the attack works
An API key is a string that some Google Cloud APIs accept instead of a principal's credentials. Google describes a standard key as a way to associate a request with a project for billing and quota. It does not authenticate a principal, so IAM cannot check who the caller is. A key can also be bound to a service account, and requests made with such a key are processed as if the service account had made them. Google's best practices call API keys bearer credentials: whoever holds the string can use it. A key can be limited with application restrictions (websites, IP addresses, applications) and API restrictions, and a key without them is not tied to a caller or to a set of APIs.
An attacker who reaches a project can create a key of their own, or read the string of a key that already exists. The second path creates nothing new and changes nothing, and the key that leaves the environment is one that production applications already use. Reading a key string needs only apikeys.keys.getKeyString, which the API Keys Viewer role includes as well as the API Keys Admin role.
The API Keys API (apikeys.googleapis.com) records both. google.api.apikeys.v2.ApiKeys.CreateKey and UndeleteKey are Admin Activity entries. google.api.apikeys.v2.ApiKeys.GetKeyString is a Data Access entry, so it is written only where Data Access audit logs are enabled for the service.
What an attacker needs
- To create a key, the API Keys Admin role (
roles/serviceusage.apiKeysAdmin) on the project, or another role with the same permissions. - To read a key string, the
apikeys.keys.getKeyStringpermission, which the API Keys Admin and API Keys Viewer roles both include. - To bind a key to a service account, an organization policy that allows it. Google blocks this by default with the constraint
iam.managed.disableServiceAccountApiKeyCreation.
Impact
Use of the APIs that accept the key, from anywhere the key's restrictions allow, in the name of the project. Google warns that an exposed key can lead to unexpected charges and to unauthorized access to data. A key bound to a service account acts with that service account's access. A key string that was read keeps working for as long as the key exists and its restrictions admit the caller, and replacing the key means changing every application that uses it.
Detection rules
API Key Created or Restored in Google Cloud
Detects an API key being created in a Google Cloud project, or a deleted key being restored (Admin Activity audit log of the API Keys API). Both are long-running operations and usually write two entries, one when the operation starts and one when it ends. A new key is a bearer credential that works from outside the environment. Check its restrictions and whether it is bound to a service account.
title: API Key Created or Restored in Google Cloud
id: 7cf76e9c-324d-4ba1-9aae-7cee2600f91b
status: experimental
description: >-
Detects an API key being created in a Google Cloud project, or a deleted key
being restored (Admin Activity audit log of the API Keys API). Both are
long-running operations and usually write two entries, one when the
operation starts and one when it ends. A new key is a bearer credential that
works from outside the environment. Check its restrictions and whether it
is bound to a service account.
references:
- https://docs.cloud.google.com/api-keys/docs/audit-logging
- https://docs.cloud.google.com/docs/authentication/api-keys
- https://attack.mitre.org/techniques/T1098/001/
author: Forestall
date: 2026-11-16
tags:
- attack.persistence
- attack.t1098.001
logsource:
product: gcp
service: gcp.audit
detection:
selection:
protoPayload.serviceName: apikeys.googleapis.com
protoPayload.methodName:
- google.api.apikeys.v2.ApiKeys.CreateKey
- google.api.apikeys.v2.ApiKeys.UndeleteKey
condition: selection
falsepositives:
- Developers and deployment pipelines that create keys for client applications, maps or AI services. Exclude the pipeline identity by protoPayload.authenticationInfo.principalEmail in a filter_* selection, and review keys created by people in production projects.
- Each operation usually appears twice, at its start and at its end.
level: low
False positives
- Developers and deployment pipelines that create keys for client applications, maps or AI services. Exclude the pipeline identity by protoPayload.authenticationInfo.principalEmail in a filter_* selection, and review keys created by people in production projects.
- Each operation usually appears twice, at its start and at its end.
API Key String Read in Google Cloud
Detects a read of the key string of an existing API key in a Google Cloud project (GetKeyString, Data Access audit log of the API Keys API). The call returns the secret value of a key that applications already use, creates nothing and changes nothing. It needs only the apikeys.keys.getKeyString permission, which the API Keys Viewer role includes. The entry is written only where Data Access audit logs are enabled for the API Keys API.
title: API Key String Read in Google Cloud
id: 64d5ca25-4de2-436e-83f8-03e3cc9c4869
status: experimental
description: >-
Detects a read of the key string of an existing API key in a Google Cloud
project (GetKeyString, Data Access audit log of the API Keys API). The call
returns the secret value of a key that applications already use, creates
nothing and changes nothing. It needs only the apikeys.keys.getKeyString
permission, which the API Keys Viewer role includes. The entry is written
only where Data Access audit logs are enabled for the API Keys API.
references:
- https://docs.cloud.google.com/api-keys/docs/audit-logging
- https://docs.cloud.google.com/iam/docs/roles-permissions/serviceusage
- https://attack.mitre.org/techniques/T1552/
author: Forestall
date: 2026-11-16
tags:
- attack.credential-access
- attack.t1552
logsource:
product: gcp
service: gcp.audit
detection:
selection:
protoPayload.serviceName: apikeys.googleapis.com
protoPayload.methodName: google.api.apikeys.v2.ApiKeys.GetKeyString
condition: selection
falsepositives:
- Deployment tools and infrastructure-as-code pipelines that read key strings to pass them to applications, and administrators who display a key in the console. Exclude the pipeline identity by protoPayload.authenticationInfo.principalEmail in a filter_* selection, and review reads by people and reads of several keys by one caller.
level: medium
False positives
- Deployment tools and infrastructure-as-code pipelines that read key strings to pass them to applications, and administrators who display a key in the console. Exclude the pipeline identity by protoPayload.authenticationInfo.principalEmail in a filter_* selection, and review reads by people and reads of several keys by one caller.
Triage
- Identify the caller (principalEmail), the project and the key the entry names (protoPayload.resourceName), and check whether the caller normally manages API keys.
- For a new or restored key, open it in the console and check its restrictions and whether it is bound to a service account. An unrestricted key that nobody asked for needs an owner or has to go.
- For a key string read, check whether the caller is a deployment identity that reads keys as part of its work or a person, and whether the same caller read the strings of several keys within a short time.
- Review the API usage of the project for requests that do not match the applications that own the key. Google names usage monitoring as the way to notice unauthorized use of a key.
- If the event is not explained, review what else the caller did in the project around that time.
Response
Once the attack is confirmed:
- Delete a key that the attacker created. For an existing key whose string was read, rotate it. Create a replacement with the same restrictions, move the applications to it and delete the old key.
- Watch for the deleted key coming back. A deleted API key can be restored within 30 days, and the restore is recorded as
UndeleteKey. - Contain the identity that created the key or read the string, and remove its API Keys roles.
- Review the API usage and the charges of the project for the time the key was exposed. If the key was bound to a service account, review that service account's activity as well.
- Add API and application restrictions to the keys that remain, so that a key string alone is worth less the next time.
Mitigation
- Keep the organization policy constraint
iam.managed.disableServiceAccountApiKeyCreationenforced, so that keys cannot be bound to service accounts except for the services you allow. - Set both API restrictions and application restrictions on every key, as Google recommends, and delete keys that are no longer used.
- Grant the API Keys Admin and API Keys Viewer roles narrowly. The Viewer role is enough to read every key string in the project.
- Rotate keys on a schedule, and keep them out of source code and repositories.
- Enable Data Access audit logs for the API Keys API, otherwise reads of key strings leave no audit entry.
Frequently asked questions
Does an API key identify who is calling?
Not a standard key. Google describes a standard API key as a way to associate a request with a project for billing and quota, and states that it does not authenticate a principal, so IAM cannot check the caller's authorization. A key that is bound to a service account is different. Requests made with it are processed as if the bound service account had made them.
Why does the key string rule stay silent in my environment?
`GetKeyString` needs a permission of type ADMIN_READ, so Google writes it to the Data Access audit log. Data Access audit logs are disabled by default, except for BigQuery, and have to be enabled for the API Keys API. Until then a read of a key string leaves no audit entry, and the rule has nothing to match.
Why do I see two entries for one new key?
`CreateKey` is a long-running operation. Google's audit logging page for API keys says that such methods usually generate two audit log entries, one when the operation starts and another when it ends. The same applies to `UndeleteKey`. Treat the pair as one event when you count or deduplicate alerts.
Is deleting the key enough?
Deleting it stops the exposure, with one caveat. A deleted API key can be restored within 30 days, so an identity that still holds the API Keys Admin role can bring it back. Remove that right, and watch for `UndeleteKey`. For a key that applications depend on, create a replacement with the same restrictions and move the applications first.
References
- MITRE ATT&CK T1098.001: Account Manipulation: Additional Cloud Credentials
- MITRE ATT&CK T1552: Unsecured Credentials
- API Keys audit logging
- Manage API keys
- Best practices for managing API keys
- Service Usage roles and permissions (API Keys Admin, API Keys Viewer)
- Restrict service account usage (organization policy constraints)
- Respond to compromised Google Cloud credentials