Admission Controller
Spotter can be deployed as a Kubernetes admission controller to provide real-time security policy enforcement. This deployment mode validates resources at admission time, preventing insecure configurations from being deployed to your cluster.
Prerequisites
Section titled “Prerequisites”- Docker
- kind
- kubectl
One-Command Setup
Section titled “One-Command Setup”# Complete setup scriptbash -c 'set -eecho "🚀 Setting up Spotter admission controller..."
# Create kind clusterecho "📦 Creating kind cluster..."kind create cluster --name spotter-test
# Build and load imageecho "🔨 Building and loading image..."docker build --target admission -t spotter:latest .docker save spotter:latest | kind load image-archive --name spotter-test /dev/stdin
# Generate certificates and deployecho "🔐 Deploying admission controller..."cd deployments/admission-controller./generate-local-certs.shkubectl apply -f local-deployment.yamlkubectl apply -f local-webhook.yaml
# Wait for readyecho "⏳ Waiting for ready..."kubectl wait --for=condition=ready pod -l app=spotter-admission-controller -n spotter-system --timeout=15s
echo "✅ Setup complete! Run tests below."'
Quick Testing
Section titled “Quick Testing”1. Create test namespace
Section titled “1. Create test namespace”kubectl create namespace test-spotter
2. Test secure pod (should succeed)
Section titled “2. Test secure pod (should succeed)”kubectl apply -f - <<EOFapiVersion: v1kind: Podmetadata: name: secure-pod namespace: test-spotterspec: containers: - name: nginx image: nginx:1.20@sha256:10f14ffa93f8dedf1057897b745e5ac72ac5655c299dade0aa434c71557697ea securityContext: runAsNonRoot: true runAsUser: 1000 allowPrivilegeEscalation: false readOnlyRootFilesystem: true capabilities: drop: ["ALL"] seccompProfile: type: RuntimeDefault resources: requests: memory: "64Mi" cpu: "250m" limits: memory: "128Mi" cpu: "500m" securityContext: runAsNonRoot: true runAsUser: 1000EOF
3. Test privileged pod (should be rejected)
Section titled “3. Test privileged pod (should be rejected)”kubectl apply -f - <<EOFapiVersion: v1kind: Podmetadata: name: privileged-pod namespace: test-spotterspec: containers: - name: nginx image: nginx:latest securityContext: privileged: true runAsUser: 0EOF
4. Check results
Section titled “4. Check results”# Check podskubectl get pods -n test-spotter
# Check logs for violationskubectl logs -l app=spotter-admission-controller -n spotter-system --tail=20
# Check events for rejectionskubectl get events -n test-spotter --sort-by='.lastTimestamp'
Expected Results
Section titled “Expected Results”Secure pod: ✅ Created successfully
Privileged pod: ❌ Rejected with security violations
Log output shows:
level=INFO msg="Resource passed security evaluation" kind=Pod name=secure-podlevel=ERROR msg="Security violations detected" kind=Pod name=privileged-pod total_violations=15 critical=3
Manual Setup Steps (if needed)
Section titled “Manual Setup Steps (if needed)”1. Create cluster
Section titled “1. Create cluster”kind create cluster --name spotter-test
2. Build image
Section titled “2. Build image”docker build -f Dockerfile.admission -t spotter:latest .docker save spotter:latest | kind load image-archive --name spotter-test /dev/stdin
3. Deploy
Section titled “3. Deploy”cd deployments/admission-controller./generate-local-certs.shkubectl apply -f local-deployment.yamlkubectl apply -f local-webhook.yaml
4. Verify
Section titled “4. Verify”kubectl wait --for=condition=ready pod -l app=spotter-admission-controller -n spotter-system --timeout=60skubectl logs -l app=spotter-admission-controller -n spotter-system
All-in-One Test Script
Section titled “All-in-One Test Script”Save as test-spotter.sh
and run with bash test-spotter.sh
:
#!/bin/bashset -e
echo "🧪 Testing Spotter admission controller..."
# Test namespacekubectl create namespace test-spotter --dry-run=client -o yaml | kubectl apply -f -
# Test 1: Secure pod (should pass)echo "✅ Testing secure pod..."kubectl apply -f - <<EOFapiVersion: v1kind: Podmetadata: name: secure-pod namespace: test-spotterspec: containers: - name: nginx image: nginx:1.20@sha256:10f14ffa93f8dedf1057897b745e5ac72ac5655c299dade0aa434c71557697ea securityContext: runAsNonRoot: true runAsUser: 1000 allowPrivilegeEscalation: false capabilities: drop: ["ALL"]EOF
# Test 2: Privileged pod (should fail)echo "❌ Testing privileged pod..."kubectl apply -f - <<EOF || echo "Pod correctly rejected by admission controller"apiVersion: v1kind: Podmetadata: name: privileged-pod namespace: test-spotterspec: containers: - name: nginx image: nginx:latest securityContext: privileged: true runAsUser: 0EOF
echo ""echo "📊 Results:"kubectl get pods -n test-spotterecho ""echo "🔍 Recent logs:"kubectl logs -l app=spotter-admission-controller -n spotter-system --tail=10
Monitoring
Section titled “Monitoring”# Check statuskubectl get pods -n spotter-system
# View logskubectl logs -f -l app=spotter-admission-controller -n spotter-system
# Check webhook configkubectl get validatingadmissionwebhook spotter-validating-webhook
# Health checkkubectl exec -n spotter-system deployment/spotter-admission-controller -- wget -qO- http://localhost:8080/health
Troubleshooting
Section titled “Troubleshooting”Pod not starting:
kubectl describe pod -n spotter-system -l app=spotter-admission-controller
Image not found:
docker save spotter:latest | kind load image-archive --name spotter-test /dev/stdin
Certificate issues:
cd deployments/admission-controller && ./generate-local-certs.shkubectl apply -f local-webhook.yaml
Webhook not working:
kubectl logs -l app=spotter-admission-controller -n spotter-system | grep "admission request"
Cleanup
Section titled “Cleanup”kubectl delete namespace test-spotterkubectl delete -f local-webhook.yaml -f local-deployment.yamlkind delete cluster --name spotter-test
Key Features
Section titled “Key Features”- 140+ security rules loaded automatically
- Validates: pods, deployments, services, jobs, etc.
- Excludes: system namespaces (kube-system, etc.)
- Mode: CREATE operations only (not updates)
- Logging: Severity-based summaries with violation details
- Failure policy: Ignore (lenient for testing)
This guide provides everything needed to test the Spotter admission controller locally with kind cluster in a straightforward manner.
For more deployment examples and advanced configurations, check the Spotter GitHub repository.