systemprompt_security/authz/audit/
mod.rs1mod db_sink;
18mod repository;
19
20use async_trait::async_trait;
21
22use super::types::{AuthzDecision, AuthzRequest};
23
24pub use db_sink::DbAuditSink;
25pub use repository::{
26 AUDIT_WRITE_FAILED_TOTAL, GovernanceDecisionRecord, GovernanceDecisionRepository,
27 insert_governance_decision,
28};
29
30#[derive(Debug, Clone, Copy, PartialEq, Eq)]
31pub enum AuthzSource {
32 WebhookFault,
33 DenyAllDefault,
34 AllowAllUnrestricted,
35 ExtensionHook,
36 RuleBased,
37}
38
39impl AuthzSource {
40 pub const fn policy(self) -> &'static str {
41 match self {
42 Self::WebhookFault => "authz_hook_fault",
43 Self::DenyAllDefault => "authz_default_deny",
44 Self::AllowAllUnrestricted => "authz_unrestricted",
45 Self::ExtensionHook => "authz_extension_hook",
46 Self::RuleBased => "authz_rule_based",
47 }
48 }
49}
50
51#[async_trait]
55pub trait AuthzAuditSink: Send + Sync + std::fmt::Debug {
56 async fn record(&self, req: &AuthzRequest, decision: &AuthzDecision, source: AuthzSource);
57}
58
59#[derive(Debug, Default, Clone, Copy)]
60pub struct NullAuditSink;
61
62#[async_trait]
63impl AuthzAuditSink for NullAuditSink {
64 async fn record(&self, _req: &AuthzRequest, _decision: &AuthzDecision, _source: AuthzSource) {}
65}