turbot/steampipe-mod-kubernetes-compliance

Control: Pod containers secrets should be defined as files

Description

This check ensures that the container in the Pod has secrets defined as files.

Usage

Run the control in your terminal:

powerpipe control run kubernetes_compliance.control.pod_container_secrets_defined_as_files

Snapshot and share results via Turbot Pipes:

powerpipe login
powerpipe control run kubernetes_compliance.control.pod_container_secrets_defined_as_files --share

SQL

This control uses a named query:

select
coalesce(uid, concat(path, ':', start_line)) as resource,
case
when env like '%valueFrom%' and env like '%secretKeyRef%' then 'alarm'
else 'ok'
end as status,
case
when env like '%valueFrom%' and env like '%secretKeyRef%' then c ->> 'name' || ' container has secrets defined.'
else c ->> 'name' || ' container has no secrets defined.'
end as reason,
name as pod_name
, coalesce(context_name, '') as context_name, namespace, source_type, coalesce(path || ':' || start_line || '-' || end_line, '') as path
from
kubernetes_pod,
jsonb_array_elements(containers) c,
jsonb_array_elements_text(c -> 'env') as env
union
select
coalesce(uid, concat(path, ':', start_line)) as resource,
case
when env like '%secretRef%' then 'alarm'
else 'ok'
end as status,
case
when env like '%secretRef%' then c ->> 'name' || ' container has secrets defined.'
else c ->> 'name' || ' container has no secrets defined.'
end as reason,
name as pod_name
, coalesce(context_name, '') as context_name, namespace, source_type, coalesce(path || ':' || start_line || '-' || end_line, '') as path
from
kubernetes_pod,
jsonb_array_elements(containers) c,
jsonb_array_elements_text(c -> 'envFrom') as env;

Tags