Skip to main content

Firewall

Struct Firewall 

Source
pub struct Firewall { /* private fields */ }
Expand description

Firewall 主组件。持有 extractors / scorer / policy 引擎 / 审计账本 / PII scanner。

Implementations§

Source§

impl Firewall

Source

pub fn new( ledger: Arc<Ledger>, policy: PolicyEngine, config: FirewallConfig, ) -> Firewall

组装一个 Firewall:内置 7 个 extractor + 提供的 policy + scorer + 默认 DefaultScanner(见 Firewall::with_scanner 注入自定义)。

Source

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)。

Source

pub fn audit_persist_failures(&self) -> u64

返回 preflight audit 写失败累计(进程生命周期内)。0 = 一切正常。

R2 MUST-FIX 2:替代旧的 eprintln! 观测通道。测试可用以验证 audit 是否静默降级。

Source

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 导致静默绕过。

步骤(ADR 0003 §D3 + 方案 §3.3 + ADR 0004 §D8):

  1. 所有 extractor 合并产出 EffectVector
  2. 通过 DescriptorOracle 查询 descriptor 当前信任状态
  3. RiskScorer 打分 + reasons
  4. PolicyEngine 按规则评估,获得 PolicyDecision (FirewallConfig::allowed_scopes 自动合并到 PolicyContext.allowlists)
  5. 组装 DecisionRecord,调用 Ledger::record_decision 入账
  6. 若 Approve,create_approval 入 approvals 表(带 server/tool/args_hash 上下文)

Trait Implementations§

Source§

impl Debug for Firewall

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.