Repository navigation
fix: reject symlink destinations in local filesystem writer - #807
Conversation
|
Fixed the Windows release build failure in cc6f2ca. Verified full application builds for all five release targets (Windows amd64, Linux amd64/arm64, Darwin amd64/arm64). Linux regression tests pass, and the writer tests cross-compile for the remaining targets. These cross-compilation checks do not execute Windows/macOS tests. The PR description now documents the implementation, scope, and exact validation. |
|
CI follow-up: the Windows binary build and Release Build Preflight now pass for cc6f2ca, and Windows create/update integration jobs pass as well. The linked Erlang Helm failure occurs after Draft successfully generates the files and the image successfully builds. Both deployed app containers repeatedly terminate with This points to an Erlang application/runtime memory issue rather than a no-follow file-open failure. The template and integration resource settings were not changed by this PR. The precise source of the Erlang memory use is not established by these logs; it needs a separate runtime reproduction/profile before choosing a memory-limit or VM-configuration change. |
|
Reproduction attempt completed in the requested development subscription/resource group, using an isolated namespace on an existing AKS cluster, plus local Docker/kind controls. The CI OOM did not reproduce.
These results do not establish the CI-specific cause. Its exact built image was in an ephemeral registry; the rebuilt image is not byte-identical. CI runs Ubuntu 26.04, so host kernel/cgroup/process-accounting differences also remain. Capturing the exact image and memory.events/memory.stat/process RSS on the failing CI runner is the next useful diagnostic step. No application memory limits or VM flags were changed during these tests. |
|
Updated the kind test stack and added resource diagnostics for the next CI run:
Validation: YAML parsing and bash syntax checks passed, the new pinned kind/node pair successfully created a cluster, and all three diagnostic scripts executed successfully locally. New finding: the Erlang image now reproduces OOMKilled/exit 137 locally on this updated node image, whereas it was healthy on the earlier v1.34.0 node image. An experimental Erlang scheduler cap did not resolve startup failures. Therefore this update is an instrumented CI experiment, not a confirmed OOM fix. The newer node image reports containerd 2.3.4; runtime/node-image differences now warrant investigation. Captured local evidence is under /tmp/opencode/draft-erlang-repro/updated-kind-oom-diagnostics.log. |
|
The updated CI run still fails, but diagnostics rule out node memory exhaustion: the runner has 4 vCPUs / 15.61GiB RAM with approximately 14GiB available; the kind Docker container has no explicit memory cap and Kubernetes reports MemoryPressure=False. Local root-cause experiment: on the updated kind node, the Erlang container inherits an open-file limit ( Confirmed under the original deployment constraints: patched only the local test deployment startup command to This explains why giving the kind node more memory is not the appropriate fix and why this runtime limit disproportionately affects Erlang. The local A/B test establishes the nofile limit as the trigger in the reproduction; the failing CI pod nofile limit itself was not captured in this run. A targeted nofile-limit correction should be tested next rather than increasing application memory. No additional repository changes made in this investigation. |
|
Historical pipeline comparison strengthens the runner-environment hypothesis and confirms this OOM predates PR #807:
Across the Oct 22, Nov 1, and Nov 14 logs: same sample commit 8922db58edd2981d2ecd9bd2c20a8da6ed680a15; same erlang:27.0-alpine and alpine:3.17 base-image digests; rebar3 3.28.0 and elli 3.3.0; same 1Gi limit. The Nov 1 passing and Nov 14 failing Helm deployments even have the same pod-template hash (8b8f64f7d). The branch comparison between those runs changes codeql workflow and Go dependency files, not Erlang templates/integration configuration. The observed pass/fail boundary therefore correlates with ubuntu-latest moving from 24.04 to 26.04, not the no-follow change or kind version alone. The newer runner lists kernel 7.0.0-1019-azure, systemd 259.9, Docker 29.4.2. The exact changed runtime default still needs isolation: historical jobs did not print pod nofile limits, and old runner software metadata could not be retrieved. Mechanism evidence: Erlang OTP 27 source (erts/emulator/sys/common/erl_poll.c, initialization around lines 2086-2106) reads sysconf(_SC_OPEN_MAX) and explicitly notes the port-table size is based on max_fds and should not be huge. This supports the local A/B result: inherited nofile=1,073,741,816 causes ~2GiB RSS; nofile=65,536 restores normal startup under the unchanged 1Gi cap. It does not substitute for measuring the failing CI pod limit. |
|
Updated the generated Erlang Dockerfile entrypoint to apply Verified using a freshly generated Dockerfile and rebuilt sample image, launched with the problematic inherited nofile limit of 1,073,741,816 and the original 1Gi memory / 1 CPU limits:
This targets the locally reproduced Erlang startup memory issue directly; CI will validate it in the previously failing environment. |
David Gamero (davidgamero)
left a comment
There was a problem hiding this comment.
lgtm
Summary
Prevent generated output files from following a symlink at the destination and truncating or writing its target. Repository-controlled symlinks at fixed output names can otherwise redirect generated content outside the checkout; validation of template value bytes does not protect the output path.
openFileNoFollowhelper while retaining the shared write and close error handling.O_WRONLY | O_CREATE | O_TRUNC | O_NOFOLLOW, rejecting a final-component symlink atomically during open.CreateFilewithFILE_FLAG_OPEN_REPARSE_POINTandOPEN_ALWAYSto open without following the final reparse point or truncating it. Inspect the opened handle, reject reparse points, and only then truncate the same handle. This avoids a separate path-check/open race.Why platform-specific files are necessary
The initial version failed the Windows release preflight because
syscall.O_NOFOLLOWis undefined on Windows. A runtimeGOOSconditional cannot fix this: Go still resolves constants and type-checks references in runtime branches at compile time. Platform-specific source selection keeps the Unix flag out of Windows builds and provides the Windows no-follow equivalent.Scope
This protects the final path component. Symlinked parent directories require separate hardening; this change does not establish checkout-root confinement.
Validation
go test ./pkg/templatewriter/... ./pkg/osutilon Linux.GOOS=<os> GOARCH=<arch> go build -o /tmp/opencode/draft-nofollow-<target> ..go test -exec=true ./pkg/templatewriter/writers; these checks compile but do not execute foreign-platform tests.git diff --check.