|
| 1 | +apiVersion: admissionregistration.k8s.io/v1 |
| 2 | +kind: ValidatingAdmissionPolicy |
| 3 | +metadata: |
| 4 | + name: "servicecidrs.default" |
| 5 | + annotations: |
| 6 | + kubernetes.io/description: >-2 |
| 7 | + A ValidatingAdmissionPolicy that restricts the IP address ranges that can be |
| 8 | + used for ClusterIP type Services. Deploying this admission policy and its |
| 9 | + associated ValidatingAdmissionPolicyBinding prevents creating (or updating) |
| 10 | + a ServiceCIDR outside the permitted ranges. |
| 11 | +spec: |
| 12 | + failurePolicy: Fail |
| 13 | + matchConstraints: |
| 14 | + resourceRules: |
| 15 | + - apiGroups: ["networking.k8s.io"] |
| 16 | + apiVersions: ["v1","v1beta1"] |
| 17 | + operations: ["CREATE", "UPDATE"] |
| 18 | + resources: ["servicecidrs"] |
| 19 | + matchConditions: |
| 20 | + - name: 'exclude-default-servicecidr' |
| 21 | + expression: "object.metadata.name != 'kubernetes'" |
| 22 | + variables: |
| 23 | + - name: allowed |
| 24 | + expression: "['10.96.0.0/16','2001:db8::/64']" |
| 25 | + validations: |
| 26 | + - expression: "object.spec.cidrs.all(currentCIDR, variables.allowed.exists(allowedCIDR, cidr(allowedCIDR).containsCIDR(currentCIDR)))" |
| 27 | +--- |
| 28 | +apiVersion: admissionregistration.k8s.io/v1 |
| 29 | +kind: ValidatingAdmissionPolicyBinding |
| 30 | +metadata: |
| 31 | + name: "servicecidrs-binding" |
| 32 | + annotations: |
| 33 | + kubernetes.io/description: >-2 |
| 34 | + A ValidatingAdmissionPolicyBinding to restricts the IP address ranges that |
| 35 | + can be used for ClusterIP type Services. Deploying this binding and its |
| 36 | + associated ValidatingAdmissionPolicy prevents creating (or updating) |
| 37 | + a ServiceCIDR that falls outside the permitted ranges. |
| 38 | +spec: |
| 39 | + policyName: "servicecidrs.default" |
| 40 | + validationActions: [Deny,Audit] |
| 41 | + |
0 commit comments