Repository navigation
Conversation
无管理员时启动签发 30 分钟一次性 token(库中只存 sha256,stdout 打印一次), register 必须携带;ADMIN_USERNAME/ADMIN_PASSWORD 幂等建首管并跳过 token, ADMIN_RESET_TOKEN 开启单次恢复通道。并发抢注用 pg_advisory_xact_lock 串行化, 注册关闭判据改为「存在任何管理员行(含软禁)」;用户名唯一索引覆盖全表, 禁用者的名字不可复用。前端按 bootstrap-status 切换初始化/登录并补 token 字段。
This was referenced Oct 24, 2026
This was referenced Nov 14, 2026
…n wiring + doc counts)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
做了什么
GET /api/auth/bootstrap-status(匿名):{needs_bootstrap, enforce_mode};无任何管理员行(含软删)时needs_bootstrap=true,enforce_mode当前恒为off。BOOTSTRAP TOKEN:,bi_setting只存 sha256 + 过期时间;首次建号成功即删除。POST /api/auth/register改为必须携带bootstrap_token;缺失/过期/不匹配返回 20200,文案与登录失败可区分。ADMIN_USERNAME+ADMIN_PASSWORD:启动期幂等创建首管并跳过 token(已有管理员时不动)。ADMIN_RESET_TOKEN:开启POST /api/auth/recover-admin,单次有效(记录已用令牌 hash),成功重置首个有效管理员口令并撤销其全部会话。pg_advisory_xact_lock串行化;注册关闭判据从「存在存活用户」改为「存在任何管理员行」。怎么做
service/auth/bootstrap.go;Register在事务内先取 advisory lock,再校验管理员存在性、bootstrap token、用户名复用,最后建号 + 认领 owner + 签发会话 + 消费 token。main.go在迁移后、路由装配前调用EnsureBootstrap,把打印动作留在进程入口;SetupRoutes接收已装配的 auth service。测试证据
cd backend && go test -race -count=1 ./...全绿。TEST_DATABASE_URL指向临时库):两个并发 register 只允许一个成功,失败方 20200;token 被消费、needs_bootstrap转 false。pnpm check(仅既有 CSS 警告)、tsc --noEmit、scripts/gate-frontend-tests.sh(67 文件 / 956 用例全绿)、pnpm build。/account自动进入注册态并显示 token 字段 → 填入启动日志 token → 注册成功,显示alice / admin与 PAT 区;bootstrap-status返回needs_bootstrap=false;用新账号口令登录成功;recover-admin:错误令牌 20200,正确令牌 200,旧口令登录失败、新口令成功,同一恢复令牌再用 → 20200;ADMIN_USERNAME/ADMIN_PASSWORD启动路径:日志无BOOTSTRAP TOKEN,直接登录成功;idx_user_username阻止软删用户名复用。备注
make api-gen:仓库已知的前端半步失败/后端缺少oapi-codegen/runtime依赖,本次只手工维护 openapi 与前端手写类型;生成物未改动。