← Policy catalog
</> ValidatingAdmissionPolicy · Apache-2.0

Permits Egress to 0.0.0.0/0

egressnetworkpolicy-allow-all

severityModerate resourceEgressNetworkPolicies productOpenShift bundles1

An Allow entry for 0.0.0.0/0 makes the namespace OpenShift SDN egress firewall permit every pod in it to reach any off-cluster address, so a compromised workload can stage tooling and exfiltrate data freely.

Rejects unless

!object.spec.?egress.orValue([]).exists(e,
  e.?type.orValue('') == 'Allow' &&
  e.?to.cidrSelector.orValue('') == '0.0.0.0/0'
)

OpenShift EgressNetworkPolicies must not Allow egress to 0.0.0.0/0.

Remediation

Replace 0.0.0.0/0 with the specific destination CIDRs the namespace needs and keep a trailing Deny rule for everything else. Field: spec.egress[*].to.cidrSelector.

Applies to

  • egressnetworkpolicies · network.openshift.io/v1 · CREATE, UPDATE

Manifest

apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingAdmissionPolicy
metadata:
  name: egressnetworkpolicy-allow-all
  annotations:
    kubeapt.io/uuid: "3da7d46e-f1bb-49aa-8257-8986598e88a9"
    security.kubeapt.io/displayName: "Permits Egress to 0.0.0.0/0"
    security.kubeapt.io/description: "An Allow entry for 0.0.0.0/0 makes the namespace OpenShift SDN egress firewall permit every pod in it to reach any off-cluster address, so a compromised workload can stage tooling and exfiltrate data freely."
    security.kubeapt.io/resource: "EgressNetworkPolicies"
    security.kubeapt.io/severity: "Moderate"
    security.kubeapt.io/remediation: "Replace 0.0.0.0/0 with the specific destination CIDRs the namespace needs and keep a trailing Deny rule for everything else. Field: spec.egress[*].to.cidrSelector."
    security.kubeapt.io/product: "OpenShift"
spec:
  failurePolicy: Fail
  matchConstraints:
    resourceRules:
    - apiGroups:
      - network.openshift.io
      apiVersions:
      - v1
      operations:
      - CREATE
      - UPDATE
      resources:
      - egressnetworkpolicies
  validations:
  - expression: |
      !object.spec.?egress.orValue([]).exists(e,
        e.?type.orValue('') == 'Allow' &&
        e.?to.cidrSelector.orValue('') == '0.0.0.0/0'
      )
    message: |
      OpenShift EgressNetworkPolicies must not Allow egress to 0.0.0.0/0.

Save it as egressnetworkpolicy-allow-all.yaml — the commands below assume that name.

Validate with kubeapt

Check a workload against this one policy, before anything is installed on a cluster.

$ kubeapt validate -p ./egressnetworkpolicy-allow-all.yaml -r ./workload.yaml

Or without the file, from the published policy set — -r takes a directory too:

$ kubeapt policies download && kubeapt validate --policy-name egressnetworkpolicy-allow-all -r ./manifests

Or against every namespace in the cluster your kubeconfig points at:

$ kubeapt validate --policy-name egressnetworkpolicy-allow-all -A