egressnetworkpolicy-allow-all
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.
!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.
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.
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.
Check a workload against this one policy, before anything is installed on a cluster.
$ kubeapt validate -p ./egressnetworkpolicy-allow-all.yaml -r ./workload.yamlOr without the file, from the published policy set — -r takes a directory too:
$ kubeapt policies download && kubeapt validate --policy-name egressnetworkpolicy-allow-all -r ./manifestsOr against every namespace in the cluster your kubeconfig points at:
$ kubeapt validate --policy-name egressnetworkpolicy-allow-all -A