Security and tenant context
Authentication, product authorization and tenant isolation are distinct. Core service calls currently assume that their caller has already checked membership and the permission to perform the operation on the selected resources. Do not treat an input tenant or resource ID as authorization.
The caller establishes TenantContext.with(tenant_id) only after authorization.
It opens a transaction and sets the PostgreSQL tenant context for that
transaction; nested contexts and entering it with an open transaction are
rejected. It must also be established deliberately for jobs. Database RLS is a
separate defense against cross-tenant access, not a substitute for checking
membership or product permissions.
For example, after a trusted product boundary has resolved and authorized the integer IDs:
entries = TenantContext.with(authorized_tenant_id) do Core::RecipientSelection.call( tenant_id: authorized_tenant_id, resource_ids: authorized_resource_ids )endThis is an internal Ruby example, not a complete authentication or permission flow. It returns names and phone numbers; avoid logging or exposing the result to unauthorized users. Never put real personal data in tests or documentation. See tenant isolation ADR and database role ADR for proposed architecture.