Files
prompts/.dockerignore
sneak 533fc61817
All checks were successful
check / check (push) Successful in 7s
Keep secrets out of the Docker build context at every depth (closes #29)
The canonical .dockerignore was three lines -- .git, node_modules, .DS_Store
-- while the canonical Dockerfile does `COPY . .`, so a developer's local
.env, *.pem or *.key was shipped into the build context and could land in an
image layer. Nothing surfaced it because .gitignore covers those patterns, so
the files are invisible to every git-based check.

The obvious repair, copying .gitignore's secret patterns across, is worse than
the gap it closes. .dockerignore does not use .gitignore semantics: Docker
matches with Go filepath.Match, `*` does not cross `/`, and a pattern without
a leading `**/` is anchored at the build-context root. A file listing .env,
*.pem and *.key therefore reads as solved, reviews as solved, and protects
only the repository root, while config/.env and certs/server.key still ship.
The three-line file at least invited scrutiny; the transplanted form
manufactures confidence and stops anyone looking.

So every depth-independent pattern here carries the `**/` prefix and only
genuinely root-anchored entries stay unprefixed. `**/node_modules` fixes a
defect the three-line file had today for any nested node_modules,
independently of the secret exposure.

Coverage is not limited to the three patterns the issue names, because the
enumeration found more shapes reaching the image. `**/*.env` covers the
prod.env / local.env convention, which the .env and .env.* spellings miss
entirely; `**/.envrc` is a secrets file by direnv convention; `**/*.p12` and
`**/*.pfx` are bundles carrying private keys; and `**/id_rsa`, `**/id_dsa`,
`**/id_ecdsa`, `**/id_ed25519` are the extensionless SSH keys that were
covered before only when someone happened to append a .key suffix.

Matching is case-sensitive, so `**/*.key` does not match certs/SERVER.KEY,
which is reachable on the case-insensitive filesystems most laptops use.
Doubling each pattern with an ALL-CAPS twin is not the fix: measured against
the planted set it still ships certs/Server.Key and certs/Ca.Pem while reading
as though case were handled, which is this issue's failure mode restated in a
new place. filepath.Match supports character ranges, so the secret-material
extensions use `**/*.[kK][eE][yY]`, `**/*.[pP][eE][mM]`, `**/*.[pP]12` and
`**/*.[pP][fF][xX]`, covering every capitalisation in one line each. Names
that exist in exactly one spelling because a tool writes them -- .env, .envrc,
id_rsa -- stay literal.

Deliberately not covered: bare `key` and `pem` filenames, which no tool
produces and which collide with legitimate paths (a `**/key` pattern would
delete an internal/key/ package directory from the context); `**/id_*`, which
would match ordinary source such as id_generator.go; and *.crt and *.cer,
which are public certificates rather than secrets and are sometimes a
legitimate build input. Each of those is planted as a positive control and
verified present in the image after the change.

The OS and editor patterns are included on their own merits rather than by
mirroring .gitignore. None of them is ever a build input, and editor state in
particular churns under a developer's hands, so each one is a source of
`COPY . .` invalidation carrying no information about the source tree. Now
that the checks are keyed on CHECK_EPOCH rather than on accidental context
churn, there is no reason left to keep churn in the context. Language build
artifacts are deliberately absent: they are per-repo, and the file's header
comment tells consuming repos to add their own host-built binaries, which is
the case that actually bites -- a host `make build` drops a multi-megabyte
artifact into the context where .gitignore hides it from every git-based
check. That comment gives the anchored form explicitly, `/myapp` rather than
`**/myapp`, because the prefixed spelling also matches cmd/myapp/ and deletes
the package directory. The header comment is the only part of this guidance a
consuming repo actually receives, since it is vendored with the file.

.gitignore is untouched. Its semantics are the inverse: an unanchored pattern
already matches at any depth, so `**/`-prefixing it produces a file that is
wrong in a way that looks careful. That asymmetry is why "derive one from the
other" was the wrong instruction, and it is now written down in
REPO_POLICIES.md in both directions, together with the case-sensitivity rule
and the requirement to verify by enumerating the image rather than by reading
the patterns. Every consuming repo inherits .dockerignore by copy, so the trap
has to live where the next person looks, not only be fixed once here. Both
repo checklists gain the same requirements, since they are what an agent reads
while extending the file.

Verified by planting twenty-eight secret shapes at the root and up to three
directories below it -- including CA.PEM, SERVER.KEY, Server.Key, Ca.Pem,
config/prod.env, config/local.env, deploy/secrets/.envrc, extensionless SSH
keys and PKCS#12 bundles -- alongside seven positive controls, then building a
standalone probe image doing `COPY . .` and listing what actually landed
inside it. Before: nineteen of the twenty-eight in the image. Against three
naive forms: unprefixed leaks twenty-one, `**/`-prefixed lowercase-only leaks
six, ALL-CAPS-doubled still leaks two. After: zero, with all seven controls
still present, including internal/key/key.go, pkg/pem/decode.go,
internal/id_generator.go and certs/ca.crt.

Transferred-context size is recorded but load-bearing on nothing, and the runs
show why: a build reported 2.18kB transferred while 43 files, five of them
secrets, were in the image. BuildKit transfers only the delta from the
previous build, so the number describes the transfer and not the contents.

Planted files were removed and their absence confirmed against the filesystem
rather than against `git status`, which could not have seen them.

`make docker` re-run after the change: the check layer executed rather than
being served from cache, so the CHECK_EPOCH verification still holds under the
altered build context.
2026-08-09 16:27:17 +00:00

2.1 KiB