build(image): the app layers name the runtime user, so the chown layer is gone

By the maintainer's decision of 2026-11-25, recorded in the handover. The option as
offered: "Drop the duplicate chown layer", as offered: "`COPY --chown` on the app file
layers instead of a final `chown -R`. Every file under `/app` stays owned by uid 1000,
compared file by file in the rebuilt image."

`RUN chown -R ousast /app` ran after the last COPY, so it copied every file of `/app`
into a second layer: 194 MB beside the 189 MB `benchmarks` layer in the local image,
and the build of 2026-11-25 spent 311 of its 470 seconds in it. The line is removed, and
the copies it covered take `--chown=1000` as `benchmarks` already did: `pyproject.toml`,
`README.md` and `LICENSE` in one, `src` in the other. Nothing after the last COPY writes
under `/app`: the pip install runs with the uv_build backend and left nothing there in
the image built on 2026-11-25.

Two things are expected to change besides the layer. `/app` itself, which `WORKDIR`
creates, is owned by root, where `chown -R` made it uid 1000. And the files that were
gid 0 take gid 1000. No tracked use writes into `/app` as the runtime user: compose runs
in `/work` and writes under `/reports`, the wrapper `ops/ousast-docker` works in the
mounted repository, and the workflows build and push.

Tests: the new `tests/test_task_images.py::test_app_layers_carry_their_owner` fails on
a `RUN chown` in the final stage and on a `COPY` into it that does not start with
`COPY --chown=1000 `. It failed before the change (1 failed, 15 passed) and passes
after; with `tests/test_search_image.py`, 17 passed. On scratch copies it fails when
the chown line is put back and when the flag is dropped from `COPY src ./src`.
`test_digest_required_and_code_last` found its code line by `COPY src `; it accepts the
new prefix, and its ordering check is unchanged. ruff, mypy, the three gates and
compileall pass, and the gates print what they printed before the change. An independent
reviewer approved the change in one round.

Not claimed here: the rebuilt image. It follows in this step's next part, with the
proof that every file under `/app` is owned by uid 1000 and that `/app` holds the
tracked files only.
This commit is contained in:
Marius Ciepluch
2026-11-26 10:36:59 +01:00
parent 005bffb677
commit a706a7d811
2 changed files with 15 additions and 4 deletions
+12 -1
View File
@@ -37,7 +37,7 @@ def test_digest_required_and_code_last(name, variant):
assert f"ARG TASK_{variant}_DIGEST" in lines
ref = f"ghcr.io/norandom/ousast-task-base:${{TASK_{variant}_TAG}}@${{TASK_{variant}_DIGEST}}"
assert any(line.startswith(f"FROM {ref}") for line in lines)
code = next(i for i, line in enumerate(lines) if line.startswith("COPY src "))
code = next(i for i, line in enumerate(lines) if line.startswith(("COPY src ", "COPY --chown=1000 src ")))
for i, line in enumerate(lines):
if "apt-get" in line or "--from=joern-build" in line or "frontend-retention-install.py" in line:
assert i < code
@@ -215,3 +215,14 @@ def test_search_pilot_files_stay_out_of_the_image():
assert private in patterns, f"{private} is not excluded from the build context"
# Docker cleans each line, so `!benchmarks/search/private` lets the directory back in as well.
assert not any(line.startswith(f"!{private}".rstrip("/")) for line in patterns), f"{private} is let back in"
def test_app_layers_carry_their_owner():
"""`COPY --chown` on every layer under /app: a final `chown -R` would store each of its files twice."""
lines = instructions("Dockerfile")
final_stage = lines[max(i for i, line in enumerate(lines) if line.startswith("FROM ")) :]
assert not any(line.startswith("RUN chown") for line in final_stage), "a chown over /app stores its files twice"
copies = [line for line in final_stage if line.startswith("COPY ") and "--from=" not in line]
assert copies
for line in copies:
assert line.startswith("COPY --chown=1000 "), f"{line} does not name the runtime user"