agent-auth-broker 0.0.8 → 0.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +310 -310
  2. package/dist/index.js +1 -1
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -1,129 +1,129 @@
1
1
  # Agent Auth Broker
2
2
 
3
- [English](README.en.md)
3
+ [中文](README-zh.md)
4
4
 
5
- AI Agent 集中式凭证管理与授权代理服务。Agent 不直接持有任何 API Key OAuth Token,而是通过 Broker 发起调用,Broker 负责权限校验、凭证注入、执行代理和审计日志。
5
+ A centralized credential management and authorization proxy for AI Agents. Agents never hold any API keys or OAuth tokens directly. Instead, they call the Broker, which handles permission enforcement, credential injection, execution, and audit logging.
6
6
 
7
7
  ---
8
8
 
9
- ## 架构概览
9
+ ## Architecture
10
10
 
11
11
  ```
12
- AgentClaude / OpenClaw 等)
12
+ AI Agent (Claude / OpenClaw / etc.)
13
13
  |
14
14
  | broker_call(connector, action, params)
15
15
  v
16
16
  MCP Server
17
17
  |
18
- | 验证 Agent Token
18
+ | Validates Agent Token
19
19
  v
20
20
  Broker Core
21
- | 权限检查 -> 凭证解密 -> 执行
21
+ | Permission check -> Credential decryption -> Execution
22
22
  v
23
- 第三方 APIGitHub 等)
23
+ Third-party API (GitHub, etc.)
24
24
  |
25
- | Bearer Token Broker 注入,Agent 不可见
25
+ | Bearer Token injected by Broker, invisible to Agent
26
26
  v
27
- 响应结果返回给 Agent
27
+ Response returned to Agent
28
28
  ```
29
29
 
30
- **核心优势:**
30
+ **Key benefits:**
31
31
 
32
- - Agent 永远不接触真实凭证,Token 泄露风险为零
33
- - 操作级别细粒度权限控制(如只允许 `github:list_repos`,禁止 `github:create_issue`)
34
- - 参数约束,限制操作范围(如只允许访问特定组织的仓库)
35
- - 完整的防篡改审计日志(HMAC-SHA256 哈希链)
32
+ - Agents never touch real credentials — token leakage risk is eliminated
33
+ - Operation-level fine-grained access control (e.g., allow `github:list_repos`, deny `github:create_issue`)
34
+ - Parameter constraints to scope operations (e.g., restrict access to a specific GitHub organization)
35
+ - Tamper-evident audit log chain (HMAC-SHA256)
36
36
 
37
37
  ---
38
38
 
39
- ## 项目结构
39
+ ## Repository Structure
40
40
 
41
41
  ```
42
42
  agent-auth-broker/
43
43
  ├── apps/
44
- │ ├── web/ # Next.js 14 — Admin UI + Broker APIPostgreSQL
44
+ │ ├── web/ # Next.js 14 — Admin UI + Broker API (PostgreSQL)
45
45
  │ │ └── prisma/schema.prisma
46
- │ ├── mcp-server/ # MCP Serverstdio + Streamable HTTP 传输)
47
- │ └── cli/ # CLI 工具 — broker init/serve/validate/ui
46
+ │ ├── mcp-server/ # MCP Server (stdio + Streamable HTTP transport)
47
+ │ └── cli/ # CLI tool — broker init/serve/validate/ui
48
48
  ├── packages/
49
- │ ├── local-runtime/ # 纯本地运行时(YAML 驱动,无需数据库)
50
- │ ├── core/ # 核心业务逻辑(数据库模式)
51
- │ ├── connectors/ # 第三方服务适配器(支持插件化动态加载)
52
- │ ├── crypto/ # AES-256-GCM 加密工具
53
- │ └── shared-types/ # 共享类型定义
54
- ├── Dockerfile # 多阶段 Docker 构建
55
- ├── docker-compose.yml # web + postgres 一键部署
56
- ├── .github/workflows/ # CI/CDbuild + typecheck + test + npm publish
57
- ├── package.json # pnpm monorepo
49
+ │ ├── local-runtime/ # Local runtime (YAML-driven, no database required)
50
+ │ ├── core/ # Core business logic (database schema)
51
+ │ ├── connectors/ # Third-party service adapters (plugin-based dynamic loading)
52
+ │ ├── crypto/ # AES-256-GCM encryption utilities
53
+ │ └── shared-types/ # Shared TypeScript type definitions
54
+ ├── Dockerfile # Multi-stage Docker build
55
+ ├── docker-compose.yml # One-command web + postgres deployment
56
+ ├── .github/workflows/ # CI/CD (build + typecheck + test + npm publish)
57
+ ├── package.json # pnpm monorepo root
58
58
  └── turbo.json
59
59
  ```
60
60
 
61
61
  ---
62
62
 
63
- ## 核心特性
64
-
65
- **安全**
66
- - AES-256-GCM 双层加密(MEK 加密 DEKDEK 加密凭证数据)
67
- - ReDoS 防护(safe-regex2 验证正则模式安全性)
68
- - 审计日志哈希链防篡改(HMAC-SHA256
69
- - 安全响应头(X-Content-Type-OptionsX-Frame-OptionsCSP 等)
70
- - OAuth State 数据库持久化,防 CSRF 攻击
71
- - Token SHA-256 哈希比对认证
72
-
73
- **权限模型**
74
- - 操作级别权限控制
75
- - 参数正则约束(限制操作范围)
76
- - 速率限制(滑动窗口算法)
77
- - 策略过期时间
78
- - Scope 组简化权限配置
79
-
80
- **可观测性**
81
- - pino 结构化日志(支持 `BROKER_LOG_LEVEL` 配置)
82
- - 审计日志输出到 stdout 或文件
83
- - `/api/health` 健康检查端点
84
-
85
- **扩展性**
86
- - Connector 插件化(支持 npm 包或本地路径动态加载)
87
- - `ConnectorAdapter` 接口含可选的 `validateCredential` 方法
88
- - 内置 GitHub Connector10 个操作)
63
+ ## Features
64
+
65
+ **Security**
66
+ - AES-256-GCM two-layer encryption (MEK encrypts DEK, DEK encrypts credential data)
67
+ - ReDoS protection via safe-regex2 for all regex pattern validation
68
+ - Tamper-evident audit log chain (HMAC-SHA256 hash chain)
69
+ - Secure HTTP response headers (X-Content-Type-Options, X-Frame-Options, CSP, etc.)
70
+ - OAuth State persisted to database to prevent CSRF attacks
71
+ - Token authentication via SHA-256 hash comparison
72
+
73
+ **Permission Model**
74
+ - Operation-level access control
75
+ - Parameter regex constraints to limit operation scope
76
+ - Rate limiting with sliding window algorithm
77
+ - Policy expiration timestamps
78
+ - Scope groups for simplified permission configuration
79
+
80
+ **Observability**
81
+ - Structured logging via pino (configurable via `BROKER_LOG_LEVEL`)
82
+ - Audit log output to stdout or file
83
+ - `/api/health` endpoint for health checks
84
+
85
+ **Extensibility**
86
+ - Plugin-based Connector system (load from npm packages or local paths dynamically)
87
+ - `ConnectorAdapter` interface with optional `validateCredential` method
88
+ - Built-in GitHub Connector with 10 operations
89
89
 
90
90
  ---
91
91
 
92
- ## 三种运行模式
92
+ ## Operation Modes
93
93
 
94
- | 模式 | 适用场景 | 外部依赖 | 配置方式 |
95
- |------|---------|---------|---------|
96
- | **File Mode** | 个人开发者、单 Agent | | `broker.yaml` + 环境变量 |
97
- | **Local Mode** | 小团队本地开发 | PostgreSQL | `.env` + 数据库 |
98
- | **Remote Mode** | 生产环境、多用户 | PostgreSQL + Web Server | Web UI 管理 |
94
+ | Mode | Use Case | External Dependencies | Configuration |
95
+ |------|----------|-----------------------|---------------|
96
+ | **File Mode** | Individual developers, single Agent | None | `broker.yaml` + environment variables |
97
+ | **Local Mode** | Small teams, local development | PostgreSQL | `.env` + database |
98
+ | **Remote Mode** | Production, multi-user | PostgreSQL + Web Server | Managed via Web UI |
99
99
 
100
- **模式优先级(MCP Server 启动时自动判断):**
100
+ **Mode selection priority (resolved automatically at MCP Server startup):**
101
101
 
102
102
  ```
103
- BROKER_URL 已设置 Remote Mode(最高优先级)
104
- DATABASE_URL 已设置 Local Mode
105
- BROKER_CONFIG 已设置 File Mode
103
+ BROKER_URL is set -> Remote Mode (highest priority)
104
+ DATABASE_URL is set -> Local Mode
105
+ BROKER_CONFIG is set -> File Mode
106
106
  ```
107
107
 
108
108
  ---
109
109
 
110
- ## 安装
110
+ ## Installation
111
111
 
112
- ### 方式一:npm 全局安装(推荐)
112
+ ### Option 1: Global npm install (recommended)
113
113
 
114
114
  ```bash
115
115
  npm install -g agent-auth-broker
116
116
  broker --version
117
117
  ```
118
118
 
119
- ### 方式二:npx 直接使用(无需安装)
119
+ ### Option 2: Run with npx (no installation required)
120
120
 
121
121
  ```bash
122
122
  npx agent-auth-broker init
123
123
  npx agent-auth-broker serve
124
124
  ```
125
125
 
126
- ### 方式三:从源码构建
126
+ ### Option 3: Build from source
127
127
 
128
128
  ```bash
129
129
  git clone https://github.com/your-org/agent-auth-broker.git
@@ -135,18 +135,18 @@ node apps/cli/dist/index.js --version
135
135
 
136
136
  ---
137
137
 
138
- ## 快速开始:File Mode
138
+ ## Quick Start: File Mode
139
139
 
140
- 最轻量的接入方式,只需一个 YAML 配置文件和环境变量,无需数据库和 Web Server。
140
+ The lightest-weight integration — requires only a YAML configuration file and environment variables, with no database or web server.
141
141
 
142
- ### 第一步:初始化配置
142
+ ### Step 1: Initialize configuration
143
143
 
144
144
  ```bash
145
145
  broker init
146
- # 或:npx agent-auth-broker init
146
+ # or: npx agent-auth-broker init
147
147
  ```
148
148
 
149
- 生成的 `broker.yaml`:
149
+ Generated `broker.yaml`:
150
150
 
151
151
  ```yaml
152
152
  version: "1"
@@ -158,35 +158,35 @@ agents:
158
158
  credentials:
159
159
  - id: github-main
160
160
  connector: github
161
- token: ${GITHUB_TOKEN} # 引用环境变量,凭证不落盘
161
+ token: ${GITHUB_TOKEN} # References an environment variable — credential never written to disk
162
162
 
163
163
  policies:
164
164
  - agent: my-agent
165
165
  credential: github-main
166
166
  actions:
167
- - "*" # 允许所有操作
167
+ - "*" # Allow all operations
168
168
 
169
169
  audit:
170
170
  enabled: true
171
171
  output: stdout
172
172
  ```
173
173
 
174
- ### 第二步:设置环境变量
174
+ ### Step 2: Set environment variables
175
175
 
176
176
  ```bash
177
177
  export GITHUB_TOKEN="ghp_your_personal_access_token"
178
178
  ```
179
179
 
180
- ### 第三步:验证配置
180
+ ### Step 3: Validate configuration
181
181
 
182
182
  ```bash
183
- broker validate # 验证配置文件格式
184
- broker diagnose # 诊断凭证连接(实际调用 GitHub API 验证)
183
+ broker validate # Validate configuration file format
184
+ broker diagnose # Diagnose credential connectivity (calls the GitHub API to verify)
185
185
  ```
186
186
 
187
- ### 第四步:配置 MCP Server
187
+ ### Step 4: Configure the MCP Server
188
188
 
189
- `claude_desktop_config.json` `.claude/settings.json` 中添加:
189
+ Add the following to `claude_desktop_config.json` or `.claude/settings.json`:
190
190
 
191
191
  ```json
192
192
  {
@@ -203,7 +203,7 @@ broker diagnose # 诊断凭证连接(实际调用 GitHub API 验证)
203
203
  }
204
204
  ```
205
205
 
206
- 从源码运行时,将 `"command": "broker"` 替换为:
206
+ When running from source, replace `"command": "broker"` with:
207
207
 
208
208
  ```json
209
209
  "command": "node",
@@ -212,13 +212,13 @@ broker diagnose # 诊断凭证连接(实际调用 GitHub API 验证)
212
212
 
213
213
  ---
214
214
 
215
- ## broker.yaml 配置详解
215
+ ## broker.yaml Configuration Reference
216
216
 
217
- ### 凭证配置
217
+ ### Credential Configuration
218
218
 
219
- **方式一:环境变量引用(推荐)**
219
+ **Option 1: Environment variable reference (recommended)**
220
220
 
221
- 凭证通过 `${ENV_VAR}` 语法引用,明文不写入配置文件:
221
+ Credentials are referenced via `${ENV_VAR}` syntax. No plaintext credentials are written to disk.
222
222
 
223
223
  ```yaml
224
224
  credentials:
@@ -227,13 +227,13 @@ credentials:
227
227
  token: ${GITHUB_TOKEN}
228
228
  ```
229
229
 
230
- **方式二:AES-256-GCM 加密存储**
230
+ **Option 2: AES-256-GCM encrypted storage**
231
231
 
232
- 凭证需要持久化时,配置 `encryption_key` 后使用加密存储:
232
+ For scenarios requiring credential persistence, configure `encryption_key` and use encrypted storage:
233
233
 
234
234
  ```yaml
235
235
  version: "1"
236
- encryption_key: ${BROKER_MASTER_KEY} # 主加密密钥(64 位十六进制)
236
+ encryption_key: ${BROKER_MASTER_KEY} # Master encryption key (64-char hex string)
237
237
 
238
238
  credentials:
239
239
  - id: github-main
@@ -241,155 +241,155 @@ credentials:
241
241
  encrypted: "base64-encrypted-string"
242
242
  ```
243
243
 
244
- ### 权限策略
244
+ ### Permission Policies
245
245
 
246
246
  ```yaml
247
247
  policies:
248
248
  - agent: my-agent
249
249
  credential: github-main
250
250
 
251
- # 方式一:允许所有操作
251
+ # Option 1: Allow all operations
252
252
  actions:
253
253
  - "*"
254
254
 
255
- # 方式二:使用 Scope 组(自动展开)
255
+ # Option 2: Use scope groups (auto-expanded)
256
256
  # actions:
257
- # - "github:read" # 展开为 7 个只读操作
258
- # - "github:write" # 展开为 3 个写操作
257
+ # - "github:read" # Expands to 7 read-only operations
258
+ # - "github:write" # Expands to 3 write operations
259
259
 
260
- # 方式三:精确指定操作
260
+ # Option 3: Specify operations explicitly
261
261
  # actions:
262
262
  # - "github:list_repos"
263
263
  # - "github:create_issue"
264
264
 
265
- # 可选:参数约束(正则匹配)
265
+ # Optional: Parameter constraints (regex matching)
266
266
  # param_constraints:
267
267
  # repo:
268
- # pattern: "^myorg/.*" # repo 参数必须以 myorg/ 开头
268
+ # pattern: "^myorg/.*" # repo parameter must start with myorg/
269
269
 
270
- # 可选:速率限制(滑动窗口算法)
270
+ # Optional: Rate limiting (sliding window algorithm)
271
271
  # rate_limit:
272
272
  # max_calls: 100
273
273
  # window_seconds: 3600
274
274
 
275
- # 可选:策略过期时间
275
+ # Optional: Policy expiration
276
276
  # expires_at: "2025-12-31T23:59:59Z"
277
277
  ```
278
278
 
279
- ### Scope
279
+ ### Scope Groups
280
280
 
281
- | Scope | 展开为 |
282
- |-------|--------|
281
+ | Scope | Expands To |
282
+ |-------|------------|
283
283
  | `github:read` | `list_repos`, `get_repo`, `list_issues`, `get_issue`, `list_prs`, `get_file`, `search_code` |
284
284
  | `github:write` | `create_issue`, `comment_issue`, `create_pr` |
285
285
 
286
- ### 审计日志配置
286
+ ### Audit Log Configuration
287
287
 
288
288
  ```yaml
289
289
  audit:
290
290
  enabled: true
291
- output: stdout # stdout:输出到 stderr(适合 MCP stdio 模式)
291
+ output: stdout # Outputs to stderr (appropriate for MCP stdio mode)
292
292
  # output: file
293
293
  # file: ./broker-audit.log
294
294
  ```
295
295
 
296
296
  ---
297
297
 
298
- ## CLI 命令参考
298
+ ## CLI Reference
299
299
 
300
- 所有命令支持 `-c, --config <path>` 指定配置文件路径,默认从当前目录向上查找 `broker.yaml`。
300
+ All commands support `-c, --config <path>` to specify the configuration file. By default, the CLI searches upward from the current directory for `broker.yaml`.
301
301
 
302
302
  ```bash
303
- # 初始化
304
- broker init # 生成 broker.yaml 模板
305
- broker init --force # 覆盖已有配置
303
+ # Initialization
304
+ broker init # Generate broker.yaml template
305
+ broker init --force # Overwrite existing configuration
306
306
 
307
- # 验证和诊断
308
- broker validate # 校验配置文件格式
309
- broker diagnose # 检查环境变量和凭证连接
307
+ # Validation and diagnostics
308
+ broker validate # Validate configuration file format
309
+ broker diagnose # Check environment variables and credential connectivity
310
310
 
311
- # Agent 管理
312
- broker agent create <id> [-n <name>] # 创建 Agent
313
- broker agent list # 列出所有 Agent
314
- broker agent remove <id> # 移除 Agent
311
+ # Agent management
312
+ broker agent create <id> [-n <name>] # Create an Agent
313
+ broker agent list # List all Agents
314
+ broker agent remove <id> # Remove an Agent
315
315
 
316
- # Token 管理
317
- broker token generate <agent-id> # 生成 Agent Token(仅显示一次)
318
- broker token generate <agent-id> --force # 覆盖已有 Token
319
- broker token revoke <agent-id> # 撤销 Token
320
- broker token list # 列出所有 Token 状态
316
+ # Token management
317
+ broker token generate <agent-id> # Generate an Agent Token (displayed once)
318
+ broker token generate <agent-id> --force # Overwrite existing Token
319
+ broker token revoke <agent-id> # Revoke a Token
320
+ broker token list # List Token status for all Agents
321
321
 
322
- # 凭证管理
323
- broker credential add <connector> --env <VAR> # 添加环境变量引用凭证
324
- broker credential add <connector> --token <val> # 直接指定 Token(不推荐)
325
- broker credential list # 列出所有凭证
326
- broker credential remove <id> # 移除凭证
322
+ # Credential management
323
+ broker credential add <connector> --env <VAR> # Add a credential via environment variable reference
324
+ broker credential add <connector> --token <val> # Add a credential with inline token (not recommended)
325
+ broker credential list # List all credentials
326
+ broker credential remove <id> # Remove a credential
327
327
 
328
- # 策略管理
329
- broker policy set <agent> <credential> [--actions "*"] # 设置策略
330
- broker policy list # 列出所有策略
331
- broker policy remove <agent> <credential> # 移除策略
328
+ # Policy management
329
+ broker policy set <agent> <credential> [--actions "*"] # Set a policy
330
+ broker policy list # List all policies
331
+ broker policy remove <agent> <credential> # Remove a policy
332
332
 
333
- # 测试操作
334
- broker test <connector> <action> # 测试 Connector 操作
335
- broker test github list_repos # 示例:列出 GitHub 仓库
336
- broker test github list_issues -p '{"repo":"owner/repo"}' # 带参数
337
- broker test github create_issue --dry-run # 仅权限检查,不实际调用
333
+ # Testing operations
334
+ broker test <connector> <action> # Test a Connector operation
335
+ broker test github list_repos # Example: list GitHub repositories
336
+ broker test github list_issues -p '{"repo":"owner/repo"}' # With parameters
337
+ broker test github create_issue --dry-run # Permission check only, no actual API call
338
338
 
339
- # 启动 MCP Server
340
- broker serve # stdio 模式(支持配置热重载)
341
- broker serve --agent <id> # 指定 Agent ID
339
+ # Start MCP Server
340
+ broker serve # stdio mode (with config hot-reload)
341
+ broker serve --agent <id> # Specify Agent ID
342
342
 
343
- # Web UIFile Mode 可视化管理)
344
- broker ui # 启动 Web UI(默认端口 3200
345
- broker ui --port 8080 # 自定义端口
343
+ # Web UI (File Mode visual management)
344
+ broker ui # Start Web UI (default port 3200)
345
+ broker ui --port 8080 # Custom port
346
346
  ```
347
347
 
348
- ### Token 认证流程
348
+ ### Token Authentication Flow
349
349
 
350
- 1. 生成 Token:`broker token generate my-agent`(Token 仅显示一次)
351
- 2. Token SHA-256 哈希自动写入 `broker.yaml` `token_hash` 字段
352
- 3. MCP 配置中通过环境变量 `BROKER_AGENT_TOKEN` 传入 Token 明文
353
- 4. MCP Server 启动时通过哈希比对确认 Agent 身份
350
+ 1. Generate a Token: `broker token generate my-agent` (Token is displayed once only)
351
+ 2. The SHA-256 hash of the Token is automatically written to the `token_hash` field in `broker.yaml`
352
+ 3. Pass the Token plaintext via the `BROKER_AGENT_TOKEN` environment variable in your MCP configuration
353
+ 4. The MCP Server verifies Agent identity at startup via hash comparison
354
354
 
355
- 未设置 `BROKER_AGENT_TOKEN` 时,退回到 `--agent` 参数或默认使用第一个 Agent
355
+ If `BROKER_AGENT_TOKEN` is not set, the Server falls back to the `--agent` parameter, or defaults to the first Agent in the configuration.
356
356
 
357
- ### 配置热重载
357
+ ### Configuration Hot-Reload
358
358
 
359
- `broker serve` 运行时自动监视 `broker.yaml` 变更,修改配置无需重启 MCP Server
359
+ `broker serve` automatically watches `broker.yaml` for changes. Configuration updates take effect without restarting the MCP Server:
360
360
 
361
- - 使用 `fs.watch` 监视文件,300ms 防抖避免重复触发
362
- - 重载失败时保留旧配置并输出错误日志
363
- - 进程退出时自动清理 watcher
361
+ - Uses `fs.watch` with 300ms debounce to prevent duplicate triggers
362
+ - On reload failure, the previous configuration is retained and an error is logged
363
+ - The file watcher is cleaned up automatically on process exit
364
364
 
365
365
  ### File Mode Web UI
366
366
 
367
- `broker ui` 启动轻量级 Web 界面(默认 `http://localhost:3200`),方便可视化管理 `broker.yaml`:
367
+ `broker ui` starts a lightweight web interface (default: `http://localhost:3200`) for managing `broker.yaml` visually:
368
368
 
369
- - 使用 Node.js 内置 `http` 模块,零外部依赖
370
- - 支持 Agent、Credential、Policy 的增删操作
371
- - YAML 预览(Token 自动脱敏)
372
- - 所有变更实时写入 `broker.yaml` 文件
369
+ - Built on Node.js built-in `http` module — no external dependencies
370
+ - Supports create and delete operations for Agents, Credentials, and Policies
371
+ - YAML preview with automatic token redaction
372
+ - All changes are written to `broker.yaml` immediately
373
373
 
374
374
  ---
375
375
 
376
- ## MCP Server 配置
376
+ ## MCP Server Configuration
377
377
 
378
- ### Streamable HTTP 传输(可选)
378
+ ### Streamable HTTP Transport (optional)
379
379
 
380
- 默认传输方式为 stdio。如需通过 HTTP 暴露 MCP Server(例如多 Agent 共享一个 MCP Server),可启用 HTTP 传输:
380
+ The default transport is stdio. To expose the MCP Server over HTTP (e.g., for multiple Agents sharing a single MCP Server), enable HTTP transport:
381
381
 
382
382
  ```bash
383
383
  MCP_TRANSPORT=http MCP_PORT=3200 MCP_AUTH_TOKEN=your-secret broker serve
384
384
  ```
385
385
 
386
- 客户端请求时携带 Bearer Token
386
+ Clients must include the Bearer Token in requests:
387
387
 
388
388
  ```
389
389
  Authorization: Bearer your-secret
390
390
  ```
391
391
 
392
- ### 三种模式的 MCP 配置
392
+ ### MCP Configuration by Mode
393
393
 
394
394
  **File Mode**
395
395
 
@@ -408,7 +408,7 @@ Authorization: Bearer your-secret
408
408
  }
409
409
  ```
410
410
 
411
- **Local Mode(直连 PostgreSQL)**
411
+ **Local Mode (direct PostgreSQL connection)**
412
412
 
413
413
  ```json
414
414
  {
@@ -426,7 +426,7 @@ Authorization: Bearer your-secret
426
426
  }
427
427
  ```
428
428
 
429
- **Remote ModeHTTP 调用 Web Server)**
429
+ **Remote Mode (HTTP call to Web Server)**
430
430
 
431
431
  ```json
432
432
  {
@@ -445,45 +445,45 @@ Authorization: Bearer your-secret
445
445
 
446
446
  ---
447
447
 
448
- ## Docker 部署
448
+ ## Docker Deployment
449
449
 
450
- 使用 docker-compose 一键启动 Web Server + PostgreSQL
450
+ Start the Web Server and PostgreSQL with a single command using docker-compose:
451
451
 
452
452
  ```bash
453
- # 复制并修改环境变量
453
+ # Copy and configure environment variables
454
454
  cp apps/web/.env.example apps/web/.env
455
455
 
456
- # 构建并启动
456
+ # Build and start
457
457
  docker-compose up -d
458
458
 
459
- # 查看日志
459
+ # View logs
460
460
  docker-compose logs -f web
461
461
  ```
462
462
 
463
- `docker-compose.yml` 包含:
463
+ `docker-compose.yml` includes:
464
464
 
465
- - `web` 服务:Next.js 14 Admin UI + Broker API,端口 3100
466
- - `postgres` 服务:PostgreSQL 14,数据持久化到 volume
465
+ - `web` service: Next.js 14 Admin UI + Broker API, port 3100
466
+ - `postgres` service: PostgreSQL 14, data persisted to a named volume
467
467
 
468
- 多阶段 Docker 构建,最终镜像只包含生产所需文件。
468
+ Multi-stage Docker build — the final image contains only production artifacts.
469
469
 
470
470
  ---
471
471
 
472
- ## Web UILocal / Remote Mode
472
+ ## Web UI (Local / Remote Mode)
473
473
 
474
- ### 环境要求
474
+ ### Requirements
475
475
 
476
476
  - Node.js >= 20
477
477
  - pnpm >= 9.15
478
478
  - PostgreSQL >= 14
479
479
 
480
- ### 配置
480
+ ### Configuration
481
481
 
482
482
  ```bash
483
483
  cp apps/web/.env.example apps/web/.env
484
484
  ```
485
485
 
486
- `apps/web/.env` 必填项:
486
+ Required fields in `apps/web/.env`:
487
487
 
488
488
  ```env
489
489
  DATABASE_URL="postgresql://user:password@localhost:5432/agent_auth_broker"
@@ -494,283 +494,283 @@ GITHUB_CLIENT_ID="your-github-oauth-app-client-id"
494
494
  GITHUB_CLIENT_SECRET="your-github-oauth-app-client-secret"
495
495
  ```
496
496
 
497
- ### 初始化数据库并启动
497
+ ### Initialize Database and Start
498
498
 
499
499
  ```bash
500
- pnpm db:generate # 生成 Prisma Client
501
- pnpm db:push # 推送 Schema(开发环境)
502
- # pnpm db:migrate # 创建迁移文件(生产环境)
500
+ pnpm db:generate # Generate Prisma Client
501
+ pnpm db:push # Push schema (development)
502
+ # pnpm db:migrate # Create migration files (production)
503
503
 
504
504
  pnpm build
505
- pnpm dev:web # 访问 http://localhost:3100
505
+ pnpm dev:web # Visit http://localhost:3100
506
506
  ```
507
507
 
508
- ### 使用流程
508
+ ### Workflow
509
509
 
510
- 1. **注册 Agent**:Admin UI -> Agents -> 创建 Agent -> 复制 Token(`agnt_xxxx`,仅显示一次)
511
- 2. **连接凭证**:Admin UI -> Credentials -> 通过 OAuth 连接 -> 凭证自动加密存储
512
- 3. **配置策略**:Admin UI -> Agent Policies -> 选择凭证、操作列表、参数约束
513
- 4. **配置 MCP Server**:将 Token 填入 MCP 配置的 `BROKER_AGENT_TOKEN` 环境变量
510
+ 1. **Register an Agent**: Admin UI -> Agents -> Create Agent -> Copy Token (`agnt_xxxx`, displayed once)
511
+ 2. **Connect credentials**: Admin UI -> Credentials -> Connect via OAuth -> Credentials are encrypted automatically
512
+ 3. **Configure policies**: Admin UI -> Agent Policies -> Select credential, allowed operations, and parameter constraints
513
+ 4. **Configure MCP Server**: Set the Agent Token in the `BROKER_AGENT_TOKEN` environment variable in your MCP configuration
514
514
 
515
515
  ---
516
516
 
517
- ## MCP 工具说明
517
+ ## MCP Tools
518
518
 
519
- MCP Server 启动后自动暴露以下工具:
519
+ The MCP Server exposes the following tools upon startup:
520
520
 
521
- ### 固定工具
521
+ ### Fixed Tools
522
522
 
523
- | 工具 | 说明 |
524
- |------|------|
525
- | `broker_call` | 通用调用入口,指定 connector + action + params |
526
- | `broker_list_tools` | 列出当前 Agent 被授权的所有工具 |
523
+ | Tool | Description |
524
+ |------|-------------|
525
+ | `broker_call` | Universal invocation entry point: specify connector + action + params |
526
+ | `broker_list_tools` | List all tools the current Agent is authorized to use |
527
527
 
528
- ### 动态命名工具
528
+ ### Dynamic Named Tools
529
529
 
530
- 根据 Agent 的权限策略自动生成,格式为 `{connector}_{action}`:
530
+ Generated automatically based on the Agent's permission policies, in the format `{connector}_{action}`:
531
531
 
532
- | 工具 | 等价调用 |
533
- |------|---------|
532
+ | Tool | Equivalent Call |
533
+ |------|----------------|
534
534
  | `github_list_repos` | `broker_call({ connector: "github", action: "list_repos" })` |
535
535
  | `github_create_issue` | `broker_call({ connector: "github", action: "create_issue", ... })` |
536
536
  | `github_search_code` | `broker_call({ connector: "github", action: "search_code", ... })` |
537
537
 
538
- Agent 只能看到自身被授权的工具,未授权的工具不会出现在工具列表中。
538
+ Agents only see tools they are authorized to use. Unauthorized tools are not included in the tool list.
539
539
 
540
540
  ---
541
541
 
542
- ## GitHub Connector 操作列表
543
-
544
- | action | 说明 | 必填参数 |
545
- |--------|------|---------|
546
- | `list_repos` | 列出已授权用户的仓库 | — |
547
- | `get_repo` | 获取仓库信息 | `repo`(格式:`owner/repo`)|
548
- | `list_issues` | 列出仓库的 Issue | `repo` |
549
- | `get_issue` | 获取单个 Issue 详情 | `repo`, `issue_number` |
550
- | `create_issue` | 创建 Issue | `repo`, `title` |
551
- | `comment_issue` | Issue 上添加评论 | `repo`, `issue_number`, `body` |
552
- | `list_prs` | 列出 Pull Request | `repo` |
553
- | `create_pr` | 创建 Pull Request | `repo`, `title`, `head`, `base` |
554
- | `get_file` | 获取文件内容(自动 Base64 解码)| `repo`, `path` |
555
- | `search_code` | 搜索代码 | `q` |
542
+ ## GitHub Connector Operations
543
+
544
+ | action | Description | Required Parameters |
545
+ |--------|-------------|---------------------|
546
+ | `list_repos` | List repositories for the authenticated user | — |
547
+ | `get_repo` | Get repository information | `repo` (format: `owner/repo`) |
548
+ | `list_issues` | List issues in a repository | `repo` |
549
+ | `get_issue` | Get details of a single issue | `repo`, `issue_number` |
550
+ | `create_issue` | Create an issue | `repo`, `title` |
551
+ | `comment_issue` | Add a comment to an issue | `repo`, `issue_number`, `body` |
552
+ | `list_prs` | List pull requests | `repo` |
553
+ | `create_pr` | Create a pull request | `repo`, `title`, `head`, `base` |
554
+ | `get_file` | Get file contents (Base64-decoded automatically) | `repo`, `path` |
555
+ | `search_code` | Search code | `q` |
556
556
 
557
557
  ---
558
558
 
559
- ## 权限模型
559
+ ## Permission Model
560
560
 
561
- ### 权限检查流程
561
+ ### Permission Check Flow
562
562
 
563
563
  ```
564
- 请求到达
564
+ Request received
565
565
  |
566
- +--> Agent 是否激活? -> DENIED_AGENT_INACTIVE
566
+ +--> Is the Agent active? -> DENIED_AGENT_INACTIVE
567
567
  |
568
- +--> 是否有匹配的策略? -> DENIED_NO_POLICY
568
+ +--> Is there a matching policy? -> DENIED_NO_POLICY
569
569
  |
570
- +--> 操作是否在允许列表? -> DENIED_ACTION_NOT_ALLOWED
570
+ +--> Is the action in the allow list? -> DENIED_ACTION_NOT_ALLOWED
571
571
  |
572
- +--> 参数是否满足约束? -> DENIED_PARAM_CONSTRAINT
572
+ +--> Do the parameters satisfy constraints? -> DENIED_PARAM_CONSTRAINT
573
573
  |
574
- +--> 凭证是否过期? -> DENIED_CREDENTIAL_EXPIRED
574
+ +--> Has the credential expired? -> DENIED_CREDENTIAL_EXPIRED
575
575
  |
576
- +--> 是否超出速率限制? -> DENIED_RATE_LIMIT
576
+ +--> Has the rate limit been exceeded? -> DENIED_RATE_LIMIT
577
577
  |
578
578
  v
579
- 执行操作
579
+ Execute operation
580
580
  ```
581
581
 
582
- ### 拒绝原因码
582
+ ### Denial Reason Codes
583
583
 
584
- | 错误码 | 含义 |
585
- |--------|------|
586
- | `DENIED_AGENT_INACTIVE` | Agent 已被停用 |
587
- | `DENIED_NO_POLICY` | Agent 无匹配策略 |
588
- | `DENIED_ACTION_NOT_ALLOWED` | 操作不在允许列表中 |
589
- | `DENIED_PARAM_CONSTRAINT` | 参数不满足约束条件 |
590
- | `DENIED_CREDENTIAL_EXPIRED` | 凭证已过期或被撤销 |
591
- | `DENIED_RATE_LIMIT` | 超出速率限制 |
584
+ | Code | Meaning |
585
+ |------|---------|
586
+ | `DENIED_AGENT_INACTIVE` | The Agent has been deactivated |
587
+ | `DENIED_NO_POLICY` | No policy matches this Agent and connector |
588
+ | `DENIED_ACTION_NOT_ALLOWED` | The operation is not in the allow list |
589
+ | `DENIED_PARAM_CONSTRAINT` | A parameter does not satisfy the configured constraint |
590
+ | `DENIED_CREDENTIAL_EXPIRED` | The credential has expired or been revoked |
591
+ | `DENIED_RATE_LIMIT` | The rate limit has been exceeded |
592
592
 
593
- ### 参数约束示例
593
+ ### Parameter Constraint Example
594
594
 
595
595
  ```yaml
596
596
  param_constraints:
597
597
  repo:
598
- pattern: "^myorg/.*" # repo 参数必须以 myorg/ 开头
598
+ pattern: "^myorg/.*" # repo parameter must start with myorg/
599
599
  ```
600
600
 
601
- 正则模式在加载时经过 safe-regex2 验证,防止 ReDoS 攻击。
601
+ All regex patterns are validated with safe-regex2 on load to prevent ReDoS attacks.
602
602
 
603
603
  ---
604
604
 
605
- ## 加密方案
605
+ ## Encryption
606
606
 
607
- 凭证数据采用 AES-256-GCM **双层加密**:
607
+ Credentials are protected with **two-layer AES-256-GCM encryption**:
608
608
 
609
609
  ```
610
- BROKER_MASTER_KEY(环境变量,不落盘)
610
+ BROKER_MASTER_KEY (environment variable, never written to disk)
611
611
  |
612
- +--> 加密生成 DEKData Encryption Key,每条凭证独立)
612
+ +--> Encrypts DEK (Data Encryption Key, unique per credential)
613
613
  |
614
- +--> 加密凭证 JSON(含 access_token 等敏感字段)
614
+ +--> Encrypts credential JSON (access_token and other sensitive fields)
615
615
  |
616
- +--> 加密结果存入数据库
616
+ +--> Ciphertext stored in database
617
617
  ```
618
618
 
619
- - MEKMaster Encryption Key)仅存在于环境变量,不落盘
620
- - DEK 加密后存入数据库的 `encryptionKeyId` 字段
621
- - 凭证明文从不进入日志或 HTTP 响应体
622
- - File Mode AES 加密存储同样使用 `BROKER_MASTER_KEY`
619
+ - The MEK (Master Encryption Key) exists only as an environment variable and is never persisted
620
+ - The DEK is stored in the database (encrypted) in the `encryptionKeyId` field
621
+ - Credential plaintext never appears in logs or HTTP response bodies
622
+ - File Mode encrypted storage uses the same `BROKER_MASTER_KEY`
623
623
 
624
624
  ---
625
625
 
626
- ## 审计日志
626
+ ## Audit Logging
627
627
 
628
- 所有操作(包括被拒绝的请求)均记录审计日志。
628
+ All operations — including denied requests — are recorded in the audit log.
629
629
 
630
- **日志字段:**
630
+ **Log fields:**
631
631
 
632
- - Agent IDConnectorAction
633
- - 权限检查结果(`permissionResult`)
634
- - 脱敏后的请求摘要(敏感字段替换为 `[REDACTED]`)
635
- - HTTP 状态码、错误信息
636
- - IP 地址、User-Agent
637
- - 时间戳、哈希链值
632
+ - Agent ID, Connector, Action
633
+ - Permission check result (`permissionResult`)
634
+ - Redacted request summary (sensitive fields replaced with `[REDACTED]`)
635
+ - HTTP status code and error message
636
+ - IP address and User-Agent
637
+ - Timestamp and hash chain value
638
638
 
639
- **防篡改机制:**
639
+ **Tamper-evidence:**
640
640
 
641
- 审计日志采用 HMAC-SHA256 哈希链,每条记录包含前一条记录的哈希值,形成不可篡改的链式结构。应用层只允许 INSERT,不允许 UPDATE DELETE 审计记录。
641
+ Audit logs use an HMAC-SHA256 hash chain. Each record includes the hash of the previous record, forming a chain that cannot be altered without detection. The application layer enforces INSERT-only access — UPDATE and DELETE operations on audit records are not permitted.
642
642
 
643
- **输出配置:**
643
+ **Output configuration:**
644
644
 
645
645
  ```yaml
646
646
  audit:
647
647
  enabled: true
648
- output: stdout # MCP stdio 模式下输出到 stderr
648
+ output: stdout # Outputs to stderr in MCP stdio mode
649
649
  # output: file
650
650
  # file: ./broker-audit.log
651
651
  ```
652
652
 
653
653
  ---
654
654
 
655
- ## 扩展 Connector
655
+ ## Extending Connectors
656
656
 
657
- ### 内置方式
657
+ ### Built-in Integration
658
658
 
659
- `packages/connectors/src/` 下新建目录,实现 `ConnectorAdapter` 接口,并在 `registry.ts` 中注册:
659
+ Create a new directory under `packages/connectors/src/`, implement the `ConnectorAdapter` interface, and register it in `registry.ts`:
660
660
 
661
661
  ```typescript
662
- // packages/connectors/src/feishu/index.ts
663
- export const feishuConnector: ConnectorAdapter = {
664
- info: { id: 'feishu', name: '飞书', version: '1.0.0' },
662
+ // packages/connectors/src/slack/index.ts
663
+ export const slackConnector: ConnectorAdapter = {
664
+ info: { id: 'slack', name: 'Slack', version: '1.0.0' },
665
665
  getActions() {
666
666
  return [
667
- { id: 'send_message', name: '发送消息', params: [...] },
667
+ { id: 'post_message', name: 'Post Message', params: [...] },
668
668
  ]
669
669
  },
670
670
  async execute(action, params, credential) {
671
- // 实现调用逻辑
671
+ // Implementation
672
672
  },
673
673
  async validateCredential(credential) {
674
- // 可选:验证凭证有效性
674
+ // Optional: validate credential on load
675
675
  },
676
676
  }
677
677
 
678
678
  // packages/connectors/src/registry.ts
679
- import { feishuConnector } from './feishu/index'
679
+ import { slackConnector } from './slack/index'
680
680
 
681
681
  const connectors = new Map([
682
682
  ['github', githubConnector],
683
- ['feishu', feishuConnector], // 注册新 Connector
683
+ ['slack', slackConnector], // Register new Connector
684
684
  ])
685
685
  ```
686
686
 
687
- ### 插件化动态加载
687
+ ### Plugin-based Dynamic Loading
688
688
 
689
- 支持从 npm 包或本地路径动态加载 Connector,无需修改核心代码:
689
+ Connectors can be loaded from npm packages or local paths at runtime, without modifying core code:
690
690
 
691
691
  ```typescript
692
692
  import { loadConnectorPlugin } from '@agent-auth-broker/connectors'
693
693
 
694
- // npm 包加载
695
- await loadConnectorPlugin('my-broker-connector-feishu')
694
+ // Load from npm package
695
+ await loadConnectorPlugin('my-broker-connector-slack')
696
696
 
697
- // 从本地路径加载
697
+ // Load from local path
698
698
  await loadConnectorPlugin('./plugins/my-connector')
699
699
  ```
700
700
 
701
- 插件需导出符合 `ConnectorAdapter` 接口的对象作为默认导出。
701
+ Plugins must export a `ConnectorAdapter`-conforming object as their default export.
702
702
 
703
703
  ---
704
704
 
705
- ## 环境变量参考
705
+ ## Environment Variables
706
706
 
707
- | 变量 | 用途 | 适用模式 |
708
- |------|------|---------|
709
- | `BROKER_CONFIG` | broker.yaml 文件路径 | File Mode |
710
- | `DATABASE_URL` | PostgreSQL 连接串 | Local / Remote |
711
- | `BROKER_MASTER_KEY` | 主加密密钥(64 位十六进制字符串) | Local / Remote / File(加密存储) |
712
- | `BROKER_AGENT_TOKEN` | Agent 认证 Token | 所有模式 |
713
- | `BROKER_AGENT_ID` | 指定 Agent ID(无 Token 时使用) | File Mode |
707
+ | Variable | Purpose | Mode |
708
+ |----------|---------|------|
709
+ | `BROKER_CONFIG` | Path to broker.yaml | File Mode |
710
+ | `DATABASE_URL` | PostgreSQL connection string | Local / Remote |
711
+ | `BROKER_MASTER_KEY` | Master encryption key (64-char hex string) | Local / Remote / File (encrypted storage) |
712
+ | `BROKER_AGENT_TOKEN` | Agent authentication token | All modes |
713
+ | `BROKER_AGENT_ID` | Specify Agent ID (used when no token is set) | File Mode |
714
714
  | `BROKER_URL` | Web Server URL | Remote Mode |
715
- | `MCP_TRANSPORT` | 传输方式:`stdio`(默认)或 `http` | MCP Server |
716
- | `MCP_PORT` | HTTP 传输端口(默认 3200 | MCP Server HTTP 模式 |
717
- | `MCP_AUTH_TOKEN` | HTTP Bearer Token | MCP Server HTTP 模式 |
718
- | `BROKER_LOG_LEVEL` | 日志级别(默认 `info`) | 所有模式 |
715
+ | `MCP_TRANSPORT` | Transport type: `stdio` (default) or `http` | MCP Server |
716
+ | `MCP_PORT` | HTTP transport port (default: 3200) | MCP Server HTTP mode |
717
+ | `MCP_AUTH_TOKEN` | HTTP Bearer Token | MCP Server HTTP mode |
718
+ | `BROKER_LOG_LEVEL` | Log level (default: `info`) | All modes |
719
719
  | `GITHUB_TOKEN` | GitHub Personal Access Token | File Mode |
720
- | `NEXTAUTH_SECRET` | NextAuth.js 密钥 | Web |
721
- | `NEXTAUTH_URL` | Web 应用 URL | Web |
720
+ | `NEXTAUTH_SECRET` | NextAuth.js secret | Web |
721
+ | `NEXTAUTH_URL` | Web application URL | Web |
722
722
  | `GITHUB_CLIENT_ID` | GitHub OAuth App Client ID | Web |
723
723
  | `GITHUB_CLIENT_SECRET` | GitHub OAuth App Client Secret | Web |
724
724
 
725
725
  ---
726
726
 
727
- ## 开发命令
727
+ ## Development Commands
728
728
 
729
729
  ```bash
730
- # 安装依赖
730
+ # Install dependencies
731
731
  pnpm install
732
732
 
733
- # 构建所有包
733
+ # Build all packages
734
734
  pnpm build
735
735
 
736
- # 单独构建
736
+ # Build individual packages
737
737
  pnpm build:web
738
738
  pnpm build:mcp
739
739
  pnpm --filter=agent-auth-broker build
740
740
 
741
- # 开发模式(热重载)
741
+ # Development mode (with hot reload)
742
742
  pnpm dev
743
743
  pnpm dev:web
744
744
 
745
- # 数据库操作(Local / Remote Mode
746
- pnpm db:generate # 生成 Prisma Client
747
- pnpm db:push # 推送 Schema(开发环境)
748
- pnpm db:migrate # 创建迁移文件(生产环境)
745
+ # Database operations (Local / Remote Mode)
746
+ pnpm db:generate # Generate Prisma Client
747
+ pnpm db:push # Push schema (development)
748
+ pnpm db:migrate # Create migration files (production)
749
749
 
750
- # 代码检查
750
+ # Linting
751
751
  pnpm lint
752
752
 
753
- # 运行测试
753
+ # Run tests
754
754
  pnpm test
755
755
  ```
756
756
 
757
757
  ---
758
758
 
759
- ## 测试
759
+ ## Testing
760
760
 
761
- 使用 Vitest 测试框架,包含 70+ 个测试用例,覆盖以下模块:
761
+ The project uses Vitest with 70+ test cases covering the following modules:
762
762
 
763
- - 加密与解密(AES-256-GCM,包含边界情况)
764
- - Scope 展开逻辑(scope 组解析与去重)
765
- - 配置文件加载(环境变量替换、格式校验)
766
- - 权限检查(所有拒绝场景)
767
- - 速率限制(滑动窗口算法)
768
- - 审计日志哈希链(防篡改验证)
763
+ - Encryption and decryption (AES-256-GCM, including edge cases)
764
+ - Scope expansion logic (scope group parsing and deduplication)
765
+ - Configuration loading (environment variable substitution, format validation)
766
+ - Permission checking (all denial scenarios)
767
+ - Rate limiting (sliding window algorithm)
768
+ - Audit log hash chain (tamper-evidence verification)
769
769
 
770
770
  ```bash
771
- pnpm test # 运行所有测试
772
- pnpm test --watch # 监视模式
773
- pnpm test --coverage # 生成覆盖率报告
771
+ pnpm test # Run all tests
772
+ pnpm test --watch # Watch mode
773
+ pnpm test --coverage # Generate coverage report
774
774
  ```
775
775
 
776
776
  ---
package/dist/index.js CHANGED
@@ -7386,7 +7386,7 @@ var testCommand = new Command10("test").description("\u6D4B\u8BD5\u8C03\u7528 co
7386
7386
 
7387
7387
  // src/index.ts
7388
7388
  var program = new Command11();
7389
- program.name("broker").description("Agent Auth Broker CLI \u2014 AI Agent \u51ED\u8BC1\u7BA1\u7406\u4E0E\u6388\u6743\u4EE3\u7406").version("0.0.8");
7389
+ program.name("broker").description("Agent Auth Broker CLI \u2014 AI Agent \u51ED\u8BC1\u7BA1\u7406\u4E0E\u6388\u6743\u4EE3\u7406").version("0.0.9");
7390
7390
  program.addCommand(initCommand);
7391
7391
  program.addCommand(validateCommand);
7392
7392
  program.addCommand(diagnoseCommand);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agent-auth-broker",
3
- "version": "0.0.8",
3
+ "version": "0.0.9",
4
4
  "description": "AI Agent 集中式凭证管理与授权代理 CLI 工具",
5
5
  "type": "module",
6
6
  "license": "MIT",