feat(server): enforce tenant boundary on all request-scoped lookups (6/7)#185
Draft
abhinav-galileo wants to merge 1 commit intoabhi/rfc-1-1-pr5-python-sdk-targetfrom
Draft
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
7bf2e63 to
11c4a6f
Compare
Adds services/tenant_scoped_lookups.py with helpers for Agent, Control, Policy, and Target that return 404 on cross-tenant access. Sweeps every lookup path in agents, controls, policies, evaluation, and target endpoints to use these helpers. initAgent now returns 409 with a non-disclosing message when Agent.name is taken by another tenant, since Agent.name is still globally unique at the schema level. New test_tenant_enforcement.py covers cross-tenant access negatives for every affected path plus a same-tenant sanity test.
11c4a6f to
55574c1
Compare
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.
Stacked on top of #183. Addresses review feedback that PR1-PR5 record `tenant_id` but do not enforce the tenant boundary on reads/writes, allowing cross-tenant access and cross-tenant data mixing in runtime evaluation.
What this PR enforces
Every request-scoped lookup of a tenant-owned row (`Agent`, `Control`, `Policy`, `Target`) goes through a helper in `services/tenant_scoped_lookups.py` that returns 404 on cross-tenant access. Affected paths:
initAgent special case
`Agent.name` is still globally unique at the schema level, so a callers in tenant B cannot create an agent with a name tenant A already owns. Before: this would upsert onto tenant A's row. After: 409 `AGENT_NAME_CONFLICT` with a generic "agent name is not available" message that does not disclose which tenant holds the name.
What is still out of scope
Test plan