turbot/kubernetes_compliance

Query: network_policy_default_dont_allow_egress

Usage

powerpipe query kubernetes_compliance.query.network_policy_default_dont_allow_egress

SQL

with default_allows_all_egress_count as (
select
namespace,
name,
uid,
context_name,
tags,
_ctx,
p.path,
p.start_line,
p.end_line,
p.source_type,
-- Get the count of default allow Egress policy
count(*) filter (where rule = '{}') as num_allow_all_rules
from
kubernetes_network_policy p
left join jsonb_array_elements(egress) as rule on true
group by
namespace,
name,
uid,
context_name,
rule,
policy_types,
tags,
_ctx,
p.path,
p.start_line,
p.end_line,
p.source_type
)
select
coalesce(uid, concat(path, ':', start_line)) as resource,
case
when num_allow_all_rules > 0 then 'alarm'
else 'ok'
end as status,
case
when num_allow_all_rules > 0 then name || ' allows all egress'
else name || ' does not allow all egress'
end as reason,
name as network_policy_name
, coalesce(context_name, '') as context_name, namespace, source_type, coalesce(path || ':' || start_line || '-' || end_line, '') as path
from
default_allows_all_egress_count;

Controls

The query is being used by the following controls: