When it is written
Attaching a service account to a resource (a Compute Engine instance or template, a Cloud Run service, a Cloud Run function, a GKE node pool, an App Engine app, a Cloud Scheduler job, a Pub/Sub subscription and others) requires iam.serviceAccounts.actAs on that service account, a permission the Service Account User role (roles/iam.serviceAccountUser) holds. When a principal uses it, IAM writes this entry. Google's example is an Admin Activity entry (cloudaudit.googleapis.com%2Factivity, permissionType ADMIN_WRITE), so it is written without any Data Access setting.
In Google's example, authenticationInfo.principalEmail is the caller, resourceName and request.name name the service account (projects/-/serviceAccounts/<email>), the request type is CanActAsServiceAccountRequest with a project_number, and the response says success: true. The resource type is audited_resource with project_id, method and service labels. The example comes from attaching a service account to a Compute Engine instance, yet the entry does not name the instance: to learn which resource got the service account, look for the creating service's own entry (an instance creation, a Cloud Run deployment...) by the same caller at the same time.
Most resources take their service account only when they are created; Compute Engine instances can also change it later. Attaching a service account of another project needs the iam.disableCrossProjectServiceAccountUsage constraint to be off in the service account's project.
How to turn it on
Google Cloud Audit Logs records iam.serviceAccounts.actAs calls to iam.googleapis.com without any setup. Vendor documentation
Admin Activity audit logs (changes to the configuration or metadata of a resource, such as allow policies, service accounts and keys) are written in every project, folder and organization without any setup. They can't be turned off or excluded, cost nothing, and are kept for 400 days in the _Required log bucket, a period you can't change. Data Access audit logs are off by default for every service except BigQuery: they cover reading configuration or metadata (ADMIN_READ) and reading or writing user data (DATA_READ, DATA_WRITE). Turn them on per service, or for all services, in the auditConfigs section of the IAM policy of the organization, folder or project; a project inherits what its folder and organization turn on and can't turn it off. A principal can be exempted per service and log type (exemptedMembers), and its calls then write no Data Access entry. They go to the _Default bucket, kept for 30 days by default, and can add charges.
- Google Workspace and Cloud Identity audit logs (Admin, Login, Groups, OAuth token and SAML events) reach Cloud Logging only after a super administrator turns on sharing with Google Cloud: Admin console > Account > Account settings > Legal and compliance > Sharing options > Enabled. They are written at the organization level (
organizations/<org-id>/logs/...), and which of them are shared depends on the edition. Admin audit events are Admin Activity entries. - To keep the records longer and send them to a SIEM, route them with a sink: an aggregated sink at the organization collects the entries of every folder and project under it, to Pub/Sub, Cloud Storage, BigQuery or a log bucket.
- The Logs Viewer role (
roles/logging.viewer) reads Admin Activity entries; Data Access entries in_Defaultneed Private Logs Viewer (roles/logging.privateLogViewer). - The lookup command reads one project. Organization-level entries (Workspace and Cloud Identity, and changes made on an organization or folder) are read with
--organization=<org-id>or--folder=<folder-id>in its place. - Google gives no delivery delay for Cloud Audit Logs; Workspace states that shared data arrives in near real time.
gcloud projects get-iam-policy <project-id> --format="yaml(auditConfigs)"gcloud organizations get-iam-policy <org-id> --format="yaml(auditConfigs)"gcloud logging sinks list --organization=<org-id>gcloud logging buckets list --project=<project-id>gcloud logging read 'protoPayload.methodName="iam.serviceAccounts.actAs"' --project=<project-id> --freshness=7d --limit=5Fields
The operation’s own fields first, then the fields every Google Cloud Audit Logs record has. Field names are the JSON paths of the record as the vendor documents it.
| Field | What it holds |
|---|---|
protoPayload. | The email of the service account that was attached (Google's example shows the bare email). |
protoPayload. | A project number carried in the request; Google's example does not say whether it is the project of the resource or of the service account. |
protoPayload. | true when the caller was allowed to act as the service account. |
resource. | The project the entry belongs to (resource.type is audited_resource). |
Fields every Google Cloud Audit Logs record has (22)
| Field | What it holds |
|---|---|
logName | The log the entry belongs to: the project, folder or organization, then cloudaudit.googleapis.com%2Factivity (Admin Activity), %2Fdata_access, %2Fsystem_event or %2Fpolicy (Policy Denied). |
resource. | The kind of monitored resource the entry is about (project, service_account, audited_resource...). |
resource. | The labels that identify that resource; which ones depends on resource.type (project_id, email_id...). |
timestamp | When the operation took place. |
receiveTimestamp | When Cloud Logging received the entry; later than timestamp. |
severity | The severity of the entry (NOTICE for most audit entries, ERROR for many failed calls). |
insertId | An identifier Cloud Logging gives the entry, unique within the log. |
protoPayload.Read by 1 rule | The API service the operation was performed by (iam.googleapis.com, admin.googleapis.com). |
protoPayload.Read by 1 rule | The method that was called, usually the API method name. The operation this page is about. |
protoPayload. | The resource the operation targets, as a path without the service name (projects/<id>/serviceAccounts/<email>). |
protoPayload.Read by 1 rule | The account that made the request: a user, a service account, or the service account acting for an external identity. Never redacted for a write or a call that succeeded; a read that failed with permission denied can hide it, unless the caller is a service account. |
protoPayload. | For a request made with service account credentials obtained by impersonation, the chain of principals that delegated to it, in the order the delegation happened. |
protoPayload. | The service account key used to create or exchange the credentials, when one was. |
protoPayload. | One entry per resource and IAM permission checked, with granted true or false. |
protoPayload. | The address the request came from. Google replaces some internal and VM callers with placeholder values (private, gce-internal-ip). |
protoPayload. | The client's user agent as the caller sent it; not authenticated. |
protoPayload. | The result as a google.rpc.Code number: absent or 0 when the call succeeded, 7 (PERMISSION_DENIED), 5 (NOT_FOUND) and others when it failed. |
protoPayload. | The error message of a failed call. |
protoPayload. | The request, as the service's API reference documents it; large, sensitive or duplicated parameters can be left out. |
protoPayload. | The response, with the same limits as request. |
protoPayload. | Other data the service records about the operation. Google Workspace entries put the Admin console event here (event: eventName, eventType and its parameter list). |
protoPayload. | The older place for service-specific data, deprecated in favour of metadata but still written by some services. |
Values to know
protoPayload.authenticationInfo.principalEmail
| Value | Meaning | Signal |
|---|---|---|
a user account (not `*.gserviceaccount.com`) | A person attached the service accountThe case the detection rule reports. Confirm the person is expected to deploy with this account; a privileged account deserves a look every time. | Attack signal |
`*.gserviceaccount.com` | A service account attached it, usually a pipelineLeft out by the rule on purpose. | Expected |
Volume and noise
Deployment pipelines running as service accounts produce most entries, and the rule leaves them out. What remains are people deploying by hand: common in development projects, rarer in production. A person attaching a service account that holds roles on a folder or the organization, or one they have never attached before, is the entry to read first.
Keeping it manageable
- Compare
protoPayload.request.namewith your list of privileged service accounts; review every match on those, as the rule's false positive note suggests. - Exclude projects where manual deployment is normal, or limit the rule to the service accounts that matter.
- Pair the entry with the deployment entry of the same caller and time to learn which resource now runs as the account.
- Check whether the caller was granted the Service Account User role on that account shortly before, a hypothesis on the attack page.
Sample event
A Google Cloud Audit Logs record in the vendor’s format, with made-up values.
{
"protoPayload": {
"@type": "type.googleapis.com/google.cloud.audit.AuditLog",
"authenticationInfo": {
"principalEmail": "j.doe@corp.example.com"
},
"requestMetadata": {
"callerIp": "203.0.113.24",
"requestAttributes": {},
"destinationAttributes": {}
},
"serviceName": "iam.googleapis.com",
"methodName": "iam.serviceAccounts.actAs",
"resourceName": "projects/-/serviceAccounts/deployer@corp-prod-01.iam.gserviceaccount.com",
"authorizationInfo": [
{
"resource": "projects/-/serviceAccounts/deployer@corp-prod-01.iam.gserviceaccount.com",
"permission": "iam.serviceAccounts.actAs",
"granted": true,
"permissionType": "ADMIN_WRITE"
}
],
"request": {
"@type": "type.googleapis.com/CanActAsServiceAccountRequest",
"name": "deployer@corp-prod-01.iam.gserviceaccount.com",
"project_number": "111122223333"
},
"response": {
"@type": "type.googleapis.com/CanActAsServiceAccountResponse",
"success": true
}
},
"insertId": "1x2y3z4a5b6c",
"resource": {
"type": "audited_resource",
"labels": {
"project_id": "corp-prod-01",
"method": "iam.serviceAccounts.actAs",
"service": "iam.googleapis.com"
}
},
"timestamp": "2026-11-18T09:30:12.345678Z",
"severity": "NOTICE",
"logName": "projects/corp-prod-01/logs/cloudaudit.googleapis.com%2Factivity",
"receiveTimestamp": "2026-11-18T09:30:13.012345678Z"
}Attacks this event reveals
Detection rules that read this event:
Detection logic (hypotheses that join this event with others) for:
Frequently asked questions
Why does the entry not say which resource got the service account?
Google's example entry names only the service account and the caller. Look for the entry the creating service writes at the same time, such as a Compute Engine or Cloud Run entry by the same principal.