Table: k8s_networking_network_policies

This table shows data for Kubernetes (K8s) Networking Network Policies.

The primary key for this table is uid.

Columns

NameType
_cq_iduuid
_cq_parent_iduuid
contextutf8
kindutf8
api_versionutf8
nameutf8
namespaceutf8
uid (PK)utf8
resource_versionutf8
generationint64
deletion_grace_period_secondsint64
labelsjson
annotationsjson
owner_referencesjson
finalizerslist<item: utf8, nullable>
spec_pod_selectorjson
spec_ingressjson
spec_egressjson
spec_policy_typeslist<item: utf8, nullable>
status_conditionsjson

Example Queries

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

Network policy default deny egress

SELECT
  uid AS resource_id,
  'Network policy default deny egress' AS title,
  context AS context,
  name AS namespace,
  name AS resource_name,
  CASE
  WHEN (
    SELECT
      count(*)
    FROM
      k8s_networking_network_policies
    WHERE
      namespace = k8s_core_namespaces.name
      AND context = k8s_core_namespaces.context
      AND spec_policy_types @> ARRAY['Egress']
      AND spec_pod_selector::STRING = '{}'
      AND ((spec_egress IS NULL) OR jsonb_array_length(spec_egress) = 0)
  )
  = 0
  THEN 'fail'
  ELSE 'pass'
  END
    AS status
FROM
  k8s_core_namespaces;

Network policy default deny ingress

SELECT
  uid AS resource_id,
  'Network policy default deny ingress' AS title,
  context AS context,
  name AS namespace,
  name AS resource_name,
  CASE
  WHEN (
    SELECT
      count(*)
    FROM
      k8s_networking_network_policies
    WHERE
      namespace = k8s_core_namespaces.name
      AND context = k8s_core_namespaces.context
      AND spec_policy_types @> ARRAY['Ingress']
      AND spec_pod_selector::STRING = '{}'
      AND ((spec_ingress IS NULL) OR jsonb_array_length(spec_ingress) = 0)
  )
  = 0
  THEN 'fail'
  ELSE 'pass'
  END
    AS status
FROM
  k8s_core_namespaces;