管理台可以密码登录、按角色进入,并把 Watchman 会话 token 交给浏览器。HXOPS 真实跳转仍未联调。 Co-authored-by: Cursor <cursoragent@cursor.com>
4.6 KiB
4.6 KiB
Task Context Pack
Task Goal
M02 用 Casdoor 做身份和三个粗角色。当前只实现 S2:可替换的 Casdoor 端口、服务端会话、密码登录、当前用户和退出。不保护平台写接口,不接收 HXOPS 断言,不做界面。
Knowledge Posture
- Mode: standard
- Maturity: L1
Current Slice Or Group
S2 会话与密码登录。用户已确认继续。S1 已复审 PASS。S3 及以后未批准开做。
Gate Policy
- Recommended: strict
- Selected: balanced
- finalApprovalRequired: true
- Policy Notes: S2 是 high-risk、risk_score 4、critic-required。做完必须停,不能续跑 S3。S1 的验签模块保持不动,除非 S2 必须调用它且不改变其拒绝规则。
Bugfix Context
不适用。
Requirement Source
.task/2026-11-17/m02-auth/requirement.md
Implementation Source
.task/2026-11-17/m02-auth/implementation-plan.md 的 Slice 2
Involved Modules Or Areas
services/watchman 内新建 watchman.auth 校验模块和对应测试。
Loaded Context
Global Rules
AGENTS.md 的安全底线:秘密不入库、不进日志。D19 已确认授权模型。
Knowledge Map Matches
无单独认证知识区。以任务需求和 M01 当前代码为准。
Path-Proximity Rules
services/watchman 下没有 MODULE_RULES.md。
Excluded Context
未加载 Cron、报警、企微、syops 实现源码。S1 不读 .env.local。
Loaded Rules
standards://api/api-envelope?version=1.1.0(本切片不新增 HTTP)standards://security/red-line?version=1.1.0standards://engineering/code-comments?version=1.1.1(实现时检索原文)- D14、D19
Loaded Docs
- M02 requirement 与 implementation plan
docs/decisions.md的 D19、O10
Execution Mode
- Mode: sequential
- Current Slice Or Group: S2
- Parallel Members: 无
- Fallback Order: 2
- Shared Files:
app.py、config.py、迁移目录 - Merge Owner: 主 Agent
- Conflict Resolution Rule: 不并行
- Validation Level: slice
Execution Chain
用户确认 S2 → critic → 只实现 S2 → 跑 pytest → 异系列审查 → 停在 S3 之前。
Allowed Modification Scope
services/watchman/src/watchman/auth/services/watchman/src/watchman/api/的登录路由和注册services/watchman/src/watchman/core/config.pyservices/watchman/src/watchman/models/与services/watchman/migrations/,仅限会话表services/watchman/tests/的登录与会话测试.env.example已有占位,不要写入真实值
Forbidden Modification Scope
- 前端页面、平台写接口的授权、HXOPS 断言
D:\PROJECT\syops的任何写入- 读取、打印或复制
.env.local里的密钥 - 新的直接依赖和
uv.lock改写 - 角色表、用户授权表、密码哈希
Key Existing Classes Or Entrypoints
- S1:
watchman.auth.token_verifier.verify_rs256_token UnauthorizedError为 41000,ServiceUnavailableError为 503 且retryable- 信封:
watchman.core.response.success_body - RLS:
migrations/versions/20261117_0001_platform_rls.py,set_tenant只用服务端WATCHMAN_TENANT_ID - 路由注册在
watchman.api.app.create_app
Required Behavior
密码登录通过可注入端口。成功写入会话并保存端口返回的角色,失败 41000。端口未配置或不可用返回 503,且不建立会话。当前用户不返回秘密。退出后同一会话不能再读到当前用户。健康检查仍匿名。租户只来自服务端配置。不保存密码、client secret 和 Casdoor token。
Non-goals
平台写接口收口、对象检查、HXOPS 断言、登录页、真实 Casdoor 网络测试。
Implementation Steps
- 增加带 RLS 的会话表和迁移,字段只包括身份主体、签发方、显示名、角色快照、角色确认时间、过期时间、服务端租户。
- 登录、当前用户、退出。Casdoor 调用可替换,测试不访问网络。
- 断言响应里没有密码、secret 和 token。
Validation Commands
uv run pytest services/watchman/tests -q
Assumptions
- 会话 8 小时。角色快照可以写入,但 5 分钟后的重新确认属于 S3。
- 浏览器会话用 HttpOnly cookie。本地 HTTP 开发不强制 Secure。
- 真实 Casdoor 客户端可以写,但测试必须注入替身,不能读取
.env.local。
Risks
- 迁移一旦执行,回滚要有 down。
- 测试若加载本机
.env.local,可能误打真实 Casdoor。 - S2 结束时平台写接口仍然匿名可写。
Stop Conditions
- critic 判定不能安全开做时停止。
- S2 审查完成或需要用户决定时停止。
- 不开始 S3。