feat(authz): server-side @owner injection and audit-column auto-fill#63
Merged
Merged
Conversation
The Cedar @owner policy decides per-record access by comparing resource.<owner_field> == principal.id, but the create_entity handler never populated the owner field server-side. A client POSTing {"created_by": "user:victim"} would plant a row under the victim's id — impersonation, denial of access to the actual creator, or both. Strip-on- update was likewise missing: a passing record-level can_modify check could be followed by a write that quietly transferred ownership. This change: - inject_owner_on_create force-sets the @owner field to the principal's id (stripped to match Cedar's principal.id attribute shape) on every create. Any client-supplied value is overwritten. - strip_owner_on_update drops the @owner field from any PUT/PATCH body so ownership is immutable post-create. - inject_audit_columns_on_create / _on_update auto-fill conventional created_by / updated_by / created_at / updated_at columns when the schema declares them. Closes the WebhookSubscription.created_by drift reported in the audit and gives every operator schema a free, spoof-proof audit trail without per-handler wiring. Wired into routes/entities.rs at create_entity (owner + create audit columns), update_entity (strip owner + update audit columns), and patch_entity (same as update). 11 new unit tests cover the helpers plus the impersonation regression specifically. Third of four PRs from the production-audit gap review. D (Cedar engine audit emission) is next.
3 tasks
rrrodzilla
added a commit
that referenced
this pull request
May 26, 2026
Release rolling up the production-audit gap PRs (#61, #62, #63, #64). BREAKING (pre-1.0 minor): schema-forge-backend 0.11 → 0.12 AuthStore trait gains required `record_login(username, at)` method. Downstream impls must add it. schema-forge-acton 0.30 → 0.31 DynAuthStore trait gains required `record_login` shim. `access::filter_entity_fields` now returns `Vec<String>` (dropped field names) instead of `()`. Callers binding the return value must update.
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
owner_write/owner_restrictpolicies decide per-record access by comparingresource.<owner_field> == principal.id, butcreate_entitynever populated the owner field server-side. A caller posting{"created_by": "user:victim"}would plant a row under the victim's id.inject_owner_on_createforce-sets@ownerto the principal id (stripped to match Cedar'sprincipal.idattribute shape) and overwrites any client value.strip_owner_on_updatedrops the@ownerfield from PUT / PATCH bodies so ownership is immutable post-create. Without this, a passingcan_modifycheck could be followed by a write that quietly handed the record to another user.inject_audit_columns_on_create/_on_updatefillcreated_by/created_at/updated_by/updated_atwhen the schema declares them. Closes theWebhookSubscription.created_bydrift from the audit report and gives every operator schema a free, spoof-proof audit trail without per-handler wiring.Third of four PRs from the production-audit gap review. Follows #61 / #62. PR-D (Cedar engine deny audit) is up next.
Test plan
cargo nextest run --workspace --features schema-forge-acton/surrealdb— 1680 passedcargo clippy --workspace --features schema-forge-acton/surrealdb --all-targets— cleaninject_owner_on_create_*(4),strip_owner_on_update_*(2),inject_audit_columns_*(4), incl. the spoof regression