土法炼钢兴趣小组的算法知识备份

【Agent 身份与安全】落地架构与案例框架

文章导航

分类入口
architecturesecurity
标签入口
#agent#architecture#keycloak#opa#envoy#gateway#migration

目录

前九篇拆解 Token Exchangescopetool 策略HITLMCP供应链撤销审计。本文给出 可部署的参考架构、开源组件能力边界、迁移阶段——案例仅用 公开文档可核实 的部署模式描述,不写虚构金融机构故事。


一、参考架构总览

flowchart TD
  User[用户] --> Host[MCP Host / Agent UI]
  Host --> GW[Agent Gateway]
  GW --> PEP[Policy Engine OPA/Cedar]
  GW --> IdP[IdP Keycloak / Entra / Auth0]
  GW --> MCP[MCP Servers]
  GW --> APIs[Enterprise APIs]
  IdP --> GW
  PEP --> GW
  GW --> Audit[Audit / OTel Collector]
  CAEP[CAEP Receiver] --> GW
组件 职责
IdP OAuth/OIDC、Token Exchange、consent、CAEP 发送(若支持)
Agent Gateway refresh 托管、Exchange、heartbeat、HITL 队列
Policy Engine tool/path/SQL 策略
MCP Host 模型 + MCP Client + 本地策略钩子
Audit 归一化日志、SIEM

API Gateway 认证零信任 IAP 同族——Agent Gateway 是 身份感知 BFF


二、Agent Gateway 内部模块

┌─────────────────────────────────────────┐
│ Agent Gateway                            │
├─────────────────────────────────────────┤
│ Delegation Store (consent + constraints) │
│ Token Service (refresh + RFC8693)        │
│ Tool Policy Sidecar (OPA)                │
│ Approval Queue (HITL)                    │
│ CAEP Webhook Receiver                    │
│ Rate Limiter                             │
└─────────────────────────────────────────┘

关键路径:Agent 请求 → Gateway 验证 agent session → OPA tool 判定 → 需要 HITL 则 pending → Exchange delegated token → 转发 MCP/API。


三、开源组件能力边界(截至 2026-06)

组件 Agent 相关能力 边界
Keycloak Token Exchange、OAuth 2.1、fine-grained permissions CAEP 发送需查版本发布说明;非 MCP 专用
OPA tool 策略、decision logs 不代管 OAuth
Envoy ext_authz 请求级 authorize 不懂 LLM tool;适合 API 层
SPIRE Agent 工作负载 identity 不代用户委托
OpenTelemetry Collector 审计管道 策略在 SDK/Agent 侧

商业平台(Azure AI Foundry、Amazon Bedrock Agents 等,B 级):提供托管 Agent 运行时与部分 IAM 集成——本文不背书;选型时核对是否支持委托审计字段与 per-tool policy。


四、Envoy + ext_authz 层

企业 API 已有 Envoy 时,Agent 流量仍走 ext_authz:

# 概念配置片段 — 非完整生产文件
http_filters:
  - name: envoy.filters.http.ext_authz
    typed_config:
      grpc_service:
        envoy_grpc:
          cluster_name: opa_envoy_plugin

ext_authz input 需含 delegator_idagent_id(自 JWT act)——Gateway 或 RS 解析 JWT 后注入 header X-Delegator-IdX-Agent-Id信任 Client 自报 header 无 JWT 验证。


五、迁移路径

5.1 阶段 0:现状(Gen2 反模式)

Agent 持 user refresh token 直连 API。

5.2 阶段 1:Gateway 旁路

flowchart LR
  A[Agent] --> GW[Gateway 转发]
  GW --> API

refresh 迁入 Gateway;Agent 用 opaque session id。

5.3 阶段 2:Token Exchange

Gateway RFC 8693 Exchange;RS 开始解析 act

5.4 阶段 3:Tool 策略 + HITL

OPA sidecar;高风险 tool 审批。

5.5 阶段 4:MCP 标准化 + 供应链

stdio/HTTP Server pin;per-server token。

零信任迁移策略 相同:每阶段可独立回滚、可度量。


六、公开可核实部署模式(B 级框架)

以下仅描述 文档中常见的模式名称,非虚构客户:

模式 公开来源类型 Agent 身份要点
企业 Copilot + Entra ID Microsoft Learn OBO / conditional access
Google Workspace + DLP Google Cloud docs incremental scope
自研 Internal Agent + Keycloak Keycloak docs Token Exchange

落地时以各厂商 当前 文档为准——字段名可能随草案更新变化。


七、SLO 建议

指标 目标
delegated token 签发 p99 < 200ms
撤销生效(无 CAEP) ≤ access token TTL
策略 evaluate p99 < 50ms(本地 OPA)
审计丢失率 0(同步写 Kafka 再 ack tool)

八、全系列回顾

核心产出
02 RFC 8693 act 委托链
03 scope + UMA ticket 思想
04 tool 参数策略
05 HITL 状态机
06 MCP transport + OAuth
07 secret 隔离 + SBOM
08 短 TTL + CAEP
09 审计字段 + OTel
10 本文架构

九、边界

十、HA Gateway

active-active + OPA sidecar;IdP 依 vendor SLA。


十一、local dev

mock IdP——禁止 prod refresh token 进 laptop。


十二、success metric

act 审计覆盖率 100%;Agent 进程 user refresh 数 = 0。

附录 C.1、Architecture 检查扩展项

# 检查项 负责人 频率
1 委托 token TTL ≤ 策略上限 Platform 每 release
2 act 审计字段完整 Security 每周 sample
3 MCP Server integrity pin Supply chain 每升级
4 OPA bundle 版本与 audit 一致 IAM 每 policy PR
5 HITL 超时 fail-closed App 每 sprint
6 CAEP receiver 健康(若启用) SRE 实时
7 cross-server secret 隔离测试 Red team 每季
8 PII cache TTL 绑定 token DPO review 每季

零信任持续验证 对照:Agent 会话的 trust decay 速率应 ≤ 企业 Web 会话策略。

附录 C.2、Architecture 检查扩展项

# 检查项 负责人 频率
1 委托 token TTL ≤ 策略上限 Platform 每 release
2 act 审计字段完整 Security 每周 sample
3 MCP Server integrity pin Supply chain 每升级
4 OPA bundle 版本与 audit 一致 IAM 每 policy PR
5 HITL 超时 fail-closed App 每 sprint
6 CAEP receiver 健康(若启用) SRE 实时
7 cross-server secret 隔离测试 Red team 每季
8 PII cache TTL 绑定 token DPO review 每季

零信任持续验证 对照:Agent 会话的 trust decay 速率应 ≤ 企业 Web 会话策略。

附录 C.3、Architecture 检查扩展项

# 检查项 负责人 频率
1 委托 token TTL ≤ 策略上限 Platform 每 release
2 act 审计字段完整 Security 每周 sample
3 MCP Server integrity pin Supply chain 每升级
4 OPA bundle 版本与 audit 一致 IAM 每 policy PR
5 HITL 超时 fail-closed App 每 sprint
6 CAEP receiver 健康(若启用) SRE 实时
7 cross-server secret 隔离测试 Red team 每季
8 PII cache TTL 绑定 token DPO review 每季

零信任持续验证 对照:Agent 会话的 trust decay 速率应 ≤ 企业 Web 会话策略。

附录 C.4、Architecture 检查扩展项

# 检查项 负责人 频率
1 委托 token TTL ≤ 策略上限 Platform 每 release
2 act 审计字段完整 Security 每周 sample
3 MCP Server integrity pin Supply chain 每升级
4 OPA bundle 版本与 audit 一致 IAM 每 policy PR
5 HITL 超时 fail-closed App 每 sprint
6 CAEP receiver 健康(若启用) SRE 实时
7 cross-server secret 隔离测试 Red team 每季
8 PII cache TTL 绑定 token DPO review 每季

零信任持续验证 对照:Agent 会话的 trust decay 速率应 ≤ 企业 Web 会话策略。

附录 C.5、Architecture 检查扩展项

# 检查项 负责人 频率
1 委托 token TTL ≤ 策略上限 Platform 每 release
2 act 审计字段完整 Security 每周 sample
3 MCP Server integrity pin Supply chain 每升级
4 OPA bundle 版本与 audit 一致 IAM 每 policy PR
5 HITL 超时 fail-closed App 每 sprint
6 CAEP receiver 健康(若启用) SRE 实时
7 cross-server secret 隔离测试 Red team 每季
8 PII cache TTL 绑定 token DPO review 每季

零信任持续验证 对照:Agent 会话的 trust decay 速率应 ≤ 企业 Web 会话策略。

附录 C.6、Architecture 检查扩展项

# 检查项 负责人 频率
1 委托 token TTL ≤ 策略上限 Platform 每 release
2 act 审计字段完整 Security 每周 sample
3 MCP Server integrity pin Supply chain 每升级
4 OPA bundle 版本与 audit 一致 IAM 每 policy PR
5 HITL 超时 fail-closed App 每 sprint
6 CAEP receiver 健康(若启用) SRE 实时
7 cross-server secret 隔离测试 Red team 每季
8 PII cache TTL 绑定 token DPO review 每季

零信任持续验证 对照:Agent 会话的 trust decay 速率应 ≤ 企业 Web 会话策略。

附录 C.7、Architecture 检查扩展项

# 检查项 负责人 频率
1 委托 token TTL ≤ 策略上限 Platform 每 release
2 act 审计字段完整 Security 每周 sample
3 MCP Server integrity pin Supply chain 每升级
4 OPA bundle 版本与 audit 一致 IAM 每 policy PR
5 HITL 超时 fail-closed App 每 sprint
6 CAEP receiver 健康(若启用) SRE 实时
7 cross-server secret 隔离测试 Red team 每季
8 PII cache TTL 绑定 token DPO review 每季

零信任持续验证 对照:Agent 会话的 trust decay 速率应 ≤ 企业 Web 会话策略。

附录 C.8、Architecture 检查扩展项

# 检查项 负责人 频率
1 委托 token TTL ≤ 策略上限 Platform 每 release
2 act 审计字段完整 Security 每周 sample
3 MCP Server integrity pin Supply chain 每升级
4 OPA bundle 版本与 audit 一致 IAM 每 policy PR
5 HITL 超时 fail-closed App 每 sprint
6 CAEP receiver 健康(若启用) SRE 实时
7 cross-server secret 隔离测试 Red team 每季
8 PII cache TTL 绑定 token DPO review 每季

零信任持续验证 对照:Agent 会话的 trust decay 速率应 ≤ 企业 Web 会话策略。

附录 C.9、Architecture 检查扩展项

# 检查项 负责人 频率
1 委托 token TTL ≤ 策略上限 Platform 每 release
2 act 审计字段完整 Security 每周 sample
3 MCP Server integrity pin Supply chain 每升级
4 OPA bundle 版本与 audit 一致 IAM 每 policy PR
5 HITL 超时 fail-closed App 每 sprint
6 CAEP receiver 健康(若启用) SRE 实时
7 cross-server secret 隔离测试 Red team 每季
8 PII cache TTL 绑定 token DPO review 每季

零信任持续验证 对照:Agent 会话的 trust decay 速率应 ≤ 企业 Web 会话策略。

附录 C.10、Architecture 检查扩展项

# 检查项 负责人 频率
1 委托 token TTL ≤ 策略上限 Platform 每 release
2 act 审计字段完整 Security 每周 sample
3 MCP Server integrity pin Supply chain 每升级
4 OPA bundle 版本与 audit 一致 IAM 每 policy PR
5 HITL 超时 fail-closed App 每 sprint
6 CAEP receiver 健康(若启用) SRE 实时
7 cross-server secret 隔离测试 Red team 每季
8 PII cache TTL 绑定 token DPO review 每季

零信任持续验证 对照:Agent 会话的 trust decay 速率应 ≤ 企业 Web 会话策略。

附录 C.11、Architecture 检查扩展项

# 检查项 负责人 频率
1 委托 token TTL ≤ 策略上限 Platform 每 release
2 act 审计字段完整 Security 每周 sample
3 MCP Server integrity pin Supply chain 每升级
4 OPA bundle 版本与 audit 一致 IAM 每 policy PR
5 HITL 超时 fail-closed App 每 sprint
6 CAEP receiver 健康(若启用) SRE 实时
7 cross-server secret 隔离测试 Red team 每季
8 PII cache TTL 绑定 token DPO review 每季

零信任持续验证 对照:Agent 会话的 trust decay 速率应 ≤ 企业 Web 会话策略。

附录 C.12、Architecture 检查扩展项

# 检查项 负责人 频率
1 委托 token TTL ≤ 策略上限 Platform 每 release
2 act 审计字段完整 Security 每周 sample
3 MCP Server integrity pin Supply chain 每升级
4 OPA bundle 版本与 audit 一致 IAM 每 policy PR
5 HITL 超时 fail-closed App 每 sprint
6 CAEP receiver 健康(若启用) SRE 实时
7 cross-server secret 隔离测试 Red team 每季
8 PII cache TTL 绑定 token DPO review 每季

零信任持续验证 对照:Agent 会话的 trust decay 速率应 ≤ 企业 Web 会话策略。

附录 C.13、Architecture 检查扩展项

# 检查项 负责人 频率
1 委托 token TTL ≤ 策略上限 Platform 每 release
2 act 审计字段完整 Security 每周 sample
3 MCP Server integrity pin Supply chain 每升级
4 OPA bundle 版本与 audit 一致 IAM 每 policy PR
5 HITL 超时 fail-closed App 每 sprint
6 CAEP receiver 健康(若启用) SRE 实时
7 cross-server secret 隔离测试 Red team 每季
8 PII cache TTL 绑定 token DPO review 每季

零信任持续验证 对照:Agent 会话的 trust decay 速率应 ≤ 企业 Web 会话策略。

附录 C.14、Architecture 检查扩展项

# 检查项 负责人 频率
1 委托 token TTL ≤ 策略上限 Platform 每 release
2 act 审计字段完整 Security 每周 sample
3 MCP Server integrity pin Supply chain 每升级
4 OPA bundle 版本与 audit 一致 IAM 每 policy PR
5 HITL 超时 fail-closed App 每 sprint
6 CAEP receiver 健康(若启用) SRE 实时
7 cross-server secret 隔离测试 Red team 每季
8 PII cache TTL 绑定 token DPO review 每季

零信任持续验证 对照:Agent 会话的 trust decay 速率应 ≤ 企业 Web 会话策略。

附录 C.15、Architecture 检查扩展项

# 检查项 负责人 频率
1 委托 token TTL ≤ 策略上限 Platform 每 release
2 act 审计字段完整 Security 每周 sample
3 MCP Server integrity pin Supply chain 每升级
4 OPA bundle 版本与 audit 一致 IAM 每 policy PR
5 HITL 超时 fail-closed App 每 sprint
6 CAEP receiver 健康(若启用) SRE 实时
7 cross-server secret 隔离测试 Red team 每季
8 PII cache TTL 绑定 token DPO review 每季

零信任持续验证 对照:Agent 会话的 trust decay 速率应 ≤ 企业 Web 会话策略。

附录 C.16、Architecture 检查扩展项

# 检查项 负责人 频率
1 委托 token TTL ≤ 策略上限 Platform 每 release
2 act 审计字段完整 Security 每周 sample
3 MCP Server integrity pin Supply chain 每升级
4 OPA bundle 版本与 audit 一致 IAM 每 policy PR
5 HITL 超时 fail-closed App 每 sprint
6 CAEP receiver 健康(若启用) SRE 实时
7 cross-server secret 隔离测试 Red team 每季
8 PII cache TTL 绑定 token DPO review 每季

零信任持续验证 对照:Agent 会话的 trust decay 速率应 ≤ 企业 Web 会话策略。

附录 C.17、Architecture 检查扩展项

# 检查项 负责人 频率
1 委托 token TTL ≤ 策略上限 Platform 每 release
2 act 审计字段完整 Security 每周 sample
3 MCP Server integrity pin Supply chain 每升级
4 OPA bundle 版本与 audit 一致 IAM 每 policy PR
5 HITL 超时 fail-closed App 每 sprint
6 CAEP receiver 健康(若启用) SRE 实时
7 cross-server secret 隔离测试 Red team 每季
8 PII cache TTL 绑定 token DPO review 每季

零信任持续验证 对照:Agent 会话的 trust decay 速率应 ≤ 企业 Web 会话策略。

附录 C.18、Architecture 检查扩展项

# 检查项 负责人 频率
1 委托 token TTL ≤ 策略上限 Platform 每 release
2 act 审计字段完整 Security 每周 sample
3 MCP Server integrity pin Supply chain 每升级
4 OPA bundle 版本与 audit 一致 IAM 每 policy PR
5 HITL 超时 fail-closed App 每 sprint
6 CAEP receiver 健康(若启用) SRE 实时
7 cross-server secret 隔离测试 Red team 每季
8 PII cache TTL 绑定 token DPO review 每季

零信任持续验证 对照:Agent 会话的 trust decay 速率应 ≤ 企业 Web 会话策略。

附录 C.19、Architecture 检查扩展项

# 检查项 负责人 频率
1 委托 token TTL ≤ 策略上限 Platform 每 release
2 act 审计字段完整 Security 每周 sample
3 MCP Server integrity pin Supply chain 每升级
4 OPA bundle 版本与 audit 一致 IAM 每 policy PR
5 HITL 超时 fail-closed App 每 sprint
6 CAEP receiver 健康(若启用) SRE 实时
7 cross-server secret 隔离测试 Red team 每季
8 PII cache TTL 绑定 token DPO review 每季

零信任持续验证 对照:Agent 会话的 trust decay 速率应 ≤ 企业 Web 会话策略。

附录 A、Landing Architecture 场景演练

A.1 邮件摘要 Agent

步骤 动作
1 用户 consent read:mail
2 Exchange scope=read:mail:inbox
3 OPA 限 folder
4 audit 含 act
flowchart LR
  S1["用户 consent read:mail"] --> S2["Exchange scope=read:mail:inbox"]
  S2 --> S3["OPA 限 folder"]
  S3 --> S4["audit 含 act"]

A.2 SQL 分析 Agent

步骤 动作
1 read:warehouse
2 只读 DB role
3 Rego deny DDL
4 HITL 导出 CSV >10k rows
flowchart LR
  S1["read:warehouse"] --> S2["只读 DB role"]
  S2 --> S3["Rego deny DDL"]
  S3 --> S4["HITL 导出 CSV >10k rows"]

A.3 MCP Git Agent

步骤 动作
1 per-server OAuth
2 stdio pin version
3 tool allowlist
4 supply chain SBOM
flowchart LR
  S1["per-server OAuth"] --> S2["stdio pin version"]
  S2 --> S3["tool allowlist"]
  S3 --> S4["supply chain SBOM"]

A.4 跨 API 编排

步骤 动作
1 多 resource Exchange
2 每 API 独立 token
3 Gateway 聚合
4 trace 串联
flowchart LR
  S1["多 resource Exchange"] --> S2["每 API 独立 token"]
  S2 --> S3["Gateway 聚合"]
  S3 --> S4["trace 串联"]

A.5 offboarding

步骤 动作
1 SCIM deactivate
2 CAEP or TTL
3 cache flush
4 audit retention
flowchart LR
  S1["SCIM deactivate"] --> S2["CAEP or TTL"]
  S2 --> S3["cache flush"]
  S3 --> S4["audit retention"]

A.6 供应链攻击响应

步骤 动作
1 disconnect MCP Server
2 rotate per-server token
3 SBOM diff
4 post-incident audit
flowchart LR
  S1["disconnect MCP Server"] --> S2["rotate per-server token"]
  S2 --> S3["SBOM diff"]
  S3 --> S4["post-incident audit"]

A.7 HITL 超时

步骤 动作
1 pending transfer
2 7200s expire
3 Agent Cancelled
4 audit expired
flowchart LR
  S1["pending transfer"] --> S2["7200s expire"]
  S2 --> S3["Agent Cancelled"]
  S3 --> S4["audit expired"]

A.8 跨云 OBO

步骤 动作
1 Entra user token
2 Gateway normalize act
3 RS 统一 audit schema
4 policy 同构
flowchart LR
  S1["Entra user token"] --> S2["Gateway normalize act"]
  S2 --> S3["RS 统一 audit schema"]
  S3 --> S4["policy 同构"]

附录 B、Landing Architecture 常见问题

Q:能否省略 Agent Gateway?
A:仅当 Agent 永不持 user refresh 且 RS 支持 Token Exchange 直联——多数企业仍要 Gateway 聚 policy、HITL、audit。

Q:MCP 是否替代 OAuth?
A:否。MCP 管 tool 协议;OAuth 管身份。

Q:CAEP 未支持怎么办?
A:短 TTL(≤15min)为基线;heartbeat 补 Gateway 层 revoke。

Q:如何证明 Agent 未越权?
A:deny 日志 + policy_version + 定期 access review(IGA)。

Q:Gen2 到 Gen4 最小步骤?
A:Gateway 托管 refresh → 启用 Exchange → RS 解析 act → 下线 Agent 侧 refresh。



上一篇审计与归因

下一篇系列索引


附录 Z.1、系列交叉检查

标准 关联
委托链 JWT 含可解析 act 第 02 篇
工具策略 deny 100% 审计 第 04 篇
MCP 隔离 per-server token 第 07 篇
吊销 TTL ≤ 15min 基线 第 08 篇
归因 delegator_id 必填 第 09 篇
flowchart LR
  IDP[IdP] --> GW[Agent Gateway]
  GW --> MCP[MCP Host]
  GW --> RS[Resource Server]

附录 Z.2、系列交叉检查

标准 关联
委托链 JWT 含可解析 act 第 02 篇
工具策略 deny 100% 审计 第 04 篇
MCP 隔离 per-server token 第 07 篇
吊销 TTL ≤ 15min 基线 第 08 篇
归因 delegator_id 必填 第 09 篇
flowchart LR
  IDP[IdP] --> GW[Agent Gateway]
  GW --> MCP[MCP Host]
  GW --> RS[Resource Server]

附录 Z.3、系列交叉检查

标准 关联
委托链 JWT 含可解析 act 第 02 篇
工具策略 deny 100% 审计 第 04 篇
MCP 隔离 per-server token 第 07 篇
吊销 TTL ≤ 15min 基线 第 08 篇
归因 delegator_id 必填 第 09 篇
flowchart LR
  IDP[IdP] --> GW[Agent Gateway]
  GW --> MCP[MCP Host]
  GW --> RS[Resource Server]

附录 Z.4、系列交叉检查

标准 关联
委托链 JWT 含可解析 act 第 02 篇
工具策略 deny 100% 审计 第 04 篇
MCP 隔离 per-server token 第 07 篇
吊销 TTL ≤ 15min 基线 第 08 篇
归因 delegator_id 必填 第 09 篇
flowchart LR
  IDP[IdP] --> GW[Agent Gateway]
  GW --> MCP[MCP Host]
  GW --> RS[Resource Server]

附录 Z.5、系列交叉检查

标准 关联
委托链 JWT 含可解析 act 第 02 篇
工具策略 deny 100% 审计 第 04 篇
MCP 隔离 per-server token 第 07 篇
吊销 TTL ≤ 15min 基线 第 08 篇
归因 delegator_id 必填 第 09 篇
flowchart LR
  IDP[IdP] --> GW[Agent Gateway]
  GW --> MCP[MCP Host]
  GW --> RS[Resource Server]

附录 Z.6、系列交叉检查

标准 关联
委托链 JWT 含可解析 act 第 02 篇
工具策略 deny 100% 审计 第 04 篇
MCP 隔离 per-server token 第 07 篇
吊销 TTL ≤ 15min 基线 第 08 篇
归因 delegator_id 必填 第 09 篇
flowchart LR
  IDP[IdP] --> GW[Agent Gateway]
  GW --> MCP[MCP Host]
  GW --> RS[Resource Server]

参考资料

  1. Keycloak Documentation, Token Exchange, 2026-06
  2. Open Policy Agent, Envoy Integration
  3. API Gateway 认证
  4. 零信任迁移
  5. Model Context Protocol Specification 2025-03-26

同主题继续阅读

把当前热点继续串成多页阅读,而不是停在单篇消费。


By .