Integrating Cluster Scanning into CI/CD
Integrating Cluster Scanning into CI/CD
Implement pre-deployment cluster security checks:
# GitLab CI/CD with Kubernetes scanning
stages:
- build
- scan
- deploy
variables:
KUBE_NAMESPACE: production
IMAGE_TAG: $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA
security-scan:
stage: scan
image: aquasec/trivy:latest
script:
# Scan container image
- trivy image --exit-code 1 --severity CRITICAL,HIGH $IMAGE_TAG
# Scan Kubernetes manifests
- trivy config --exit-code 1 ./k8s/
# Check cluster security posture
- |
kubectl apply --dry-run=client -f ./k8s/ -o json | \
trivy config --input - --exit-code 1
cluster-compliance:
stage: scan
image: snyk/snyk:docker
script:
# Scan Kubernetes manifests with Snyk
- snyk iac test ./k8s/ --severity-threshold=high
# Test deployed resources
- snyk iac test --remote --target-name=$KUBE_NAMESPACE
# Monitor cluster state
- snyk iac monitor --remote --target-name=$KUBE_NAMESPACE