Skip to main content

0009: Every request, message and job runs as an explicit caller; no caller means no access

Status: Accepted ยท Date: 2026-10-13

Contextโ€‹

Entity isolation is enforced in one place, EntityGuard, through ICallerContext.CanAccessEntity. The HTTP implementation treated "no HTTP user" as a trusted internal call, so every message consumer and job could act on every entity. That was true by accident: anyone able to publish to the broker could act on any entity, and a new background path (or a bug that dropped the user) would silently get full access. Audit rows had no caller outside HTTP, and integrations:admin also granted every entity, so an admin token meant for configuration could read every document.

Decisionโ€‹

  • An ambient CallerScope (an AsyncLocal, so it reaches nested scopes and audit writes) names the caller for work outside a request:
    • message consumers run as their publisher (MessageCallerFilter, the outermost consume filter). With Messaging:Publishers configured, the publisher is the AMQP user_id, which RabbitMQ verifies, and its entities come from configuration. Without it, every message is trusted for every entity, as before;
    • scheduled jobs run as the system (JobRunner), system:<job>;
    • HTTP requests use the token, with CallerScope only recording the entity for audit.
  • No caller means no entity access. HttpCallerContext denies when there is neither a scope nor a signed-in user.
  • integrations:admin implies every operation scope but not entity access.
  • The caller is recorded everywhere: created_by / modified_by columns, the append-only admin_audit table for money and configuration changes (same transaction as the change), and provider_call_audit (now with the entity).

Consequencesโ€‹

  • A new background path must begin a CallerScope (tests that call services directly do the same), or it fails closed with 403 entity_forbidden / _error.
  • Enabling publisher trust needs one broker user per publishing service, each setting user_id (see the runbook). Redeliveries keep the original publisher: our own broker user carries it in Integrations-Publisher, a header trusted only on messages from that user.
  • Admin tokens that also need data must ask for entities:all or entity claims: a breaking change, in the CHANGELOG.
  • The ambient scope is invisible in method signatures. The alternative, passing a caller through every service call, touched every Application method for the same result.