fix(data-access): reject subjects outside the caller's org
Writes and deletes of relationships now refuse any subject that is not a member of the caller's own organisation. The subject must carry the organisation origin and an origin_id equal to the token's, compared as text. Anything else is PERMISSION_DENIED before authorization runs, so the org-owner shortcut never sees it.
Until now the write path decided only from the object and the caller. Validation parsed object and role ids, authorization let an org owner through unconditionally, and storage minted a principal for whatever identity the request named. Nothing looked at the subject. The one place that did bind a subject to the token was the self-or-owner lookup; this change applies the same rule to writes and deletes.
That gap mattered because a relationship row has no organisation of its own. Objects are bare UUIDs, and the only thing tying a grant to an org is its subject's origin_id. So the owner of org X could send:
subject: { origin: ORIGIN_ORGANIZATION, origin_id: <org Y>, local_id: "5" }
object: { id: <any object uuid> }
role: { id: <artifact_admin> }Validation passed because the object and role were well formed. Authorization passed because the caller owned some org. The grant was stored, user 5 of org Y gained the role, and org Y's audit showed it as one of their own. The same shape on delete removed another org's grants.
This closes the subject side only. An owner can still name an object UUID that belongs to another org, because the service stores no resource hierarchy. That half waits on the hierarchy work already noted next to the ancestor trust note in the relationships API doc.
Found as finding 1 of the internal security review of 2026-10-12. The API doc is updated in the same MR.