Skip to content

fix(auth): admins can access any task; expose super_admin_mode; introduce authorize() PDP - #589

Merged
andyne13 merged 3 commits into
refactor/hexagonalfrom
fix/admin-task-access
Jun 29, 2026
Merged

fix(auth): admins can access any task; expose super_admin_mode; introduce authorize() PDP#589
andyne13 merged 3 commits into
refactor/hexagonalfrom
fix/admin-task-access

Conversation

@andyne13

@andyne13 andyne13 commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

First slice of the admin-UI permission work (review item #1), done through a small, extensible authorization seam rather than an inline bypass.

Problem

Admins see every user's task in the admin jobs list, but the task status/error/logs/cancel endpoints (all guarded by require_task_owner) were owner-only — no admin path. So an admin clicking another user's job in the admin UI got a guaranteed 403 dead-end.

Change

  • Single authorization decision point: AuthService.authorize(user, action, resource) — deny-by-default, policy in one place instead of inlined at call sites (the fragmentation that produced these bugs). Today it handles task:access (owner or admin); unknown actions raise rather than silently allow. It's the seam other checks migrate onto, with a TODO(org) for org-scoped admins.
  • require_task_owner now delegates to it (covers all four task endpoints).
  • Expose super_admin_mode via the admin-only /config so the admin UI permission layer can mirror the backend rule (admins only bypass partition checks when SUPER_ADMIN_MODE is on) instead of assuming every admin has partition access.

Scope / non-goals

  • No org model — extensible seam only (see docs/refactoring/AUTHORIZATION_ARCHITECTURE.md, Phase 0).
  • The MCP path has its own divergent task-auth; intentionally not touched here — it needs a separate senior review of the MCP auth model.

Verification

  • Unit: 1471 passing (added direct authorize() tests + require_task_owner admin-allow / non-owner-deny).
  • Running stack: admin → another user's task 200 (was 403); owner → own task 200; non-owner non-admin 403; /config returns super_admin_mode with rdb intact.

Summary by CodeRabbit

  • New Features

    • Updated the admin /config response to return settings in a client-friendly serialized format and added a super_admin_mode field.
    • Introduced centralized authorization policy support for action-based decisions.
  • Bug Fixes

    • Improved task access authorization so admins can access tasks regardless of ownership, while non-admins remain restricted; unknown actions are rejected.
  • Tests

    • Added unit tests covering admin vs non-admin task access and validation for unknown authorization actions.

… admin UI

Admins see every user's task in the admin jobs list, but the task status/error/
logs/cancel endpoints (all via require_task_owner) were owner-only, so clicking
another user's job in the admin UI was a guaranteed 403 dead-end.

Introduce a single authorization decision point — AuthService.authorize(user,
action, resource), deny-by-default — and route require_task_owner through it
instead of inlining the check. Today it handles task access (owner OR admin); it
is the seam other authz checks migrate onto, with a TODO(org) for org-scoped
admins. Expose super_admin_mode via the admin-only /config so the admin UI's
permission layer mirrors the backend rule instead of assuming every admin has
partition access.

Design: docs/refactoring/AUTHORIZATION_ARCHITECTURE.md (Phase 0).
@coderabbitai

coderabbitai Bot commented Jun 29, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@andyne13, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 16 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 709f2cdd-07b9-4454-bc83-2934ddd9c2d6

📥 Commits

Reviewing files that changed from the base of the PR and between 1d01cec and 234098d.

📒 Files selected for processing (2)
  • openrag/services/orchestrators/auth_service.py
  • tests/unit/services/orchestrators/test_auth_service.py
📝 Walkthrough

Walkthrough

AuthService.authorize is added as a deny-by-default policy entry point routed by action string. require_task_owner now delegates task-access checks to it. The /config endpoint returns JSON-encodable settings plus super_admin_mode. Tests cover the new authorization behavior and updated dependency flow.

Changes

Authorization centralization

Layer / File(s) Summary
AuthService.authorize implementation
openrag/services/orchestrators/auth_service.py, tests/unit/services/orchestrators/test_auth_service.py
Adds deny-by-default authorize(user, action, resource) with task:access admin bypass, owner check, and unknown-action ValueError; tests cover allow/deny cases and error handling.
require_task_owner delegation and /config update
openrag/api/dependencies/auth.py, openrag/api/main.py, tests/unit/api/dependencies/test_auth.py
Injects AuthService into require_task_owner, replaces the inline ownership check with AuthService.authorize, returns jsonable_encoder(settings) plus super_admin_mode from /config, and updates dependency tests for admin access and 403 denial.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

A rabbit hopped by with a policy chart,
One gate for access, one tidy start.
Admins may bound, owners may stay,
super_admin_mode sparkles in the config display.
Hop hop — the checks now all know their part. 🐇

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 30.77% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title is specific and accurately summarizes the main auth and config changes in the PR.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/admin-task-access

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

Comment @coderabbitai help to get the list of available commands.

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@openrag/services/orchestrators/auth_service.py`:
- Around line 547-554: The `AuthService.authorize` handling for `task:access`
can incorrectly allow access when both the user identity and task owner are
missing, because the equality check in `resource.get("user_id") ==
cls._uget(user, "id", None)` treats two absent values as a match. Update the
`authorize` branch to explicitly require both `user_id` and the user `id` to be
present before comparing, while preserving the admin shortcut, and add a
regression test covering `user=None` and a task with missing or null `user_id`
to ensure deny-by-default behavior.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: e266baaa-cbc7-4aba-898c-e49dbba7318c

📥 Commits

Reviewing files that changed from the base of the PR and between 20451b9 and b30e9b0.

📒 Files selected for processing (5)
  • openrag/api/dependencies/auth.py
  • openrag/api/main.py
  • openrag/services/orchestrators/auth_service.py
  • tests/unit/api/dependencies/test_auth.py
  • tests/unit/services/orchestrators/test_auth_service.py

Comment thread openrag/services/orchestrators/auth_service.py Outdated
andyne13 added 2 commits June 29, 2026 10:38
Satisfy the layer-import guard (api must not import services directly) by
injecting auth_service through DI in require_task_owner instead of importing
AuthService, matching how the partition dependencies call check_partition_access.
Also apply ruff format.
…default)

Comparing resource.user_id to user.id returned True when both were None, so a
missing/partially-hydrated principal or a malformed task (user_id=None) could be
authorized. Require both ids present before comparing. Adds a regression test.

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

Approved!
I tested the task access flow locally: owner access works, admin access to another user’s task works, and another non-admin user is still denied. /config also exposes super_admin_mode as expected.

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

I've tested it and it works

@andyne13
andyne13 merged commit f5e2dae into refactor/hexagonal Jun 29, 2026
6 checks passed
@andyne13
andyne13 deleted the fix/admin-task-access branch June 29, 2026 14:38
@Ahmath-Gadji Ahmath-Gadji added the fix Fix issue label Jun 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fix Fix issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants