Skip to content

feat(queries): add ingress whitelist open-to-all detection queries#8021

Open
cx-antero-silva wants to merge 7 commits intoCheckmarx:masterfrom
cx-antero-silva:whitelist_for_ingress_queries
Open

feat(queries): add ingress whitelist open-to-all detection queries#8021
cx-antero-silva wants to merge 7 commits intoCheckmarx:masterfrom
cx-antero-silva:whitelist_for_ingress_queries

Conversation

@cx-antero-silva
Copy link
Copy Markdown
Contributor

@cx-antero-silva cx-antero-silva commented Mar 30, 2026

Reason for Proposed Changes

Security groups, Kubernetes NetworkPolicies, and nginx Ingress controllers can all be misconfigured to allow inbound traffic from any IP address. Three specific scenarios were identified as gaps in KICS coverage:

  1. K8s NetworkPolicy with no from block — an ingress rule that omits the from selector allows traffic from every source, including the public internet. This is distinct from the existing Network Policy Is Not Targeting Any Pod query.
  2. AWS Security Group ingress with a very broad but non-zero CIDR — CIDR ranges like 10.0.0.0/1 or 0.0.0.0/7 cover hundreds of millions of IP addresses yet are not caught by the existing unrestricted_security_group_ingress query which only flags exact /0 ranges.
  3. nginx Ingress whitelist-source-range explicitly set to all IPs — setting the nginx.ingress.kubernetes.io/whitelist-source-range annotation to 0.0.0.0/0 or ::/0 disables source-IP restriction entirely. This affects both raw Kubernetes manifests and Helm-rendered charts.

Proposed Changes

  • assets/queries/k8s/network_policy_ingress_not_restricted (HIGH, CWE-668)

    • Detects NetworkPolicy ingress rules with no from block (empty rule {} or rule with only ports).
    • Handles both explicit policyTypes: [Ingress] and the implicit case where policyTypes is absent.
    • Positive cases: - {}, - ports: [{protocol: TCP, port: 80}]
    • Negative cases: rules with from.ipBlock, from.podSelector, from.namespaceSelector
  • assets/queries/terraform/aws/security_group_ingress_with_wide_cidr_range (HIGH, CWE-668)

    • Detects ingress CIDR prefix lengths of /1/8 across aws_security_group, aws_vpc_security_group_ingress_rule, and aws_security_group_rule resources.
    • Excludes 0.0.0.0/0 (already covered by unrestricted_security_group_ingress) and 10.0.0.0/8 (RFC 1918 Class-A private range).
    • Positive cases: 10.0.0.0/1, 0.0.0.0/7, 128.0.0.0/1
    • Negative cases: 10.0.0.0/16, 192.168.0.0/24, 10.0.0.0/8, 0.0.0.0/0
  • assets/queries/k8s/ingress_whitelist_open_to_all (HIGH, CWE-668)

    • Detects Kubernetes Ingress resources where nginx.ingress.kubernetes.io/whitelist-source-range contains 0.0.0.0/0 or ::/0.
    • Uses contains() to also catch combined strings like "10.0.0.0/16,0.0.0.0/0".
    • Applies to both raw K8s manifests and Helm charts (KICS renders Helm templates before evaluation).
    • Positive cases: "0.0.0.0/0", "::/0", "10.0.0.0/16,0.0.0.0/0"
    • Negative cases: "10.0.0.0/16,192.168.0.0/24", "203.0.113.42/32"

Each query includes metadata.json, query.rego, positive/negative YAML or Terraform fixtures, and positive_expected_result.json.

I submit this contribution under the Apache-2.0 license.

Add three new queries targeting undetected ingress exposure scenarios
where source-IP whitelists are set to or effectively allow all addresses:

- k8s/network_policy_ingress_not_restricted (HIGH): detects NetworkPolicy
  ingress rules that omit the 'from' block, allowing traffic from every
  source IP on the network.

- terraform/aws/security_group_ingress_with_wide_cidr_range (HIGH): detects
  aws_security_group, aws_vpc_security_group_ingress_rule, and
  aws_security_group_rule resources whose ingress CIDR prefix length is
  between /1 and /8 (covering 16 M – 2 B IPs). Complements the existing
  unrestricted_security_group_ingress query (/0) without duplicating it.
  Excludes 10.0.0.0/8 (RFC 1918 Class-A private range).

- k8s/ingress_whitelist_open_to_all (HIGH): detects Kubernetes Ingress
  resources (including Helm-rendered charts) where the nginx annotation
  'nginx.ingress.kubernetes.io/whitelist-source-range' is explicitly set
  to '0.0.0.0/0' or '::/0', disabling source-IP restriction entirely.

Each query includes positive/negative test fixtures and
positive_expected_result.json.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@cx-antero-silva cx-antero-silva requested a review from a team as a code owner March 30, 2026 09:54
@cx-antero-silva cx-antero-silva self-assigned this Mar 30, 2026
cx-antero-silva and others added 6 commits March 30, 2026 10:56
…fixtures

kubernetesjsonschema.dev has an invalid SSL certificate (resolves to
netlify.app), causing kubeval to fail when fetching:
  - networkpolicy-networking-v1.json
  - ingress-networking-v1.json

Add the four new query test files to the kubeval ignore list, consistent
with the existing workaround used for hpa_targets_invalid_object.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
kubernetesjsonschema.dev has an invalid SSL certificate (the domain now
resolves to Netlify but the cert covers only *.netlify.app), causing
kubeval to hard-fail when fetching schemas for Pod, StatefulSet,
NetworkPolicy, Ingress, PodSecurityPolicy, CronJob, and other kinds.

Adding --ignore-missing-schemas tells kubeval to skip validation for
resource types whose schema cannot be retrieved, rather than exiting
with an error. This unblocks the check for all affected queries across
the repository without requiring every broken fixture to be listed in
the ignore file.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant