返回 Papers
AI 底层逻辑 / 经典论文

Zanzibar / Cedar / OPA:授权与 Policy Architecture

一句话:

381ai-foundations/papers/38-zanzibar-cedar-opa-authorization-policy-architecture.md

Zanzibar / Cedar / OPA 授权与 Policy Architecture 解读

面向对象: AI Architect / Enterprise Architect / Platform PM / Security Architect / Regulated AI Product Owner。 核心问题: AI Agent 和企业 AI 平台为什么不能只靠 prompt 控制权限?Zanzibar、Cedar、OPA 代表的授权与策略架构如何成为 AI runtime 的安全底座? 学习目标: 理解 ReBAC、ABAC、RBAC、policy-as-code、PDP/PEP、externalized authorization,并映射到 RAG 权限过滤、Agent 工具调用、客户数据访问、金融零售审批和审计。


Source Anchors

SourceLink用途
Zanzibar paperhttps://research.google/pubs/zanzibar-googles-consistent-global-authorization-system/理解大规模一致性授权和关系型访问控制
Cedar docshttps://docs.cedarpolicy.com/理解专门用于应用授权的 policy language 和 ABAC/RBAC 组合
Open Policy Agent docshttps://openpolicyagent.org/docs理解通用 policy-as-code 和 externalized policy decision
OPA policy languagehttps://openpolicyagent.org/docs/policy-language理解 Rego 规则语言的输入、数据和决策模型
NIST AI RMFhttps://www.nist.gov/itl/ai-risk-management-framework把授权、策略和控制纳入 AI 风险治理

一句话:

AI runtime 的权限边界必须由可测试、可审计、可版本化的 policy system 执行,而不是由模型自觉遵守。


1. 为什么 AI 让授权架构重新重要

传统应用里,用户点击按钮,后端检查权限。AI Agent 时代,模型可能:

  • 读取文档。
  • 查询 CRM。
  • 调用支付工具。
  • 修改 case。
  • 发送邮件。
  • 生成信贷 memo。
  • 建议客服话术。
  • 触发工作流。

如果权限只写在 prompt 里,问题会很快出现:

  • Prompt injection 诱导模型越权。
  • RAG 检索到用户不该看到的文档。
  • Agent 工具 schema 暴露了敏感字段。
  • 客户 facing AI 泄露内部政策或他人数据。
  • 员工 copilot 继承了过宽系统权限。
  • 审计无法证明某次工具调用为什么被允许。

所以 AI 平台需要外部化授权:

AI / app requests action
  -> Policy Enforcement Point
  -> Policy Decision Point
  -> allow / deny / require approval / filter
  -> audit log

2. RBAC / ABAC / ReBAC

模型核心问题适合局限
RBAC用户是什么角色员工系统、基础权限角色爆炸,缺少上下文
ABAC属性是否满足条件风险、地域、时间、数据分类属性治理复杂
ReBAC主体和资源有什么关系文档共享、组织结构、客户-顾问关系关系图和一致性复杂

AI 场景通常需要组合:

allow if
  user role permits
  and user/customer/resource relationship permits
  and action risk tier permits
  and data sensitivity permits
  and purpose/consent permits
  and runtime context permits

例子:

  • 客服可以读取自己队列客户的公开产品资料,但不能读取财富高净值客户敏感投资记录。
  • AML analyst 可以读取分配案件证据,但不能让 customer-facing AI 输出内部 SAR 判断。
  • Agent 可以草拟邮件,但金额变更、拒贷、账户冻结必须人工审批。

3. Zanzibar: 关系型授权

Zanzibar 的产品直觉:

权限可以表达为用户、对象、关系之间的图,并在大规模系统中一致地判断“这个主体能否对这个对象做这个动作”。

简化模型:

document:123#viewer@user:alice
folder:finance#editor@group:risk-team
case:456#assignee@user:bob
customer:789#relationship_manager@user:claire

AI 映射:

AI 能力ReBAC 价值
RAG 权限过滤只召回用户有关系权限的文档
Case copilot只读取被分配案件和相关证据
Customer 360 assistant依据客户-员工关系过滤字段
Multi-agent handoff代理之间共享上下文前检查关系
Knowledge graph区分事实关系和访问关系

关键架构点:

  • 授权要在检索前执行,不能等 LLM 生成后再遮盖。
  • RAG index 需要携带 ACL/relationship metadata。
  • 权限变更要能快速影响检索和工具调用。
  • 审计要记录 subject、object、relation、action、policy version。

4. Cedar: 应用授权策略

Cedar 的定位适合表达应用级授权政策:

principal can action on resource when context satisfies conditions

适合 AI 的原因:

  • 可以把权限从应用代码和 prompt 中抽出来。
  • 可表达 principal、action、resource、context。
  • 支持策略版本、测试和审计。
  • 适合细粒度应用授权和多租户 SaaS。

AI Agent 工具调用示例:

principal: employee or agent acting on behalf of employee
action: read_customer_profile / draft_email / submit_payment_adjustment
resource: customer/account/case/tool
context: channel, risk_tier, consent, queue_assignment, confidence, human_approved

高级设计:

  • Agent 不是超级用户,必须有 delegated authority。
  • “代表某人执行”要记录 actor、subject、delegation、tool、purpose。
  • 高风险 action 可以返回 require_approval,不是只有 allow/deny。
  • 策略要覆盖 read、retrieve、summarize、recommend、draft、execute 不同动作级别。

5. OPA / Rego: Policy-as-Code

OPA 的核心价值:

把策略决策从应用中外部化,用统一 policy engine 对输入和数据做决策。

AI 平台中可用于:

  • Tool gateway authorization。
  • RAG retrieval filter。
  • Model routing policy。
  • Data loss prevention decision。
  • Prompt/response policy。
  • Deployment release gate。
  • Kubernetes / infrastructure policy。
  • API access control。

PDP/PEP 架构:

Application / Agent / Gateway
  -> PEP builds input
  -> PDP evaluates policy + data
  -> decision
  -> PEP enforces
  -> audit trace

Policy input 示例:

{
  "actor": "employee_123",
  "acting_as": "agent_session_456",
  "action": "call_tool:update_customer_address",
  "resource": "customer_789",
  "context": {
    "channel": "internal_copilot",
    "risk_tier": "medium",
    "customer_consent": true,
    "human_approved": false,
    "case_assigned": true
  }
}

决策不一定只是 allow/deny:

  • allow。
  • deny。
  • mask。
  • require human approval。
  • require step-up auth。
  • allow read-only。
  • allow draft only。
  • log and monitor。
  • kill switch。

6. AI Runtime Policy Architecture

User / Agent Session
  -> Identity and delegation service
  -> Context builder
  -> Policy Enforcement Point
  -> Policy Decision Point
       -> role data
       -> relationship graph
       -> resource metadata
       -> consent / purpose
       -> risk tier
       -> policy version
  -> tool / retrieval / model / workflow
  -> audit log and evidence store

6.1 RAG 权限过滤

错误方式:

retrieve all -> send to model -> ask model not to reveal unauthorized content

正确方式:

query
  -> subject/resource policy check
  -> retrieve only authorized chunks
  -> generate answer with citations
  -> output policy check

6.2 Tool Gateway

工具不是函数列表,而是受控能力:

Tool actionRisk tierPolicy
read_policylowallow if employee authenticated
read_customer_profilemediumallow if assigned relationship and purpose valid
draft_emailmediumallow draft, require human send
update_addresshighrequire approval and customer verification
freeze_accountcriticalblock for AI, human workflow only

6.3 Decision Service

Policy engine 可以作为 decision service 的一部分:

model recommends action
  -> policy engine checks eligibility and authority
  -> decision service chooses allow / review / deny
  -> workflow records evidence

7. Policy Testing 与治理

Policy-as-code 必须像代码一样测试:

测试类型例子
Unit policy test某角色是否能读取某资源
Negative test未分配员工不能看客户记录
Regression test新政策不破坏已有低风险流程
Red-team testprompt injection 不能绕过工具权限
Permission boundary testRAG 不召回未授权 chunk
Segregation of duties同一人不能创建并批准高风险动作
Break-glass test紧急访问必须记录和过期
Policy simulation上线前计算会影响多少用户/流程

治理产物:

  • Policy inventory。
  • Decision rights map。
  • PDP/PEP architecture。
  • Policy test suite。
  • Approval workflow。
  • Change log。
  • Simulation report。
  • Exception register。
  • Audit evidence pack。

8. 金融零售案例

8.1 客服 Copilot

权限:

  • 可读公开产品信息。
  • 可读当前会话客户的基础资料。
  • 不可读无关客户。
  • 只能草拟回复,不能自动发送高风险承诺。

控制:

  • RAG 前置权限过滤。
  • 客户敏感字段 masking。
  • 高风险话术触发人工审批。
  • 记录引用、策略版本、用户确认。

8.2 信贷 Copilot

权限:

  • 贷审人员可读申请材料和政策。
  • Agent 可检查缺失字段和草拟 memo。
  • Agent 不得做最终拒贷决定。

控制:

  • adverse action reason 由正式决策系统产生。
  • AI 可解释政策,但不能创造新政策。
  • 所有输出进入 case record。

8.3 AML / Fraud

权限:

  • Analyst 只能访问分配案件。
  • 高敏感调查结论不能暴露给客服或客户-facing AI。
  • 外部数据和内部 typology 有不同访问等级。

控制:

  • ReBAC based case assignment。
  • tool action risk tier。
  • break-glass emergency access。
  • audit review。

9. 面试表达

30 秒版本

AI Agent 的权限不能靠 prompt。Prompt 是行为引导,不是安全边界。我会用 PDP/PEP、policy-as-code、关系型授权、属性授权和审计日志来控制 RAG 检索、工具调用、数据访问和高风险动作。Zanzibar 提供关系授权思路,Cedar 适合应用级授权策略,OPA 适合通用 policy decision 和平台治理。

2 分钟版本

我会把 AI runtime 的每次检索和工具调用都看成授权请求。PEP 在 agent gateway、retrieval service 或 application backend 中构造输入,PDP 根据用户身份、代理委托、资源关系、动作风险、客户同意、数据分类、policy version 和上下文返回 allow、deny、mask 或 require approval。RAG 权限必须在检索前执行,不能把未授权内容交给模型后再要求它不要泄露。工具调用也要按 read、draft、recommend、execute 分层,高风险动作必须进入人工审批或直接禁止。策略要有测试、模拟、变更审批和审计证据。

架构师版本

AI policy architecture 是 identity、relationship graph、attribute store、policy engine、tool gateway、retrieval filter、decision service 和 audit evidence 的组合。它把治理从文档变成 runtime control,是 regulated AI 能进入生产的前提。


10. 作品集任务

选择一个 AI Agent 场景,产出:

  1. PDP/PEP 架构图。
  2. 10 条 tool action risk tier。
  3. RBAC + ABAC + ReBAC 权限矩阵。
  4. RAG permission filtering 设计。
  5. 15 条 policy tests。
  6. Policy change approval workflow。
  7. Audit evidence schema。
  8. 一页 incident drill: prompt injection 试图越权调用工具时如何拦截、记录和复盘。