turbot/kubernetes_compliance

Query: network_policy_default_dont_allow_ingress

Usage

powerpipe query kubernetes_compliance.query.network_policy_default_dont_allow_ingress

SQL

with default_allows_all_ingress_count as (
select
namespace,
name,
uid,
context_name,
_ctx,
tags,
p.path,
p.start_line,
p.end_line,
p.source_type,
-- Get the count of default allow Ingress policy
count(*) filter (
where
rule = '{}'
) as num_allow_all_rules
from
kubernetes_network_policy p
left join jsonb_array_elements(ingress) 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(p.path, ':', p.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 ingress'
else name || ' does not allow all ingress'
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_ingress_count p;

Controls

The query is being used by the following controls: