You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
test: tie the token picker's permissions to the bearer routes (closes #208) - #411
The token picker kept a hand-written list of permissions and levels, and nothing tied it to the routes or to the tenant policy. The list now lives in one place, with a test on each side.
BEARER_GRANTS (packages/domain, api-token-policy.ts) lists each permission a scoped token can be granted, with its level. It holds the same 12 entries the picker offered, and exports the BearerPermission type.
Domain test (organization-policy.spec.ts): the tenant policy accepts each grant at its level and at no other level. The one exception is audit.read, which the policy accepts everywhere; its routes read the organization's log.
API test (route-role-matrix.spec.ts):
every bearer route's permission must be offered at the route's scope;
nothing is offered that no bearer route accepts.
The message names the route and what the picker must offer.
Web: the picker builds its list from BEARER_GRANTS and keeps only the labels, in a Record<BearerPermission, string>, so a new grant without a label does not compile. The web app now depends on @shipkeep/domain (workspace link, pure code, no new external dependency). The production build passes.
How it was tested
Domain (120), API unit (673, including the matrix) and web (251) suites pass, with lint and typecheck.
I removed secret.write from the list as a check. The matrix test then failed with: POST …/secrets: the token picker must offer secret.write at environment. Without the label the web would also fail to compile.
Security considerations
No behaviour change. The picker offers the same permissions at the same levels, and the API still validates every token it is given.
Summary by CodeRabbit
New Features
The access-token scope picker now displays the bearer permissions available for each scope, helping you choose an appropriate scope when creating a token.
Permission options are aligned with the access levels supported by bearer-enabled routes, including organization, project, and environment access.
BEARER_GRANTS in the domain lists what a token can be granted and at
which level; a domain test checks the tenant policy accepts each one
there, and the route matrix test fails when a bearer route and the list
disagree. The web picker uses the list and must label every entry.
Signed-off-by: samuel mbabhazi <[email protected]>
Reviewing files that changed from the base of the PR and between 7390ee4 and 31aee84.
Files ignored due to path filters: 1
pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml, !pnpm-lock.yaml
You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.
Use the checkbox below for a quick retry:
Trigger review
No actionable comments were generated in the recent review.
Walkthrough
The domain package now defines bearer permission grants by scope. The web token scope picker derives its permission entries from those grants. Tests check grant compatibility with tenant policy and alignment between grants and bearer-enabled tenant routes.
Changes: Bearer Permission Scope Alignment
Layer / File(s)
Summary
Bearer grant contract packages/domain/src/lib/api-token-policy.ts, packages/domain/src/lib/organization-policy.spec.ts
The domain package defines scope levels and bearer permission grants. Tests check that tenant policy accepts each grant at its declared level, with a uniqueness exception for audit.read.
Picker and route alignment package.json, apps/web/tsconfig.app.json, apps/web/src/app/access/token-scope-picker.ts, apps/api/src/route-role-matrix.spec.ts
The web app references the domain package, and the picker derives its permission entries from the grants. Route tests check that bearer-enabled tenant routes use grants offered at the route’s access scope, and that no grant is unused by those routes.
This change ties the token picker's permissions to a shared domain list and adds tests that keep it aligned with the bearer routes. The picker offers the same options as before, so no user-facing change is expected. No merge-blocking risk was found.
Security architecture risk: Minimal · up to 7390e
The shared grant list preserves the same twelve permission and scope choices. Server-side token validation and authorization remain unchanged, while the added checks help detect permission drift. No introduced or worsened security risk was established.
Retained concerns
No architecture-level concerns identified.
Security review details
Security Blast Radius
observed — The relocated choices include organization-level administration and environment-level deployment and secret writes. Those permission/level pairs already existed in the picker; the inspected change adds no new pair or broader resource level.
Trust Boundaries and Controls
observed — Client-selected scopes remain untrusted inputs to server-side issuance checks. At use time, the unchanged authentication code checks credential ownership and liveness, project confinement, matching token scope, and the owner's current authority. Importing the display contract into the browser does not replace these checks.
Pre-merge checks: 4
Check name
Status
Explanation
Description Check
Check skipped - CodeRabbit’s high-level summary is enabled.
Title check
The title names the main change: tests that tie the token picker's permissions to the bearer routes. The changeset adds a shared BEARER_GRANTS allowlist in packages/domain, derives the picker's list f…
Linked Issues check
[#208] Acceptance criterion: a test fails when a bearer route has a permission the picker does not offer, or offers it at another level. The PR adds a check in apps/api/src/route-role-matrix.spec.ts. …
Out of Scope Changes check
Each changed file connects to #208 or to the tests that enforce it. api-token-policy.ts adds the single grant list and BearerPermission type. organization-policy.spec.ts checks grants against tenant p…
Full details: Title check
Explanation
The title names the main change: tests that tie the token picker's permissions to the bearer routes. The changeset adds a shared BEARER_GRANTS allowlist in packages/domain, derives the picker's list from it, and adds spec checks that compare grants, tenant policy, and bearer routes. The title is specific and matches the linked issue #208. It is concise and does not use vague terms.
Full details: Linked Issues check
Explanation
[#208] Acceptance criterion: a test fails when a bearer route has a permission the picker does not offer, or offers it at another level. The PR adds a check in apps/api/src/route-role-matrix.spec.ts. Every bearer-enabled tenant route's permission must be offered in BEARER_GRANTS at that route's scope. The check also fails when BEARER_GRANTS offers a permission that no bearer route accepts. The web picker (apps/web/src/app/access/token-scope-picker.ts) now derives its PERMISSIONS from BEARER_GRANTS and keeps only labels. The picker's offered set and levels therefore equal the grants that the matrix test checks against routes. A new route with an ungranted permission, or with a wrong scope, fails the test. Supporting changes are a domain grant list (api-token-policy.ts), a domain policy test (organization-policy.spec.ts), and the workspace dependency and tsconfig reference that let web import the domain package. Limits: the summary does not show that the matrix test reads docs/generated/route-role-matrix.md, and it does not explicitly confirm removal of the picker's validPermissionScope copy. The route-based test meets the stated acceptance criterion without either. Source inspection was not available to confirm these details.
Full details: Out of Scope Changes check
Explanation
Each changed file connects to #208 or to the tests that enforce it. api-token-policy.ts adds the single grant list and BearerPermission type. organization-policy.spec.ts checks grants against tenant policy. route-role-matrix.spec.ts checks grants against bearer routes. token-scope-picker.ts consumes the grants and requires a label for each. package.json and apps/web/tsconfig.app.json add the workspace dependency and project reference that the web import requires. The PR description states no behavior change, and the summary shows the same 12 entries. No unrelated change is evident from the summary. pnpm-lock.yaml is in ignored_files and was not reviewed. Its absence does not affect this assessment.
Finishing Touches
Generate unit tests (beta)
Commit to this branch
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
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
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.
Closes #208.
What changed
The token picker kept a hand-written list of permissions and levels, and nothing tied it to the routes or to the tenant policy. The list now lives in one place, with a test on each side.
BEARER_GRANTS(packages/domain, api-token-policy.ts) lists each permission a scoped token can be granted, with its level. It holds the same 12 entries the picker offered, and exports theBearerPermissiontype.Domain test (organization-policy.spec.ts): the tenant policy accepts each grant at its level and at no other level. The one exception is
audit.read, which the policy accepts everywhere; its routes read the organization's log.API test (route-role-matrix.spec.ts):
The message names the route and what the picker must offer.
Web: the picker builds its list from
BEARER_GRANTSand keeps only the labels, in aRecord<BearerPermission, string>, so a new grant without a label does not compile. The web app now depends on@shipkeep/domain(workspace link, pure code, no new external dependency). The production build passes.How it was tested
secret.writefrom the list as a check. The matrix test then failed with:POST …/secrets: the token picker must offer secret.write at environment. Without the label the web would also fail to compile.Security considerations
No behaviour change. The picker offers the same permissions at the same levels, and the API still validates every token it is given.
Summary by CodeRabbit