Skip to content

Instantly share code, notes, and snippets.

@aceat64
Created July 14, 2023 01:31
Show Gist options
  • Save aceat64/f34823ffd654d7594e7a34b7987ecdd8 to your computer and use it in GitHub Desktop.
Save aceat64/f34823ffd654d7594e7a34b7987ecdd8 to your computer and use it in GitHub Desktop.
ValidatingAdmissionPolicy to prevent use of :latest or :edge container images
apiVersion: admissionregistration.k8s.io/v1alpha1
kind: ValidatingAdmissionPolicy
metadata:
name: "reject-lastest-and-edge"
spec:
failurePolicy: Fail
matchConstraints:
resourceRules:
- apiGroups: ["apps"]
apiVersions: ["v1"]
operations: ["CREATE", "UPDATE"]
resources: ["deployments"]
- apiGroups: ["batch"]
apiVersions: ["v1"]
operations: ["CREATE", "UPDATE"]
resources: ["jobs"]
validations:
- expression: "object.spec.template.spec.containers.all(c, !c.image.endsWith(':edge'))"
message: "containers images can not be :latest tag"
- expression: "object.spec.template.spec.containers.all(c, !c.image.endsWith(':edge'))"
message: "containers images can not be :edge tag"
---
apiVersion: admissionregistration.k8s.io/v1alpha1
kind: ValidatingAdmissionPolicyBinding
metadata:
name: "reject-lastest-and-edge-binding"
spec:
policyName: "reject-lastest-and-edge"
matchResources:
namespaceSelector: {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment