Refactor authorization logic to eliminate wildcard scope forms - #3130
Merged
Thushani-Jayasekera merged 1 commit intoAug 4, 2026
Merged
Conversation
…ing that every required scope must be explicitly declared and matched exactly. Update related tests and documentation to reflect this change, enhancing clarity on scope management and access control.
Thushani-Jayasekera
requested review from
AnuGayan,
Arshardh,
CrowleyRajapakse,
HeshanSudarshana,
HiranyaKavishani,
Induwara04,
Krishanx92,
PasanT9,
Piumal1999,
RakhithaRR,
Tharsanan1,
VirajSalaka,
ashera96,
chamilaadhi,
dushaniw,
hisanhunais,
lasanthaS,
malinthaprasan,
pubudu538,
renuka-fernando,
senthuran16,
tgtshanika,
tharikaGitHub,
tharindu1st and
thivindu
as code owners
August 4, 2026 17:01
Contributor
📝 WalkthroughWalkthroughThe change removes wildcard scope authorization. Scope validation rejects wildcard segments, backend checks require exact scope matches, and portal permission checks follow the same rules. Documentation and enforcement tests now describe and verify explicit scopes and ChangesExplicit Scope Authorization
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
renuka-fernando
approved these changes
Aug 4, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Purpose
Make the AI Workspace UI reflect the caller's actual permissions, and make the Platform API's
authorization model something a UI can mirror exactly.
Before this change the UI offered every action to every signed-in user: a viewer or subscriber
could open a create form, fill it in, submit, and only then get a
403from the Platform API.The role-to-scope table also over-granted (subresource scopes listed alongside a parent
:managethat already covers them), and scope matching supported a
:*wildcard form that nothing in theplatform declared or used — a second, undocumented way for a scope to grant an operation.
What changed
1. Authorization: exact scopes only, no wildcard form
ScopeEnforcer(platform-api/internal/middleware/authorization.go) now admits a request onlywhen a held scope appears verbatim in the matched operation's accepted-scope list. The
scopeSatisfieswildcard-expansion helper is gone, along with its test file.*in any segment as malformed at startup, so a wildcard grantcan no longer be written into
role-to-scope-mapping.yaml.HasEffectiveScopematches exactly, the same way the enforcer does.:manage: a resource's:managescope is listed in its own and itssubresources' accepted-scope sets in
openapi.yaml, which is what makesap:gateway:managecover
ap:gateway:token:create. That is declared per-operation in the spec rather than inferredby pattern matching, so the spec remains the single source of truth for what a scope grants.
changing any existing grant. Wildcard support can be reintroduced later if a real need appears.
Docs updated to match:
GO-AUTH-019in.claude/rules/authentication_authorization.md, Rule 4 ofthe
rest-api-oauth-scopesskill, and the scope-convention header inrole-to-scope-mapping.yaml.2. Role-to-scope mapping and Helm values cleaned up
:manageon the same role (ap_adminnolonger lists
ap:gateway:token:manage,ap:llm_provider:api_key:manage, and so on). Asubresource scope is now granted only to roles that do not hold the parent
:manage.ap:api_key:all:manageis kept explicit and commented as an ownership override — it widenswhich users' keys are reachable, not which actions, and is never implied by
ap:api_key:read.ap_publishertightened: LLM providers are read-only for a publisher (creating, editing,deleting and deploying providers are admin tasks); it keeps
ap:secret:manage, which backs theupstream auth values on the proxies it configures.
kubernetes/helm/platform-api-helm-chart/values.yamlkept in sync with theap_adminentry,with the same reasoning documented inline.
3. AI Workspace: permission-aware UI
portals/ai-workspace/src/auth/permissions.tsholds the scope constants (derived fromopenapi.yaml'sx-required-scopes,ap:prefix) pluscheckPermission, surfaced to componentsas
hasPermission(scope)from the auth provider.checkPermissionmirrors the backend: exactmatch, own-level
:manage, then each ancestor:manage— because those are the scopes eachoperation actually lists.
ap:api_key:all:manageis excluded from:managederivation, matchingthe one operation in the spec whose accepted-scope list omits its parent.
Actions the user cannot perform are now disabled with a tooltip rather than hidden, so the UI stays
predictable and the boundary is visible. Applied across projects, applications (including API keys
and associations), gateways and gateway policies, REST/MCP/LLM proxies, provider templates, service
providers, and external servers.
Two details worth noting:
NO_PERMISSION_TOOLTIP) deliberately does not name the missing scope — naming itwould let a caller probe the authorization model.
DISABLED_ACTION_SXdims controls rendered as links (component={RouterLink}), since a disabled<a>blocks the click but does not pick up the theme's disabled colouring — without it thecontrol looks enabled while doing nothing, which reads as a broken button rather than a
permission boundary.
The UI check is a UX affordance only; the Platform API remains the enforcement point for every
operation.
Verification
go build ./...andgo test ./internal/middleware/... ./internal/server/...inplatform-apipass. Enforcer and plugin-enforcement tests now assert a wildcard scope grants nothing, and
role-map validation tests assert
*in any segment is rejected.tsc --noEmitonportals/ai-workspacereports no new errors from these changes (the repo haspre-existing type errors in unrelated files).