Skip to content

feat(deploy): CronJob manifest for scheduled in-cluster RBAC scans - #59

Merged
rrskris merged 2 commits into
kaaval:mainfrom
Maqbool61:feat/cronjob-manifest
Jul 18, 2026
Merged

rrskris merged 2 commits into
kaaval:mainfrom
Maqbool61:feat/cronjob-manifest

Conversation

@Maqbool61

Copy link
Copy Markdown
Contributor

Closes #33

What this adds

A deploy/cronjob.yaml manifest that runs the headless Kaaval CLI on a
schedule, 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.yaml

Seven Kubernetes resources in one manifest:

  • Namespace — kaaval
  • ServiceAccount — kaaval-scanner
  • ClusterRole kaaval-scanner-reader — read-only access to RBAC objects
    (roles, clusterroles, rolebindings, clusterrolebindings), matching
    the minimal role documented in docs/ci-integration.md
  • ClusterRoleBinding — binds the scanner ServiceAccount to the reader role
  • ClusterRole kaaval-policyreport-writer — write access to
    policyreports and clusterpolicyreports only
  • ClusterRoleBinding — binds the scanner ServiceAccount to the writer role
  • CronJob kaaval-rbac-scan — daily at 02:00 UTC (edit spec.schedule
    to taste), concurrencyPolicy: Forbid

Two-phase pod design — keeps the scanner image read-only and kubectl-free:

  • Init container (kaaval-scan, ghcr.io/kaaval/kaaval:latest) — scans
    in-cluster RBAC and writes PolicyReport YAML to a shared emptyDir volume
  • Main container (kubectl-apply, bitnami/kubectl:latest) — applies
    the 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 writable
emptyDir at /tmp covers Python's temporary files.

SELinux note — no host-path mounts, so no :z volume flags are needed.
The ServiceAccount token is a projected volume managed by the kubelet, which
sets the correct SELinux label automatically.

docs/ci-integration.md

New Scheduled in-cluster scans section covering:

  • Deploy with kubectl apply -f deploy/cronjob.yaml
  • One-shot trigger: kubectl create job --from=cronjob/kaaval-rbac-scan ...
  • Verification: kubectl get polr -A / kubectl get cpolr
  • Security context details and SELinux guidance
  • How to customise the schedule and add score/severity gates

Verification

Tested against a local kind cluster via make setup-dev:

kubectl apply -f deploy/cronjob.yaml
# namespace/kaaval created
# serviceaccount/kaaval-scanner created
# clusterrole.rbac.authorization.k8s.io/kaaval-scanner-reader created
# clusterrolebinding.rbac.authorization.k8s.io/kaaval-scanner-reader created
# clusterrole.rbac.authorization.k8s.io/kaaval-policyreport-writer created
# clusterrolebinding.rbac.authorization.k8s.io/kaaval-policyreport-writer created
# cronjob.batch/kaaval-rbac-scan created

kubectl create job --from=cronjob/kaaval-rbac-scan kaaval-rbac-scan-manual -n kaaval
# job.batch/kaaval-rbac-scan-manual created  →  Status: Completed

kubectl get polr -A
# NAMESPACE   NAME          PASS   FAIL   AGE
# default     kaaval-rbac   0      1      49s

kubectl get cpolr
# NAME          PASS   FAIL   AGE
# kaaval-rbac   0      26     49s

Fresh PolicyReport and ClusterPolicyReport objects appear under
source: Kaaval, with the 26 deliberately-planted RBAC misconfigurations
from the testbed correctly flagged.

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]>
@Maqbool61
Maqbool61 force-pushed the feat/cronjob-manifest branch from 541deed to 67bf9c4 Compare July 14, 2026 20:48

@rrskris rrskris left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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. 🙏

Comment thread deploy/cronjob.yaml Resolved
@Maqbool61
Maqbool61 requested a review from rrskris July 18, 2026 06:38
…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]>
@Maqbool61
Maqbool61 force-pushed the feat/cronjob-manifest branch from 20f9726 to a6b61ef Compare July 18, 2026 07:03
@Maqbool61

Copy link
Copy Markdown
Contributor Author

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. 🙏

Thanks for the thorough review — all three points addressed and tested end-to-end on a local kind cluster before pushing.

1. ghcr.io/kaaval/kaaval:latest → :edge
Fixed. Updated the init container image to ghcr.io/kaaval/kaaval:edge.

2. bitnami/kubectl:latest → rancher/kubectl:v1.31.0
Fixed. Swapped to rancher/kubectl:v1.31.0 — maintained, pinned by version tag, matches the project's posture.

3. PolicyReport CRDs prerequisite
Added a Prerequisites section to the docs/ci-integration.md scheduled scans section, with inline CRD manifests and a pointer to policy-reporter as an alternative. The kubectl apply step now clearly requires the CRDs to be present first.

Verified on kind:

kubectl apply -f deploy/cronjob.yaml
kubectl create job --from=cronjob/kaaval-rbac-scan kaaval-rbac-scan-manual -n kaaval
# Job completed in ~6s

kubectl get cpolr kaaval-rbac
# NAME          AGE
# kaaval-rbac   2m

ClusterPolicyReport created with 5 findings under source: Kaaval, contextual scores,
remediation, and CIS benchmark refs all present. kubectl get polr -A returns nothing
as expected on a fresh kind cluster (no namespaced RBAC misconfigs).

@rrskris rrskris left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@rrskris
rrskris merged commit 642b2b3 into kaaval:main Jul 18, 2026
6 checks passed
rrskris added a commit that referenced this pull request Jul 18, 2026
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]>
@Maqbool61
Maqbool61 deleted the feat/cronjob-manifest branch July 18, 2026 14:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CronJob manifest for scheduled in-cluster scans

2 participants