Repository navigation
fix(installer): provision project credential key during upgrades - #1316
Merged
Merged
Conversation
Robert0622
approved these changes
Nov 25, 2026
Robert0622
left a comment
Collaborator
There was a problem hiding this comment.
评审 dd0f3b7(基于 main 7bebfa5)。代码看过,也在部署环境里实测了升级路径,没有发现阻塞问题,通过。
代码
start.sh pull:configure.sh --project-credential-key放在lock_compose_upgrade之后、compose pull/up之前执行,补齐密钥和启动平台都在同一把升级锁里。之后导出的空值会被unset,Compose 能从.env读到密钥。configure.sh:--project-credential-key模式只处理密钥,不会顺带补LOOPFORGE_DATA_DIR、AGENTFLOW_CREDENTIAL_KEYS。按最后一条匹配判断,这和 dotenv 后写覆盖前写的规则一致。""、''和行尾# 注释都算空值,注释会保留;非空值不改。.env不存在时直接退出并提示先安装。save_existing_env:先写同目录临时文件,再os.replace替换。文件权限沿用原来的;.env是符号链接时写到链接目标,链接本身保留;按newline=''读写,CRLF 不会被改掉。
部署实测(本机部署:MySQL 8.4.7 全新库,平台用本 PR 代码构建。容器里没有 Docker,所以 docker 换成了替身:环境变量插值交给真实的 docker-compose v2.40.3 config 计算,up 时用算出来的 platform 环境启动真实平台进程,exec mysql 指向本机 MySQL。凭据都是合成的。)
- 在 main 上复现问题:准备一份 #1295 之前的
.env(没有密钥),执行./start.sh pull。退出码为 0,但.env里没有密钥,平台进程拿到的AGENTFLOW_PROJECT_CREDENTIAL_KEY为空,新建项目凭据返回 503「请为平台配置 AGENTFLOW_PROJECT_CREDENTIAL_KEY」。 - 用本 PR 升级同一套部署,同时导出空的
AGENTFLOW_PROJECT_CREDENTIAL_KEY=:输出Configured AGENTFLOW_PROJECT_CREDENTIAL_KEY in existing .env。新增的值能解码出 32 字节,.env只多了这一行,权限仍是 600。平台进程里的密钥和.env一致,新建项目凭据返回 201。 - 再升级两次(不导出这个变量):都提示
Keeping existing .env,.env的 sha256 没有变化,平台进程重建。用不带 value 的 PUT 改名(需要解密原来的密文),返回 200。对照组:把.env换成另一把合法密钥再执行 pull,脚本保留了这把换上的密钥,同样的 PUT 返回 400「无法解密项目凭据」。换回原密钥后再执行 pull,又能正常解密。由此可以确认:前面的 200 确实是解密成功,已有的非空密钥也不会被覆盖。 - 边界情况:
- CRLF 文件、
export AGENTFLOW_PROJECT_CREDENTIAL_KEY="" # project key、权限 640:补上了密钥,CRLF、export前缀、注释和权限都保留,平台进程里的密钥与.env一致。 .env里没有密钥、外部导出了非空密钥:这把密钥原样写进.env,平台用的就是它。下一次 pull 不导出变量,平台仍然用同一把密钥。.env是符号链接:写入了链接目标,链接保留。
- CRLF 文件、
测试
python3 scripts/test-install.py -q:本 PR 70 个测试通过(跳过 2 个,都是 Bash 3.2 用例),main 69 个通过。新增的test_start_pull_configures_project_credential_key_once拿到 main 的脚本上跑,missing、empty、quoted empty、provided 四个子用例失败,说明这个测试能抓住这个问题。bash -n start.sh、bash -n scripts/configure.sh、git diff --check、python3 scripts/check-public.py通过。CI 全绿。
P3(不阻塞):外部导出空值的情况只在 pull 里处理了。用 docker-compose 验证过:导出 AGENTFLOW_PROJECT_CREDENTIAL_KEY= 后,即使 .env 里有密钥,config 算出来的值仍为空。所以带着这样的空导出执行 ./start.sh、dev 或 release(都走 install.sh)重建平台,还是会拿到空密钥。可以考虑把这行 unset 挪到 compose() 或 install.sh 里,这样所有入口都能覆盖到。
Robert0622
pushed a commit
that referenced
this pull request
Nov 25, 2026
Bring in #1316, #1319 and #1318. Conflicts in orchestration and workspace docs, run admission, the MCP run tool, the LOOP designer prompt, catalog and sharing comments, the Web flow, issue and run views, index.html and the sandbox selection Web test are resolved by taking main's behaviour and applying this branch's LOOP terminology. Rename the user-visible SOP copy that #1319 added outside the conflicts (OpenAPI, run admission errors, the runtime sandbox picker and its assistant prompt) with the same rules. Co-Authored-By: Claude Code <noreply@anthropic.com>
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.
What changed
#1295 introduced the encryption key for project credentials. An existing Compose installation upgraded with
./start.sh pullcould start without a usable key and return HTTP 503 when saving a project credential.AGENTFLOW_PROJECT_CREDENTIAL_KEYunder the Compose upgrade lock before starting the platform. Fill a missing or blank setting in.envand reuse a configured key on subsequent upgrades.Scope
Compatibility
The official Compose install and upgrade paths share the key initializer. Custom deployments supply a stable key to their platform processes through their own configuration.
Validation
python3 scripts/test-install.py -qin Linux passed 68 tests. The two Bash 3.2 tests skipped there passed on macOS.bash -n start.sh,bash -n scripts/configure.sh,git diff --check, andpython3 scripts/check-public.pypassed.Safety