Skip to content

test: tie the token picker's permissions to the bearer routes (closes #208) - #411

Merged
samuelmbabhazi merged 2 commits into
mainfrom
feat/208-picker-matrix
Nov 21, 2026
Merged

samuelmbabhazi merged 2 commits into
mainfrom
feat/208-picker-matrix

Conversation

@samuelmbabhazi

@samuelmbabhazi samuelmbabhazi commented Nov 21, 2026 •

Copy link
Copy Markdown
Collaborator

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

coderabbitai Bot commented Nov 21, 2026 •

Copy link
Copy Markdown

Explain Change →

Important

Review skipped

Review was skipped as selected files did not have any reviewable changes.

Files ignored due to path filters: 1

  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml, !pnpm-lock.yaml
Run configuration

Commits

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.

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

Change: Other

Merge Risk: Minimal · previous review 7390e

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: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed 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 Passed [#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 Passed 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
Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 0d1e3a9 and 7390ee4.

Files ignored due to path filters: 1

  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml, !pnpm-lock.yaml
Files selected for processing: 6

  • apps/api/src/route-role-matrix.spec.ts
  • apps/web/src/app/access/token-scope-picker.ts
  • apps/web/tsconfig.app.json
  • package.json
  • packages/domain/src/lib/api-token-policy.ts
  • packages/domain/src/lib/organization-policy.spec.ts

Limit details: You’ve used all 10 included reviews currently available.

@samuelmbabhazi
samuelmbabhazi merged commit e98050d into main Nov 21, 2026
24 checks passed
@samuelmbabhazi
samuelmbabhazi deleted the feat/208-picker-matrix branch November 21, 2026 15:28
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.

Token picker: test that its permissions match the route matrix

1 participant