feat(opa): 链上撤销状态位读取落契约,未接入即 fail-closed 拒

- opa.rs 新增 RevocationViewSource{CallerSupplied,ChainRead} + ChainRevocationReader
  + UnconfiguredRevocationReader + resolve_revocation;decide 撤销来源二选一
- 链读后端未接入时声明 chain 必拒(REVOCATION_CHAIN_UNVERIFIED),
  绝不默认 revoked=false 放行;撤销仍 fail-closed 且无缓存
- CLI 支持 --revocation chain,输出区分 chain-read / 本地桩两种来源标注
- 第 17 条判据扩到 41 真闭环 + 22 零依赖,新增链读 fail-closed 负向
- CLAUDE.md / INTEGRATION_ANALYSIS.md / MEMORY.md 同步撤销来源与诚实边界
This commit is contained in:
admin committed 2026-11-07 19:58:18 +08:00
1 parent d6330862d9
commit ccf74fc3cd
7 files changed
+172 -26

No files matched your search

+26 -6
View File
@@ -19,7 +19,9 @@ use mpc_chain::admission::{chain_admit, MemberCache};
use mpc_chain::objects::{
object_digest, ChainObject, ComputeOrder, Member, PolicyBundleRecord, Receipt,
};
use mpc_chain::opa::{decide, sign_bundle, DecideRequest, OpaRunner};
use mpc_chain::opa::{
decide, sign_bundle, DecideRequest, OpaRunner, RevocationView, RevocationViewSource,
};
use mpc_chain::outbox::{EnqueueOutcome, Outbox};
use mpc_chain::policy::{governance_boundary, HardRuleSet, OpaPolicyBundle};
use mpc_chain::rpc::{ChainClient, HttpChainClient};
@@ -81,11 +83,13 @@ const CHAIN_USAGE: &str = "用法:
--bundle PATH --key PATH --id STR --issuer STR --expires N
--policy production-module|development-software --out PATH
mpc chain opa decide 验签 → 有效期/撤销 → 真 opa eval → decision 落 outbox
--bundle PATH --manifest PATH --input PATH --revocation PATH
--bundle PATH --manifest PATH --input PATH --revocation PATH|chain
--query STR --now N --outbox PATH --order-id STR
★ opa 只在宿主/控制面 spawn 外部二进制,**不在 guest 内执行**;
撤销视图由调用方每次显式给(链上状态位读取未落地);
撤销来源两种:--revocation PATH 给调用方本地桩,或 --revocation chain 声明
走链上撤销状态位读取(**链读后端未接入 ⇒ fail-closed 拒**,绝不默认
revoked=false 放行);
decision 只是 outbox 存证,不是已签名交易、也没有上链。
★ --transport 必须显式给:stub 只允许桩自测,tlcp 是生产路径。
@@ -650,10 +654,25 @@ fn cmd_opa_decide(args: &[String]) -> Result<(), String> {
// 缺 opa 二进制必须在这里明确报错,不许降级成「默认拒绝」蒙过去。
let runner = OpaRunner::resolve().map_err(|e| e.to_string())?;
let manifest_text = read(req(&o, "--manifest")?)?;
let revocation_text = read(req(&o, "--revocation")?)?;
// 撤销来源:显式 `--revocation chain` 声明走链上读取(当前后端未接入,
// decide 会 fail-closed 拒);否则必须是本地桩文件路径。缺参由 req 必填报错。
let revocation_arg = req(&o, "--revocation")?;
let revocation = if revocation_arg == "chain" {
RevocationViewSource::ChainRead
} else {
let text = read(revocation_arg)?;
RevocationViewSource::CallerSupplied(
RevocationView::from_json(&text).map_err(|e| e.to_string())?,
)
};
// 先取标注再移动(revocation 会被 move 进 DecideRequest)。
let rev_src_label = match &revocation {
RevocationViewSource::ChainRead => "chain-read",
RevocationViewSource::CallerSupplied(_) => "caller-supplied-local-view-not-chain-read",
};
let r = DecideRequest {
manifest_text: &manifest_text,
revocation_text: &revocation_text,
revocation,
bundle_path: Path::new(req(&o, "--bundle")?),
input_path: Path::new(req(&o, "--input")?),
query,
@@ -676,7 +695,7 @@ fn cmd_opa_decide(args: &[String]) -> Result<(), String> {
out.pop(); // 去掉结尾的 },补上本层的诚实标注字段
let bin = runner.binary.display().to_string();
println!(
"{},\"query\":\"{}\",\"outbox\":\"{}\",\"opaBinary\":\"{}\",\"opaInGuest\":false,\"revocationSource\":\"caller-supplied-local-view-not-chain-read\",\"chainRecorded\":false,\"decisionStoredAs\":\"outbox-pending-not-signed-tx\",\"warning\":\"{}\"}}",
"{},\"query\":\"{}\",\"outbox\":\"{}\",\"opaBinary\":\"{}\",\"opaInGuest\":false,\"revocationSource\":\"{}\",\"chainRecorded\":false,\"decisionStoredAs\":\"outbox-pending-not-signed-tx\",\"warning\":\"{}\"}}",
out,
esc(query),
match outcome {
@@ -684,6 +703,7 @@ fn cmd_opa_decide(args: &[String]) -> Result<(), String> {
EnqueueOutcome::AlreadyPresent => "already-present",
},
esc(&bin),
rev_src_label,
esc(OPA_HONESTY_WARNING)
);
Ok(())