1. Resources
  2. Detection rules
  3. Cloud Build Build or Trigger Used to Run Code as the Build Service Account

Cloud Build Build or Trigger Used to Run Code as the Build Service Account detection rules

An attacker who can create builds or build triggers in Cloud Build runs their own build steps as the build service account, which is often a default account with broad access to the project.

Platform
Google Cloud
Severity
High
Log source
Google Cloud Audit Logs
Last updated
MITRE ATT&CK technique
T1648Serverless Execution
Tactic
Execution
Rule formats
Sigmaand queries for: SplunkMicrosoft SentinelIBM QRadar
What an attacker needs
The permission cloudbuild.builds.create in a project whose builds run as a service account with more access than the caller.
Impact
Code execution as the build service account, which with a broadly privileged default account means most of the project, repeated on every run of a changed trigger.
Response
Cancel unapproved builds, restore or delete the changed trigger, and review everything the build service account did since the build started.
Mitigation
Run builds with a user-managed service account that has minimal roles, and limit cloudbuild.builds.create in production to the pipeline.
API methods
google.devtools.cloudbuild.v1.CloudBuild.CreateBuildgoogle.devtools.cloudbuild.v1.CloudBuild.RetryBuildgoogle.devtools.cloudbuild.v1.CloudBuild.RunBuildTriggergoogle.devtools.cloudbuild.v1.CloudBuild.CreateBuildTriggergoogle.devtools.cloudbuild.v1.CloudBuild.UpdateBuildTrigger
Threat groups
None listed in MITRE ATT&CK for this technique

How the attack works

A Cloud Build build is a list of steps that run in containers, and it runs as a service account. Unless a build names a user-managed account in its serviceAccount field, Cloud Build chooses a default. Google changed that default in May and June 2024. Projects that ran their first build before the change keep the legacy Cloud Build service account (PROJECT_NUMBER@cloudbuild.gserviceaccount.com), and newer projects use the Compute Engine default service account. Google states that the default service account may have permissions that are unnecessarily broad, such as access to any Cloud Storage bucket in the project, and recommends a user-managed account for builds.

Whoever can submit a build decides what its steps do, so the right to create builds is the right to act as the build service account. Every Cloud Build method that starts or defines a build, CreateBuild, RetryBuild, RunBuildTrigger, CreateBuildTrigger and UpdateBuildTrigger, needs only the permission cloudbuild.builds.create, which the Cloud Build Editor role contains. Google states that a user who submits a build with the Compute Engine default service account or a user-created one also needs iam.serviceAccounts.actAs on that account. The legacy account is owned by Google and nobody can be granted that permission on it. A trigger adds persistence, because it stores the build definition and the service account and runs them again on every matching repository event. All of these calls are Admin Activity audit entries under cloudbuild.googleapis.com, which are always written.

What an attacker needs

  • cloudbuild.builds.create in the project, for example through the Cloud Build Editor role or the Editor basic role.
  • Where the build runs as the Compute Engine default service account or a user-managed account, iam.serviceAccounts.actAs on that account.
  • A build service account with more access than the caller, which is common where a default service account is still in use.

Impact

Code execution as the build service account. The build steps can use everything that account's roles allow, such as reading and writing storage buckets, pushing container images that other workloads later run, and deploying to other services. With the Compute Engine default service account and the Editor role that is most of the project. A changed trigger repeats this on every push to the connected repository until somebody notices the trigger.

Detection rules

Cloud Build Build Started Directly by a User Account

Detects a user account, not a service account, creating a build, retrying one or running a build trigger by hand (Admin Activity audit log, always written). The build steps run as the build service account, so a person who starts a build directly acts with that account's access. Google states that the default build service account may have unnecessarily broad permissions. Pipelines act as service accounts and are left out on purpose, which keeps the rule to the less common case of a person starting a build. Google documents the method names, their permissions and the log type, but not which request fields the entry keeps, so the rule does not see the build steps or the service account. Google marks the three methods as long-running operations, which usually write a start and a completion entry for one build. Federated callers without a principalEmail are not matched.

LevelLowStatusExperimentalLog sourceGoogle Cloud Audit Logs
title: Cloud Build Build Started Directly by a User Account
id: 5fe8eeca-9a04-44c2-808a-2540f6719c29
status: experimental
description: >-
  Detects a user account, not a service account, creating a build, retrying
  one or running a build trigger by hand (Admin Activity audit log, always
  written). The build steps run as the build service account, so a person
  who starts a build directly acts with that account's access. Google
  states that the default build service account may have unnecessarily
  broad permissions. Pipelines act as service accounts and are left out on
  purpose, which keeps the rule to the less common case of a person
  starting a build. Google documents the method names, their permissions
  and the log type, but not which request fields the entry keeps, so the
  rule does not see the build steps or the service account. Google marks
  the three methods as long-running operations, which usually write a start
  and a completion entry for one build. Federated callers without a
  principalEmail are not matched.
references:
  - https://docs.cloud.google.com/build/docs/securing-builds/audit-logs
  - https://docs.cloud.google.com/build/docs/cloud-build-service-account
  - https://docs.cloud.google.com/build/docs/cloud-build-service-account-updates
author: Forestall
date: 2026-11-18
tags:
  - attack.execution
  - attack.t1648
logsource:
  product: gcp
  service: gcp.audit
detection:
  selection:
    protoPayload.serviceName: cloudbuild.googleapis.com
    protoPayload.methodName:
      - google.devtools.cloudbuild.v1.CloudBuild.CreateBuild
      - google.devtools.cloudbuild.v1.CloudBuild.RetryBuild
      - google.devtools.cloudbuild.v1.CloudBuild.RunBuildTrigger
    protoPayload.authenticationInfo.principalEmail|contains: '@'
  filter_service_accounts:
    protoPayload.authenticationInfo.principalEmail|endswith: .gserviceaccount.com
  condition: selection and not 1 of filter_*
falsepositives:
  - Developers who submit builds from their own account, which is normal in development projects. Limit the rule to production projects, or exclude projects where manual builds are expected, and review every match in a project whose build service account is privileged.
  - Engineers who run a trigger by hand to repeat a failed deployment.
level: low

False positives

  • Developers who submit builds from their own account, which is normal in development projects. Limit the rule to production projects, or exclude projects where manual builds are expected, and review every match in a project whose build service account is privileged.
  • Engineers who run a trigger by hand to repeat a failed deployment.

Cloud Build Trigger Created or Updated

Detects creation and update of a Cloud Build trigger (Admin Activity audit log, always written). A trigger stores a build definition, the repository event that starts it and the service account the build runs as, and runs them again on every matching event. A new or changed trigger is therefore a lasting way to run build steps as that service account. Google lists the permission cloudbuild.builds.create for both methods, the same one that submitting a build needs. Google documents the method names, their permissions and the log type, but not which request fields the entry keeps, so the rule matches on the method name alone and does not see what was changed. Read the trigger named in protoPayload.resourceName and check its steps, its repository and its service account.

LevelMediumStatusExperimentalLog sourceGoogle Cloud Audit Logs
title: Cloud Build Trigger Created or Updated
id: 25fe37d5-c311-45d9-85ce-f0aac8fbdb38
status: experimental
description: >-
  Detects creation and update of a Cloud Build trigger (Admin Activity audit
  log, always written). A trigger stores a build definition, the repository
  event that starts it and the service account the build runs as, and runs
  them again on every matching event. A new or changed trigger is therefore
  a lasting way to run build steps as that service account. Google lists
  the permission cloudbuild.builds.create for both methods, the same one
  that submitting a build needs. Google documents the method names, their
  permissions and the log type, but not which request fields the entry
  keeps, so the rule matches on the method name alone and does not see what
  was changed. Read the trigger named in protoPayload.resourceName and check
  its steps, its repository and its service account.
references:
  - https://docs.cloud.google.com/build/docs/securing-builds/audit-logs
  - https://docs.cloud.google.com/build/docs/securing-builds/configure-user-specified-service-accounts
  - https://docs.cloud.google.com/build/docs/cloud-build-service-account-updates
author: Forestall
date: 2026-11-18
tags:
  - attack.execution
  - attack.t1648
logsource:
  product: gcp
  service: gcp.audit
detection:
  selection:
    protoPayload.serviceName: cloudbuild.googleapis.com
    protoPayload.methodName:
      - google.devtools.cloudbuild.v1.CloudBuild.CreateBuildTrigger
      - google.devtools.cloudbuild.v1.CloudBuild.UpdateBuildTrigger
  condition: selection
falsepositives:
  - Pipeline maintenance by the team that owns the build configuration, often through infrastructure-as-code. Exclude that pipeline identity by principalEmail in a filter_* selection, and review trigger changes made by people in production projects.
level: medium

False positives

  • Pipeline maintenance by the team that owns the build configuration, often through infrastructure-as-code. Exclude that pipeline identity by principalEmail in a filter_* selection, and review trigger changes made by people in production projects.

Detection logic

Patterns that need more than one event, a baseline or knowledge of your own environment. Each is a hypothesis to build and tune in your SIEM, not a ready rule.

Build trigger changed and run by hand by the same principal

Detection hypothesisSequence of events

An attacker who wants one build to run under the pipeline's identity does not wait for the next push. They change an existing trigger, run it by hand, and may change it back. A trigger update followed within minutes by a manual run of the same trigger by the same caller is that pattern.

  1. An UpdateBuildTrigger or CreateBuildTrigger entry from cloudbuild.googleapis.com. Note the trigger in protoPayload.resourceName and the caller in protoPayload.authenticationInfo.principalEmail.
  2. Within 30 minutes a RunBuildTrigger entry by the same caller for the same trigger.
  3. Raise the priority when a second UpdateBuildTrigger entry for the trigger follows the run, which suggests the change was reverted.

EventsUpdateBuildTriggerCreateBuildTriggerRunBuildTrigger

LimitsAn engineer who fixes a trigger and tests it produces the same sequence, so the content of the change decides. Google publishes no example of these entries, so check how your entries name the trigger before joining on it. The 30 minutes are a starting point.

Triage

  • Identify the caller (protoPayload.authenticationInfo.principalEmail) and the build or trigger in protoPayload.resourceName, and check whether the caller normally submits builds or maintains triggers in that project.
  • Read the build or the trigger as it is now. Check the steps, the source repository, the service account it runs as and where its logs go.
  • Find out which service account the project's builds use by default and what that account can do, and whether the caller could already do the same without it.
  • Look for audit entries with the build service account as caller after the build started, starting with allow policy changes, service account key creation, image pushes and deployments.
  • For a changed trigger, compare it with its definition in source control or with its last known state, and check whether it was run by hand right after the change.

Response

Once the attack is confirmed:

  1. Cancel running builds that are not approved, and restore or delete the trigger that was created or changed.
  2. Review what the build service account did since the build started and remove what was created, such as service account keys, role bindings, container images and deployed revisions.
  3. Treat container images and artifacts that the build pushed as untrusted. Rebuild them from reviewed source and redeploy the workloads that pulled them.
  4. Contain the caller. Reset its credentials and remove its Cloud Build roles and its Service Account User role on the build service account.
  5. Move the project's builds to a user-managed service account with minimal roles if a default account was in use.

Mitigation

  • Run builds with a user-managed service account that has only the roles the pipeline needs, as Google recommends, and name it in every trigger.
  • Use the organization policy constraints cloudbuild.useBuildServiceAccount, cloudbuild.useComputeServiceAccount and cloudbuild.disableCreateDefaultServiceAccount to control which default service account builds may use.
  • Limit cloudbuild.builds.create in production projects to the pipeline identity and the people who maintain it. Developers who only need to see builds can have the Cloud Build Viewer role.
  • Grant the Service Account User role on the build service account itself, not on the project, so that only intended identities can submit builds that run as it.
  • Enforce the constraint iam.automaticIamGrantsForDefaultServiceAccounts, so that the Compute Engine default service account does not receive the Editor role automatically.

Frequently asked questions

Which service account does a Cloud Build build run as?

The one named in the build's `serviceAccount` field, or a default if none is named. Google documents that projects whose first build ran before the change of May and June 2024 keep the legacy Cloud Build service account, and that newer projects use the Compute Engine default service account. An organization can steer this with the constraints `cloudbuild.useBuildServiceAccount` and `cloudbuild.useComputeServiceAccount`.

Why does the right to create a build matter so much?

Because the caller writes the build steps, and the steps run as the build service account. Google lists the same permission, `cloudbuild.builds.create`, for creating a build, retrying one, running a trigger and creating or updating a trigger. Google also states that the default service account may have unnecessarily broad permissions. Where that is so, anyone with the permission can use that access.

Do the rules show which service account or which steps a build used?

No. Google documents the method names, their permissions and the log type of these entries, but not which request fields the entry keeps. The rules therefore match on the method name and the caller. The build or trigger named in `protoPayload.resourceName` has to be read to see its steps and its service account.

Why is the build rule limited to user accounts?

Builds are created all day by pipelines, and a rule on every build would only produce noise. Pipelines and triggers act as service accounts. A person who submits a build directly, or runs a trigger by hand, is the less common case and the one an attacker with a stolen user credential produces. Builds submitted by a compromised service account are not matched by that rule.

References

We respect your privacy

We use cookies to keep this site secure and working properly. With your permission, we also use optional cookies to understand usage and improve the experience. Cookie Policy

You can change your choice at any time.