turbot/steampipe-mod-gcp-compliance

Control: 4.1 Ensure That Instances Are Not Configured To Use the Default Service Account

Description

It is recommended to configure your instance to not use the default Compute Engine service account because it has the Editor role on the project.

When a default Compute Engine service account is created, it is automatically granted the Editor role (roles/editor) on your project which allows read and write access to most Google Cloud Services. This role includes a very large number of permissions. To defend against privilege escalations if your VM is compromised and prevent an attacker from gaining access to all of your project, you should either revoke the Editor role from the default Compute Engine service account or create a new service account and assign only the permissions needed by your instance. To mitigate this at scale, we strongly recommend that you disable the automatic role grant by adding a constraint to your organization policy.

The default Compute Engine service account is named [PROJECT_NUMBER]-compute@developer.gserviceaccount.com.

Remediation

From Google Cloud Console

  1. Go to the VM instances page by visiting: https://console.cloud.google.com/compute/instances.
  2. Click on the instance name to go to its VM instance details page.
  3. Click STOP and then click EDIT.
  4. Under the section API and identity management, select a service account other than the default Compute Engine service account. You may first need to create a new service account.
  5. Click Save and then click START.

From Google Cloud CLI

  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>
  1. Restart the instance:
gcloud compute instances start <INSTANCE_NAME>

Default Value

By default, Compute instances are configured to use the default Compute Engine service account.

Usage

Run the control in your terminal:

powerpipe control run gcp_compliance.control.cis_v400_4_1

Snapshot and share results via Turbot Pipes:

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

SQL

This control uses a named query:

select
self_link resource,
case
when name like 'gke-%' and labels ? 'goog-gke-node' then 'skip'
when account ->> 'email' like '%-compute@developer.gserviceaccount.com' then 'alarm'
else 'ok'
end as status,
case
when name like 'gke-%' and labels ? 'goog-gke-node'
then title || ' created by GKE.'
when account ->> 'email' like '%-compute@developer.gserviceaccount.com'
then title || ' configured to use default service account.'
else title || ' not configured with default service account.'
end as reason
, location as location, project as project
from
gcp_compute_instance,
jsonb_array_elements(service_accounts) account;

Tags