Consider giving this repo a ✨! Thanks!!!
Special thanks to @khannaabhi for contributing this guide.
This app uses the following tools:
- A running K8s cluster
- Install OPA Gatekeeper by running the following commands
kubectl apply -f https://raw.githubusercontent.com/open-policy-agent/gatekeeper/release-3.8/deploy/gatekeeper.yaml
- Install Golang
- Install the Gatekeeper's constraint-template and constraint by running the following command
kubectl apply -f opa-template.yaml
kubectl apply -f opa-policy.yaml
- Create a deployment resource which violates the policy.
kubectl apply -f deployment.yaml
- The creation of deployment resource was rejected by OPA Gatekeeper as it violates the policy.
- The violation can be solved by changing the image tag from
latest
to a proper tag (eg.1.23.0
)
OPA Gatekeeper is only meant to work on the CD layer by design. However we can extend it to run on the CI layer by writing some go code using the OPA library.
To test the above functionality build & execute the go script:
go build . && ./opa-gatekeeper
- The scripts outputs the policy violations.