feat(presidio): derive id_salt per user_path
Follow-up to #1676 (proposal 1 of #1675), as announced there.
Problem. With one id_salt per installation the same value has the same {id} everywhere — a provider that sees several clients of one installation can correlate a person across all of them (in our case across every bot that goes through the gateway).
Change. New setting id_salt_scope: instance (the default, unchanged behaviour) or user_path. With user_path, each request's key is derived from id_salt and the request's user path — HKDF-Expand (RFC 5869), PRK = id_salt, info = label + path — so the same value has different IDs for different clients and the same ID within one, and a placeholder restores only for the client it was made for. A request without a user path (the master key) is a client of its own. The user path is the tenant boundary GoModel already has (bound to managed API keys), so no second secret per tenant is needed. Placeholders are built per exchange in Plugin.mapping, which now calls settings.idSaltFor(x.Meta.UserPath); format, restore, stream and tool-call arguments are untouched.
Switching the scope changes every ID, so placeholders from earlier requests stop resolving — documented, to be set before the first tenant goes live.
Tests. TestPlaceholderIDSaltScope (validation, derivation, instance ignores the path), TestHashedIDsPerUserPath (two clients on one plugin instance: different IDs for the same person, each restores its own, never the other's), and an e2e case with two X-GoModel-User-Path clients on one instance including a streamed restore and a streamed non-restore. Docs en + de.
Summary by CodeRabbit
- New Features
- Added an ID salt scope setting for Presidio. The default shares hashed IDs across clients; the optional user-path scope creates distinct IDs per user path while keeping them stable within that path. Requests without a user path use a separate scope.
- Bug Fixes
- Instances that allocate placeholders with mismatched scopes are rejected. Responses containing unresolved placeholders are not cached.
- Documentation
- Updated the Presidio guardrails documentation to explain scope options, placeholder ID behavior, and the impact of changing scopes, including that existing placeholders may no longer resolve.