1. Resources
  2. Detection rules
  3. Cloud Run Workload or Function Deployed to Run as a Service Account (actAs Escalation)

Cloud Run Workload or Function Deployed to Run as a Service Account (actAs Escalation) detection rules

An attacker who can deploy to Cloud Run or Cloud Run functions and attach a service account runs their own code as that account and gains its roles, which are often broader than their own.

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 right to create or update a Cloud Run workload or a function, plus iam.serviceAccounts.actAs on a service account with more access than the caller.
Impact
Code execution as the attached service account, which with the Editor role or with rights to change allow policies means control of the project.
Response
Delete the workload or redeploy its last known-good revision, then disable the service account until its issued tokens have expired if it is privileged.
Mitigation
Grant the Service Account User role on individual service accounts only, and give each workload its own account with the minimal roles it needs.
API methods
*CloudFunctionsService.CreateFunction*CloudFunctionsService.UpdateFunction*FunctionService.CreateFunction*FunctionService.UpdateFunctiongoogle.cloud.run.v1.Services.CreateServicegoogle.cloud.run.v1.Services.ReplaceServicegoogle.cloud.run.v2.Services.CreateServicegoogle.cloud.run.v2.Services.UpdateServicegoogle.cloud.run.v1.Jobs.CreateJobgoogle.cloud.run.v1.Jobs.ReplaceJobgoogle.cloud.run.v2.Jobs.CreateJobgoogle.cloud.run.v2.Jobs.UpdateJoband 3 more in the rules below
Threat groups
None listed in MITRE ATT&CK for this technique

How the attack works

Code on Cloud Run (services, jobs and worker pools) and in Cloud Run functions runs as a service account, which Google calls the service identity. The account is chosen when the workload is deployed and can be replaced with any later deployment. Attaching a service account requires the iam.serviceAccounts.actAs permission on it, which the Service Account User role contains. When no account is named, Cloud Run uses the Compute Engine default service account, which might hold the Editor role on the project. A principal that can deploy, and can attach an account with more access than its own, therefore runs code with that account's access. Google's guidance on service accounts describes this as a way for a user to get access they would not have otherwise.

The deployment is an Admin Activity audit entry, which is always written. Cloud Run records CreateService, ReplaceService and UpdateService and the matching job and worker pool methods under run.googleapis.com, and Cloud Run functions records CreateFunction and UpdateFunction under cloudfunctions.googleapis.com. Google Cloud also logs the attachment itself: when a principal uses actAs to attach a service account to a resource, IAM writes an Admin Activity entry with the method name iam.serviceAccounts.actAs that names the service account and the principal. Running the code leaves less, because RunJob and CallFunction are Data Access events that exist only where those logs are enabled.

What an attacker needs

  • Permission to create or update a Cloud Run service, job or worker pool (run.services.create, run.services.update and the matching run.jobs and run.workerpools permissions) or a function (cloudfunctions.functions.create, cloudfunctions.functions.update).
  • iam.serviceAccounts.actAs on a service account that has more access than the caller, for example through the Service Account User role granted on a whole project.
  • A way to make the code run, such as a request to the service, a trigger or a job execution.

Impact

Code execution as the attached service account. The code obtains access tokens and ID tokens for the account from the metadata server and can use everything the account's roles allow. With the default service account and the Editor role that is most of the project. With an account that can change allow policies or create service account keys it becomes lasting control.

Detection rules

Cloud Run Function Created or Updated

Detects creation and update of a function through the Cloud Functions API, in the v1 API (CloudFunctionsService) and in the v2 API and its alpha and beta versions (FunctionService). Both are Admin Activity audit log entries, which are always written. Each call sets the code the function runs and its runtime service account, so it is the event behind running code as an attached service account. 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 fires on every deployment. Google marks these methods as long-running operations, which usually write a start and a completion entry for one change. The function is named in protoPayload.resourceName. The service account that was attached is in the iam.serviceAccounts.actAs entry that the same caller produces, which has a rule of its own on this page. Calling a function through the API (CallFunction) is a Data Access event and is not matched.

LevelLowStatusExperimentalLog sourceGoogle Cloud Audit Logs
title: Cloud Run Function Created or Updated
id: 205ea60f-c04e-4d87-81d5-919e3d266f4a
status: experimental
description: >-
  Detects creation and update of a function through the Cloud Functions API,
  in the v1 API (CloudFunctionsService) and in the v2 API and its alpha and
  beta versions (FunctionService). Both are Admin Activity audit log entries,
  which are always written. Each
  call sets the code the function runs and its runtime service account, so
  it is the event behind running code as an attached service account. 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 fires on every deployment. Google marks these methods as
  long-running operations, which usually write a start and a completion
  entry for one change. The function is named in protoPayload.resourceName.
  The service account that was attached is in the iam.serviceAccounts.actAs
  entry that the same caller produces, which has a rule of its own on this
  page. Calling a function through the API (CallFunction) is a Data Access
  event and is not matched.
references:
  - https://docs.cloud.google.com/functions/docs/monitoring/audit-logging
  - https://docs.cloud.google.com/functions/docs/securing/function-identity
  - https://docs.cloud.google.com/iam/docs/attach-service-accounts
author: Forestall
date: 2026-11-18
tags:
  - attack.execution
  - attack.t1648
logsource:
  product: gcp
  service: gcp.audit
detection:
  selection:
    protoPayload.serviceName: cloudfunctions.googleapis.com
    protoPayload.methodName|endswith:
      - CloudFunctionsService.CreateFunction
      - CloudFunctionsService.UpdateFunction
      - FunctionService.CreateFunction
      - FunctionService.UpdateFunction
  condition: selection
falsepositives:
  - Every deployment by developers and CI/CD pipelines. Exclude the deployment identities by principalEmail in a filter_* selection, or limit the rule to production projects, and review deployments by anyone else.
level: low

False positives

  • Every deployment by developers and CI/CD pipelines. Exclude the deployment identities by principalEmail in a filter_* selection, or limit the rule to production projects, and review deployments by anyone else.

Cloud Run Service, Job or Worker Pool Created or Updated

Detects creation and update of a Cloud Run service, job or worker pool in the v1 and v2 APIs (Admin Activity audit log, always written). Each of these calls sets the container the workload runs and the service account it runs as, so it is the event behind running code as an attached service account. 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 fires on every deployment. The workload is named in protoPayload.resourceName. The service account that was attached is in the iam.serviceAccounts.actAs entry that the same caller produces, which has a rule of its own on this page. Executing a job (RunJob) is a Data Access event and is not matched.

LevelLowStatusExperimentalLog sourceGoogle Cloud Audit Logs
title: Cloud Run Service, Job or Worker Pool Created or Updated
id: e6c90d9e-491e-40c0-8a40-ed0ad4c95522
status: experimental
description: >-
  Detects creation and update of a Cloud Run service, job or worker pool in
  the v1 and v2 APIs (Admin Activity audit log, always written). Each of
  these calls sets the container the workload runs and the service account
  it runs as, so it is the event behind running code as an attached service
  account. 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 fires on every deployment. The workload is named
  in protoPayload.resourceName. The service account that was attached is in
  the iam.serviceAccounts.actAs entry that the same caller produces, which
  has a rule of its own on this page. Executing a job (RunJob) is a Data
  Access event and is not matched.
references:
  - https://docs.cloud.google.com/run/docs/audit-logging
  - https://docs.cloud.google.com/run/docs/securing/service-identity
  - https://docs.cloud.google.com/iam/docs/attach-service-accounts
author: Forestall
date: 2026-11-18
tags:
  - attack.execution
  - attack.t1648
logsource:
  product: gcp
  service: gcp.audit
detection:
  selection:
    protoPayload.serviceName: run.googleapis.com
    protoPayload.methodName:
      - google.cloud.run.v1.Services.CreateService
      - google.cloud.run.v1.Services.ReplaceService
      - google.cloud.run.v2.Services.CreateService
      - google.cloud.run.v2.Services.UpdateService
      - google.cloud.run.v1.Jobs.CreateJob
      - google.cloud.run.v1.Jobs.ReplaceJob
      - google.cloud.run.v2.Jobs.CreateJob
      - google.cloud.run.v2.Jobs.UpdateJob
      - google.cloud.run.v2.WorkerPools.CreateWorkerPool
      - google.cloud.run.v2.WorkerPools.UpdateWorkerPool
  condition: selection
falsepositives:
  - Every deployment by developers and CI/CD pipelines. Exclude the deployment identities by principalEmail in a filter_* selection, or limit the rule to production projects, and review deployments by anyone else.
level: low

False positives

  • Every deployment by developers and CI/CD pipelines. Exclude the deployment identities by principalEmail in a filter_* selection, or limit the rule to production projects, and review deployments by anyone else.

Service Account Attached to a Resource by a User Account

Detects a user account using the iam.serviceAccounts.actAs permission to attach a service account to a resource. Google documents that IAM writes an audit entry for this, with the method name iam.serviceAccounts.actAs under iam.googleapis.com. Google's example is an Admin Activity entry, which is always written. Code on the resource then runs as that service account, so the entry marks the moment a person puts a workload under an identity that may have more access than their own. The service account is in protoPayload.resourceName and in request.name, and the person in principalEmail. Google's example of the entry does not name the resource, and the entry is written for every kind of resource a service account can be attached to, not only for Cloud Run and Cloud Run functions. Read it together with the deployment entry of the same caller. Attachments made by a service account, which is how deployment pipelines work, are left out on purpose.

LevelMediumStatusExperimentalLog sourceGoogle Cloud Audit Logs
title: Service Account Attached to a Resource by a User Account
id: a5778a01-3b29-44c7-8467-0db6fb5f2b23
status: experimental
description: >-
  Detects a user account using the iam.serviceAccounts.actAs permission to
  attach a service account to a resource. Google documents that IAM writes
  an audit entry for this, with the method name iam.serviceAccounts.actAs
  under iam.googleapis.com. Google's example is an Admin Activity entry,
  which is always written. Code on the resource then runs as that service
  account, so the entry marks the moment a person puts a workload under an
  identity that may have more access than their own. The service account is
  in protoPayload.resourceName and in request.name, and the person in
  principalEmail. Google's example of the entry does not name the resource,
  and the entry is written for every kind of resource a service account can
  be attached to, not only for Cloud Run and Cloud Run functions. Read it
  together with the
  deployment entry of the same caller. Attachments made by a service
  account, which is how deployment pipelines work, are left out on purpose.
references:
  - https://docs.cloud.google.com/iam/docs/attach-service-accounts
  - https://docs.cloud.google.com/iam/docs/audit-logging/examples-service-accounts
  - https://docs.cloud.google.com/iam/docs/best-practices-service-accounts
author: Forestall
date: 2026-11-18
tags:
  - attack.execution
  - attack.t1648
logsource:
  product: gcp
  service: gcp.audit
detection:
  selection:
    protoPayload.serviceName: iam.googleapis.com
    protoPayload.methodName: iam.serviceAccounts.actAs
    protoPayload.authenticationInfo.principalEmail|contains: '@'
  filter_service_accounts:
    protoPayload.authenticationInfo.principalEmail|endswith: .gserviceaccount.com
  condition: selection and not 1 of filter_*
falsepositives:
  - Developers and administrators who deploy by hand, which is common in development projects. Limit the rule to the service accounts that matter by adding protoPayload.resourceName to the selection, or exclude projects where manual deployment is normal, and review every match on a privileged service account.
level: medium

False positives

  • Developers and administrators who deploy by hand, which is common in development projects. Limit the rule to the service accounts that matter by adding protoPayload.resourceName to the selection, or exclude projects where manual deployment is normal, and review every match on a privileged service account.

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.

Service account attached and a workload deployed by the same principal

Detection hypothesisJoins two logsNeeds your own lists

The deployment entry says who deployed what, and the attachment entry says who attached which service account. Neither says that a privileged account now runs somebody's code. Joined on the caller and the time, and compared with a list of privileged service accounts, the two entries show exactly that.

  1. An iam.serviceAccounts.actAs entry from iam.googleapis.com. Note the service account in request.name and the caller in authenticationInfo.principalEmail.
  2. Within 5 minutes before or after it, the same caller has a create or update entry from run.googleapis.com or cloudfunctions.googleapis.com, the methods of the two deployment rules on this page. Note the workload in protoPayload.resourceName.
  3. Compare the service account with your list of privileged service accounts and the caller with your deployment identities. Alert when the account is on the first list and the caller is not on the second.

Eventsiam.serviceAccounts.actAsCreateServiceReplaceServiceUpdateServiceCreateFunctionUpdateFunction

LimitsGoogle's example of the attachment entry does not name the resource, so the join rests on caller and time and can pair a deployment with an attachment to something else by the same caller, such as a virtual machine. Without a list of privileged service accounts the result is every deployment. The 5 minutes are a starting point.

Principal attaches a service account shortly after being granted the right to

Detection hypothesisSequence of events

An attacker who lacks actAs on a useful service account grants it to themselves, or to an identity they control, and deploys right after. A grant of the Service Account User role followed within hours by the first attachment of that account by the new member is the escalation path being opened and used.

  1. A google.iam.admin.v1.SetIAMPolicy entry from iam.googleapis.com whose response.bindings give a member the role roles/iam.serviceAccountUser. The service account is in request.resource and the caller in authenticationInfo.principalEmail.
  2. Within 24 hours that member is the caller of an iam.serviceAccounts.actAs entry whose request.name is the same service account.
  3. Read the deployment entries of that caller around the attachment to see what was deployed.

Eventsgoogle.iam.admin.v1.SetIAMPolicyiam.serviceAccounts.actAs

LimitsA team that sets up a new service is granted the role and deploys in the same way, so the grant needs a change record. A role granted on the project, folder or organization is recorded by Resource Manager and is not seen by the first step. The 24 hours are a starting point.

Service account attached and a job, pipeline or data service created by the same principal

Detection hypothesisJoins two logsNeeds your own lists

Cloud Run and Cloud Run functions are not the only services that run a resource as an attached service account. Scheduled jobs, workflow environments, data pipelines and builds do the same, and the attachment entry is written for every kind of resource. The same join therefore finds the escalation in those services.

  1. An iam.serviceAccounts.actAs entry from iam.googleapis.com. Note the service account in request.name and the caller in authenticationInfo.principalEmail.
  2. Within 5 minutes before or after it, the same caller has an Admin Activity entry google.cloud.scheduler.v1.CloudScheduler.CreateJob or UpdateJob, or google.cloud.orchestration.airflow.service.v1.Environments.CreateEnvironment or UpdateEnvironment.
  3. Or, in the same window, google.cloud.datafusion.v1.DataFusion.CreateInstance or dataflow.jobs.create. Note the resource in protoPayload.resourceName.
  4. Compare the service account with your list of privileged service accounts and the caller with your deployment identities, and alert when the account is on the first list and the caller is not on the second.

Eventsiam.serviceAccounts.actAsgoogle.cloud.scheduler.v1.CloudScheduler.CreateJobgoogle.cloud.scheduler.v1.CloudScheduler.UpdateJobgoogle.cloud.orchestration.airflow.service.v1.Environments.CreateEnvironmentgoogle.cloud.orchestration.airflow.service.v1.Environments.UpdateEnvironmentgoogle.cloud.datafusion.v1.DataFusion.CreateInstancedataflow.jobs.create

LimitsGoogle documents the attachment entry with a Compute Engine example and does not list which services write it, so a service that does not write it is not found this way. The method names are those of the audit logging pages of Cloud Scheduler, Cloud Composer, Cloud Data Fusion and Dataflow. Vertex AI and Workbench are left out because their method names could not be confirmed on a Google page. The 5 minutes are a starting point.

Triage

  • Find the service account that was attached. Read the iam.serviceAccounts.actAs entry of the same caller at the same time. The account is in protoPayload.resourceName and in request.name.
  • Check what that account can do, and whether the caller (principalEmail) could already do the same without it.
  • Check whether the caller is the usual deployment identity for the workload named in protoPayload.resourceName, and whether the entry created the workload or changed an existing one.
  • Review the revision or function source that was deployed, and look for Admin Activity entries with the service account as caller after the deployment, starting with allow policy changes and service account key creation.
  • If the deployment is not approved, treat the service account's access as used and continue with the response steps.

Response

Once the attack is confirmed:

  1. Stop the workload. Delete the service, job, worker pool or function, or redeploy the last known-good revision with its former service identity, and remove the triggers and schedules that invoke it.
  2. Deal with tokens that were already issued. Google states that service account access tokens stay valid until they expire, by default up to 60 minutes, and cannot be revoked. If the account is privileged, disable it or apply a deny policy until they have expired, after checking which other workloads depend on it.
  3. Review the audit entries that have the service account as caller since the deployment, and remove what it created, such as service account keys, role bindings, service accounts and other workloads.
  4. Contain the principal that deployed. Reset its credentials and remove its Service Account User role on the account and its deployment rights.
  5. Check the other workloads that use the same service account for revisions nobody deployed.

Mitigation

  • Grant the Service Account User role on individual service accounts, not on a project or a folder, so that a deployer can attach only the accounts meant for their workloads.
  • Give every service and function its own user-managed service account with the minimal roles it needs, and keep privileged service accounts out of projects where many people can deploy.
  • Enforce the organization policy constraint iam.automaticIamGrantsForDefaultServiceAccounts, so that the default service accounts do not receive the Editor role automatically.
  • Limit the rights to create and update Cloud Run workloads and functions in production projects to the deployment pipeline.
  • Keep the constraint iam.disableCrossProjectServiceAccountUsage enforced, which is its default. It stops a service account from being attached to a resource in another project.

Frequently asked questions

Does Google Cloud log the use of the actAs permission?

Yes. Google documents that when a principal uses `iam.serviceAccounts.actAs` to attach a service account to a resource, IAM generates an audit log with the principal's email address and details about the service account. In Google's example the method name is `iam.serviceAccounts.actAs`, the service name `iam.googleapis.com`, and the account is in `resourceName` and `request.name`. Neither Google's description nor its example of the entry includes the resource the account was attached to, which is why it has to be read together with the deployment entry.

Why do the deployment rules have a low level?

Every deployment of a Cloud Run service, job, worker pool or function writes the same entries, whoever makes it and whichever service account is attached. The rules cannot tell a privileged account from a harmless one, because that depends on the roles the account holds. They become useful when they are limited to callers outside the deployment pipeline or joined with the attachment entry, as the detection logic on this page describes.

What happens when a deployment names no service account?

Cloud Run then uses the Compute Engine default service account. Google states that this account might automatically be granted the Editor role on the project and strongly recommends disabling the automatic grant with the constraint `iam.automaticIamGrantsForDefaultServiceAccounts`. In organizations created after May 3, 2024 the constraint is enforced by default. Where the grant is still in place, a deployment without a named account runs with Editor.

Can I see the deployed code being run?

Only in part. Executing a Cloud Run job (`RunJob`) and calling a function through the API (`CallFunction`) are Data Access audit events, which exist only where Data Access logs are enabled for the service. The more reliable trace is what the code does with its identity, which appears as audit entries with the service account as the caller.

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.