Skip to content

fix(api): attribute a confirmation issued with an API token to that token - #358

Merged
samuelmbabhazi merged 2 commits into
mainfrom
fix/348-confirmation-token-actor
Nov 19, 2026
Merged

samuelmbabhazi merged 2 commits into
mainfrom
fix/348-confirmation-token-actor

Conversation

@samuelmbabhazi

@samuelmbabhazi samuelmbabhazi commented Nov 19, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #348. Raised by the security audit of 19 November (finding 7).

What changed

ConfirmationCommands.issue publishes confirmation.issued with resourceActor(context) instead of a hard-coded user actor: api_token with the token's id when an API token made the request, user otherwise. This is the convention every resource mutation already follows (applications, deployments, fleet). The confirmation itself is unchanged: it is still bound to the user behind the token (sub), who has to use it.

Why

An API token with organization.read and the action's permission can request a confirmation. The audit event then named only the user, so automation could not be told apart from a person in the browser at this step. Authorization and the confirmation check were not affected.

How it was tested

confirmation-http.integration.spec.ts, on a real PostgreSQL:

  • a confirmation requested over HTTP with a real API token (scopes organization.read and node.manage) records exactly one confirmation.issued with actorKind: 'api_token' and the token's id, keeps sub as the admin's id, and contains neither the API token nor the confirmation token;
  • the existing browser-session case now also checks actorKind: 'user'.

With the previous command, the token case fails on actorKind. Unit tests of the module, nx run api:lint and api:typecheck pass.

Security considerations

Audit attribution only: permission rechecks, the single-use confirmation and the transactional audit (a store failure fails the command) are unchanged.

Summary by CodeRabbit

  • Bug Fixes
    • Audit records for confirmations issued through API tokens now identify the token as the actor, while the confirmation remains associated with its user.
    • Audit records exclude API tokens and confirmation tokens.
    • Confirmation issuance by an administrator continues to record the administrator as the actor.

…oken

confirmation.issued always named the user as its actor, so a confirmation requested by an automation could not be told apart from one requested in the browser. It now uses resourceActor, as every resource mutation does: the API token when one made the request, the user otherwise. The confirmation stays bound to the user behind the token.

Closes #348

Signed-off-by: samuel mbabhazi <[email protected]>
@coderabbitai

coderabbitai Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

Explain Change →

Important

Review skipped

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

Run configuration

Commits

Reviewing files that changed from the base of the PR and between cec752a and 0cdbeff.

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 confirmation-issued audit event now records the actor derived from the request security context. Integration tests cover API-token attribution and administrator user attribution.

Changes: Confirmation audit attribution

Layer / File(s) Summary
Derive and verify the confirmation audit actor
apps/api/src/modules/confirmations/application/confirmation-commands.ts, apps/api/src/modules/confirmations/confirmation-http.integration.spec.ts
The command uses resourceActor(context) for the confirmation.issued event. Integration tests verify the API-token actor and ID, confirm the confirmation remains bound to the token’s user, check that credentials are not stored, and expect an administrator to be recorded as a user.

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

Change: Bug fix · Severity of issue fixed: Low

Suggested labels: track:control-plane

Merge Risk: Minimal · previous review cec75

Confirmation issuance audit events now attribute API-token requests to the token and keep user attribution for browser sessions. Authorization and the confirmation subject are unchanged. No merge-blocking risk was found.

Security architecture risk: Minimal · up to cec75

The change improves attribution of automated requests without expanding access or changing confirmation ownership. No introduced material security, failure-containment, or rollback risk was identified.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The changed effect is limited to audit attribution for already-authorized confirmation requests. Organization and resource scope, action permission, exact-name verification, and confirmation ownership remain independent of the selected audit actor; the change does not grant additional destructive authority.

Trust Boundaries and Controls

  • observed — The token actor identifier comes from the authenticated principal, not the request body. Before issuance, the command revalidates that the presented credential matches both the expected token and user, remains live, and permits the requested action and resource scope.

Resilience and Maintainability Implications

  • inferred — The existing account-lock transaction encloses issuance and synchronous audit persistence, so audit or signing failure propagates before commit. Repeated successful issuance creates distinct confirmations rather than introducing idempotent replay. Consumption still uses one conditional update matching user, organization, action, target, expiry, and unused state, preventing concurrent double consumption. The PR changes none of these transition rules.
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 change: confirmations issued with an API token are now attributed to that token instead of the user. The raw summary and objectives both describe this change to the audit actor in …
Linked Issues check Passed [#348] Requires the confirmation.issued event to use the resource actor convention, keep the API-token ID and user identity, cover browser and API-token requests, and keep permission rechecks and tran…
Out of Scope Changes check Passed The source change is limited to the confirmation.issued actor in ConfirmationCommands.issue and its import of resourceActor. The import also keeps the existing SecurityContext type alias. The test cha…
Full details: Title check

Explanation

The title names the change: confirmations issued with an API token are now attributed to that token instead of the user. The raw summary and objectives both describe this change to the audit actor in ConfirmationCommands.issue, and the title's fix(api) prefix matches the scope. The title is specific and does not overstate the change, since authorization and single-use behavior are unchanged.

Full details: Linked Issues check

Explanation

[#348] Requires the confirmation.issued event to use the resource actor convention, keep the API-token ID and user identity, cover browser and API-token requests, and keep permission rechecks and transactional audit failure behavior.

At head, ConfirmationCommands.issue publishes confirmation.issued with actor: resourceActor(context) (confirmation-commands.ts). resourceActor (identity/application/resource-security-context.ts) returns kind 'api_token' with id apiCredential.id when an API credential is present, otherwise kind 'user' with id userId, and it carries ip. This matches the previous hard-coded user actor for browser sessions, and it adds the token ID for API-token requests. The confirmation still stores userId (sub), so the user identity is preserved.

The diff changes only the actor expression and its import. The access.require call, the runTenant store insert, and the single-use token logic are unchanged. The event publish stays inside the same transactional flow as before.

Tests: the PR description states that confirmation-http.integration.spec.ts covers an API-token request (actorKind 'api_token', token ID, sub preserved, no raw token stored) and a browser-session request (actorKind 'user'). I did not inspect the test file. This verdict relies on the source change and the reported test coverage.

Full details: Out of Scope Changes check

Explanation

The source change is limited to the confirmation.issued actor in ConfirmationCommands.issue and its import of resourceActor. The import also keeps the existing SecurityContext type alias. The test changes cover the same audit actor behavior for browser-session and API-token requests. Authorization, permission rechecks, the single-use confirmation, and audit transaction behavior are not modified in the reviewed diff. All changes connect directly to #348.

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 71f34c8 and cec752a.

Files selected for processing: 2

  • apps/api/src/modules/confirmations/application/confirmation-commands.ts
  • apps/api/src/modules/confirmations/confirmation-http.integration.spec.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 3 remain after this review.

@samuelmbabhazi
samuelmbabhazi merged commit 40fb82b into main Nov 19, 2026
22 checks passed
@samuelmbabhazi
samuelmbabhazi deleted the fix/348-confirmation-token-actor branch November 19, 2026 15:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Preserve API-token attribution when issuing a confirmation token

1 participant