Skip to content

fix(docker): add writable /tmp to the scratch-based image - #1105

Merged
sami-alajrami merged 1 commit into
mainfrom
add-tmp-dir-to-docker-image
Aug 19, 2026
Merged

sami-alajrami merged 1 commit into
mainfrom
add-tmp-dir-to-docker-image

Conversation

@sami-alajrami

@sami-alajrami sami-alajrami commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

Kosli's temp-dir usage (directory fingerprinting, evidence tarballing) relies on os.MkdirTemp, which fails when /tmp doesn't exist at all, as is the case in the scratch base image. Stage an empty dir in the builder stage and copy it into the final image as a world-writable /tmp.

fixes kosli-dev/server#6508

Checklist

Kosli's temp-dir usage (directory fingerprinting, evidence tarballing)
relies on os.MkdirTemp, which fails when /tmp doesn't exist at all, as
is the case in the scratch base image. Stage an empty dir in the
builder stage and copy it into the final image as a world-writable /tmp.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@claude

claude Bot commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

Claude finished @sami-alajrami's task in 49s —— View job


Review: add writable /tmp to the scratch-based image ✅

  • Read the Dockerfile change
  • Analyze correctness of the /tmp approach
  • Post review feedback

This is a clean, well-scoped fix. Since the final image is FROM scratch, you can't RUN mkdir/chmod in it — staging an empty dir in the builder and copying it with --chmod is the correct idiomatic pattern for this. 👍

Correctness

  • --chmod=1777 reproduces standard /tmp semantics (world-writable + sticky bit so processes can't delete each other's files). This matters because the container has no USER directive, so os.MkdirTemp may run as root or an arbitrary UID depending on how the image is invoked (docker run -u, Kubernetes runAsUser); 1777 keeps it writable in all cases.
  • The # syntax=docker/dockerfile:1 directive at the top ensures BuildKit is used, which is required for COPY --chmod. So this is safe.
  • os.TempDir() returns /tmp on Linux by default (unless $TMPDIR is set), so os.MkdirTemp will now resolve correctly. ✔️

Non-blocking observations

  1. No automated regression guard. The failure this fixes (missing /tmp breaking os.MkdirTemp) can silently regress if the base image or COPY line changes later. Consider a tiny CI smoke step that runs the built image against an operation exercising temp-dir usage (e.g. a directory fingerprint or attest), so a broken /tmp fails the build rather than surfacing in production.
  2. Minor: the mkdir -p /image-tmp step lands in the builder stage, so it doesn't affect the final image at all — no concern, just noting the -p is harmless here.

Security: 1777 is the correct, expected permission for /tmp; the sticky bit is present, so this doesn't weaken isolation beyond standard host /tmp behavior. No concerns.

Nice, minimal fix — LGTM.
add-tmp-dir-to-docker-image

@sami-alajrami
sami-alajrami merged commit ebc82f6 into main Aug 19, 2026
25 of 26 checks passed
@sami-alajrami
sami-alajrami deleted the add-tmp-dir-to-docker-image branch August 19, 2026 12:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants