Skip to content

Add user and workdir elfuse launch flags - #286

Open
henrybear327 wants to merge 2 commits into
sysprog21:mainfrom
henrybear327:oci/add_user_workdir_flag
Open

Add user and workdir elfuse launch flags#286
henrybear327 wants to merge 2 commits into
sysprog21:mainfrom
henrybear327:oci/add_user_workdir_flag

Conversation

@henrybear327

@henrybear327 henrybear327 commented Aug 11, 2026

Copy link
Copy Markdown
Collaborator

Summary by cubic

Adds --user UID[:GID] and --workdir DIR to select the guest identity and initial working directory, enforced in elfuse_launch so every launcher (including elfuse-oci run) behaves consistently. Previously guests started with the built‑in uid/gid and the host cwd; now callers can set both, with refusals that prevent privilege confusion and starting outside the sysroot.

  • --user: digits-only numeric spec; a bare UID sets GID=UID. Staged before bring-up so auxv AT_UID/AT_GID match getuid/getgid, consumed once per launch, and cleared on any early failure. Refuses --fakeroot unless --user 0:0. Symbolic name resolution stays in elfuse-oci.
  • --workdir: requires a guest-absolute path. Resolved under --sysroot after the casefold probe and must resolve inside the sysroot (carve‑out for --sysroot /). Paths that exist only on the host are rejected. /dev/shm workdirs are refused to avoid following a symlink leaf and to keep guest-visible spelling stable. Cwd is set before the first guest instruction and path state is refreshed.
  • CLI/API: --help/usage include both flags. launch_args_t adds has_creds, uid, gid, and cwd_guest. New proc_set_initial_ids/proc_clear_initial_ids implement consume‑once staging. All failure paths, including refusals before prepare, unlink a temp FUSE ELF.
  • Tests/docs: tests/test-launch-flags.sh covers parse/rejection, sysroot containment, /dev/shm refusal, and fakeroot pairing; tests/test-identity-override-host.c pins consume‑once/clear semantics. docs/usage.md documents the flags and rules.

Written for commit 4cc9f15. Summary will update on new commits.

Review in cubic

cubic-dev-ai[bot]

This comment was marked as resolved.

jserv

This comment was marked as resolved.

@henrybear327
henrybear327 force-pushed the oci/add_user_workdir_flag branch from 9911813 to cd98b4e Compare August 12, 2026 14:35
@henrybear327
henrybear327 requested a review from jserv August 12, 2026 18:08
@henrybear327

This comment was marked as resolved.

@henrybear327
henrybear327 marked this pull request as draft August 12, 2026 18:09
@henrybear327
henrybear327 force-pushed the oci/add_user_workdir_flag branch 2 times, most recently from 20a5e74 to 238f4de Compare August 13, 2026 12:14
@henrybear327
henrybear327 marked this pull request as ready for review August 13, 2026 12:14
@henrybear327
henrybear327 marked this pull request as draft August 13, 2026 12:27
cubic-dev-ai[bot]

This comment was marked as resolved.

@henrybear327
henrybear327 marked this pull request as ready for review August 13, 2026 20:12
cubic-dev-ai[bot]

This comment was marked as resolved.

@henrybear327
henrybear327 marked this pull request as draft August 13, 2026 20:20
jserv

This comment was marked as resolved.

@henrybear327
henrybear327 force-pushed the oci/add_user_workdir_flag branch 3 times, most recently from 4ed9d1b to 5c797e3 Compare August 14, 2026 13:10
@henrybear327
henrybear327 marked this pull request as ready for review August 14, 2026 13:11
@henrybear327
henrybear327 requested a review from jserv August 14, 2026 13:11

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 10 files

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread src/core/launch.c
Comment thread src/main.c Outdated

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 3 files (changes from recent commits).

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread tests/test-launch-flags.sh Outdated
@henrybear327
henrybear327 force-pushed the oci/add_user_workdir_flag branch from 2c96a2f to a3626fc Compare August 14, 2026 22:03
An OCI image front end needs to set the guest identity and working
directory without patching the runtime; both flags map onto
launch_args_t fields and `elfuse-oci run` drives exactly this
interface.

The --user identity is staged before bring-up (proc_set_initial_ids)
so the auxv AT_UID/AT_GID snapshot taken by build_linux_stack matches
what getuid()/getgid() later report. proc_identity_init consumes the
staged value, and the elfuse_launch fail path calls
proc_clear_initial_ids: a bring-up that fails before proc_init would
otherwise leave the value staged for the next launch in the same host
process.

parse_id_component accepts digits only. strtoul negates the unsigned
result, so "-0" would parse as root and "-18446744073709551615" as uid
1, identities the spec on the command line never names.

--workdir rejects non-absolute paths up front instead of silently
resolving them against the host cwd, and is applied by elfuse_launch
after the casefold probe so the translation sees the sysroot's real
case behavior. The resolved host path must sit inside the sysroot
prefix: proc_resolve_sysroot_path falls back to the host spelling
when the sysroot has no entry at the path, which is the overlay
contract for guest syscalls but would start the guest in a
same-named host directory here, so the launch refuses it.

--fakeroot and a non-root --user are refused together. Fakeroot starts
the guest as uid/gid 0 and uid_is_permitted() grants every id switch
on that basis; a non-root --user would keep that grant while the guest
reported an unprivileged uid, letting the guest call setuid(0) at
will. The refusal lives in elfuse_launch beside the Rosetta GDB check,
so every launcher inherits the privilege rule, and it exits through
the shared fail unwind so a FUSE-materialized temp ELF is unlinked
even when bring-up never starts.

tests/test-launch-flags.sh covers the refusal, the parse rules, and
the --workdir sysroot containment; its sign, leading-space, and
negated-zero cases were observed failing against the strtoul spelling,
while the UINT32_MAX boundary and empty-GID cases are regression
guards that spelling also rejected. tests/test-identity-override-host.c
pins the staging consume-once and clear semantics as regression guards
(the cross-launch leak needs two bring-ups in one host process, which
no launcher performs). docs/usage.md documents both flags, the
containment rule, and the two-sided root requirement behind the
fakeroot refusal.
path_translate_at redirects /dev/shm/<leaf> into the per-UID host
backing dir and returns before sysroot resolution, so elfuse_launch ran
only sys_chdir's real-directory branch for such a workdir. The plain
chdir followed a symlink leaf that shm_open_leaf's O_NOFOLLOW fd
refuses, and proc_cwd_refresh published the backing location, so getcwd
reported /private/tmp/elfuse-shm-<uid>/<leaf> where a guest chdir into
the same directory reports /dev/shm/<leaf>.

Entering the leaf correctly needs that O_NOFOLLOW fd and the virtual-cwd
publish, which would make launch.c a second holder of the never-follow
duty dev_shm_resolve_path enumerates, for a workdir no image asks for.
The flag refuses the path instead, on the same grounds
guest_bootstrap_prepare refuses a /dev/shm ELF interpreter.

The test chmods the backing root because create_private_dir rejects a
group or other permission bit, and that failure surfaces as a resolve
error rather than the refusal the case measures. The leaf itself never
has to exist: path_translate_at sets is_dev_shm from the guest prefix
alone.
@henrybear327
henrybear327 force-pushed the oci/add_user_workdir_flag branch from a3626fc to 4cc9f15 Compare August 14, 2026 22:18
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