Control: Cloudfunction functions should restrict deployments manager permission
Description
This control ensures that Cloudfunction function does not allow deployments manager permissions.
Usage
Run the control in your terminal:
powerpipe control run gcp_compliance.control.cloudfunction_function_no_deployments_manager_permission
Snapshot and share results via Turbot Pipes:
powerpipe loginpowerpipe control run gcp_compliance.control.cloudfunction_function_no_deployments_manager_permission --share
SQL
This control uses a named query:
with role_with_deployments_manager_permission as ( select distinct name, project from gcp_iam_role, jsonb_array_elements_text(included_permissions) as p where not is_gcp_managed and p in ('deploymentmanager.deployments.create', 'deploymentmanager.deployments.update' ) ), policy_with_deployments_manager_permission as ( select distinct entity, project from gcp_iam_policy, jsonb_array_elements(bindings) as p, jsonb_array_elements_text(p -> 'members') as entity where p ->> 'role' in ('roles/deploymentmanager.editor' ) or p ->> 'role' in (select name from role_with_deployments_manager_permission ))select f.project as resource, case when f.service_account_email is not null then 'alarm' else 'ok' end as status, case when f.service_account_email is not null then f.title || ' allow deployment manager''s permission.' else f.title || ' restrict deployment manager''s permission.' end as reason , f.project as project , f.project as projectfrom gcp_cloudfunctions_function as f left join policy_with_deployments_manager_permission as b on f.project = b.project and b.entity = concat('serviceAccount:' || f.service_account_email);