Skip to content

Instantly share code, notes, and snippets.

@squeed
Created June 18, 2024 11:51
Show Gist options
  • Save squeed/54763c7b21e6ce107913fb279239ad30 to your computer and use it in GitHub Desktop.
Save squeed/54763c7b21e6ce107913fb279239ad30 to your computer and use it in GitHub Desktop.
CEL: require default-allow policies
apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingAdmissionPolicy
metadata:
name: "only-allow-ccnp-default-allow"
spec:
failurePolicy: Fail
matchConstraints:
resourceRules:
- apiGroups: ["cilium.io"]
apiVersions: ["v2"]
resources: ["ciliumclusterwidenetworkpolicies"]
operations: ["CREATE", "UPDATE"]
validations:
- expression: >-
!( has(object.spec.ingress) || has(object.spec.ingressDeny) ) ||
( has(object.spec.enableDefaultDeny.ingress) && object.spec.enableDefaultDeny.ingress == false)
message: "CCNPs must explicitly disallow ingress default-deny"
- expression: >-
!( has(object.spec.egress) || has(object.spec.egressDeny) ) ||
( has(object.spec.enableDefaultDeny.egress) && object.spec.enableDefaultDeny.egress == false)
message: "CCNPs must explicitly disallow egress default-deny"
---
apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingAdmissionPolicyBinding
metadata:
name: "only-allow-ccnp-default-allow"
spec:
policyName: "only-allow-ccnp-default-allow"
validationActions: [Deny]
matchResources:
resourceRules:
- apiGroups: ["cilium.io"]
apiVersions: ["v2"]
resources: ["ciliumclusterwidenetworkpolicies"]
operations: ["CREATE", "UPDATE"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment