skillhub/openspec/changes/split-api-token-skill-capabilities/proposal.md
小妍儿 ✨ 3ee80f996b
feat(auth): split API token skill capabilities (#1049) (#1078)
* docs(openspec): propose split API token skill capabilities

Define five token capabilities (read, submit, publish-private, manage,
delete), the route mapping, combined-operation limits, token minting
limits, legacy token and CLI compatibility, and negative test design.

Refs #1049

Signed-off-by: 千乘妍 (Xiaoyaner) <xiaoyaner0201@users.noreply.github.com>

* docs(openspec): clarify token compatibility and bundle snapshot boundaries

Refs #1049

Signed-off-by: 千乘妍 (Xiaoyaner) <258399167+xiaoyaner0201@users.noreply.github.com>

* docs(auth): inventory Bundle authorization provenance

Record persisted evidence and fail-closed recovery rules before implementing snapshots.

Refs #1049

Signed-off-by: 千乘妍 (Xiaoyaner) <258399167+xiaoyaner0201@users.noreply.github.com>

* feat(auth): split token capabilities and classify route policies

Preserve Suite deletion authorization and verify legacy route compatibility against the original ordered catalog.

Refs #1049

Signed-off-by: 千乘妍 (Xiaoyaner) <258399167+xiaoyaner0201@users.noreply.github.com>

* feat(auth): enforce token ceilings on combined skill operations

Persist Bundle initiator capability snapshots and fail closed on unknown historical authority during recovery and retry.

Refs #1049

Signed-off-by: 千乘妍 (Xiaoyaner) <258399167+xiaoyaner0201@users.noreply.github.com>

* feat(auth): bound token issuance and expose effective capabilities

Validate requested scopes and expiry before rotation or extension. Expose capability discovery and machine-readable authorization errors without broadening token privileges.

Refs #1049

Signed-off-by: 千乘妍 (Xiaoyaner) <258399167+xiaoyaner0201@users.noreply.github.com>

* feat(tokens): add Web capability presets and CLI authorization guidance

Issue candidate-only login tokens, display effective capabilities and legacy compatibility, and require explicit delete authorization without automatic reissuance. Verify real HTTP candidate and legacy publication flows.

Refs #1049

Signed-off-by: 千乘妍 (Xiaoyaner) <258399167+xiaoyaner0201@users.noreply.github.com>

* docs(auth): document token capabilities and upgrade boundaries

Describe bounded issuance, compatibility aliases, CLI delete authorization, administrator upload changes, fail-closed Bundle recovery and the omitted-scopes deprecation schedule.

Refs #1049

Signed-off-by: 千乘妍 (Xiaoyaner) <258399167+xiaoyaner0201@users.noreply.github.com>

* docs(auth): align capability action boundaries

Document manage authorization for review withdrawal and keep DTO imports formatted with backend conventions.

Refs #1049

Signed-off-by: 千乘妍 (Xiaoyaner) <258399167+xiaoyaner0201@users.noreply.github.com>

* fix(publish): limit visibility ceiling check to token calls

Session uploads keep their previous path, and a missing locked row no longer raises a null pointer before the existing visibility checks run.

Refs #1049

Signed-off-by: 千乘妍 (Xiaoyaner) <258399167+xiaoyaner0201@users.noreply.github.com>

* fix(auth): preserve rerelease ceilings and explain bundle blocks

Carry token capabilities through rerelease and resolve visibility under the publication lock. Localize permanent Bundle authorization failures and hide ineffective retry actions.

Refs #1049

Signed-off-by: 千乘妍 (Xiaoyaner) <258399167+xiaoyaner0201@users.noreply.github.com>

* fix(auth): classify main's public routes and renumber bundle snapshot migration

main added public GET site-presentation routes and its own V122 migration. Record the new routes in the catalog baseline as unchanged public routes and move the Bundle authorization snapshot to V123.

Refs #1049

Signed-off-by: 千乘妍 (Xiaoyaner) <258399167+xiaoyaner0201@users.noreply.github.com>

* test(site): pin presentation upgrade check to V122

The upgrade test counted every migration after V121; with the Bundle snapshot now at V123 it saw two. Target V122 so it keeps checking only the presentation seed.

Refs #1049

Signed-off-by: 千乘妍 (Xiaoyaner) <258399167+xiaoyaner0201@users.noreply.github.com>

* fix(auth): compare token expiry ceilings at stored precision

Token expiry is stored at microsecond precision. On Linux CI Instant.now() carries nanoseconds, so a child token asking for exactly its parent's expiry compared as later and was rejected. Truncate requested expiry to microseconds before the ceiling check.

Refs #1049

Signed-off-by: 千乘妍 (Xiaoyaner) <258399167+xiaoyaner0201@users.noreply.github.com>

* fix(auth): renumber bundle snapshot migration after main's V123

main 22409aba added V123__homepage_recommendations. Move the Bundle authorization snapshot to V124 and record main's public site-recommendations routes in the token catalog baseline as unchanged public routes.

Refs #1049

Signed-off-by: 千乘妍 (Xiaoyaner) <258399167+xiaoyaner0201@users.noreply.github.com>

* test(auth): keep built-in skill sync out of token flow side-effect checks

Since main 22409aba the built-in skill sync can publish after startup, asynchronously, and its storage writes landed inside the 'denied rerelease writes nothing' assertion on CI. Disable built-in sync for this test class, as other integration tests already do.

Refs #1049

Signed-off-by: 千乘妍 (Xiaoyaner) <258399167+xiaoyaner0201@users.noreply.github.com>

* fix(auth): block bundle recovery with unknown authorization

Signed-off-by: XiaoSeS <87064762+XiaoSeS@users.noreply.github.com>
(cherry picked from commit cb8fb05d77d4b455032cbc2d3a1fdc2dd7bce894)
Signed-off-by: XiaoSeS <87064762+XiaoSeS@users.noreply.github.com>

* feat(web): redesign token credentials and compact permission controls

Signed-off-by: XiaoSeS <87064762+XiaoSeS@users.noreply.github.com>
(cherry picked from commit acd3615ee57a4bb432980601bb883a1a86906d1a)
Signed-off-by: XiaoSeS <87064762+XiaoSeS@users.noreply.github.com>

* chore(web): regenerate API types from integrated backend

Signed-off-by: XiaoSeS <87064762+XiaoSeS@users.noreply.github.com>

* fix(web): complete token locales and static analytics markers

Signed-off-by: XiaoSeS <87064762+XiaoSeS@users.noreply.github.com>

* test(auth): preserve operation-level bundle authorization errors

Signed-off-by: XiaoSeS <87064762+XiaoSeS@users.noreply.github.com>

---------

Signed-off-by: 千乘妍 (Xiaoyaner) <xiaoyaner0201@users.noreply.github.com>
Signed-off-by: 千乘妍 (Xiaoyaner) <258399167+xiaoyaner0201@users.noreply.github.com>
Signed-off-by: XiaoSeS <87064762+XiaoSeS@users.noreply.github.com>
Co-authored-by: 千乘妍 (Xiaoyaner) <xiaoyaner0201@users.noreply.github.com>
Co-authored-by: XiaoSeS <87064762+XiaoSeS@users.noreply.github.com>
2026-11-16 11:02:38 +08:00

51 lines
4.1 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

## Why
Issue #1049:自动化调用方需要一个“只能上传候选并提交审核”的 Token。当前 `skill:publish` 同时放行上传、送审、
PRIVATE `confirm-publish`、可见范围调整、归档、撤回和标签维护,无法只授予前两项。Token 一旦泄漏,持有人可以把
PRIVATE 候选直接发布为 `PUBLISHED`,不产生审核任务。
核对现有实现(main `929f3f1`,与 v0.2.26 镜像同一 revision)和本地干净实例时,还发现几处会突破 Token 能力上限的路径:
- 持有 `token:manage` 的 Token 可以签出带 `skill:delete` 的新 Token,自身却没有删除能力。
- SUPER_ADMIN 账号的 Token 上传 PRIVATE 时直接成为 `PUBLISHED`,不经 `confirm-publish`。
- 在已批准的 `NAMESPACE_ONLY` 技能上以 PRIVATE 上传新版本,会当场把技能改为 PRIVATE,其他空间成员立即失去访问。
- 新建 Token 接受任意 scope 字符串;`DELETE /api/v1/skills/{id}/subscription` 被删除规则通配命中,取消订阅需要 `skill:delete`。
## What Changes
- 技能写入能力拆成 `skill:submit`、`skill:publish-private`、`skill:manage`;`skill:read`、`skill:delete` 保留。
有效权限 = 账号/空间权限 ∩ Token 能力 ∩ 资源状态和治理规则。
- 每个现有要求 `skill:publish` 的技能写接口都有明确的新归属,并由目录完整性测试保证不遗漏。
- 组合操作按实际执行的能力检查:已有技能上改变可见性的上传同时要求提交与管理;重新发布不能绕过私有发布;
经 Token 调用时不使用 SUPER_ADMIN 直发捷径。
- Suite/Bundle 内部私有发布按发起时保存的权限判断;空快照只有能按原操作 ID 证实历史发起方式和旧授权时才兼容,
来源不明时阻塞,恢复与失败重试不能继承当前执行者权限。
- Token 创建、轮换、续期按展开后的有效能力检查,新 Token 不得超过调用 Token;省略 scopes 和旧版别名同样适用。
未知 scope 拒绝。
- “读取技能”新增本人所属空间及角色、当前 Token 有效能力的查询。
- 存量 `skill:publish` Token 的存储与原 scope 路由授权保持不变并标记旧版兼容;SUPER_ADMIN Token 上传
PRIVATE 不再自动直发,须显式确认,SUPER_ADMIN 会话上传行为不变;新建入口的宽默认值有明确退出计划。
- CLI 登录(设备码、浏览器回跳)改签 `skill:read + skill:submit`;旧 CLI 的 publish、送审保持可用,
`remove` 需要显式授予删除权限。
- 保留稳定错误码 `error.apiToken.scope.missing` 与 `error.apiToken.endpoint.unsupported`。
## Capabilities
### New Capabilities
- `api-token-capabilities`:API Token 的技能能力划分、接口映射、组合操作上限、Token 签发上限、查询接口和兼容迁移。
### Modified Capabilities
无已归档 capability。`docs/03-authentication-design.md` 第 5 节的作用域说明随实现同步更新。
## Impact
- **Auth**:`RouteSecurityPolicyRegistry` 路由映射、`ApiTokenScopeService` 能力展开、`ApiTokenService`/`TokenController` 签发校验、`DeviceAuthService` 默认能力。
- **Domain/app service**:`SkillPublishService` 上传可见性与 SUPER_ADMIN 捷径、`SkillReviewSubmitService#confirmPublish`、Suite Bundle 执行与恢复。
- **API**:`/api/cli/v1/auth/whoami` 响应增加有效能力;`/api/{v1,web}/me/namespaces` 对 Token 开放;Token 创建对未知 scope 返回 400。需要重新生成 OpenAPI 类型。
- **Web**:Token 创建对话框增加预设与能力说明;Token 列表展示能力与兼容状态;`cli-auth` 改签新能力。
- **CLI**:`whoami` 展示能力;`remove` 缺少删除权限时给出明确提示。
- **兼容**:存量 Token 的 scope 存储及原路由授权保留;SUPER_ADMIN Token 上传 PRIVATE 不再直发,需显式确认;
SUPER_ADMIN 会话上传行为不变;旧 CLI 发布与送审可用。
- **Out of scope**:Suite 权限细分、Token 人工审批、多人维护(#732)、可信成员免审(#1068)、namespace 级 Token 绑定。