Usecase of security checks against Kubernetes resources by Kyverno.
- Install KinD and Kyverno 1.10
- (Optional) Create OSCAL Component Defintion
- Generate Kyverno Policy (C2P Compliance to Policy)
E.g.
python samples_public/kyverno/compliance_to_policy.py -o /tmp/deliverable-policy
$ python samples_public/kyverno/compliance_to_policy.py -o /tmp/deliverable-policy tree /tmp/deliverable-policy disallow-capabilities - disallow-capabilities.yaml allowed-base-images - 02-setup-cm.yaml - allowed-base-images.yaml
- Deploy the generated policies
E.g.
kubectl apply -R -f /tmp/deliverable-policy
$ kubectl apply -R -f /tmp/deliverable-policy namespace/platform created configmap/baseimages created Warning: Validation failure actions enforce/audit are deprecated, use Enforce/Audit instead. clusterpolicy.kyverno.io/allowed-base-images created clusterpolicy.kyverno.io/disallow-capabilities created
- Check policy results
$ kubectl get policyreport,clusterpolicyreport -A NAMESPACE NAME PASS FAIL WARN ERROR SKIP AGE kube-system policyreport.wgpolicyk8s.io/cpol-allowed-base-images 0 12 0 0 0 19s kube-system policyreport.wgpolicyk8s.io/cpol-disallow-capabilities 9 2 0 0 0 19s kyverno policyreport.wgpolicyk8s.io/cpol-allowed-base-images 0 18 0 0 0 9s kyverno policyreport.wgpolicyk8s.io/cpol-disallow-capabilities 18 0 0 0 0 9s local-path-storage policyreport.wgpolicyk8s.io/cpol-allowed-base-images 0 3 0 0 0 16s local-path-storage policyreport.wgpolicyk8s.io/cpol-disallow-capabilities 3 0 0 0 0 16s
- Collect policy/cluster policy reports as PVP Raw results
kubectl get policyreport -A -o yaml > /tmp/policyreports.wgpolicyk8s.io.yaml kubectl get clusterpolicyreport -o yaml > /tmp/clusterpolicyreports.wgpolicyk8s.io.yaml
- Generate Assessment Result (C2P Result to Compliance)
python samples_public/kyverno/result_to_compliance.py \ -polr /tmp/policyreports.wgpolicyk8s.io.yaml \ -cpolr /tmp/clusterpolicyreports.wgpolicyk8s.io.yaml \ > /tmp/assessment_results.json
- OSCAL Assessment Results is not human readable format. You can see the merged report in markdown by a quick viewer.
e.g. result.md
c2p tools viewer \ -cdef ./plugins_public/tests/data/kyverno/component-definition.json \ -ar /tmp/assessment_results.json