8000 ci(security): Bandit gate enforces the governed policy in security.toml (#1738) by GBOGEB · Pull Request #2819 · GBOGEB/ABACUS · GitHub
[go: up one dir, main page]

Skip to content

ci(security): Bandit gate enforces the governed policy in security.toml (#1738) - #2819

Open
GBOGEB wants to merge 1 commit into
mainfrom
fix/1738-bandit-gate-follows-governed-policy
Open

GBOGEB wants to merge 1 commit into
mainfrom
fix/1738-bandit-gate-follows-governed-policy

Conversation

@GBOGEB
@GBOGEB GBOGEB commented Nov 28, 2026
Copy link
Copy Markdown
Owner

PR Decision Brief

Purpose / why: Turn Security Scanning from a permanent red into a gate that can be required, as #1738 asks (Bandit findings classified, with a disposition per class).

Before -> after: Before, the job runs bandit -r . and exits on Bandit's any-finding status. On main 4390fb9 that is 25,058 findings, of which 24,065 are pytest asserts in tests, and the job is red on every run. After, the same repository-wide scan runs, and blocking follows the policy that .github/security/security.toml already declares. Result: 183 blocking findings (55 in code, 128 in tests), each listed in bandit-policy-decision.json.

Scope / excluded work:

  • In scope: scripts/ci/bandit_policy_gate.py (new), its tests, and the Run Bandit step plus artifact list in ci-cd-tests.yml.
  • Unchanged: scan scope (still -r .), the raw report, bandit_report_guard.py, the new-debt ratchet, Safety, security.toml itself.
  • Excluded: fixing the 183 findings. That's lanes per rule; the two B324s are in a separate PR.

Related issue, parent wave or dependency: #1738. It's on the C-PATH admission path: Bandit → #1738 → MAIN-GREEN → #1860.

1. Verification (do not guess)

Admission: HOLD until separately verified under the effective ruleset.

Evidence State Native receipt / owner
Tests, including failure / negative path PASS (local) tests/test_bandit_policy_gate.py 14 passed. Covers classification per policy branch, test-path recognition, ordering, exit codes 0/1/2, a bad report, a bad or missing policy, and the committed policy loading
Security, policy, A10 PASS (local) Step replayed with the real 25,058-finding report: guard VALID, gate raw=25058 blocking=183 blocking_in_code=55, step exit 1, exit_code output kept for downstream steps
Coverage (cohort, numerator, denominator) PENDING Native PR checks
Exact head SHA / run / attempt BLOCKED GitHub Actions is billing-locked on the account since 2026-11-21 20:11Z; no job can start

First red / blocker / owner: Account billing lock (owner). After that, the gate stays red on the 183 policy-blocking findings, which is intended.

2. Risk and reviewer decision

Risk and rollback:

  • The watch list now blocks in tests too: 128 findings, mostly B105 password-like strings in fixtures. That follows the policy text, "must never be suppressed without review". If the owner wants fixtures exempt, that's a security.toml change, reviewed on its own.
  • Rollback: revert the commit.

Focus for independent review:

  1. Does waiving B101 only in test paths match the intent of security.toml?
  2. Is the test-path regex right? It matches tests/, testing/, test_*.py, *_test.py and conftest.py.

Next action / named owner: Security owner reviews the policy reading. After merge, burn the 183 down by rule lane.

3. Optional machine evidence projection

Not yet populated. This section is informational and cannot grant merge admission.


Generated by Claude Code

…ml (#1738)

Root: the Security Scanning job ran `bandit -r .` and exited with Bandit's
any-finding status, ignoring the governed policy in
.github/security/security.toml (severity/confidence medium, B101 waived in
tests only, watch rules never suppressed). On main 4390fb9 that is 25,058
raw findings, 24,065 of them pytest asserts in tests, so the gate was red
permanently and had to stay out of the required contexts.

scripts/ci/bandit_policy_gate.py reads that policy and decides:
- watch rules (B105, B106, B108, B201, B301, B302, B324, B506, B601, B602)
  block everywhere, tests included
- other findings block at medium+ severity AND medium+ confidence
- B101 is waived in test files only; other listed skips (B603) everywhere
- exit 0 clean / 1 blocking / 2 unreadable report or policy (fail closed)

The scan stays repository-wide and its raw report is unchanged; the
decision JSON is uploaded beside it. On main 4390fb9: raw 25,058 ->
blocking 183 (55 in code, 128 in tests): B105 73, B310 29, B314 27,
B102 14, B108 13, B106 12, B602 6, B103 4, B506 3, B324 2. The gate stays
red on those until each is fixed or adjudicated.

14 tests; the workflow step was replayed locally against the real report.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RiTqsSEPVgsB1tgV1nng6C
@chatgpt-codex-connector
chatgpt-codex-connector Bot commented Nov 28, 2026 •
Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-28T16:07:38.655181Z 1706baa PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1706baab3e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

# tests only) instead of Bandit's any-finding exit status (#1738).
set +e
python scripts/ci/bandit_policy_gate.py bandit-report.json \
--policy .github/security/security.toml \
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Trigger the gate for policy-only changes

The new --policy dependency is absent from both on.push.paths and on.pull_request.paths, so a commit changing only .github/security/security.toml never runs this security job. Moreover, scripts/ci_pr_debt_ratchet.py does not register this file as Bandit configuration, so in a mixed PR the enforcement block at lines 960-967 can ignore the gate's failed outcome when FULL_SCAN is not required. A malformed policy or a change to thresholds/watch rules can therefore take effect without being validated by the gate; add the policy to both path filters and the ratchet's Bandit configuration inputs.

Useful? React with 👍 / 👎.

# (watch rules everywhere; medium+/medium+ otherwise; B101 waived in
# tests only) instead of Bandit's any-finding exit status (#1738).
set +e
python scripts/ci/bandit_policy_gate.py bandit-report.json \
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Treat the new gate as a Bandit environment input

Changes to scripts/ci/bandit_policy_gate.py trigger this workflow as Python changes, but the script is not listed in scripts/ci_pr_debt_ratchet.py's TOOL_ENVIRONMENT_FILES. Consequently, a semantic weakening of the classifier can pass the per-file Bandit ratchet, leave FULL_SCAN unset, and have its own gate outcome ignored by the enforcement block at lines 960-967. Register this new admission script as a Bandit environment input, just as the ratchet already protects itself from admitting its own weakening.

Useful? React with 👍 / 👎.

Comment on lines +62 to +64
if rule in TEST_ONLY_SKIPS and rule in policy["skips"] and in_tests:
return "waived_test_only_skip"
if rule in policy["watch"]:
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Check watch rules before test-only skips

If a rule such as B101 remains in [bandit.skips] while being promoted into [bandit.watch], a finding in a test file returns waived_test_only_skip before the watch membership is checked. That contradicts this gate's stated invariant that watch rules block everywhere and makes the natural policy edit of adding a rule to watch ineffective unless the editor also knows to remove it from skips; evaluate policy["watch"] first.

Useful? React with 👍 / 👎.

This branch has not been deployed

No deployments
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

0