Enforce per-object ACLs on semantic search results - #1345
Merged
Conversation
/search/semantic fetched candidate objects straight from Arango by id with no user/ACL check at all, so any authenticated caller could get back objects they have no READ permission on -- ChromaDB's nearest-neighbor lookup has no concept of ACLs, so filtering has to happen per-candidate at fetch time, the same way permission_on_target/permission_on_ids do for other endpoints (user.has_permissions(extended_id, Permission.READ)). Since ACL filtering happens after the similarity search, overfetch from Chroma when RBAC is enforced so dropped candidates don't shrink the result count below what was asked for -- not a guarantee, just a best-effort cushion; a user with narrow-enough visibility can still get fewer results than requested.
1 task
ChromaDB's PersistentClient caches its underlying connection per Python process (SharedSystemClient._identifier_to_system, a process-wide dict): the first PersistentClient(path=...) call in a process gets cached and reused for that process's lifetime, so a long-running process never sees writes made by a *different* process against the same on-disk files. The scheduled indexer runs in the celery worker; /search/semantic is served by the API process -- without clearing the cache, the API process would keep answering from whatever snapshot it had cached at its own startup, oblivious to anything indexed afterwards, until it restarts. Verified against a live index: querying from an already-running process missed a document written seconds earlier by a separate process, and clear_system_cache() fixed it with no measurable added latency. Also surfaces each result's similarity as an explicit `semantic_score` (1 - cosine distance, higher is better) instead of leaving relevance purely implicit in list order.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
POST /search/semanticfetched candidate objects straight from Arango by id (cls.get(meta["id"])) with zero user/ACL check -- any authenticated caller got back every nearest-neighbor match regardless of what they actually have READ permission on. Harmless while nothing called this endpoint from the product; not fine once an agent (with a restricted service account) starts using it as a tool.@global_permission-style decorator only checks a blanket "can this user read anything" flag, not whether this specific object is one they can see. Reuses the same primitive aspermission_on_target/permission_on_ids:user.has_permissions(extended_id, Permission.READ)(one ACL-graph traversal per candidate), samenot RBAC_ENABLED or user.adminbypass as everywhere else.Test plan
tests/core_tests/chromadb_test.pysuite converted from callingsemantic_search()directly to going through an authenticatedTestClient, since the endpoint now readshttpreq.state.user.test_semantic_search_respects_acls: two entities, ACL granted on only one, confirms the ungranted one never appears in results.test_semantic_search_admin_bypasses_acls: confirms an admin still sees everything regardless of ACLs (matches every other RBAC bypass in the codebase).unittestsuite (schemas,apiv2,core_tests) run locally -- no regressions (10 pre-existing failures are unrelated/opt/yeti/...permission issues in this sandbox).ruff check/format --checkandty checkclean on touched files.Companion
docker-compose.yamlchange (persistent volume for the chromadb path, previously wiped on every container recreate) is in yeti-docker, not this repo.