turbot/steampipe-mod-aws-compliance

Control: IAM customer managed policies should be attached to IAM role

Description

This control checks if customer managed IAM policies are attached to an AWS Identity and Access Management (IAM) role. The rule is non-compliant if a customer managed IAM policy is not attached to any IAM role.

Usage

Run the control in your terminal:

powerpipe control run aws_compliance.control.iam_custom_managed_policy_attached_to_role

Snapshot and share results via Turbot Pipes:

powerpipe login
powerpipe control run aws_compliance.control.iam_custom_managed_policy_attached_to_role --share

SQL

This control uses a named query:

with role_attached_policies as (
select
jsonb_array_elements_text(attached_policy_arns) as policy_arn
from
aws_iam_role
)
select
arn as resource,
case
when arn in (select policy_arn from role_attached_policies) then 'ok'
else 'alarm'
end as status,
case
when arn in (select policy_arn from role_attached_policies) then title || ' attached to IAM role.'
else title || ' not attached to IAM role.'
end as reason
, account_id
from
aws_iam_policy
where
not is_aws_managed;

Tags