Skip to content

fix(auth): enforce current role permissions on custom API keys - #1004

Merged
T3ST3ST3R0N merged 1 commit into
PasarGuard:devfrom
dr-hoseyn:codex/fix-current-api-key-permission-ceiling
Oct 12, 2026
Merged

T3ST3ST3R0N merged 1 commit into
PasarGuard:devfrom
dr-hoseyn:codex/fix-current-api-key-permission-ceiling

Conversation

@dr-hoseyn

@dr-hoseyn dr-hoseyn commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

Summary

A custom API key currently retains its stored permission snapshot after the owner's role loses that permission or its scope is reduced. JWT requests respect the current role while the existing key can still access other admins' users.

Intersect custom key grants with the owning admin's current role during authentication. Missing/disabled permissions deny access and scoped grants use the narrower scope. An owner's custom key retains only its own grants and never receives owner privileges; inherited keys retain their existing behavior.

Type of change

  • Bug fix

Testing

  • 133 local tests passed on fresh SQLite databases, including existing API key, permission, and RBAC regression suites.
  • Verified revoking role access immediately blocks an existing custom key. ALL-to-OWN reductions limit both unrestricted and ALL-scoped keys to their owner's users.
  • Covered all 64 pairs of permission levels, malformed scopes, missing actions/resources, empty keys, boolean-only actions, and a permitted custom owner key without owner privileges.
  • Ruff lint/format and git diff --check passed.

Notes for reviewers

Two production Python files change. No test files, documentation files, schema changes or dependencies are included. Stored key snapshots remain intact; effective access follows the current role on each request.

Integration validation of the five open audit PRs on current dev: all patches applied together without conflicts, and 400 local tests passed in isolated fresh SQLite runs. Ruff passed on all 11 touched production files.

Summary by CodeRabbit

  • Bug Fixes
    • API-key permissions are now limited by the associated admin’s current role permissions, so keys no longer retain access beyond that role’s permissions when the role changes.
    • Owner-admin API keys are unchanged and continue to use their configured permissions. Where both the key and role grant access, the more restrictive permission scope applies. Resources not included in the role’s permissions are not available through the key.

@coderabbitai

coderabbitai Bot commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: da5145a2-a186-47c3-ba6c-7a5a3dd514b4

📥 Commits

Reviewing files that changed from the base of the PR and between 0c9b1e5 and b60ace0.


📒 Files selected for processing (2)
  • app/operation/permissions.py
  • app/routers/authentication.py

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 6 remain after this review.



Walkthrough

API-key authentication now caps non-owner admins’ stored key permissions by their current role permissions. A new helper intersects requested permissions with a ceiling. Owner admins retain the stored key permissions.

Changes

API-Key Permission Capping

Layer / File(s) Summary
Permission intersection
app/operation/permissions.py
Adds intersect_permissions to map grants to scopes and return the narrower permission for each action. It omits resources absent from the ceiling and validates the result as RolePermissions.
API-key authentication integration
app/routers/authentication.py
For non-owner admins, authentication intersects stored key permissions with current role permissions, using default RolePermissions if no role exists. Owner admins keep stored permissions. The resulting permissions are assigned to the key’s role data.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Sequence Diagram(s)

sequenceDiagram
  participant APIKeyAuthentication
  participant AdminRole
  participant intersect_permissions
  APIKeyAuthentication->>AdminRole: read current role permissions
  APIKeyAuthentication->>intersect_permissions: intersect stored key permissions with role permissions
  intersect_permissions-->>APIKeyAuthentication: return capped permissions
  APIKeyAuthentication->>APIKeyAuthentication: assign permissions to key role data
Loading

Suggested reviewers: m03ed

Merge Risk: ⚪ Minimal · up to b60ac

Custom API keys are capped by their owner’s current role permissions, with no established issue requiring a fix before merge.

Pre-merge checks | Passed 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: enforcing current role permissions on custom API keys.
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 2 files.
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 a new PR

  • 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

A rabbit checks each granted scope,
And trims it to the role’s own reach.
The owner keeps the stored key grants,
While other keys receive the cap.
Then hops away through fields of green.

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

@dr-hoseyn

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@T3ST3ST3R0N
T3ST3ST3R0N merged commit 180b4dd into PasarGuard:dev Oct 12, 2026
10 checks passed
Free-Guy-IR added a commit to Free-Guy-IR/panel that referenced this pull request Nov 2, 2026
…am up to 2026-10-17

Owner rule of 2026-10-14: upstream changes are ported only from final
upstream releases. Checked with git ls-remote on 2026-10-17 20:53 UTC;
no new release since panel v5.4.1, node v0.5.4 and node_bridge_py v0.9.2
(GitHub releases, PyPI and npm also unchanged).

Panel: the 79 Port queue entries are all dev-only, so they move to the
new "Held for an upstream release" section with their security
classification and without deadlines, and the queue is empty. Upstream
dev moved to a2fb313 with 25 commits: PasarGuard#1019 is waived (the fork deleted
the notifier workflow), the other 24 are held, three of them classified
security: yes (PasarGuard#1004 role permissions on custom API keys, PasarGuard#1005 role
limits on bulk updates, PasarGuard#1008 role disconnect policy). New branches
feat/live-core-apply and two masque commits are UNMERGED-WIP;
fix/xray-wg-allocation-view is the same patch as held ba27c1cc6.

Node: five earlier dev-only picks are on fork main 0071e2c with trailers
and leave the queue; the other eight queue entries and four new dev
commits (PasarGuard#58, PasarGuard#55, PasarGuard#104, PasarGuard#106) are held, with f72ac0ef (PasarGuard#99) and a3d2d2fe
(PasarGuard#101) marked as fixed by the fork's own fixes per the 2026-10-14
decisions. PasarGuard#100 (refuse to start without a valid API_KEY) is ported by
design: fork commit 88162e2 already fails fast.

node_bridge_py: 27be206 is ported on fork main 6116922; 22f1ef79 and the
v0.9.2 bump bec9cb22 are recorded as ported by design (the one flagged
line belongs to the fork's own add_backend, and the fork labels itself
0.9.2+singbox); upstream main's new PasarGuard#24 (9fa9f264) is held.

scripts: fork main 51edabb has upstream main bba95f274 as an ancestor, so
its thirteen queue lines are ported (decision 7 keeps them).

Against live upstream the panel gate is green (282 commits, 0 unported,
103 held, 0 owed) and every fork tracker is green.
Free-Guy-IR pushed a commit to Free-Guy-IR/panel that referenced this pull request Nov 3, 2026
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