feat(auth): accounts, sessions, RBAC and server-stamped actors

上线账号权限管理(后端):
- 迁移 000032:users + user_sessions(token 只存 sha256,服务端可即时撤销)
- bcrypt 密码、8 次失败锁 15 分钟、统一 401 错误防用户名枚举
- 三角色 viewer/engineer/admin;HttpOnly+SameSite=Lax 会话 cookie,滑动续期
- 强制改密锁定:must_change_password 会话只能走 auth 端点;首登 dobotai
- bootstrap:users 表为空时创建 admin(初始密码 dobotai,强制改密)
- 生产双闸授权/回滚/失败重试收敛为 admin 角色;AuthorizedBy 用会话身份
- 全部业务写端点删除手填 actor 字段(operator_ref/reviewer_ref/created_by/
  sealed_by/confirmed_by),服务端从会话注入;auth 关闭的开发 socket 回退 system
- 成员管理 API:列表/创建/改角色/启停/重置密码,最后一名 active admin 保护
- RBAC 矩阵纯函数契约测试 + 中间件行为测试(登录/锁定/角色/审计戳)
- 附带修复:GET /api/v1/users 曾被 GET=viewer 规则误放行(测试抓到)
This commit is contained in:
2026-09-13 15:30:24 +08:00
committed by 姚章浩
parent 6592df01b6
commit fbe80ad784
16 changed files with 1656 additions and 86 deletions
+5
View File
@@ -44,6 +44,10 @@ func run(ctx context.Context, getenv func(string) string) error {
if err := postgresstore.ApplyMigrations(ctx, pool); err != nil {
return err
}
authStore := postgresstore.NewStore(pool)
if err := bootstrapInitialAdmin(ctx, authStore, time.Now); err != nil {
return err
}
releaseAuthorizationToken := ""
if config.ProductionReleaseRequestsEnabled {
releaseAuthorizationToken, err = weknora.ReadAPIKeyFile(config.ProductionReleaseAuthTokenFile)
@@ -82,6 +86,7 @@ func run(ctx context.Context, getenv func(string) string) error {
ProductionBackupRestoreVerified: config.ProductionBackupRestoreVerified,
ProductionReleaseAuthorizerRef: config.ProductionReleaseAuthorizerRef,
ProductionReleaseAuthorizationToken: releaseAuthorizationToken,
Auth: &httpapi.AuthConfig{Store: authStore, SessionTTL: 12 * time.Hour},
})
if err != nil {
return err