fix(audit): scope enterprise audit logs by org#1291
Open
Nav-Prak wants to merge 3 commits into
Open
Conversation
Stamp every audit row with the actor's organization (resolved from the database and cached per actor) and constrain the audit-log list and export queries to the caller's org, so a tenant admin cannot read another organization's audit trail. - Add org_id to the AuditableAction event and thread it through _make_row; resolve it from the actor in _buffer_row when unset, so all handlers get attributed without per-call-site changes. - Add an org_id filter to list_audit_logs and export_audit_logs. - Set org_id=None on mocked users in existing audit-log tests so they keep exercising the unscoped path unchanged. - Add tenant-scope regression tests for list/export scoping, row attribution, and resolver caching. Part of AUDIT2 tenant-scoping, split out of BlazeUp-AI#1184.
SCIM delete_user emits UserDeleted after the user row is deleted, so the _buffer_row fallback that resolves org_id from the actor finds nothing and the audit row lands with org_id="" -- hidden from the tenant's admins by the org-scoped query. Carry org_id on the UserDeleted event, captured in delete_user before the delete, and stamp it on the audit row (the handler now passes org_id=event.org_id, which short-circuits the actor lookup). Adds a regression test driving UserDeleted through the event bus and asserting the row keeps the event's org_id without a database lookup. Part of AUDIT2 tenant-scoping, split out of BlazeUp-AI#1184.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
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.
Purpose / Description
Scope enterprise audit-log reads to the caller's organization so a tenant admin cannot list or export another organization's audit trail.
This is part of the AUDIT2 tenant-scoping work and is split out from the closed broader tenant-scope PR #1184 to keep the audit change independently reviewable.
Fixes
Approach
This change stamps audit rows with an
org_idand filters audit-log list/export queries by the current admin's org.org_idto audit event flow where needed.org_idbefore deleting the user, since the row cannot be resolved after deletion.How Has This Been Tested?
Targeted audit tenant-scope tests:
Result: audit tenant-scope tests passed, including the SCIM user-deletion org preservation case.
Lint/format:
Also re-ran adjacent audit/events/HIPAA/SCIM suites as part of split verification; no regressions were found.
Checklist