Skip to content

Add user and workdir elfuse launch flags - #286

Draft
henrybear327 wants to merge 1 commit into
sysprog21:mainfrom
henrybear327:oci/add_user_workdir_flag
Draft

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

Conversation

@henrybear327

@henrybear327 henrybear327 commented Aug 11, 2026

Copy link
Copy Markdown
Collaborator

This branch is stacked on top of #285. Thus, before #285 is merged, we will see 4 commits from it


Summary by cubic

Adds --user UID[:GID] and --workdir DIR to select the guest identity and initial cwd, enforced in elfuse_launch so all launchers (e.g., elfuse-oci run) get consistent, safe behavior.

  • --user is numeric-only; a bare UID sets GID=UID. It stages ids before bring‑up so auxv AT_UID/AT_GID match getuid/getgid. --fakeroot with a non‑root --user is refused (use --user 0:0 if needed).

  • --workdir requires a guest‑absolute path. It is translated under --sysroot after casefold probing and must resolve inside the sysroot; paths that only exist on the host are rejected. Relative paths are rejected up front.

  • The usage synopsis now shows these flags in both --help and error paths. Rosetta (x86_64) guests still refuse --gdb.

  • Implements elfuse_launch(launch_args_t) with new fields: has_creds, uid, gid, cwd_guest. Adds proc_set_initial_ids/proc_clear_initial_ids to stage/clear credentials around bring‑up.

  • Adds tests/test-launch-flags.sh for rejection and containment checks and extends identity staging tests. Updates docs/usage.md and mk/tests.mk; ELFUSE_USAGE_BODY keeps help and error usage in sync.

Written for commit 238f4de. Summary will update on new commits.

Review in cubic

cubic-dev-ai[bot]

This comment was marked as resolved.

@jserv jserv left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Rebase latest main branch and resolve conflicts.

@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

Copy link
Copy Markdown
Collaborator Author

Rebase latest main branch and resolve conflicts.

Done, and addressed all pending comments.

@henrybear327
henrybear327 marked this pull request as draft August 12, 2026 18:09
@henrybear327
henrybear327 force-pushed the oci/add_user_workdir_flag branch from cd98b4e to 20a5e74 Compare August 12, 2026 18:50
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. The staged value is consumed by
exactly one proc_identity_init, and the elfuse_launch fail path drops
an unconsumed value (proc_clear_initial_ids): a bring-up failure
before prepare's proc_init would otherwise leave it armed for the
next launch in the same host process.

--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 means
the guest starts as uid/gid 0, and the setuid permission check grants
every id switch on that basis; a non-root --user would leave that
grant in place while the guest reported an unprivileged uid, so the
guest could raise itself back to root 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; 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 current binary performs). docs/usage.md documents both flags, the
containment rule, and the two-sided root requirement behind the
fakeroot refusal.
@henrybear327
henrybear327 force-pushed the oci/add_user_workdir_flag branch 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 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.

No issues found across 10 files

Re-trigger cubic

@henrybear327
henrybear327 marked this pull request as draft August 13, 2026 20:20
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