Skip to content

sarif: feed GitHub security-severity from Contextual Risk Score - #56

Merged
rrskris merged 2 commits into
kaaval:mainfrom
Diyaaa-12:feat/security-severity-issue-32
Jul 18, 2026
Merged

rrskris merged 2 commits into
kaaval:mainfrom
Diyaaa-12:feat/security-severity-issue-32

Conversation

@Diyaaa-12

Copy link
Copy Markdown
Contributor

Closes #32

What this changes

Feeds GitHub's security-severity property in SARIF rule output from
Kaaval's Contextual Risk Score, so the Security tab sorts alerts by what
the finding means for your cluster instead of just error/warning/note.

  • Added _contextual_score_to_security_severity() helper: scales the
    contextual score (0..15 cap) to GitHub's expected 0.0-10.0 CVSS-style
    string.
  • In _print_sarif(), each rule's security-severity is set from the
    max contextual score across that rule's findings.
  • level mapping (error/warning/note) is unchanged — security-severity
    is additive, per GitHub's SARIF spec.

Type

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

Checklist

  • make test passes
  • 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/rbac-rules.md for a new rule)
  • Conventional commit messages

How you verified it

Ran python -m pytest tests/test_cli.py -v — all 12 tests pass, including
a new test_sarif_output_security_severity_is_valid that asserts
security-severity is present on every rule and parses as a float in
[0, 10]. Also ran python -m app.cli scan rbac --manifests <risky_dir> --output sarif and confirmed each rule's properties block now carries
security-severity.

@Diyaaa-12
Diyaaa-12 force-pushed the feat/security-severity-issue-32 branch from f0c5976 to fc11c34 Compare July 13, 2026 20:06

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

Back for round two and it shows — this is clean work, @Diyaaa-12. 🙌 Tracking the per-rule max and setting security-severity from it is exactly right (GitHub ranks alerts by that number), the helper is well-documented, DCO's signed, CI's green. One correctness fix and it's in.

The score_cap is wrong — and that's my fault, not yours. My issue #32 said 'score cap ~15', but I gave you a bad number. The real maximum of the Contextual Risk Score is 38.9: base CRITICAL 9.5 × environment 1.5 × data 1.5 × compliance 1.3 × exposure 1.4 (see scoring.py — the score is just that product, no clamp). You can confirm it in the dashboard screenshots in the README: the top finding scores risk 38.9.

With cap = 15, everything scoring 15 or above pins to 10.0 — and in a real production/PCI context most CRITICAL and HIGH findings clear 15 easily. So a 38.9 cluster-admin binding and a 16 wildcard both emit 10.0, and GitHub can no longer order them. That quietly erases the contextual ranking that's the whole point of the tool — the thing your SARIF output exists to surface.

The fix: map against the true maximum so GitHub's ordering mirrors Kaaval's. Rather than hardcode 38.9 (which drifts if the weights ever change), the robust move is a single source of truth in scoring.py — e.g. a MAX_CONTEXTUAL_SCORE constant computed from the weight maxima (max(_SEVERITY_BASE.values()) * max(_ENV_WEIGHT.values()) * max(_DATA_CLASS_WEIGHT.values()) * 1.3 * max(_EXPOSURE_WEIGHT.values())) — then import it here as the cap default. If you'd rather keep it simple, a documented score_cap = 38.9 with a comment pointing at the formula is fine too. Your call.

Everything else is good to go. Thanks for pushing this one — and sorry for the bum number in the issue. 🙏

Comment thread control-plane/app/cli.py Resolved
Addresses review on kaaval#56 — score_cap was 15.0 but the true max of the
Contextual Risk Score is ~38.9 (9.5 x 1.5 x 1.5 x 1.3 x 1.4). At 15,
most CRITICAL/HIGH findings in production clamped to 10.0, collapsing
GitHub's contextual ordering. MAX_CONTEXTUAL_SCORE is now derived from
the weight maxima in scoring.py as a single source of truth.

Signed-off-by: Diya Maheshwari <[email protected]>
@Diyaaa-12
Diyaaa-12 requested a review from rrskris July 15, 2026 08:29
@Diyaaa-12

Copy link
Copy Markdown
Contributor Author

Hey @rrskris, just checking in the fix is up (a1ef1c3) whenever you get a chance to take another look. No rush if you're busy, just didn't want it to slip through. 🙂

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

Verified the fix: MAX_CONTEXTUAL_SCORE derived from the weight maxima in scoring.py as the single source of truth, imported as the cap default, per-rule max feeding security-severity, and the range test locks it in. I confirmed the 1.3 compliance factor against scoring.py:45. CI and DCO green. This is exactly the robust option — merging. 🎉

Thanks for the patience on round three, @Diyaaa-12 — and again, the bad cap number in #32 was mine. You'll be in the release notes.

@rrskris
rrskris merged commit ae74a52 into kaaval:main Jul 18, 2026
6 checks passed
rrskris added a commit that referenced this pull request Jul 18, 2026
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.

SARIF: feed GitHub's security-severity from the Contextual Risk Score

2 participants