Skip to content

[M2.3e1] Project-bound API tokens - #120

Merged
samuelmbabhazi merged 6 commits into
mainfrom
feat/m2.3e-project-tokens
Nov 5, 2026
Merged

samuelmbabhazi merged 6 commits into
mainfrom
feat/m2.3e-project-tokens

Conversation

@samuelmbabhazi

Copy link
Copy Markdown
Collaborator

What changed

M2.3e1: API tokens can be bound to one project.

  • Migration 20261105150000_project_api_tokens:
    • nullable api_tokens.organization_id and project_id, set together (CHECK);
    • composite foreign key to projects(organization_id, id) with ON DELETE CASCADE: the project owns the token's lifetime;
    • an index for project listing (used by M2.3e2).
  • Domain. scopesWithinProject(scopes, project): every scope must have the same organization and project (an environment is optional). It never allows profile.read.
  • ApiTokenCommands.create. Accepts an optional project:
    • scopes outside the project give invalid_api_token_scopes;
    • the creator needs live member.manage on the project, because binding credentials to a project is project administration;
    • the audit event records the projectId.
  • ApiTokenAuthentication. Every use of a project token refuses targets outside its project (403 api_token_permission_denied). A stored project token whose scopes left the project is treated as corrupt (401).
  • HTTP. POST /api-tokens accepts an optional project, and ApiTokenDto returns project (null for account-wide tokens). The contract and client are regenerated, and the fixtures are updated.
  • Docs. The SPEC describes the behavior. The PLAN splits M2.3e into e1 (done) and e2 (directory and revocation by project administrators).

Design choices

  • The creator remains the owner. A project token can never exceed its creator's current authority, and it dies with the creator's security version, as user tokens do. This is the PLAN's "constrained by their project and creator's current permissions".
  • Management permission: member.manage at the project scope (owner, organization admin, project admin). Recorded in the SPEC.

How it was tested

  • Domain unit tests: project and environment scopes accepted; organization, account, foreign-project, empty scopes and an invalid project rejected.
  • New resource-tokens.integration.spec.ts case:
    • invalid scope sets are refused;
    • the token works on its project and environment, and gets 403 on a sibling project and on organization reads;
    • the audit event carries the projectId;
    • deleting the project deletes the token, after which authentication returns 401.
  • API (203), domain (96), web (52) and client tests, builds and the local gate pass.
  • Not run locally: the integration tests (no Docker). They run in CI-1.

Security considerations

The change only narrows authority: an extra per-use restriction and a creation-time check. There is no new credential exposure path.

@samuelmbabhazi
samuelmbabhazi merged commit 7556d13 into main Nov 5, 2026
@samuelmbabhazi
samuelmbabhazi deleted the feat/m2.3e-project-tokens branch November 5, 2026 16:25
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