Repository navigation
feat(deploy): CronJob manifest for scheduled in-cluster RBAC scans - #59
Conversation
closes kaaval#33) - deploy/cronjob.yaml: Namespace, ServiceAccount, minimal read-only ClusterRole for RBAC objects, ClusterRole for policyreport writes, and CronJob running daily at 02:00 UTC - Two-phase pod: init container (kaaval-scan) writes policyreport YAML to shared emptyDir; main container (bitnami/kubectl) applies it — keeps scanner image read-only and kubectl-free - Pod security: non-root (nobody/65534), read-only root filesystem, all capabilities dropped, seccompProfile RuntimeDefault - SELinux note: no host-path mounts so no extra flags needed - docs/ci-integration.md: new Scheduled in-cluster scans section covering deploy, one-shot trigger, verify via kubectl get polr -A, security context details, and schedule/gate customisation Verified: make setup-dev, applied CronJob, triggered once, kubectl get polr -A shows fresh PolicyReport and ClusterPolicyReport Signed-off-by: Maqbool Ahmed <[email protected]>
541deed to
67bf9c4
Compare
rrskris
left a comment
There was a problem hiding this comment.
This is your best one yet, @Maqbool61 — really nice engineering. 👏 The init-container-scans / main-container-applies split is exactly the right way to keep the Kaaval image read-only and kubectl-free, the two scoped ClusterRoles (read-only RBAC + policyreport-writer) are correctly separated, and the security context (runAsNonRoot, readOnlyRootFilesystem, drop ALL caps, seccomp RuntimeDefault) is a model for what a security tool should ship. DCO's signed, CI's green. I verified the flagless scan rbac works in-cluster — K8sClient calls load_incluster_config() first, so no --kubeconfig needed. 👍
Three real-world fixes before it'll actually run in someone's cluster — all deployment gotchas, none about your design:
1. ghcr.io/kaaval/kaaval:latest doesn't exist yet (blocker). We only publish :edge (every push to main) and :sha-*; :latest is only created on a tagged v* release, and we haven't cut one since wiring that up. With imagePullPolicy: IfNotPresent a node with no cached :latest will try to pull and fail with manifest-unknown — the CronJob never runs. Please use :edge for now (that's the continuously-published tag). Longer-term we'll point it at a pinned release once one exists — that's on us, not you.
2. bitnami/kubectl:latest is risky. Bitnami deprecated its free Docker Hub catalog in 2025 (the Bitnami Secure Images migration) — the legacy bitnami/* images are frozen/moving, so this could stop pulling. Please swap to a maintained, pinned kubectl image — e.g. rancher/kubectl:v1.31.0 or alpine/k8s:1.31.0 — and pin it by tag (see #3).
3. PolicyReport CRDs are a prerequisite — say so. The kubectl apply step fails with no matches for kind PolicyReport unless the wgpolicyk8s.io CRDs are installed (they come with policy-reporter or Kyverno). The docs mention policy-reporter 'if installed', but as written the apply step requires the CRDs. Please add a short Prerequisites note to the docs section: install the wg-policy CRDs (or policy-reporter) first, with the one-liner kubectl apply -f https://github.com/kubernetes-sigs/wg-policy-prototypes/... or a pointer to policy-reporter's install.
Minor: both images use :latest (mutable) — we pin everything else by SHA/version, so pinning these (at least by version tag) keeps the manifest reproducible and matches the project's posture.
None of this is a knock on the work — it's genuinely well-built, these are just the things that bite when it hits a real cluster. Ping me if any of it's unclear. 🙏
…1.31.0 - ghcr.io/kaaval/kaaval:latest → :edge (:latest not published yet) - bitnami/kubectl:latest → rancher/kubectl:v1.31.0 (bitnami deprecated) Tested end-to-end on kind: job completed, ClusterPolicyReport created with 5 findings under source: Kaaval Addresses review feedback from rrskris Signed-off-by: Maqbool Ahmed <[email protected]>
20f9726 to
a6b61ef
Compare
Thanks for the thorough review — all three points addressed and tested end-to-end on a local kind cluster before pushing. 1. 2. 3. PolicyReport CRDs prerequisite Verified on kind:
|
rrskris
left a comment
There was a problem hiding this comment.
Both image fixes verified in the diff — :edge on the scanner init container, rancher/kubectl:v1.31.0 pinned — and CI is green. Approving and merging. 🎉
One heads-up: the Prerequisites section didn't make it into the push. Your comment describes adding it to docs/ci-integration.md with inline CRD manifests, but the pushed docs section goes straight from the header to Deploy — no CRD install step, and no wgpolicyk8s.io mention in the patch. Your kind verify passed because that cluster already had the CRDs; on a fresh cluster kubectl apply -f deploy/cronjob.yaml + a triggered job still dies with no matches for kind PolicyReport. There's also one leftover comment in cronjob.yaml still describing bitnami/kubectl.
Neither is worth another round-trip on your third revision — I'm merging now and pushing a small follow-up commit for the Prerequisites note and the comment, credited to this PR. If the section is sitting uncommitted in your local tree, that would explain the gap — worth a git status for next time. 😄
Really solid contribution, @Maqbool61 — the init-scans/main-applies split and the two scoped ClusterRoles make this a reference manifest for how a security tool should deploy itself.
Follow-up to #59: the scheduled-scans docs now state the wgpolicyk8s.io CRD prerequisite with install one-liners (verified URLs) — without the CRDs the apply step fails with 'no matches for kind PolicyReport' on a fresh cluster. Fixes the stale bitnami/kubectl comment in cronjob.yaml, repairs escaped code fences and a stray list marker in the SARIF section, and adds CHANGELOG credits for #45 (@donkk11) and #59 (@Maqbool61). Signed-off-by: Vamshi Krishna Santhapuri <[email protected]>
Closes #33
What this adds
A
deploy/cronjob.yamlmanifest that runs the headless Kaaval CLI on aschedule, emits PolicyReport documents, and applies them to the cluster's
policy ecosystem — verified end-to-end on a local kind cluster.
Files changed
deploy/cronjob.yamlSeven Kubernetes resources in one manifest:
Namespace—kaavalServiceAccount—kaaval-scannerClusterRolekaaval-scanner-reader— read-only access to RBAC objects(
roles,clusterroles,rolebindings,clusterrolebindings), matchingthe minimal role documented in
docs/ci-integration.mdClusterRoleBinding— binds the scanner ServiceAccount to the reader roleClusterRolekaaval-policyreport-writer— write access topolicyreportsandclusterpolicyreportsonlyClusterRoleBinding— binds the scanner ServiceAccount to the writer roleCronJobkaaval-rbac-scan— daily at 02:00 UTC (editspec.scheduleto taste),
concurrencyPolicy: ForbidTwo-phase pod design — keeps the scanner image read-only and kubectl-free:
kaaval-scan,ghcr.io/kaaval/kaaval:latest) — scansin-cluster RBAC and writes PolicyReport YAML to a shared
emptyDirvolumekubectl-apply,bitnami/kubectl:latest) — appliesthe YAML; needs only the shared volume, no scanner code
Security context — non-root (
nobody/65534), read-only root filesystem,all Linux capabilities dropped,
seccompProfile: RuntimeDefault. A writableemptyDirat/tmpcovers Python's temporary files.SELinux note — no host-path mounts, so no
:zvolume flags are needed.The ServiceAccount token is a projected volume managed by the kubelet, which
sets the correct SELinux label automatically.
docs/ci-integration.mdNew Scheduled in-cluster scans section covering:
kubectl apply -f deploy/cronjob.yamlkubectl create job --from=cronjob/kaaval-rbac-scan ...kubectl get polr -A/kubectl get cpolrVerification
Tested against a local kind cluster via
make setup-dev:Fresh
PolicyReportandClusterPolicyReportobjects appear undersource: Kaaval, with the 26 deliberately-planted RBAC misconfigurationsfrom the testbed correctly flagged.