Skip to content

[M2.3f1b3] Web: API token scopes and project tokens - #186

Merged
samuelmbabhazi merged 1 commit into
mainfrom
feat/m2.3f1b3-token-scopes
Nov 7, 2026
Merged

samuelmbabhazi merged 1 commit into
mainfrom
feat/m2.3f1b3-token-scopes

Conversation

@samuelmbabhazi

Copy link
Copy Markdown
Collaborator

What changed

  • Scope picker in the token form. Until now every token created in the UI got profile.read only, so it could do nothing else. The form now offers: profile only (default), or an organization, optionally narrowed to a project and an environment, with permissions ticked one by one. Nothing is granted until it is ticked, and creating a token with no permission is refused.
  • Tie to a project. With a project chosen, a token can be bound to it.
  • Project token panel on the project page: tokens tied to the project, with revocation.
  • Panels hide on refusal. The access panel ([M2.3f1b2] Web: members and roles #185) and the new token panel render nothing when the API answers 403 or 404. Before, a project viewer saw an error and a form they could not use.
  • Token list says what each scope reaches.

Why

PLAN M2.3f1b3, the last part of M2.3f1.

How it was tested

  • token-scope-picker.spec.ts: default grant, nothing granted until ticked, narrowing drops permissions the level no longer offers, binding only on request and cleared with the project, everything cleared on an organization change, profile only when organizations cannot load.
  • token-form-store.spec.ts: the grant and project reach the request, and an empty grant sends nothing.
  • access.spec.ts: listing and revoking project tokens, and hiding panels on 404.

Local gate only (CI off). Not exercised in a real browser or against a running API, so the API's acceptance of these scope shapes rests on reading parseApiScopes, not on a run.

Security considerations

  • Least privilege by default: no permission is preselected.
  • The picker offers only permissions a bearer token can use on a route today, at a level where they can match: audit.read on one project would grant nothing, so it is not offered. member.manage stays out because those routes are session only.
  • That list is a hand-kept copy of docs/generated/route-role-matrix.md, and no test ties them together. A new bearer route needs an entry here. A stale list only hides an option; it cannot widen access.
  • The API still verifies every scope against the owner's live authority at creation and on each use. The token secret keeps the existing show-once handling.

Checklist

  • Tests, including refusals
  • No new shell invocation, no new secret exposure path
  • Audit events already emitted by the API routes
  • PLAN updated

@samuelmbabhazi
samuelmbabhazi merged commit 32ec745 into main Nov 7, 2026
@samuelmbabhazi
samuelmbabhazi deleted the feat/m2.3f1b3-token-scopes branch November 7, 2026 12:01
samuelmbabhazi added a commit that referenced this pull request Nov 7, 2026
…pts (#193)

## What changed

The token scope picker now offers each permission only at the exact
level the API accepts it: organization, project or environment.

## Why

**A bug in #186.** Choosing an organization offered `deploy.run`,
`secret.write` and others. The tenant policy (`validPermissionScope`)
accepts each permission at one level only, so the API refused the whole
token with 403, even for an owner. Deploying and secrets need an
environment, because its protection decides them.

I had assumed a wider scope covers narrower resources. My unit tests
encoded the same wrong assumption, and the browser test only tried
combinations that happened to be valid. Writing a real CLI token for
M8.2b exposed it.

## How it was tested

- Unit tests now pin the exact list at each level.
- Browser test: an environment-level token holding `environment.read`
and `deploy.run`, created through the picker, gets 200 on the
environment's applications and 403 on the project.
`tenant.browser.spec.ts` passes in Chromium with a local PostgreSQL
18.4.

## Limitation

The picker chooses one target, so one token cannot mix levels from the
UI, for example `node.manage` on the organization with `deploy.run` on
an environment. The API allows that. Create two tokens for now.

## Security considerations

Narrows what is offered; the API remains the authority.

## Checklist

- [x] Tests
- [x] No new shell invocation, no new secret exposure path
- [x] No new state change

Signed-off-by: review <[email protected]>
Co-authored-by: review <[email protected]>
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.

1 participant