turbot/gcp_compliance

Control: 4.2 Ensure that instances are not configured to use the default service account with full access to all Cloud APIs

Description

To support principle of least privileges and prevent potential privilege escalation it is recommended that instances are not assigned to default service account Compute Engine default service account with Scope Allow full access to all Cloud APIs.

Along with ability to optionally create, manage and use user managed custom service accounts, Google Compute Engine provides default service account Compute Engine default service account for an instances to access necessary cloud services. Project Editor role is assigned to Compute Engine default service account hence, This service account has almost all capabilities over all cloud services except billing. However, when Compute Engine default service account assigned to an instance it can operate in 3 scopes.

1. Allow default access: Allows only minimum access required to run an Instance (Least Privileges)
2. Allow full access to all Cloud APIs: Allow full access to all the cloud APIs/Services (Too much access)
3. Set access for each API: Allows Instance administrator to choose only those APIs that are needed to perform specific business functionality expected by instance

When an instance is configured with Compute Engine default service account with Scope Allow full access to all Cloud APIs, based on IAM roles assigned to the user(s) accessing Instance, it may allow user to perform cloud operations/API calls that user is not supposed to perform leading to successful privilege escalation.

Remediation

From Console

  1. Go to the VM instances page by visiting: https://console.cloud.google.com/compute/instances.
  2. Click on the impacted VM instance.
  3. If the instance is not stopped, click the Stop button. Wait for the instance to be stopped.
  4. Next, click the Edit button.
  5. Scroll down to the Service Account section.
  6. Select a different service account or ensure that Allow full access to all Cloud APIs is not selected.
  7. Click the Save button to save your changes and then click START.

From Command Line

  1. Stop the instance:
gcloud compute instances stop <INSTANCE_NAME>
  1. Update the instance:
gcloud compute instances set-service-account <INSTANCE_NAME> --service- account=<SERVICE_ACCOUNT> --scopes [SCOPE1, SCOPE2...]
  1. Restart the instance:
gcloud compute instances start <INSTANCE_NAME>

Default Value

While creating an VM instance, default service account is used with scope Allow default access.

Usage

Run the control in your terminal:

powerpipe control run gcp_compliance.control.cis_v200_4_2

Snapshot and share results via Turbot Pipes:

powerpipe login
powerpipe control run gcp_compliance.control.cis_v200_4_2 --share

SQL

This control uses a named query:

compute_instance_with_no_default_service_account_with_full_access

Tags