(
policy: &RlsPolicy,
compiled: &RlsPredicate,
document: &serde_json::Value,
auth: &AuthContext,
tenant_id: u64,
collection: &str,
emitter: &dyn AuditEmitter,
)
| 92 | } |
| 93 | |
| 94 | fn check_compiled_write( |
| 95 | policy: &RlsPolicy, |
| 96 | compiled: &RlsPredicate, |
| 97 | document: &serde_json::Value, |
| 98 | auth: &AuthContext, |
| 99 | tenant_id: u64, |
| 100 | collection: &str, |
| 101 | emitter: &dyn AuditEmitter, |
| 102 | ) -> crate::Result<()> { |
| 103 | let filters = match substitute_to_scan_filters(compiled, auth) { |
| 104 | Some(f) => f, |
| 105 | None => { |
| 106 | info!( |
| 107 | policy = %policy.name, |
| 108 | username = %auth.username, |
| 109 | %collection, |
| 110 | "RLS write policy: unresolved $auth reference → denied" |
| 111 | ); |
| 112 | emitter.emit( |
| 113 | AuditEvent::RlsRejected, |
| 114 | &auth.username, |
| 115 | &format!( |
| 116 | "RLS policy '{}' on '{}': unresolved session variable", |
| 117 | policy.name, collection |
| 118 | ), |
| 119 | AuditEmitContext::new( |
| 120 | Some(crate::types::TenantId::new(tenant_id)), |
| 121 | &auth.id, |
| 122 | &auth.username, |
| 123 | ), |
| 124 | ); |
| 125 | return Err(crate::Error::RejectedAuthz { |
| 126 | tenant_id: crate::types::TenantId::new(tenant_id), |
| 127 | resource: format!( |
| 128 | "RLS policy '{}' on '{}': unresolved session variable", |
| 129 | policy.name, collection |
| 130 | ), |
| 131 | }); |
| 132 | } |
| 133 | }; |
| 134 | |
| 135 | let doc_mp = nodedb_types::json_to_msgpack_or_empty(document); |
| 136 | if !filters.iter().all(|f| f.matches_binary(&doc_mp)) { |
| 137 | info!( |
| 138 | policy = %policy.name, |
| 139 | username = %auth.username, |
| 140 | %collection, |
| 141 | "RLS write policy rejected (compiled)" |
| 142 | ); |
| 143 | emitter.emit( |
| 144 | AuditEvent::RlsRejected, |
| 145 | &auth.username, |
| 146 | &format!( |
| 147 | "RLS policy '{}' on collection '{}' rejected write", |
| 148 | policy.name, collection |
| 149 | ), |
| 150 | AuditEmitContext::new( |
| 151 | Some(crate::types::TenantId::new(tenant_id)), |
no test coverage detected