Skip to content

fix(auth): the one-admin-gate guard refuses a new admin-check function; #20783 review lows (#16333) - #20795

Closed
mrveiss wants to merge 5 commits into
mainfrom
issue-16333-def-detector
Closed

mrveiss wants to merge 5 commits into
mainfrom
issue-16333-def-detector

Conversation

@mrveiss

@mrveiss mrveiss commented Nov 4, 2026 •

Copy link
Copy Markdown
Owner

Follow-up to #16333 PRs A/B/C (#20753, #20776, #20783, landed in T66). It covers the AC "a guard fails any new local def require_admin" and the three LOWs from the #20783 security review (#20787).

Thinking Path

The one-admin-gate guard reads role literals and calls. A new def require_admin(user): return is_admin_role(user["role"]) would pass it, because it calls the one predicate but is still a second gate. So the guard now also reads function names:

  • A function named like an admin check fails unless it is the gate itself, or is recorded with the reason it is not a second gate.
  • I measured the backend first: 35 such functions besides the gate itself. That is 32 at first review, plus the three WebSocket helpers (ws_security.authenticate_ws_admin and enforce_ws_admin, and task_workspace_ws._authenticate_ws_admin) that the wider verb list found.
  • Each is recorded by (file, qualified name) → reason, the reason held as data rather than a comment. The groups are: delegates to the gate; the predicate over a caller record; the WebSocket gate; owner-or-admin; the platform-admin claim; superadmin only; the predicate or an org role; Company OS membership; not authorization.
  • The recorded list is checked in both directions: a new function fails, and a recorded one that no longer exists fails too. A name defined twice in one file fails, and every reason must be non-empty.

What Changed

Verification

Python 3.14 parity venv:

repo_tests/one_admin_gate_16333_test.py + autobot_shared/repeat_grouping_test.py   14 passed
autobot-slm-backend/tests/services/test_refused_session_audit_20664.py (with grouping)  passed
auth_rbac_denial_grouping_16333_test.py + auth_rbac_denial_audit_counted_test.py      7 passed

The code-reviewer pass approved. The Trainmaster's review then approved, and its five LOWs are applied in the second push: qualified-name keys with reasons as data; one reason per entry instead of a shared comment; parametrized planted cases; infix verbs; and the corrected count. Its first-pass findings are also applied:

  • the spellings the name pattern missed;
  • the grouping docstring was overstated, so it is reworded and a recur-after-expiry test added;
  • the org-role reason is reworded;
  • a case "a" | "b" planted case is added.

It spot-checked 13 recorded functions against the code and found every reason accurate, with none needing migration.

Risks

  • Guard and docs only, plus one added audit-detail field. No route behaviour changes.
  • A future helper with an admin-like name must either use the gate or predicate inline, or be recorded with its reason. That is the point of the change.

Model Used

Claude Opus 5.5 (claude-opus-5-5)

Issue Link

Closes #20787. Refs #16333.

Recorded on #16333: the SLM decision and the list of existing tests changed by A/B/C. The SLM require_admin "legacy" wording waits for #20648, which holds autobot-slm-backend/services/auth.py.

Single-issue rationale: #16333's AC fix and its own review follow-up (#20787) touch the same guard; the other open children are blocked (#20751 on #20447, #20761 on #20587) or a separate rule (#20778).

🤖 Generated with Claude Code

@mrveiss mrveiss added backend security area: auth-rbac Wave 2 · cluster E — Auth, identity & RBAC canon phase:M4.9 One definition per concept labels Nov 4, 2026
@coderabbitai

coderabbitai Bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 12 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration
Commits

Reviewing files that changed from the base of the PR and between 09b17c2 and eb9c5bf.

Files selected for processing: 6
  • autobot-backend/auth_rbac.py
  • autobot-backend/auth_rbac_denial_grouping_16333_test.py
  • autobot-slm-backend/services/refused_session_audit.py
  • autobot_shared/repeat_grouping.py
  • autobot_shared/repeat_grouping_test.py
  • repo_tests/one_admin_gate_16333_test.py
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@mrveiss

mrveiss commented Nov 4, 2026

Copy link
Copy Markdown
Owner Author

Code review on PR #20795 (head ec05b46): APPROVE

No CRITICAL, HIGH or MEDIUM finding. Read-only review; tests were not run.

Detector (read through the regex)

  • Every planted name matches: require_admin, require_org_admin_access, is_admin, _is_superadmin, caller_is_admin, check_admin_rights, tool_admin_only, admin_check, ensure/assert/verify_admin, has_admin_access, get_admin_user, validate_admin, admin_required, _admin_only.
  • Every lookalike is rejected: list_admins, admin_panel, administrator_count, is_administrator (the (?![a-z]) lookahead), get_admin_dashboard and validate_admin_username (the $ anchor after the optional suffix), get_all_sysadmin_templates. is_admin = True is not a def.
  • match detection: MatchValue is checked, and an a | b pattern is a MatchOr of two MatchValue nodes, so the expected count of 2 holds.
  • user.role = "admin" is caught as a write; user.name = "admin" is not.
  • Testkit stubs (real_admin_gate, _check_admin_permission_stub) match the name regex, but _TEST_FILE excludes /testkit/, so the population test does not trip on them.

Recorded functions
I enumerated the matching defs at head, and they are the recorded set plus the gate itself and the excluded testkit stubs. I read the body of every recorded function. None is a second gate:

  • The first group delegates to check_admin_permission.
  • The next group is is_admin_role over a caller record.
  • Ownership-or-admin functions defer to is_admin_role.
  • The company-membership functions use require_company_admin / require_board_role.
  • _check_admin_path is a scanner probe.
  • caller_is_admin reads the flag set from is_admin_role at transcriber/deps.py:60.

Growth is visible. Any addition edits _RECORDED_DEFS in this file. The reverse check fails on stale entries.

repeat_grouping

  • The first denial is still recorded, because a new key returns 0.
  • The tracker is still capped, with expired keys evicted first.
  • The change is docs, a route field, and tests.
  • The docs match the code. An expired but still tracked key reports its repeats when it recurs, and the two new tests pin that and the full-tracker loss.
Severity File:line Issue Fix
LOW repo_tests/one_admin_gate_16333_test.py:86 The record is keyed by file and function name only. A second same-named function or method in a recorded file, such as another _is_admin, is invisible. A reason is only a comment and is not enforced. Optionally key by (file, qualname), or store {name: reason} and assert the reason is non-empty.
LOW repo_tests/one_admin_gate_16333_test.py:101-125 The "Company / org membership" comment at line 112 also sits over entries that are not membership roles. The user_management group mixes the platform-admin claim, which is is_admin_role OR the flag, with ownership. Split the comments so each reason sits next to its own entries.
LOW repo_tests/one_admin_gate_16333_test.py:334 test_the_def_detector_reads_names_not_bodies is about 40 lines, over the 30-line rule. Most of it is data. Move the planted and expected names to module constants, or parametrize.
LOW repo_tests/one_admin_gate_16333_test.py:126 Names like user_has_admin, authorize_admin and enforce_admin are not matched. Only the ^_? prefix is allowed, and the regex has no catch-all. Accept it as a heuristic, or add a pattern for a leading verb. The docstring lists some limits but not these.
LOW PR description The count is 32 recorded functions by my count, not 33. Correct the description.

@github-actions

github-actions Bot commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

Notice: 29 open PRs — past the runaway threshold (25)

This is not a request to defer this PR. There is no cap on open PRs (#19397) -- nothing blocks opening or pushing a PR.

This notice only means the count is high enough to be worth a glance for a runaway — something opening PRs in a loop, or a merge pipeline that has stalled so nothing is draining.

Currently open:

If the queue is draining normally, ignore this. Otherwise:

  1. Check whether CI is dispatching at all — see the ci-dispatch-watchdog status on these PRs
  2. Approved PRs land through the merge train the coordinator sequences (merge commits, never squash) -- check the open chore(merge-train) PR is moving, not each PR on its own
  3. Look for a loop opening near-identical PRs

Warn-only runaway detector — .github/workflows/pr-queue-gate.yml. It never blocks a merge.

@mrveiss

mrveiss commented Nov 4, 2026

Copy link
Copy Markdown
Owner Author

Code review on PR #20795 (head caad9fb): APPROVE

Delta review of caad9fb against the reviewed head ec05b46: one file, repo_tests/one_admin_gate_16333_test.py. The five LOWs:

  • Record structure: _RECORDED_DEFS is keyed by (file, qualname), with each reason stored as data. Empty reasons fail, and so does a name defined twice in one file.
  • Comments: each reason sits with its own entries.
  • Tests: the long test is parametrized over module constants.
  • Naming pattern: verbs can now appear as an infix, with planted cases.
  • Count: the PR body says 35.

I checked the three helpers the wider pattern surfaced. ws_security.authenticate_ws_admin is the WebSocket counterpart of check_admin_permission, needed because a WebSocket can't use Depends. It resolves a human user through resolve_human_user, decides through is_admin_role, excludes the service key and fails closed on every exception. enforce_ws_admin only adds the accept-then-close 4001 frame, and task_workspace_ws._authenticate_ws_admin is a pass-through. None is a second gate.
No findings.

@github-actions

github-actions Bot commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

✅ SSOT Configuration Compliance: Passing

🎉 No new hardcoded values of either class — ssot and other both block.

Known backlog in pipeline-scripts/hardcoded_values_baseline.txt is suppressed and tracked in #14371.

@mrveiss

mrveiss commented Nov 4, 2026

Copy link
Copy Markdown
Owner Author

Landed in merge train #20797 (merge commit 92572eb). This PR's reviewed head caad9fb is on main. Closing as landed.

@mrveiss mrveiss closed this Nov 4, 2026
timothybrush pushed a commit to timothybrush/AutoBot-AI that referenced this pull request Nov 4, 2026
@github-actions
github-actions Bot deleted the issue-16333-def-detector branch November 5, 2026 08:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: auth-rbac Wave 2 · cluster E — Auth, identity & RBAC canon backend phase:M4.9 One definition per concept security

Projects

None yet

Development

Successfully merging this pull request may close these issues.

security(auth): #20783 review lows — repeat grouping drops counts on expiry, role_denied endpoint, two detector gaps

1 participant