turbot/azure_compliance

Query: iam_external_user_with_owner_role

Usage

powerpipe query azure_compliance.query.iam_external_user_with_owner_role

SQL

with all_owner_users as (
select
distinct
u.display_name,
d.role_name,
u.account_enabled,
u.user_principal_name,
d.subscription_id
from
azuread_user as u
left join azure_role_assignment as a on a.principal_id = u.id
left join azure_role_definition as d on d.id = a.role_definition_id
where d.role_name = 'Owner'
), distinct_tenant as (
select
distinct tenant_id,
subscription_id,
_ctx
from
azure_tenant
)
select
a.user_principal_name as resource,
case
when a.user_principal_name like '%EXT%' then 'alarm'
else 'ok'
end as status,
case
when a.user_principal_name like '%EXT%' then a.display_name || ' is external user with ' || a.role_name || ' role.'
else a.display_name || ' is domain user with ' || a.role_name || ' role.'
end as reason,
t.tenant_id
from
distinct_tenant as t,
all_owner_users as a;

Controls

The query is being used by the following controls: