Skip to content

Add SARIF output to CLI (#1) - #10

Merged
rrskris merged 7 commits into
kaaval:mainfrom
Diyaaa-12:feat/sarif-output
Jul 12, 2026
Merged

rrskris merged 7 commits into
kaaval:mainfrom
Diyaaa-12:feat/sarif-output

Conversation

@Diyaaa-12

Copy link
Copy Markdown
Contributor

What this changes

Adds a sarif output mode to the CLI so RBAC scan findings can be uploaded to
GitHub's Security tab via github/codeql-action/upload-sarif. Each finding is
mapped to a SARIF 2.1.0 result (ruleId=rule_type, level derived from
severity, message from the remediation action), with one rule per unique
rule_type under tool.driver.rules, and CIS benchmark refs surfaced in
taxa. Also factors out a shared _finding_rows() helper so the JUnit XML
formatter in #2 can reuse the same finding→row normalization instead of
duplicating it.

Closes #1

Type

  • New detection rule / finding source
  • Bug fix
  • Feature
  • Docs
  • Refactor / chore

Checklist

  • make test passes (ran via pytest tests/test_cli.py — no make available locally on Windows, used pytest directly)
  • Added/updated tests for the behavior change
  • New rule ships with a remediation and a verified benchmark citation
    (exact CIS Kubernetes Benchmark version + ID, or a primary source — not
    an invented ID)
  • Added a fixture to hack/dev/rbac-fixtures.yaml if it's a new rule
  • Docs updated (docs/ci-integration.md — added GitHub Actions upload-sarif snippet)
  • Conventional commit messages

How you verified it

Ran:
python -m app.cli scan rbac --manifests hack/dev/rbac-fixtures.yaml --output sarif
— produced valid SARIF 2.1.0 output: $schema/version present, one
tool.driver.rules entry per distinct rule_type (10 rules for the existing
fixtures), and one results[] entry per finding with correct ruleId,
level (error/warning per severity), message.text, locations, and CIS
taxa refs.

Also ran:
pytest tests/test_cli.py -v
— 10/10 passing, including a new test_sarif_output_is_valid_shape test
asserting $schema, version, runs[0].tool.driver.rules, and
runs[0].results are present and correctly shaped.

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

Thanks @Diyaaa-12 — genuinely strong first PR. 🙌 The SARIF is valid and GitHub will accept it, you added a real shape test, updated the docs, and nicely factored out _finding_rows() so #2 (JUnit) can reuse the normalization — exactly the coordination we were hoping for. A few things to tighten before merge:

Should fix

1. Rule descriptions are instance-specific — cli.py, the rules_by_id dedup in _print_sarif. Because it takes the first finding's title, the rule-level metadata comes out as e.g. "Cluster Admin Binding via ClusterRole 'wide-open'" — a specific role name leaks into what should be a general rule description. In the Security tab a rule should describe the rule, not one instance. Use a generic description per rule_type (the humanized rule_type works well) and keep the instance detail in the result message, which you already do correctly.

2. Dispatch indentation — cli.py, the if/elif/else on args.output. The bodies are indented 6 spaces; it's valid Python but not a multiple of 4 and inconsistent with the rest of the file (flake8 E111). Please bump them to 8 spaces to match.

Nits

  1. PEP8 blank lines: two blank lines before _SEVERITY_TO_SARIF_LEVEL, _print_sarif, _apply_gate, and before the new test function (E302/E305).
  2. Add a trailing newline to test_cli.py and docs/ci-integration.md (W292).
  3. result.taxa references a taxonomy that isn't declared under run.taxonomies, so the CIS refs are technically dangling (GitHub tolerates it, so this is optional). Simplest fix: move the CIS refs into result.properties instead of taxa.
  4. Docs: add if: always() to the upload-sarif step so findings still reach the Security tab when the gate exits 1 — that's exactly the case you most want visible.

Optional: _finding_rows() carries a SARIF-specific level field — fine to leave since #2 can ignore it; just flag it when you and @Garifallos align on the shared shape.

Once the two Should fix items are in, I'll approve the CI run and we'll merge. Really nice, well-tested work — this sets a good template for the other formatters.

@Diyaaa-12

Copy link
Copy Markdown
Contributor Author

Addressed both should-fix items and all nits:

  1. Rule descriptions are now generic (humanized rule_type, e.g. "Cluster Admin Binding") — instance-specific role names stay in results[].message.text only.
  2. Fixed dispatch indentation to 8 spaces.
  3. Moved CIS refs from taxa to properties.cis_refs to avoid the dangling-taxonomy issue.
  4. docs/ci-integration.md already had if: always().
  5. Fixed PEP8 blank-line spacing and a pre-existing file-encoding issue in test_cli.py.

All 10 tests passing locally. Ready for another look 🙏

@rrskris

rrskris commented Jul 11, 2026

Copy link
Copy Markdown
Collaborator

Heads-up @Diyaaa-12 — the project was renamed today: Argus is now Kaaval (details pinned in Discussion #13). Nothing changes for your PR's substance, and GitHub redirects your existing remote automatically.

Two small things when you push your next revision:

  1. Rebase over current main (git fetch origin && git rebase origin/main) — the rename touched cli.py, so expect a couple of small conflicts in strings/docs.
  2. In your new SARIF code, use the new name where the tool name appears (e.g. the SARIF driver.name should be Kaaval, doc mentions kaaval).

Also note: we now require DCO sign-off on new commits — just add -s to your git commit. Your existing commits are grandfathered; only new ones need it. Shout if the rebase gets messy and I'll help.

@Diyaaa-12

Copy link
Copy Markdown
Contributor Author

@rrskris quick check before I finish this — should I also rename the
repo path (rrskris/Argus → rrskris/Kaaval?), docker image name
(argus-control-plane), and file names like argus.yaml in the docs?
Or should those stay as-is for now since the actual repo/file paths
haven't changed yet? Want to make sure I don't break any of the CI
examples.

@rrskris

rrskris commented Jul 11, 2026

Copy link
Copy Markdown
Collaborator

Good question @Diyaaa-12 — you don't need to rename anything yourself. The rename has already fully landed on main: the repo is kaaval/kaaval now (old URLs redirect), the image is ghcr.io/kaaval/kaaval, the context file is kaaval.yaml, and all the docs/CI examples were updated in that commit.

So the only thing to do is rebase your branch onto current main (git fetch origin && git rebase origin/main) — that brings all the renames in for free. After the rebase, just make sure the new code your PR adds uses the new name (e.g. SARIF driver.name = Kaaval, and any doc lines you're adding reference kaaval). Nothing else to touch, and please don't rename beyond that — keeps your diff focused on SARIF.

One more thing since the rebase rewrites your commits anyway: we now require DCO sign-off, so re-commit with -s (git rebase origin/main --signoff does it in one go). Shout if the rebase fights you.

@Diyaaa-12
Diyaaa-12 force-pushed the feat/sarif-output branch from b9cc822 to 7904964 Compare July 11, 2026 17:53
@Diyaaa-12

Copy link
Copy Markdown
Contributor Author

Rebased with --signoff and updated the SARIF driver.name/helpUri to Kaaval.
One thing though — git rebase origin/main came back "already up to date"
and I don't see the rename commit in git log for origin/main (still
shows 69efa8d as the tip, argus.yaml/rrskris/Argus still referenced
in docs, no kaaval.yaml in the tree). Did the rename commit maybe land
on a different branch, or should I be fetching from somewhere else? Want
to make sure I'm rebasing onto the right ref before this is ready.

@Diyaaa-12

Copy link
Copy Markdown
Contributor Author

Also noticed the CI checks are waiting on workflow approval let me know if that needs anything from my side, otherwise just flagging in case it got missed

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

Thanks for the fast turnaround @Diyaaa-12 — the structure is right where we want it: _finding_rows() is exactly the seam #2 (JUnit) needs, the shape test is solid, and the gate-semantics assertion at the end is a thoughtful touch. CI is green (the workflow-approval wait you flagged was on our side — done, nothing needed from you). Three small fixes and this is mergeable.

Your rebase question: your local origin points at your fork, and forks don't follow this repo automatically — that's why your origin/main still shows 69efa8d. Fix:

git remote add upstream https://github.com/kaaval/kaaval.git
git fetch upstream
git rebase upstream/main --signoff

(or click "Sync fork" on your fork's GitHub page first). GitHub tests your PR against the real main, so nothing was actually broken — but your local tree was pre-rename, which is exactly why the docs lines below came out with the old names.

Non-blocking follow-up (I'll file it as an issue): GitHub ranks code-scanning alerts by a security-severity property on each rule — our Contextual Risk Score is the natural feed for it, which would make the Security tab sort by our ranking. Deserves its own small PR, not this one.

Comment thread control-plane/app/cli.py Outdated
"id": row["rule_id"],
"name": row["rule_id"],
"shortDescription": {"text": _humanize_rule_type(row["rule_id"])},
"helpUri": "https://github.com/rrskris/Kaaval",

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.

https://github.com/rrskris/Kaaval doesn't exist (404) — the repo is https://github.com/kaaval/kaaval. Even better for helpUri: point it at the rule catalog, https://github.com/kaaval/kaaval/blob/main/docs/rbac-rules.md — that's the "tell me more about this rule" link GitHub shows next to each alert.

Comment thread control-plane/app/cli.py Outdated
"tool": {
"driver": {
"name": "Kaaval",
"informationUri": "https://github.com/rrskris/Kaaval",

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.

Same here — informationUri should be https://github.com/kaaval/kaaval.

Comment thread control-plane/app/cli.py Outdated

if __name__ == "__main__":
sys.exit(main())
sys.exit(main()) No newline at end of file

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.

The file lost its trailing newline in this revision — please restore it (newline after sys.exit(main())).

Comment thread docs/ci-integration.md Outdated
## GitHub Actions — SARIF upload to Security tab

\`\`\`yaml
- name: Run Argus RBAC scan

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 new section was written against the pre-rename tree — Run Argus RBAC scan → Run Kaaval RBAC scan here, and --context-file argus.yaml → kaaval.yaml on line 220. (The rest of the file was renamed on main already; only these new lines need it.)

Comment thread control-plane/tests/test_cli.py Outdated
@@ -1,5 +1,5 @@
"""
Unit tests for the headless CLI — manifest→graph parsing, context loading,
Unit tests for the headless CLI -- manifest to graph parsing, context loading,

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.

Please restore the original docstring (— manifest→graph parsing) — the em-dash and arrow are intentional and the file is UTF-8, so there was no encoding issue. Keeps the diff focused on SARIF.

Signed-off-by: Vamshi Krishna Santhapuri <[email protected]>

# Conflicts:
#	control-plane/app/cli.py
#	control-plane/tests/test_cli.py
@rrskris

rrskris commented Jul 12, 2026

Copy link
Copy Markdown
Collaborator

Heads-up @Diyaaa-12 — #39 (PolicyReport output) landed on main and touched the same --output lines as your SARIF work, which put this PR into conflict. Since the conflict was our doing, I've resolved it for you: pushed a signed merge commit (2a80770) to your branch that keeps your SARIF code untouched and unions the two features (--output now offers table|json|sarif|policyreport, both dispatch arms, both tests — all 45 pass locally).

Your branch history is intact — just git pull before you push again. The four review items from earlier are still yours: the two rrskris/Kaaval URLs, the Argus/argus.yaml names in your new docs section, the trailing newline, and the docstring revert. Once those land, this merges.

…, fix new docs lines, revert docstring

Signed-off-by: Diya Maheshwari <[email protected]>
@Diyaaa-12

Diyaaa-12 commented Jul 12, 2026 •

Copy link
Copy Markdown
Contributor Author

All four review items addressed:

  1. helpUri now points to https://github.com/kaaval/kaaval/blob/main/docs/rbac-rules.md
  2. informationUri now points to https://github.com/kaaval/kaaval
  3. Restored the trailing newline at the end of cli.py
  4. Fixed the new SARIF docs section to use Kaaval RBAC scan and kaaval.yaml (rest of the file was already renamed on main)
  5. Reverted the test_cli.py docstring — my earlier "encoding fix" was unnecessary, the file was already correct UTF-8; restored the original em-dash/arrow

All 11 tests passing locally, verified the file is proper UTF-8 with python -c "print(open(...).read())" (turned out my terminal was just displaying it oddly, the file itself was fine).

Ready for another look

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

All five items addressed and verified against the actual files — helpUri now points at the rule catalog, informationUri at the repo, trailing newline restored, the new docs section uses Kaaval/kaaval.yaml, and the docstring is back to the original. CI green across the board. Genuinely nice first contribution, @Diyaaa-12 — the _finding_rows() factoring is exactly the seam the JUnit work (#2) needed. Merging. 🎉

@rrskris
rrskris merged commit 2cffa5c into kaaval:main Jul 12, 2026
6 checks passed
@rrskris

rrskris commented Jul 12, 2026

Copy link
Copy Markdown
Collaborator

Merged — and this is a milestone worth marking: Kaaval's first community-contributed feature is live. 🎉 Thank you, @Diyaaa-12. SARIF output means anyone running Kaaval in a GitHub Actions pipeline now gets findings right in their Security tab, ranked by contextual score.

You've also unblocked the next one: the _finding_rows() helper you factored out is exactly what the JUnit XML work (#2) will build on. If you enjoyed this, #30 (friendly CLI errors) and #32 (feed GitHub's alert ranking from our score — a natural follow-on to what you just shipped) are both yours if you want them. Either way, thank you for the careful work through the review rounds. 🙏

@Diyaaa-12

Copy link
Copy Markdown
Contributor Author

Thank you so much, this really means a lot! 🙏 Glad the _finding_rows() refactor turns out to be useful for the JUnit XML work too, happy it lines up well.
I'd love to take up #32 next since it's a direct extension of the SARIF work, will get started on it soon once assigned. Might pick up #30 after that if time permits.
Thanks again for the guidance through the review rounds, learned a lot from it!

rrskris added a commit that referenced this pull request Jul 26, 2026
The architecture diagram still labelled SARIF as "(#1, in review)" and JUnit
XML as "(#2)", and the CI-integration roadmap paragraph listed both plus the
scan-diff endpoint as planned. All three have shipped (#10/#56, #81, #82).

Also fixes two stale references found while verifying the above:

- the `--output` flag table omitted `sarif` and `junit`, though the CLI has
  accepted both for several releases (`app/cli.py` choices)
- `docs/api.md` did not document `GET /rbac/scan/diff` at all

Prometheus /metrics (#3) and the Helm chart (#8) remain the open roadmap
items, so they stay under "planned next".

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.

Add SARIF output to the CLI (GitHub Security tab)

2 participants