Skip to main content

Gatekeeper hello world

Context

This project goal is to explore different use cases to test gatekeeper policy behaviours.

Prerequisites

Deploying all pods from all these use cases require admin right due to restricted namespace access

use case files:

Tutorial

Use casePolicy concernedFileRequired admin rightCommandExpected results
Pod without requesting privilegeno-privileged-containernginx-not-privileged-pod.yamlNokubectl apply -f nginx-not-privileged-pod.yaml -n customer-namespacespod/nginx-not-privileged created
Pod requesting privilegeno-privileged-containernginx-privileged-pod.yamlNokubectl apply -f nginx-privileged-pod.yaml -n customer-namespacesError from server (Forbidden): error when creating "nginx-privileged-pod.yaml": admission webhook "validation.gatekeeper.sh" denied the request ...
Deploy pod from untrusted repo and restricted namespacecontainers-shall-only-use-allowed-images. Policy not installed by defaultnginx-microsoft-repo-ns-customer-namespaces.yamlNokubectl apply -f nginx-microsoft-repo-ns-client.yaml -n customer-namespacesError from server (Forbidden): error when creating "nginx-microsoft-repo-ns-customer-namespaces.yaml": admission webhook "validation.gatekeeper.sh" denied the request:...
Deploy pod from untrusted repo and unrestricted namespacecontainers-shall-only-use-allowed-imagesnginx-microsoft-repo-ns-kube-system.yamlYeskubectl apply -f nginx-microsoft-repo-ns-kube-system.yamlpod/nginx-from-microsoft-repo created
Deploy pod from trusted repo and restricted namespacecontainers-shall-only-use-allowed-imagesnginx-artifactory-repo-ns-customer-namespaces.yamlNokubectl apply -f nginx-artifactory-repo-ns-client.yaml -n customer-namespacespod/nginx-from-artifactory-repo created
Deploy pod from trusted repo and unrestricted namespacecontainers-shall-only-use-allowed-images. Policy not installed by defaultnginx-artifactory-repo-ns-kube-system.yamlYeskubectl apply -f nginx-artifactory-repo-ns-kube-system.yamlpod/nginx-from-artifactory-repo created

Remove your test

kubectl delete pod nginx-not-privileged-pod -n customer-namespaces
kubectl delete pod nginx-privileged-pod -n customer-namespaces
kubectl delete pod nginx-microsoft-repo-ns-client -n customer-namespaces
kubectl delete pod nginx-microsoft-repo-ns-kube-system -n kube-system
kubectl delete pod nginx-artifactory-repo-ns-client -n customer-namespaces
kubectl delete pod nginx-artifactory-repo-ns-kube-system -n kube-system