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
fix(api): attribute a confirmation issued with an API token to that token - #358
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]>
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.
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: 4
Check name
Status
Explanation
Description Check
Check skipped - CodeRabbit’s high-level summary is enabled.
Title check
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
[#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
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
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 3 remain after this review.
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 #348. Raised by the security audit of 19 November (finding 7).
What changed
ConfirmationCommands.issuepublishesconfirmation.issuedwithresourceActor(context)instead of a hard-coded user actor:api_tokenwith the token's id when an API token made the request,userotherwise. 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.readand 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:organization.readandnode.manage) records exactly oneconfirmation.issuedwithactorKind: 'api_token'and the token's id, keepssubas the admin's id, and contains neither the API token nor the confirmation token;actorKind: 'user'.With the previous command, the token case fails on
actorKind. Unit tests of the module,nx run api:lintandapi:typecheckpass.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