← Policy catalog
</> ValidatingAdmissionPolicy · Apache-2.0

Permits Egress to Any Destination (Calico)

networkpolicy-calico-egress-cidr

severityModerate resourceNetworkPolicies productCalico bundles1

An Allow to 0.0.0.0/0 or ::/0 gives the selected endpoints unrestricted outbound reach, the channel a compromised workload uses to contact command-and-control hosts, pull further tooling and exfiltrate data.

Rejects unless

!object.spec.?egress.orValue([]).exists(r,
  r.?action.orValue('') == 'Allow' &&
  r.?destination.nets.orValue([]).exists(n, n == '0.0.0.0/0' || n == '::/0')
)

Calico NetworkPolicies must not Allow egress to 0.0.0.0/0 or ::/0.

Remediation

Replace 0.0.0.0/0 and ::/0 in Allow egress rules with the specific destination CIDRs the selected endpoints actually need. Field: spec.egress[*].destination.nets.

Applies to

  • networkpolicies · crd.projectcalico.org/v1 · CREATE, UPDATE

Manifest

apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingAdmissionPolicy
metadata:
  name: networkpolicy-calico-egress-cidr
  annotations:
    kubeapt.io/uuid: "35df4c68-7c63-4650-8fd2-abd7c1a3cc36"
    security.kubeapt.io/displayName: "Permits Egress to Any Destination (Calico)"
    security.kubeapt.io/description: "An Allow to 0.0.0.0/0 or ::/0 gives the selected endpoints unrestricted outbound reach, the channel a compromised workload uses to contact command-and-control hosts, pull further tooling and exfiltrate data."
    security.kubeapt.io/resource: "NetworkPolicies"
    security.kubeapt.io/severity: "Moderate"
    security.kubeapt.io/remediation: "Replace 0.0.0.0/0 and ::/0 in Allow egress rules with the specific destination CIDRs the selected endpoints actually need. Field: spec.egress[*].destination.nets."
    security.kubeapt.io/product: "Calico"
spec:
  failurePolicy: Fail
  matchConstraints:
    resourceRules:
    - apiGroups:
      - crd.projectcalico.org
      apiVersions:
      - v1
      operations:
      - CREATE
      - UPDATE
      resources:
      - networkpolicies
  validations:
  - expression: |
      !object.spec.?egress.orValue([]).exists(r,
        r.?action.orValue('') == 'Allow' &&
        r.?destination.nets.orValue([]).exists(n, n == '0.0.0.0/0' || n == '::/0')
      )
    message: |
      Calico NetworkPolicies must not Allow egress to 0.0.0.0/0 or ::/0.

Save it as networkpolicy-calico-egress-cidr.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 ./networkpolicy-calico-egress-cidr.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 networkpolicy-calico-egress-cidr -r ./manifests

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

$ kubeapt validate --policy-name networkpolicy-calico-egress-cidr -A