Default Compute Service Account With the Editor Role
The Compute Engine default service account still holds the project-wide Editor role, so any compromised workload running as it can change most resources in the project.
| Severity | High |
| CVSS 3.1 | 7.5 CVSS:3.1/AV:N/AC:H/PR:L/UI:N/S:U/C:H/I:H/A:H Open in the calculator |
| CVSS 4.0 | 7.7 CVSS:4.0/AV:N/AC:L/AT:P/PR:L/UI:N/VC:H/VI:H/VA:H/SC:N/SI:N/SA:N Open in the calculator |
| CWE | CWE-1188: Initialization of a Resource with an Insecure Default |
| MITRE ATT&CK | T1552.005 Cloud Instance Metadata API, T1078.004 Cloud Accounts |
| Category | Broken Access Control |
Description
When the Compute Engine API is enabled in a project, Google Cloud creates the Compute Engine default service account, named with the project number followed by -compute@developer.gserviceaccount.com, and, unless the constraints/iam.automaticIamGrantsForDefaultServiceAccounts organisation policy constraint is enforced, grants it the basic Editor role on the project. Virtual machines use this account unless another is chosen, and other services, such as Cloud Run, also run as it by default. Editor allows a principal to create, change and delete most resources in the project and to read most of its data, though it cannot change the project's IAM policy.
Code running on a virtual machine obtains tokens for its service account from the metadata server, at http://metadata.google.internal/, by sending the header Metadata-Flavor: Google. An attacker who gains code execution on any workload running as the default service account, or who can make it send requests to the metadata server through server-side request forgery that allows the required header, can therefore obtain a token and use it from anywhere until it expires.
On Compute Engine, the instance's access scopes also limit what the token can do. With the scope allowing full access to all Cloud APIs, the token can use everything the Editor role permits, so the attacker can read data in Cloud Storage, BigQuery and other services, change or delete resources, and deploy their own workloads for persistence; workloads configured with full access, and services that do not use access scopes, can use the whole role. The default scopes restrict most APIs, leaving the token largely limited to reading Cloud Storage and writing logs and metrics, which can still expose the project's stored data.
The finding is identified by reviewing the project's IAM policy for the default service account's Editor binding, and the service account and scopes configured on each instance and service.
Remediation
- Create a dedicated, user-managed service account for each workload, grant it only the predefined or custom roles it needs, and attach it to the workload in place of the default service account.
- Remove the Editor role from the Compute Engine default service account once no workload depends on it, testing first in a non-production project, and disable the account if nothing uses it.
- Enforce the
constraints/iam.automaticIamGrantsForDefaultServiceAccountsorganisation policy constraint so that default service accounts in new projects receive no roles automatically. - Do not combine broad roles with the scope allowing full access to all Cloud APIs, and use narrow IAM roles rather than access scopes as the main way of limiting access.
- Restrict who can attach service accounts to resources, which the Service Account User role allows, since attaching a privileged service account to a new resource is a privilege escalation path.
Confirm the fix by reviewing the project's IAM policy, expecting no Editor binding for default service accounts, and by checking each instance's attached service account and scopes.
References
Add This Finding to Your Library
In Pental this write-up is in Settings, Library. Add to my library copies it into your own, rated in your firm's CVSS version, ready to put in your own words.
Free trialYour trial starts when your portal goes live, not when you sign up, so the time you spend setting up does not count. · No card required
Only need the reporting? Our reporting tool is free and open source, with the same library.