Repository navigation
fix(config): resolve build.dockerfile against devcontainer.json, not the context - #156
Conversation
…the context
The spec resolves build.dockerfile relative to the folder holding
devcontainer.json, like build.context. We passed it through unchanged
and the runtime asked Docker for it inside the context tar, so
{"dockerfile": "Dockerfile", "context": ".."} looked for <repo>/Dockerfile
and failed with "open Dockerfile: no such file or directory".
- config: BuildSource.Dockerfile is now an absolute host path. Both
dockerfile and context are resolved after variable substitution, so
${localWorkspaceFolder}/... is no longer joined onto the config folder.
- runtime/docker: BuildSpec.Dockerfile may be absolute. Inside the
context it becomes the context-relative name; outside it is appended
to the context tar as .dockerfile.<content hash>, as `docker build -f`
does for the reference CLI. prePullBaseImages reads the host path.
- tests: config resolution cases, locateDockerfile / tar injection unit
tests, the dcvm layout and an outside-context build end to end.
Integration fixtures that relied on the bug now use "../Dockerfile".
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
Code Review — a330439 · CLEAN
Range: the whole pull request (6303809...a330439).
I found no concrete defect in the reviewed changes. The Dockerfile/context resolution and Docker build-tar adaptation are consistent with the reference CLI behavior; no surviving correctness, contract, or determinism issue was substantiated.
What I reviewed
Coverage: Reviewed the whole PR range, base 63038094d3ae17749b83f114aabd7e4a9fc9313a through head a3304397a1ba53178dc0befc62888c842218893a (one commit, 13 files). Read the governing R1–R8 directives at the base; .dap/code-review.yml is absent, so the repository-specific engineering directives and core dimensions governed. Checked source resolution and substitutions, build consumers, Docker tar generation and Docker SDK request handling, relevant reference CLI path resolution, and fixture/test changes. Verified R1/R2/R5/R6/R8 concerns; did not run tests or execute the system. Conditional state-integrity, redelivery, and version-compatibility do not apply.
CLEAN — this round found nothing. Reply in a finding's own thread to argue it. On the pull request I answer @getdapnextai review, pause and resume.
* fix(build): bound outside-context Dockerfiles to the workspace v0.5.5 (#156) reads a build.dockerfile outside the build context from the host and injects it into the context tar. The path comes from an untrusted devcontainer.json and nothing bounded it, so an absolute path, ../ traversal, ${localEnv:...} or a symlink could name any file the process can read; the daemon's parse error ("unknown instruction: ...") then echoes its first line into the build output. - runtime/docker: locateDockerfile is the only host read of the Dockerfile. It resolves symlinks on both sides and reads a file outside the context only if it is a regular file of at most 1 MiB inside BuildSpec.WorkspaceRoot; an in-context file's host copy must resolve inside the context or the workspace. Otherwise it returns *runtime.DockerfileRefusedError, naming the configured path, before the context is tarred or the daemon is called. prePullBaseImages takes the contents it read instead of reading the path again. - runtime: BuildSpec.WorkspaceRoot; empty allows nothing outside the context. The engine sets it to LocalWorkspaceFolder for the devcontainer build and compose service builds. - config: Resolve rejects, lexically, a build.dockerfile outside both the workspace and the context with *ConfigInvalidError. - In-context Dockerfiles and the #156 layout (.devcontainer/Dockerfile with "context": "..") build as in v0.5.5. - Tests: refusal cases in both packages, a no-daemon BuildImage test, and an integration test with a hostile config that asserts through a recording socket proxy that no build or pull reaches the daemon and that the secret appears in no event or error. Refs #156, crunchloop/dap#8967 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(build): read the bounded Dockerfile through os.Root The bound was checked on a resolved pathname and the file then opened by pathname again, so a directory on the way swapped for a symlink in between could carry the read outside the workspace; SameFile only compared the stat and the open, which both followed the swap. readDockerfile now opens os.Root on the resolved root and stats, opens and reads the file through it, so no symlink or ".." can leave the root whatever the tree does after the check. Any failure to open it there, after the check found it, is a refusal. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(build): confine in-context Dockerfile reads to the workspace root os.OpenRoot opens the root itself by path. For a Dockerfile inside the context, the context was tried first as the root; a context inside the workspace is a folder the repository controls, so it could be swapped for a symlink between the check and the open. Try the workspace root first: its own path lies outside what the repository controls. The context remains the root only for a context outside the workspace. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: bilby91 <2201079+bilby91@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Bug
Seen 2026-11-19 on k8-dev. The dcvm repo's
.devcontainer/devcontainer.json:with the Dockerfile at
.devcontainer/Dockerfile. VS Code and the reference CLI build.devcontainer/Dockerfilewith the repo root as the context. v0.5.4 fails:Cause
config/resolve.go(determineSource,case hasBuild) joinedContextwith the config folder but passedDockerfilethrough unchanged.runtime/docker/build.gosends the context as a tar and asks Docker forDockerfileinside it, so Docker looked for<repo root>/Dockerfile. This only worked when the context was the config folder itself (the default".").Fix
The spec, and the reference CLI's
getDockerfilePath, resolvebuild.dockerfileagainst the folder that holdsdevcontainer.json. The CLI then runsdocker build -f <abs dockerfile> <context>.BuildSource.Dockerfileis now an absolute host path (filepath.Join(configDir, …); an absolute path is kept as is). Bothdockerfileandcontextare now resolved after variable substitution, as the reference CLI does. Before,"context": "${localWorkspaceFolder}"became<configDir>//home/u/proj. It's the same resolution code, so I fixed it here rather than leave it.locateDockerfile):BuildSpec.Dockerfilemay be absolute..dockerfile.<sha256[:12]>. This is whatdocker build -fdoes: the docker CLI injects it as.dockerfile.<random>. I matched it rather than failing because the reference CLI accepts this layout (Docker handles it there), and appending a single tar entry is the smallest change that matches. The name uses a content hash instead of a random suffix so the tar stays reproducible (tarDirectorynormalizes metadata for BuildKit cache hits).prePullBaseImagesnow reads the resolved host path instead ofcontext/dockerfile.Other readers checked
useruid.go,build.go(ImageNameretag) and the feature layer (up.golayerFeatures) write their own generatedDockerfileinto a temp context and pass"Dockerfile". Relative names behave as before, so nothing changes there.svc.Build.Dockerfilewith their own context by Compose rules. Left alone: relative names behave as before.BuildSource.Dockerfile. The compose inputs hash andcompose.ConfigHashcover compose services only, and the devcontainer ID doesn't include it.Behaviour change
A config that relied on the bug (a
Dockerfileat the context root, referenced as"Dockerfile"with"context": "..") must now use"../Dockerfile", as it already must for VS Code and the reference CLI. Five integration fixtures used that layout and are updated. Recorded in CHANGELOG under Unreleased/Fixed.Tests
config:context: ".."+dockerfile: "Dockerfile"→.devcontainer/Dockerfile; default context;../build/Dockerfile; absolute path;${localWorkspaceFolder}in both fields.runtime/docker:locateDockerfile(default, relative, absolute inside, absolute outside → injected with a stable name, missing outside → error);tarDirectoryappends the extra entry with normalized metadata.TestBuildSource_WithLocalFeaturenow uses the dcvm layout and asserts the context is the repo root.TestBuildSource_DockerfileOutsideContextbuilds a Dockerfile that sits outside the context.mainwith the exact production error.Local:
make lint(0 issues) andmake testpass. The affected integration tests pass. The full suite passes locally: 46 tests in 711s, run with-timeout=40mbecause the unshardedmake test-integrationexceeds its 10m limit here (CI shards it into 3 × 15m).Follow-up
DAP pins v0.5.4. It will need a version bump to the next patch (v0.5.5) once this is released. No release tagged here.
🤖 Generated with Claude Code