Skip to content

Support dynamic guest identity (UID/GID) configuration via environment variables#109

Open
doanbaotrung wants to merge 1 commit into
sysprog21:mainfrom
open-sources-port:feature/dynamic_uid_gid
Open

Support dynamic guest identity (UID/GID) configuration via environment variables#109
doanbaotrung wants to merge 1 commit into
sysprog21:mainfrom
open-sources-port:feature/dynamic_uid_gid

Conversation

@doanbaotrung

@doanbaotrung doanbaotrung commented Jun 23, 2026

Copy link
Copy Markdown
Collaborator

Allow users to dynamically configure the simulated guest
UID and GID at runtime via environment variables, for
example: ELFUSE_GUEST_UID and ELFUSE_GUEST_GID.

If these variables are present in the host process
environment, elfuse should parse them and override
the default guest UID/GID.

Fixes #103


Summary by cubic

Add runtime overrides for the simulated guest UID/GID via ELFUSE_GUEST_UID and ELFUSE_GUEST_GID. The values propagate to auxv and procfs so programs see the correct identity.

  • New Features
    • Parse env vars in proc_identity_init() with strict uint32 parsing; ignore invalid/empty/out‑of‑range; fall back to GUEST_UID/GUEST_GID when unset.
    • Auxv AT_UID/AT_EUID/AT_GID/AT_EGID and /proc/self/{status,task/*/status} now use proc_get_* so real/effective/saved‑set and fs IDs reflect overrides.
    • Added test-identity-override-host; built and run by make check.

Written for commit da2339d. Summary will update on new commits.

Review in cubic

@doanbaotrung doanbaotrung force-pushed the feature/dynamic_uid_gid branch from af6f40e to 8a7c0d3 Compare June 23, 2026 07:54
@doanbaotrung doanbaotrung requested a review from jserv June 23, 2026 07:54
cubic-dev-ai[bot]

This comment was marked as resolved.

@doanbaotrung doanbaotrung force-pushed the feature/dynamic_uid_gid branch from 8a7c0d3 to a9f59ab Compare June 23, 2026 08:01
Comment thread src/syscall/proc-identity.c Outdated
@doanbaotrung doanbaotrung force-pushed the feature/dynamic_uid_gid branch from a9f59ab to 14d00bf Compare June 24, 2026 01:22
@doanbaotrung doanbaotrung requested a review from jserv June 24, 2026 03:28
jserv

This comment was marked as resolved.

@doanbaotrung doanbaotrung force-pushed the feature/dynamic_uid_gid branch from 14d00bf to d8fb6c2 Compare June 24, 2026 15:47
environment variables

Allow users to dynamically configure the simulated guest
UID and GID at runtime via environment variables, for
example: ELFUSE_GUEST_UID and ELFUSE_GUEST_GID.

If these variables are present in the host process
environment, elfuse should parse them and override
the default guest UID/GID.
@doanbaotrung doanbaotrung force-pushed the feature/dynamic_uid_gid branch from d8fb6c2 to da2339d Compare June 24, 2026 15:54
@doanbaotrung

This comment was marked as resolved.

@doanbaotrung doanbaotrung requested a review from jserv June 24, 2026 16:01
@jserv

jserv commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

I am not sure whether getenv is an appropriate mechanism for specifying the desired UID/GID. Instead, I am considering adopting the same approach as fakeroot.

I defer to @Max042004 for confirmation.

@Max042004

Copy link
Copy Markdown
Collaborator

fakeroot does two things at once:

  1. Process identity — it intercepts getuid()/geteuid() so the program
    believes it is root.
  2. File ownership — it intercepts chown()/stat() so ownership-sensitive
    operations stay self-consistent without real privilege.

We already implement (2). src/syscall/chown-overlay.c is literally headed
"Virtual chown overlay (fakeroot-style)":

So I prefer reframing it as the identity half of the existing overlay:
switch the interface to a fakeroot mode defaulting to root, and complete
capget/getgroups for the emulated-root case.

  • Interface. fakeroot's model is "run this and you are root" — a mode, not a
    free-form numeric knob. I'd rather expose a single switch (e.g. --fakeroot /
    ELFUSE_FAKEROOT=1) that sets uid=euid=suid=0, gid=0 in one go, aligned with
    the chown-overlay.c naming, instead of asking users to hand-set two arbitrary
    integers.
  • Consistency. To truly behave like root the whole identity surface has to
    agree. One real gap today: sc_capget() (syscall.c:1293) returns an empty
    capability set regardless of uid, so a tool that reads /proc/self/status
    CapEff or checks a specific capability still sees "not root". A named fakeroot
    mode makes it natural to flip capget (full caps) and getgroups (gid 0)
    together; a raw UID env var leaves those half-done.

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.

Support dynamic guest identity (UID/GID) configuration via environment variables

3 participants