fix(docker): 容器路径别把 .env 挂进工作区(#50) - #51
Merged
Merged
Conversation
容器里 Codex 是 danger-full-access(exec 还额外带 --dangerously-bypass-approvals-and-sandbox),前提是「挂进来的只有该看的 工作区」。而文档教的是 `-v "$PWD:/workspace"`,紧跟在 `lc init` 把凭证写进 那个目录的 .env 之后——照 README / 离线部署指南一步步走必然踩中,不是假想 场景。entrypoint 特意只注入 LITELLM_MASTER_KEY(#42),挂载把整份 .env 又 送了回来;#46 给 `lc code` 加的警告在这条路上结构上不可能触发,因为容器 根本不跑 lc。 - docker/entrypoint.sh:生成配置后检测 $PWD/.env,往 stderr 打一行警告说清 权限级别和怎么避开,只报路径不读文件。与 #46 一致:警告,不阻断。 - README / README.zh-CN / docs/offline-deployment.md / docker/Dockerfile: 4 处 `-v "$PWD:/workspace"` 改成明确的项目目录,并在紧邻位置说明原因。 - docs/threat-model.md:把容器路径并进「Credentials in the Codex workspace」 一节(两条路径同一个暴露面),并修正原来「容器路径这个分离已经成立」的 说法——挂载的就是工具目录时它不成立。 - scripts/test-entrypoint.sh:有 .env 时警告且照常执行 codex、没有时不警告、 不打印 .env 里的值。 - scripts/test-project-metadata.py:文档与 Dockerfile 不得再出现把当前目录 挂进 /workspace 的写法。 两条断言都做过变异验证(去掉检查 / 改成恒真,各自都会红)。 Closes #50 Co-Authored-By: Claude Opus 5 <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.
Closes #50
问题
容器那条路和 #46 修的宿主机那条同族,但更重,而且踩在 happy path 上。
docker/entrypoint.sh生成的是sandbox_mode = "danger-full-access",exec模式还额外带--dangerously-bypass-approvals-and-sandbox(Codex 的 Landlock/seccomp 在多数容器运行时下初始化失败,所以把容器本身当隔离边界)。这个取舍成立的前提是「挂进来的只有该看的工作区」。而文档教的是
-v "$PWD:/workspace",紧跟在lc init把凭证写进那个目录的.env之后。离线部署指南第 4 节尤其明显:内网侧刚在解包目录里跑完lc init,$PWD就是那个目录。照文档一步步走必然踩中,不是「用户手贱在工具目录里干活」。叠加两点:
LITELLM_MASTER_KEY(lc code / lc e2e 把整个 .env 注入 Codex 进程,模型敲一句 env 就能看到所有上游的凭证 #42 收紧的那条),挂载把整份.env又送了回来——里面是全部上游的地址、API Key、自定义头的值,包括这次会话用不到的。lc code加的警告在这条路上结构上不可能触发:它在bin/lc里,容器路径根本不跑lc。改了什么
姿态与 #46 保持一致:警告 + 文档,不阻断。
docker/entrypoint.shexec codex前检测$PWD/.env,往 stderr 打警告README.md/README.zh-CN.md/docs/offline-deployment.md/docker/Dockerfile-v "$PWD:/workspace"→-v "/path/to/your-project:/workspace",紧邻位置说明原因docs/threat-model.mdscripts/test-entrypoint.shscripts/test-project-metadata.py/workspace的写法几个实现选择:
$PWD/.env而不是写死/workspace,这样-w换过工作目录也成立。--version/--help的透传分支不会响。bin/lc的warn_env_in_workspace():在这个目录里用 Codex 审查 airgap-coder 自己是正当用法,且这会是个破坏性变更。断言覆盖(合并前自查)
新行为都有断言钉住,两个脚本
ci.yml和release.yml都已经在调,不需要动.github/。scripts/test-entrypoint.sh:.env→ stderr 出现警告并指出路径danger-full-access).env里的值.env→ 不出现警告(防「永远都响的警告」)scripts/test-project-metadata.py:文档与 Dockerfile 里不得出现-v "$PWD:/workspace"这类写法。怎么验证的
变异测试确认断言真的会红,不是走过场:
if false).env in the workspace did not produce a warningif true)workspace warning fired without a .env in the workspace$PWDREADME.md mounts the current directory into the container workspace本地全绿:
py_compile/bash -n/test-project-metadata.py/test-entrypoint.sh/test-version.sh/test-lc-secrets.sh,以及lc sync生成器冒烟(跑完已删除生成物,git status干净,无.env)。真实容器行为以 CI 的
dockerjob 为准。未做
按 #50 的指示,没有动「把
.env搬出仓库」——那是独立的架构决策,实现完这条之后单独开 issue 写取舍。🤖 Generated with Claude Code