Repository navigation
TOOL_SECRET_KEY 不再回退到开发密钥,缺了和 CREDENTIALS_KEY 一样拒绝启动 (#23) - #87
Merged
Merged
Conversation
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Be3SZps2JjqvyrJ1vbLmni
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Be3SZps2JjqvyrJ1vbLmni
#85 把单实例锁放在启动最前面,缺 TOOL_SECRET_KEY 时会先撞上连库失败,报错不再点名缺的变量。 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Be3SZps2JjqvyrJ1vbLmni
joesmart
force-pushed
the
joesmart/sec-tool-secret-key
branch
from
October 23, 2026 14:32
cf40b3c to
e5cbd1f
Compare
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.
改了什么
TOOL_SECRET_KEY去掉写死在仓库里的开发默认值。没设或留空时控制面启动直接报错退出,报错为「TOOL_SECRET_KEY 没设,用 openssl rand -hex 32 生成一个」,和CREDENTIALS_KEY一样。CREDENTIALS_KEY的做法一致:e2e 真栈(packages/e2e/src/stack.ts)和桌面验收脚本(packages/desktop/scripts/prove.ts)每次随机生成一把;verify 的stack.sh在 shell 和.env都没有时生成一把,存进.audit/verify-run/tool-secret.key复用;控制面测试里还没显式传toolSecretKey的 5 个文件补传。.env.example把TOOL_SECRET_KEY=从注释改为必填行;docs/开发.md的变量表改为「无,必填」,「跑起来」一节加上生成两把钥匙的说明;packages/control-plane/README.md、deploy/README.md、verify skill 同步修改。为什么这么改
issue 的建议方向是「非开发环境缺失即拒绝启动」,但仓库里没有区分开发和生产的判据:没有
NODE_ENV,也没有别的开关。现成的先例是CREDENTIALS_KEY,它在任何环境都必填,测试和 e2e 自己生成,开发靠.env提供。这次让TOOL_SECRET_KEY照同样的方式处理,两把钥匙的行为一致。没有新加一个「生产模式」开关再只在生产下拦截,理由有两个:
升级须知
.env需要加一行TOOL_SECRET_KEY=$(openssl rand -hex 32),否则pnpm dev起不来,报错会点名这个变量。TOOL_SECRET_KEY设成旧值继续用(旧值见本 PR 删掉的DEV_TOOL_SECRET_KEY),也可以删掉这些连接重建。deploy/remote/docker-compose.yml原来就用:?要求这个变量,生产部署不受影响。不在范围
多钥解密和密钥轮换(issue 里的「后续」)不在这个 PR 里。两把钥匙仍然只支持
v1:单钥。怎么验证的
packages/control-plane/test/start-keys.test.ts:用 tsx 起真实的src/main.ts,缺TOOL_SECRET_KEY、留空,以及缺CREDENTIALS_KEY时,进程都以 exit 1 退出,stderr 点名变量。在修复前的env.ts上跑,第一条是红的(stderr 里是「工具认证信息用开发密钥加密」的告警,进程最后死在连库上);修复后为绿。pnpm format:check && pnpm typecheck && pnpm lint:全部通过。pnpm --filter @baize/control-plane test:Test Files 118 passed | 1 skipped,Tests 1532 passed | 1 skipped。第一次跑有 1 条「等控制面下发报文超时」偶发失败,重跑全绿。pnpm --filter @baize/e2e test:Test Files 26 passed,Tests 53 passed。pnpm --filter @baize/desktop test:Test Files 8 passed,Tests 121 passed。node scripts/dev.mjs起了一次(docker 换成空壳,避免碰共用的 Postgres 容器;连临时库,端口 3462/5462)。带钥匙时控制面打出「控制面在 http://localhost:3462」,`/api/me` 返回 401,Web 返回 200;把TOOL_SECRET_KEY置空后,控制面报「TOOL_SECRET_KEY 没设,用 openssl rand -hex 32 生成一个」。Closes #23
🤖 Generated with Claude Code
https://claude.ai/code/session_01Be3SZps2JjqvyrJ1vbLmni