feat(open): ensure支持二次获取明文(ak存AES-GCM密文key_cipher, app.token-cipher-key派生密钥); 历史无密文Token自动轮换; V3迁移+回滚方案; 同步文档
This commit is contained in:
@@ -132,6 +132,8 @@ cp deploy/.env.example deploy/.env.dev # 填写 dev 凭据(已 gitignore,
|
||||
|
||||
仓库不提供固定 ak。每位开发者在本地生成随机 ak,只把 SHA-256 写入 `agent_api_key`,再用 `token_scope` 关联需要的作用域;明文只保存在本机客户端配置(如 `.kimi-code/mcp.json`,已 gitignore)中,不提交版本库。仓库历史中曾出现的 dev ak 必须视为已泄露并在数据库中禁用。
|
||||
|
||||
手工插入的 ak 没有 `key_cipher` 密文:走 `/mcp` 正常(只校验哈希),但被 `ensure` 命中时会触发自动轮换(旧把禁用、签发新把)——这是预期行为。
|
||||
|
||||
```bash
|
||||
AK="xqak_$(openssl rand -hex 24)" # 生成随机 ak,明文只贴进本机客户端配置
|
||||
printf %s "$AK" | shasum -a 256 # 输出的哈希写入 agent_api_key.key_hash
|
||||
@@ -211,9 +213,10 @@ curl -X POST http://localhost:8088/api/open/token/ensure \
|
||||
```
|
||||
|
||||
- 入参:`mobile`、`email` 至少一个(手机号优先);`scopeCode` 必填。人员只认企业账号(enterprise_type 0/1),查不到 → 404。
|
||||
- 已存在有效 Token → `{"created":false,"token":null,"keyPrefix":"xqak_xxx…",...}`(服务端只存哈希,**明文不可回吐**,丢了只能后台重新签发)。
|
||||
- 不存在 → 自动创建永久 Token → `{"created":true,"token":"xqak_...(明文,仅此一次)",...}`。
|
||||
- 调用写 `audit_log`(`open.token.ensure` / client_type=open-api)。
|
||||
- 已存在有效 Token → `{"created":false,"token":"xqak_...(解密既有密文得到的明文)",...}`(**支持二次获取**:服务端保存 SHA-256 哈希 + AES-GCM 密文,密钥由 `app.token-cipher-key` 派生)。
|
||||
- 已存在但无密文(历史数据)→ 自动轮换:禁用旧把、签发新把,按 `created=true` 返回新明文。
|
||||
- 不存在 → 自动创建永久 Token → `{"created":true,"token":"xqak_...(明文)",...}`。
|
||||
- 调用写 `audit_log`(`open.token.ensure` / client_type=open-api,不记录明文)。
|
||||
|
||||
**签发规则(2026-09-04 起)**:一作用域一 Token。后台签发时选 N 个作用域会生成 N 把 token,每把独立绑定单作用域;编辑存量 token 时作用域为单选。
|
||||
|
||||
|
||||
Reference in New Issue
Block a user