Table: k8s_core_pods

This table shows data for Kubernetes (K8s) Core Pods.

The primary key for this table is uid.

Columns

NameType
_cq_iduuid
_cq_parent_iduuid
contextutf8
status_host_ipinet
status_pod_ipinet
status_pod_ipslist<item: inet, nullable>
kindutf8
api_versionutf8
nameutf8
namespaceutf8
uid (PK)utf8
resource_versionutf8
generationint64
deletion_grace_period_secondsint64
labelsjson
annotationsjson
owner_referencesjson
finalizerslist<item: utf8, nullable>
spec_volumesjson
spec_init_containersjson
spec_containersjson
spec_ephemeral_containersjson
spec_restart_policyutf8
spec_termination_grace_period_secondsint64
spec_active_deadline_secondsint64
spec_dns_policyutf8
spec_node_selectorjson
spec_service_account_nameutf8
spec_automount_service_account_tokenbool
spec_node_nameutf8
spec_host_networkbool
spec_host_pidbool
spec_host_ipcbool
spec_share_process_namespacebool
spec_security_contextjson
spec_image_pull_secretsjson
spec_hostnameutf8
spec_subdomainutf8
spec_affinityjson
spec_scheduler_nameutf8
spec_tolerationsjson
spec_host_aliasesjson
spec_priority_class_nameutf8
spec_priorityint64
spec_dns_configjson
spec_readiness_gatesjson
spec_runtime_class_nameutf8
spec_enable_service_linksbool
spec_preemption_policyutf8
spec_overheadjson
spec_topology_spread_constraintsjson
spec_set_hostname_as_fqdnbool
spec_osjson
spec_host_usersbool
spec_scheduling_gatesjson
spec_resource_claimsjson
status_phaseutf8
status_conditionsjson
status_messageutf8
status_reasonutf8
status_nominated_node_nameutf8
status_start_timetimestamp[us, tz=UTC]
status_init_container_statusesjson
status_container_statusesjson
status_qos_classutf8
status_ephemeral_container_statusesjson

Example Queries

These SQL queries are sampled from CloudQuery policies and are compatible with PostgreSQL.

Pod container privileged access disabled

WITH
  pod_containers
    AS (
      SELECT
        uid, value AS container
      FROM
        k8s_core_pods CROSS JOIN jsonb_array_elements(spec_containers) AS value
    )
SELECT
  uid AS resource_id,
  'Pod container privileged access disabled' AS title,
  context AS context,
  namespace AS namespace,
  name AS resource_name,
  CASE
  WHEN (
    SELECT
      count(*)
    FROM
      pod_containers
    WHERE
      pod_containers.uid = k8s_core_pods.uid
      AND pod_containers.container->'securityContext'->>'privileged' = 'true'
  )
  > 0
  THEN 'fail'
  ELSE 'pass'
  END
    AS status
FROM
  k8s_core_pods;

Pod container privilege escalation disabled

WITH
  pod_containers
    AS (
      SELECT
        uid, value AS container
      FROM
        k8s_core_pods CROSS JOIN jsonb_array_elements(spec_containers) AS value
    )
SELECT
  uid AS resource_id,
  'Pod container privilege escalation disabled' AS title,
  context AS context,
  namespace AS namespace,
  name AS resource_name,
  CASE
  WHEN (
    SELECT
      count(*)
    FROM
      pod_containers
    WHERE
      pod_containers.uid = k8s_core_pods.uid
      AND pod_containers.container->'securityContext'->>'allowPrivilegeEscalation'
        = 'true'
  )
  > 0
  THEN 'fail'
  ELSE 'pass'
  END
    AS status
FROM
  k8s_core_pods;

Pods container hostNetwork disabled

SELECT
  uid AS resource_id,
  'Pods container hostNetwork disabled' AS title,
  context AS context,
  namespace AS namespace,
  name AS resource_name,
  CASE WHEN spec_host_network THEN 'fail' ELSE 'pass' END AS status
FROM
  k8s_core_pods;

Pod containers HostPID and HostIPC sharing disabled

SELECT
  uid AS resource_id,
  'Pod containers HostPID and HostIPC sharing disabled' AS title,
  context AS context,
  namespace AS namespace,
  name AS resource_name,
  CASE WHEN spec_host_pid OR spec_host_ipc THEN 'fail' ELSE 'pass' END AS status
FROM
  k8s_core_pods;

Pod container filesystem is read-ony

WITH
  pod_containers
    AS (
      SELECT
        uid, value AS container
      FROM
        k8s_core_pods CROSS JOIN jsonb_array_elements(spec_containers) AS value
    )
SELECT
  uid AS resource_id,
  'Pod container filesystem is read-ony' AS title,
  context AS context,
  namespace AS namespace,
  name AS resource_name,
  CASE
  WHEN (
    SELECT
      count(*)
    FROM
      pod_containers
    WHERE
      pod_containers.uid = k8s_core_pods.uid
      AND pod_containers.container->'securityContext'->>'readOnlyRootFilesystem'
        IS DISTINCT FROM 'true'
  )
  > 0
  THEN 'fail'
  ELSE 'pass'
  END
    AS status
FROM
  k8s_core_pods;

Pod container runs as non-root

WITH
  pod_containers
    AS (
      SELECT
        uid, value AS container
      FROM
        k8s_core_pods CROSS JOIN jsonb_array_elements(spec_containers) AS value
    )
SELECT
  uid AS resource_id,
  'Pod container runs as non-root' AS title,
  context AS context,
  namespace AS namespace,
  name AS resource_name,
  CASE
  WHEN (
    SELECT
      count(*)
    FROM
      pod_containers
    WHERE
      pod_containers.uid = k8s_core_pods.uid
      AND pod_containers.container->'securityContext'->>'runAsNonRoot'
        IS DISTINCT FROM 'true'
  )
  > 0
  THEN 'fail'
  ELSE 'pass'
  END
    AS status
FROM
  k8s_core_pods;

Pod service account tokens disabled

SELECT
  DISTINCT
  uid AS resource_id,
  'Pod service account tokens disabled' AS title,
  context AS context,
  namespace AS namespace,
  name AS resource_name,
  CASE
  WHEN spec_automount_service_account_token THEN 'fail'
  ELSE 'pass'
  END
    AS status
FROM
  k8s_core_pods;

Pod volume don''t have a hostPath

WITH
  pod_volumes
    AS (
      SELECT
        uid, value AS volumes
      FROM
        k8s_core_pods CROSS JOIN jsonb_array_elements(spec_volumes) AS value
    )
SELECT
  uid AS resource_id,
  e'Pod volume don\'t have a hostPath' AS title,
  context AS context,
  namespace AS namespace,
  name AS resource_name,
  CASE
  WHEN (
    SELECT
      count(*)
    FROM
      pod_volumes
    WHERE
      pod_volumes.uid = k8s_core_pods.uid
      AND (pod_volumes.volumes->>'hostPath') IS NOT NULL
  )
  > 0
  THEN 'fail'
  ELSE 'pass'
  END
    AS status
FROM
  k8s_core_pods;