tenuo-ai/tenuo

GitHub: tenuo-ai/tenuo

Tenuo 是一款面向 AI Agent 的加密能力令牌引擎,通过任务级衰减委托和离线验证防止提示注入导致的越权操作。

Stars: 35 | Forks: 3

tenuo

AI Agent 的能力令牌。

CI Crates.io PyPI Docker Docs License

Tenuo 是一种用于 AI Agent 的加密授权原语。**把它想象成预付借记卡,而不是公司 Amex 卡**:短暂的、作用域限定的能力令牌,任务结束即过期。 一张 **warrant(授权令)** 是一个经过签名的令牌,指定了 Agent 可以调用哪些工具、在什么约束下以及持续多长时间。它绑定到一个加密密钥,在约 27μs 内完成离线验证,并具有单调作用域:委托只能缩小权限,永远不能扩大它。即使 Agent 遭受提示注入,warrant 的边界依然有效。 ``` # 使用 uv(推荐) uv pip install tenuo # 或标准 pip pip install tenuo ``` Open In Colab Explorer Docker Demo Blog ## 快速开始 ``` from tenuo import configure, SigningKey, mint_sync, guard, Capability, Pattern from tenuo.exceptions import AuthorizationDenied # 1. 一次性设置:生成密钥并配置 Tenuo configure(issuer_key=SigningKey.generate(), dev_mode=True, audit_log=False) # 2. 保护函数 —— 除非 warrant 允许,否则调用将被阻止 @guard(tool="send_email") def send_email(to: str) -> str: return f"Sent to {to}" # 3. 铸造一个仅允许发送至 @company.com 的 warrant with mint_sync(Capability("send_email", to=Pattern("*@company.com"))): print(send_email(to="alice@company.com")) # -> "Sent to alice@company.com" try: send_email(to="attacker@evil.com") except AuthorizationDenied: print("Blocked: attacker@evil.com") # -> "Blocked: attacker@evil.com" ``` Agent 可能遭受提示注入。授权层并不在意。Warrant 规定只能是 `*@company.com`。请求却说是 `attacker@evil.com`。**拒绝。** 当 `mint_sync` 代码块退出时,warrant 就消失了。无需清理,无需撤销——它直接过期。 ## 为什么选择 Tenuo? IAM 回答“你是谁?”Tenuo 回答“你现在能做什么?” | 问题 | Tenuo 的回答 | |---------|----------------| | 静态 IAM 角色寿命长于任务 | Warrant 随任务过期 (TTL) | | 权限宽泛,爆炸半径大 | 约束在每次委托时收窄 | | 令牌可能被窃取和重放 | 占有证明将 warrant 绑定到密钥 | | 中心化策略服务器增加延迟 | 离线验证,无网络调用 | ## 工作原理 Tenuo 实现了**减法委托**:链中的每一步只能减少权限,永远不能增加。 ``` ┌──────────────────┐ ┌──────────────────┐ ┌──────────────────┐ │ Control Plane │ │ Orchestrator │ │ Worker │ │ │ │ │ │ │ │ Issues root │────▶│ Attenuates │────▶│ Executes with │ │ warrant │ │ for task │ │ proof │ └──────────────────┘ └──────────────────┘ └──────────────────┘ Full scope --> Narrower --> Narrowest ``` 1. **控制平面** 发布具有广泛能力的根 warrant 2. **编排器** 针对特定任务对其进行削减(作用域只能缩小) 3. **Worker** 证明其拥有绑定的密钥并执行 4. **Warrant 过期** —— 无需清理 ## Tenuo 不是什么 - **不是沙箱** —— Tenuo 授权操作,但不隔离执行。请结合容器/沙箱/VM 进行纵深防御。 - **不是提示工程** —— 没有“请不要做坏事”的指令。这是加密强制执行,而非行为层面的。 - **不是 LLM 过滤器** —— 我们不解析模型输出。我们在执行时把关工具调用。 - **不是 IAM 的替代品** —— Tenuo *补充* IAM,在身份之上添加任务范围的、递减的能力。 ## 关键特性 | 特性 | 描述 | |---------|-------------| | **离线验证** | 无网络调用,约 27μs | | **持有者绑定** | 没有密钥,被盗令牌毫无用处 | | **语义约束** | [11 种约束类型](https://tenuo.ai/constraints),包括 `Subpath`、`UrlSafe`、`Shlex`、`CEL` —— 它们以目标系统的方式解析输入([为什么这很重要](https://niyikiza.com/posts/cve-2025-66032/)) | | **单调衰减** | 能力只能缩小,永不扩大 | | **框架集成** | OpenAI, Google ADK, CrewAI, Temporal, LangChain, LangGraph, FastAPI, MCP, A2A, AutoGen | ## 集成 **OpenAI** —— 带 streaming TOCTOU 防御的直接 API 保护 ``` from tenuo.openai import GuardBuilder, Subpath, UrlSafe, Shlex, Pattern client = (GuardBuilder(openai.OpenAI()) .allow("read_file", path=Subpath("/data")) # Path traversal protection .allow("fetch_url", url=UrlSafe()) # SSRF protection .allow("run_command", cmd=Shlex(allow=["ls"])) # Shell injection protection .allow("send_email", to=Pattern("*@company.com")) .build()) # Prompt injection -> send_email(to="attacker@evil.com") -> DENIED ``` **LangChain / LangGraph** ``` from tenuo.langchain import guard_tools from tenuo.langgraph import TenuoToolNode protected = guard_tools([search_tool, email_tool]) # LangChain graph.add_node("tools", TenuoToolNode([search, email])) # LangGraph ``` **MCP** —— Model Context Protocol 客户端和服务器验证 ``` from tenuo.mcp import SecureMCPClient, MCPVerifier # Client:自动将 warrant 证明注入 tool 参数 async with SecureMCPClient("python", ["server.py"]) as client: async with mint(Capability("read_file", path=Subpath("/data"))): result = await client.tools["read_file"](path="/data/file.txt") # Server:在执行前离线验证 tool 约束 verifier = MCPVerifier(...) @mcp.tool() async def read_file(path: str, **kwargs) -> str: clean = verifier.verify_or_raise("read_file", {"path": path, **kwargs}) return open(clean["path"]).read() ```
更多集成:Google ADK, CrewAI, A2A, Temporal, FastAPI **Google ADK** ``` from tenuo.google_adk import GuardBuilder from tenuo.constraints import Subpath, UrlSafe guard = (GuardBuilder() .allow("read_file", path=Subpath("/data")) .allow("web_search", url=UrlSafe(allow_domains=["*.google.com"])) .build()) agent = Agent(name="assistant", before_tool_callback=guard.before_tool) ``` **CrewAI** —— 具有基于能力授权的多 Agent Crew ``` from tenuo.crewai import GuardBuilder guard = (GuardBuilder() .allow("search", query=Pattern("*")) .allow("write_file", path=Subpath("/workspace")) .build()) crew = guard.protect(my_crew) # All agents get enforced constraints ``` **A2A (Agent-to-Agent)** —— 基于 Warrant 的 Agent 间委托 ``` from tenuo.a2a import A2AServerBuilder server = A2AServerBuilder().name("Search Agent").url("https://...").key(my_key).trust(orchestrator_key).build() @server.skill("search", constraints={"url": UrlSafe}) async def search(query: str, url: str) -> dict: return await do_search(query, url) client = A2AClient("https://...") warrant = await client.request_warrant(signing_key=worker_key, capabilities={"search": {}}) result = await client.send_task(skill="search", warrant=warrant, signing_key=worker_key) ``` **Temporal** —— 具有基于 warrant 活动授权的持久工作流 ``` from tenuo.temporal import AuthorizedWorkflow, TenuoInterceptor, TenuoInterceptorConfig @workflow.defn class MyWorkflow(AuthorizedWorkflow): @workflow.run async def run(self, path: str) -> str: return await self.execute_authorized_activity( read_file, args=[path], start_to_close_timeout=timedelta(seconds=30), ) ``` 查看完整的 Temporal 示例:[`authorized_workflow_demo.py`](tenuo-python/examples/temporal/authorized_workflow_demo.py) | [`multi_warrant.py`](tenuo-python/examples/temporal/multi_warrant.py) | [`delegation.py`](tenuo-python/examples/temporal/delegation.py) **FastAPI** —— 从 Header 提取 warrant,离线验证 PoP ``` @app.get("/search") async def search(query: str, ctx: SecurityContext = Depends(TenuoGuard("search"))): return {"results": do_search(query)} ``` **Kubernetes** —— 参见 [Kubernetes 指南](https://tenuo.ai/kubernetes)
## 文档 | 资源 | 描述 | |----------|-------------| | **[快速入门](https://tenuo.ai/quickstart)** | 5 分钟开始运行 | | **[概念](https://tenuo.ai/concepts)** | 为什么选择能力令牌? | | **[约束](https://tenuo.ai/constraints)** | 详解所有 11 种约束类型 | | **[安全](https://tenuo.ai/security)** | 威胁模型与保证 | | **[OpenAI](https://tenuo.ai/openai)** | 带 streaming 的直接 API 保护 | | **[Google ADK](https://tenuo.ai/google-adk)** | ADK Agent 工具保护 | | **[AutoGen](https://tenuo.ai/autogen)** | AgentChat 工具保护 | | **[A2A](https://tenuo.ai/a2a)** | Agent 间委托 | | **[FastAPI](https://tenuo.ai/fastapi)** | 零样板代码 API 保护 | | **[LangChain](https://tenuo.ai/langchain)** | 工具保护 | | **[LangGraph](https://tenuo.ai/langgraph)** | 多 Agent 图安全 | | **[CrewAI](https://tenuo.ai/crewai)** | 多 Agent Crew 保护 | | **[Temporal](https://tenuo.ai/temporal)** | 持久工作流授权 | | **[MCP](https://tenuo.ai/mcp)** | Model Context Protocol 客户端 + 服务器验证 | ## 系统要求 | 组件 | 支持情况 | |-----------|-----------| | **Python** | 3.9 – 3.14 | | **Node.js** | *计划 v0.2 推出* | | **OS** | Linux, macOS, Windows | | **Rust** | 不需要 (macOS, Linux, Windows 均提供二进制 wheel) | ### 可选依赖 ``` uv pip install tenuo # Core only uv pip install "tenuo[openai]" # + OpenAI Agents SDK uv pip install "tenuo[google_adk]" # + Google ADK uv pip install "tenuo[a2a]" # + A2A (inter-agent delegation) uv pip install "tenuo[fastapi]" # + FastAPI integration uv pip install "tenuo[langchain]" # + LangChain (langchain-core ≥0.2) uv pip install "tenuo[langgraph]" # + LangGraph (includes LangChain) uv pip install "tenuo[crewai]" # + CrewAI uv pip install "tenuo[temporal]" # + Temporal workflows uv pip install "tenuo[autogen]" # + AutoGen AgentChat (Python ≥3.10) uv pip install "tenuo[mcp]" # + MCP client & server verification (Python ≥3.10) ``` ## Docker 与 Kubernetes **尝试演示** —— 查看完整委托链的实际运作: ``` docker compose up ``` 这将运行 [orchestrator -> worker -> authorizer 演示](https://tenuo.ai/demo.html),展示 warrant 的发布、委托和验证。 **官方镜像** 位于 [Docker Hub](https://hub.docker.com/u/tenuo): ``` docker pull tenuo/authorizer:0.1.0-beta.11 # Sidecar for warrant verification docker pull tenuo/control:0.1.0-beta.11 # Control plane (demo/reference) ``` **Helm Chart**: ``` helm install tenuo-authorizer ./charts/tenuo-authorizer \ --set config.trustedRoots[0]="YOUR_CONTROL_PLANE_PUBLIC_KEY" ``` 参见 [Helm chart README](./charts/tenuo-authorizer) 和 [Kubernetes 指南](https://tenuo.ai/kubernetes)。 ## 路线图 | 功能 | 状态 | |---------|--------| | A2A 集成 | 已实现 (`tenuo[a2a]`) | | AutoGen 集成 | 已实现 (`tenuo[autogen]`) | | Google ADK 集成 | 已实现 (`tenuo[google_adk]`) | | MCP 集成 | 已实现 (`tenuo[mcp]`) | | Warrant 守卫 (人工审批) | 已实现 (实验性) | | 撤销 (SRL) | 开发中 | | TypeScript/Node SDK | 计划于 v0.2 | | 感知上下文的约束 | 规范开发中 | ## Rust 正在构建 Sidecar 或网关?直接使用核心库: ``` [dependencies] tenuo = "0.1.0-beta.11" ``` 参见 [docs.rs/tenuo](https://docs.rs/tenuo) 获取 Rust API。 ## 前期工作 Tenuo 建立在 [CaMeL](https://arxiv.org/abs/2503.18813) (Debenedetti et al., 2025) 中描述的能力令牌思想之上。受 [Macaroons](https://research.google/pubs/pub41892/)、[Biscuit](https://www.biscuitsec.org/) 和 [UCAN](https://ucan.xyz/) 启发。 参见 [相关工作](https://tenuo.ai/related-work) 了解详细对比。 ## 相关报道 - [TLDR InfoSec](https://tldr.tech/infosec/2026-01-13) - "The Map is not the Territory: The Agent-Tool Trust Boundary" - [TLDR InfoSec](https://tldr.tech/infosec/2025-12-15) - "Capabilities Are the Only Way to Secure Agent Delegation" - [Awesome Object Capabilities](https://github.com/dckc/awesome-ocap) - 能力安全资源精选列表 - [Awesome LangChain](https://github.com/kyrolabs/awesome-langchain) - [Awesome LLM Agent Security](https://github.com/wearetyomsmnv/Awesome-LLM-agent-Security) - [Awesome LLMSecOps](https://github.com/wearetyomsmnv/Awesome-LLMSecOps) ## 词源 **Tenuo** (/tɛn-ju-oʊ/ • *Ten-YOO-oh*) 源自拉丁语 *tenuare*:“使变薄;削弱。” 权限在根部是宽泛的,随着沿委托链向下流动而被**削弱**。 ## 贡献 欢迎贡献。参见 [CONTRIBUTING.md](CONTRIBUTING.md)。 ### TypeScript SDK (寻求帮助) 我们计划在 v0.2 推出 TypeScript/Node SDK。如果你有兴趣领导或为此项工作做出贡献,请提交 issue 或发送邮件至 [dev@tenuo.ai](mailto:dev@tenuo.ai)。 **安全问题**:请发送邮件至 security@tenuo.ai,并使用 PGP([密钥](./SECURITY_PUBKEY.asc)),请勿提交公开 issue。 ## 准备部署到生产环境? 自托管永远免费。如需具有可观察性和撤销管理功能的托管控制平面,请 [申请 Tenuo Cloud 的早期访问权限](https://tenuo.ai/pricing.html)。 ## 许可证 MIT OR Apache-2.0,任选其一。
标签:Capabilty-based Security, JSONLines, PE 加载器, Python, Rust, Streamlit, 云端原生, 人工智能代理, 令牌衰减, 任务范围授权, 可视化界面, 委托授权, 子域名突变, 密码学, 工具调用控制, 微服务安全, 手动系统调用, 授权框架, 提示词注入防御, 无后门, 最小权限原则, 权限管理, 模型越狱, 离线验证, 网络流量审计, 能力令牌, 访问控制, 请求拦截, 软件供应链安全, 远程方法调用, 逆向工具, 通知系统, 零信任