This project demonstrates how to implement automated policy enforcement in Kubernetes clusters using Open Policy Agent (OPA) and Gatekeeper.
This project implements security best practices in Kubernetes by:
- Preventing privileged containers
- Enforcing resource limits
- Restricting container capabilities
- Implementing network policies
- Generating compliance reports
- Kubernetes cluster (v1.19+)
- kubectl configured
- Helm v3.x
- OPA Gatekeeper v3.x
.
├── README.md
├── policies/ # OPA Rego policies
│ ├── privileged-containers.rego
│ ├── resource-limits.rego
│ └── container-capabilities.rego
├── manifests/ # Kubernetes manifests
│ ├── gatekeeper/ # Gatekeeper installation
│ ├── constraints/ # Constraint templates
│ └── constraint-bindings/ # Constraint bindings
└── monitoring/ # Monitoring and reporting
└── dashboard/ # Grafana dashboard
- Install OPA Gatekeeper:
kubectl apply -f manifests/gatekeeper/
- Apply constraint templates:
kubectl apply -f manifests/constraints/
- Apply constraint bindings:
kubectl apply -f manifests/constraint-bindings/
The project implements the following policies:
- Privileged Containers: Prevents deployment of privileged containers
- Resource Limits: Enforces CPU and memory limits on all containers
- Container Capabilities: Restricts container capabilities to a minimal set
- Network Policies: Implements default deny network policies
The project includes a Grafana dashboard for monitoring policy violations and compliance status.
- Deploy the policies:
kubectl apply -f manifests/
- Monitor violations:
kubectl get constrainttemplates
kubectl get constraints
- View violation reports:
kubectl get constraintviolations
Feel free to submit issues and enhancement requests!
This project is licensed under the MIT License - see the LICENSE file for details.