turbot/steampipe-mod-terraform-gcp-compliance

Control: 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.

Usage

Run the control in your terminal:

powerpipe control run terraform_gcp_compliance.control.compute_instance_with_no_default_service_account

Snapshot and share results via Turbot Pipes:

powerpipe login
powerpipe control run terraform_gcp_compliance.control.compute_instance_with_no_default_service_account --share

SQL

This control uses a named query:

select
address as resource,
case
when (attributes_std -> 'service_account') is null and (attributes_std -> 'source_instance_template') is null then 'skip'
when (attributes_std -> 'service_account') is null and (attributes_std -> 'source_instance_template') is not null then 'skip'
when (attributes_std -> 'service_account') is not null and (attributes_std -> 'service_account' ->> 'email') is null then 'alarm'
when (attributes_std ->> 'name') like 'gke-%' and (attributes_std -> 'service_account' ->> 'email') like '%-compute@developer.gserviceaccount.com' then 'ok'
when (attributes_std -> 'service_account' ->> 'email') not like '%-compute@developer.gserviceaccount.com' then 'ok'
else 'alarm'
end status,
split_part(address, '.', 2) || case
when (attributes_std -> 'service_account') is null and (attributes_std -> 'source_instance_template') is null then ' no service account configured'
when (attributes_std -> 'service_account') is null and (attributes_std -> 'source_instance_template') is not null then ' has no service account in the instance template'
when (attributes_std -> 'service_account') is not null and (attributes_std -> 'service_account' ->> 'email') is null then ' does not have email configured in service account'
when (attributes_std ->> 'name') like 'gke-%' then ' configured to use default service account'
when (attributes_std -> 'service_account' ->> 'email') not like '%-compute@developer.gserviceaccount.com' then ' not use default service account'
else ' use default service account'
end || '.' reason
, path || ':' || start_line
from
terraform_resource
where
type in ('google_compute_instance', 'google_compute_instance_from_template', 'google_compute_instance_template');

Tags