Skip to content

Instantly share code, notes, and snippets.

@xximjasonxx
Created September 16, 2022 15:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xximjasonxx/e8c5fbffb76d480b8aab4fd3b8e96198 to your computer and use it in GitHub Desktop.
Save xximjasonxx/e8c5fbffb76d480b8aab4fd3b8e96198 to your computer and use it in GitHub Desktop.
apiVersion: templates.gatekeeper.sh/v1beta1
kind: ConstraintTemplate
metadata:
name: k8srestricttype
spec:
crd:
spec:
names:
kind: K8sRestrictType
validation:
openAPIV3Schema:
properties:
namespace:
type: string
targets:
- target: admission.k8s.gatekeeper.sh
rego: |
package k8srestrictype
violation[{ "msg": msg }] {
object := input.review.object
object.metadata.namespace == input.parameters.namespace
msg := sprintf("%v is not allowed for creation in namespace %v", [input.review.kind.kind, input.parameters.namespace])
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment