Skip to content

Fix #30: friendly error (exit 2) when --manifests path is missing or unreadable - #45

Merged
rrskris merged 1 commit into
kaaval:mainfrom
donkk11:fix/manifests-unreadable-error
Jul 18, 2026
Merged

rrskris merged 1 commit into
kaaval:mainfrom
donkk11:fix/manifests-unreadable-error

Conversation

@donkk11

@donkk11 donkk11 commented Jul 12, 2026

Copy link
Copy Markdown
Contributor

Hi! Some honest context first: I'm not a developer by trade — I'm building an evidence-gated verification benchmark ("the Nkama way": AI work has to produce a re-runnable manifest of checks, and "blocked evidence is not success"). I came across kaaval, ran issue #30 through that workflow to see if it could genuinely help, and this is what came out — AI-assisted, then independently cross-checked by a second model. Please review critically; if it's not a fit, no hard feelings closing it.

The fix. When --manifests points at a missing or unreadable path, build_graph_from_manifests() now emits a one-line error and exits 2 instead of surfacing a raw PermissionError/traceback — matching the format in the issue:

error: cannot read manifests path '/scan': permission denied
hint: on SELinux hosts, mount volumes with ':z' — e.g. -v "$PWD/k8s:/scan:z"

One non-obvious gotcha worth calling out for a security scanner. Wrapping root.exists() alone is insufficient: on a genuinely unreadable directory, Path.rglob() swallows the EACCES during traversal, so _iter_manifest_docs() yields nothing and the CLI exits 0 with a false clean scan. For a CI gate, that's the dangerous failure mode — a pipeline passing because it scanned nothing. So the fix adds an explicit readability probe (os.listdir on a dir, open on a file) before scanning, and keeps the existing streaming iteration (no eager list() materialization).

Tests. Adds tests/test_cli_manifests_errors.py — 3 cases exercising the real conditions (missing path, chmod 000 dir, chmod 000 file), not monkeypatched errors, with skipif(root) guards. Full CLI suite green (12/12). Unrelated: test_login_and_self_scan (needs a live DB) also fails on a clean checkout — untouched here.

Diff is small: control-plane/app/cli.py (+readability probe) and the new test. Thanks for building kaaval — the contextual-risk-score idea is genuinely nice. Happy to adjust naming, message wording, or test placement to match your style.

@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 exactly the kind of error handling we want, @donkk11 — genuinely nice work. 👏

You didn't just print a friendlier message; you caught the subtle trap that Path.rglob() silently swallows EACCES during traversal, which would let an unreadable path masquerade as a clean (exit 0) scan. Probing readability explicitly with os.listdir/open is the correct fix, and the error message hits all three things a good error should — what's wrong, and the exact :z command to fix it. The tests exercising real chmod 000 conditions (with sensible skips for root / perm-less filesystems) are the right call over monkeypatching. Closes #30 cleanly.

One thing before I can merge: CI is green except DCO — your commits need a sign-off. Just run git rebase --signoff main (or git commit --amend -s if it's a single commit) and force-push; the -s adds the Signed-off-by: line the DCO check requires. Once that's green I'll merge it. Thanks for picking this up! 🙏

@rrskris

rrskris commented Jul 14, 2026

Copy link
Copy Markdown
Collaborator

Hi @donkk11 — friendly nudge on this one. The code is approved and genuinely good (that EACCES-during-traversal catch was sharp), it's just waiting on one thing only you can do: a DCO sign-off on your commit. A sign-off is you certifying you have the right to contribute the change, so I can't add it for you — but it's a 30-second fix:

git commit --amend -s
git push --force-with-lease

That adds the Signed-off-by: line the DCO check needs, and once it's green I'll merge right away. Thanks again for the fix — would love to get it landed. 🙏

@donkk11
donkk11 force-pushed the fix/manifests-unreadable-error branch from 8f5c9ce to 510ffbe Compare July 15, 2026 10:52
@donkk11

donkk11 commented Jul 15, 2026

Copy link
Copy Markdown
Contributor Author

Thank you so much for the thoughtful review and the approval, @rrskris — really appreciate you taking the time, and glad the EACCES catch landed the way it was intended.

The DCO sign-off is pushed now (Signed-off-by on the latest commit). One thing I'm noticing: CI hasn't started running against the new commit yet — if this is a fork PR waiting on a maintainer approval to trigger the workflow, that might be why. Let me know if there's anything needed on my end.

Side note in case it's useful: the bug — Path.rglob() silently swallowing EACCES during traversal — was surfaced using the Nkama Fact Benchmark, a verification approach I've been building for catching exactly this kind of "false clean scan" failure mode in CLI tools. Happy to share more if you're curious.

Thanks again for the careful review — looking forward to getting this merged. 🙏

…ng or unreadable

Wrapping root.exists() alone is insufficient: Path.rglob() swallows EACCES
during traversal, so an unreadable directory would exit 0 with a false clean
scan — the dangerous failure mode for a CI security gate. Adds an explicit
readability probe (os.listdir on a dir, open on a file) before scanning and
keeps streaming iteration. Includes regression tests exercising real chmod-000
conditions (not mocked).

Built by Claude (Fable 5) under the Nkama contract; independently verified
across two rounds by gpt-5.6-sol, which rejected the first version for
silently reporting a clean scan on an unreadable directory and forced the
fix before passing it.

Co-Authored-By: Claude Fable 5 <[email protected]>
Co-Authored-By: gpt-5.6-sol <[email protected]>
Signed-off-by: KK Nkama <[email protected]>
@donkk11
donkk11 force-pushed the fix/manifests-unreadable-error branch from 510ffbe to fd234fa Compare July 15, 2026 11:11
@donkk11

donkk11 commented Jul 15, 2026

Copy link
Copy Markdown
Contributor Author

One correction to make sure credit lands where it's due: I updated the commit (now fd234fa) to add a second Co-Authored-By trailer.

The full picture — this was built by Claude (Fable 5) under the Nkama contract, then independently verified across two rounds by a separate model, gpt-5.6-sol. Round 1 was a genuine reject: it caught that an unreadable directory would silently report a clean scan (exit 0) instead of erroring — exactly the dangerous failure mode for a security-gate CLI. That forced the fix you see now, and only then did it pass verification in round 2.

Didn't want the commit to read as single-model work when the adversarial check is what actually caught the bug before it reached you. Re-signed and pushed (fd234fa), sign-off intact.

@rrskris
rrskris merged commit a50f018 into kaaval:main Jul 18, 2026
6 checks passed
@rrskris

rrskris commented Jul 18, 2026

Copy link
Copy Markdown
Collaborator

Merged — thank you @donkk11! 🎉 The chmod-000 regression tests were the deciding detail for me: an unreadable path silently producing exit 0 is exactly the failure a CI security gate can't afford, and now it's pinned by tests that exercise the real condition instead of mocks. You'll be credited in the next release notes.

The Nkama verification story is genuinely interesting — an adversarial second-model reject catching the false-clean-scan path before review is the kind of thing I'd read a write-up on. If you're looking for a next one, #40 (--version flag) is quick, and #2 (JUnit XML output) is a nice self-contained CLI feature. Hope to see you around. 🙏

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

2 participants