Run container as non-root stellar user#15
Open
fnando wants to merge 4 commits into
Open
Conversation
leighmcculloch
approved these changes
May 29, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Note
Needs #14 to be merged first.
Summary
Adds a
stellaruser (UID 1000) and drops toUSER stellarin the runtime stage, with/stellaras the home directory. Pre-creates and chowns/source,/config,/data; setsCARGO_HOME=/stellar/.cargo; copies the CLI binary root-owned at mode 0755.repro_test.pynow invokes the image with--user $(id -u):$(id -g)and-e CARGO_HOME=/tmp/cargo, which lets the workdir teardown collapse to a plainshutil.rmtree. The README documents the four well-known paths (/source,/config,/data,/stellar) in a table and explains how mounting a host directory at/stellarboth persists the cargo cache across runs and unblocks--useroverrides on Linux hosts whose UID is not 1000.Why
On Linux, the previous root-default container left bind-mounted build output (
target/wasm32v1-none/release/*.wasm,Cargo.lock) owned byroot:rooton the host — forcingsudo chownafter every build. The pain showed up in our own CI:repro_test.pycarried a workaround that ran a second container just to wipe root-owned files from a temp directory. macOS+OrbStack and Docker Desktop hid the issue via UID translation; native Linux did not. Switching to a non-privileged UID also narrows the runc/containerd escape blast radius and clears HadolintDL3002.Test plan
build_image.py --stellar-cli-version 26.0.0 --rust-version 1.94.0-slim-trixie).smoke_test_image.pypasses against the rebuilt image.repro_test.py --contract tokenpasses (build A == build B) with no root-owned files left in the temp workdir.build.ymlis green end-to-end on a Linux runner.