pub struct Firewall { /* private fields */ }Expand description
Firewall 主组件。持有 extractors / scorer / policy 引擎 / 审计账本 / PII scanner。
Implementations§
Source§impl Firewall
impl Firewall
Sourcepub fn new(
ledger: Arc<Ledger>,
policy: PolicyEngine,
config: FirewallConfig,
) -> Firewall
pub fn new( ledger: Arc<Ledger>, policy: PolicyEngine, config: FirewallConfig, ) -> Firewall
组装一个 Firewall:内置 7 个 extractor + 提供的 policy + scorer + 默认
DefaultScanner(见 Firewall::with_scanner 注入自定义)。
Sourcepub fn with_scanner(
ledger: Arc<Ledger>,
policy: PolicyEngine,
config: FirewallConfig,
scanner: Arc<dyn PiiScanner>,
) -> Firewall
pub fn with_scanner( ledger: Arc<Ledger>, policy: PolicyEngine, config: FirewallConfig, scanner: Arc<dyn PiiScanner>, ) -> Firewall
ISS-010 R2 BLOCKER 2 修复:同 new,但接受自定义 scanner,主要供测试注入
FailingScanner 真触发 fail-closed 路径(见 tests/preflight.rs)。
Sourcepub fn audit_persist_failures(&self) -> u64
pub fn audit_persist_failures(&self) -> u64
返回 preflight audit 写失败累计(进程生命周期内)。0 = 一切正常。
R2 MUST-FIX 2:替代旧的 eprintln! 观测通道。测试可用以验证
audit 是否静默降级。
Sourcepub fn evaluate(
&self,
call: &ToolInvocation,
oracle: &dyn DescriptorOracle,
scope_ctx: OAuthScopeContext,
) -> Result<FirewallOutcome, FirewallError>
pub fn evaluate( &self, call: &ToolInvocation, oracle: &dyn DescriptorOracle, scope_ctx: OAuthScopeContext, ) -> Result<FirewallOutcome, FirewallError>
评估一次 tool call。I10c-β2 R3 统一签名:OAuth 上下文由 OAuthScopeContext
必填参数显式传入,防止 HTTP MCP 集成点漏配 scope 导致静默绕过。
- 本地工具 / stdio MCP:传
OAuthScopeContext::NonOauth - HTTP MCP + OAuth access token:传
OAuthScopeContext::Scopes(scope 集合来自vigil_http_auth::ResolvedAccessToken::scope_set; 空 scope 也必须显式Scopes(vec![]),触发 fail-closed)
步骤(ADR 0003 §D3 + 方案 §3.3 + ADR 0004 §D8):
- 所有 extractor 合并产出
EffectVector - 通过
DescriptorOracle查询 descriptor 当前信任状态 RiskScorer打分 + reasonsPolicyEngine按规则评估,获得PolicyDecision(FirewallConfig::allowed_scopes自动合并到PolicyContext.allowlists)- 组装
DecisionRecord,调用Ledger::record_decision入账 - 若 Approve,
create_approval入 approvals 表(带 server/tool/args_hash 上下文)
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for Firewall
impl !UnwindSafe for Firewall
impl Freeze for Firewall
impl Send for Firewall
impl Sync for Firewall
impl Unpin for Firewall
impl UnsafeUnpin for Firewall
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more