turbot/steampipe-mod-kubernetes-compliance

Control: CronJob containers should has image pull policy set to Always

Description

This check ensures that the container in the CronJob has image pull policy set to Always.

Usage

Run the control in your terminal:

powerpipe control run kubernetes_compliance.control.cronjob_container_image_pull_policy_always

Snapshot and share results via Turbot Pipes:

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

SQL

This control uses a named query:

select
coalesce(uid, concat(path, ':', start_line)) as resource,
case
when c ->> 'image' is null or c ->> 'image' = '' then 'alarm'
when c ->> 'imagePullPolicy' is null
and (select (regexp_matches(c ->> 'image', '(?:[^\s\/]+\/)?([^\s:]+):?([^\s]*)'))[2]) not in ('latest', '') then 'alarm'
when c ->> 'imagePullPolicy' <> 'Always' then 'alarm'
else 'ok'
end as status,
case
when c ->> 'image' is null or c ->> 'image' = '' then c ->> 'name' || ' no image specified.'
when c ->> 'imagePullPolicy' is null
and (select (regexp_matches(c ->> 'image', '(?:[^\s\/]+\/)?([^\s:]+):?([^\s]*)'))[2]) not in ('latest', '') then c ->> 'name' || ' image pull policy is not specified.'
when c ->> 'imagePullPolicy' <> 'Always' then c ->> 'name' || ' image pull policy is not set to ''Always''.'
else c ->> 'name' || ' image pull policy is set to ''Always''.'
end as reason,
name as cronjob_name
, coalesce(context_name, '') as context_name, namespace, source_type, coalesce(path || ':' || start_line || '-' || end_line, '') as path
from
kubernetes_cronjob,
jsonb_array_elements(job_template -> 'spec' -> 'template' -> 'spec' -> 'containers') as c;

Tags