-
-
Save jkroepke/e75b403388389bed6913fb1bc6927ed7 to your computer and use it in GitHub Desktop.
Kubernetes ValidatingAdmissionPolicy to deny short namespaces.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| --- | |
| apiVersion: admissionregistration.k8s.io/v1 | |
| kind: ValidatingAdmissionPolicy | |
| metadata: | |
| name: deny-short-namespace-names | |
| spec: | |
| failurePolicy: Deny # Deny the request if the validation fails | |
| matchConstraints: | |
| resourceRules: | |
| - apiGroups: [""] # "" represents the core API group for Namespaces | |
| apiVersions: ["v1"] | |
| operations: ["CREATE"] # Only apply this policy during creation | |
| resources: ["namespaces"] | |
| validations: | |
| - expression: "object.metadata.name.length() >= 4" | |
| message: "Namespace names must be at least 4 characters long." | |
| --- | |
| apiVersion: admissionregistration.k8s.io/v1 | |
| kind: ValidatingAdmissionPolicyBinding | |
| metadata: | |
| name: deny-short-namespace-names-binding | |
| spec: | |
| policyName: deny-short-namespace-names | |
| validationActions: [Deny] # Ensure the policy actually denies the request | |
| matchResources: |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment