Skip to content

feat: run the CMD as root unless IGNITY_CMD_DROP_PRIVILEGES=1 - #40

Merged
amannocci merged 1 commit into
mainfrom
feat/cmd-root-by-default
Oct 23, 2026
Merged

amannocci merged 1 commit into
mainfrom
feat/cmd-root-by-default

Conversation

@amannocci

Copy link
Copy Markdown
Member

What is the change being made?

  • stage2-cmd runs the CMD as PID 1 (root) by default, even when USERMAP_UID / USERMAP_GID are set. Dropping to USERMAP_UID:USERMAP_GID is now opt-in with IGNITY_CMD_DROP_PRIVILEGES=1 (default 0). When opted in, the behaviour is unchanged: no drop for 0:0 or a non root PID 1, supplementary groups set to the gid.
  • gen-accounts checks that USERMAP_UID and USERMAP_GID are digits (grep -Eqzx "[0-9]+", like the USER check) instead of eltest -ge, which let values like 1000:0 through.
  • Tests: new test_cmd_stays_root_with_usermap_by_default. The tests expecting the CMD to drop (test_boot.py, test_least_privilege.py) set IGNITY_CMD_DROP_PRIVILEGES=1. test_accounts_reject_non_numeric_ids also asserts the error message.

Why is the change being made?

The CMD is mostly used to debug or test in the ignity ecosystem, where root is expected, while USERMAP_* is mostly set for perms. This goes back to the behaviour before 0.1.0 (#34). Users of 0.1.0 relying on the CMD drop have to set IGNITY_CMD_DROP_PRIVILEGES=1: worth a line in the release notes.

The gen-accounts bug was hidden by the drop: with USERMAP_UID=1000:0, it wrote exploit:x:1000:0:1000::... (gid 0) in the generated passwd, and test_accounts_reject_non_numeric_ids only passed because s6-applyuidgid then failed on the CMD.

How has this been tested?

  • uv run poe test: 72 passed, run on top of feat/split-packages before moving the commit onto main. Not rerun on this branch, CI covers it.
  • By hand with podman on an image built from source (debian:bookworm-slim): USERMAP_UID=1000:0 and USERMAP_GID=0:0 are rejected ("must be numbers", exit 1), 1000:1000 still writes the account.

How has this been documented?

  • README.md: IGNITY_CMD_DROP_PRIVILEGES in the parameters table and "How to customize ignity behaviour", "How to run the CMD as a non root user", the least-privilege section (SETUID row, capabilities note) and the Kubernetes examples.
  • .claude/CLAUDE.md: stage2-cmd and the runtime variables.

Related Issues

None.

The CMD is mostly used to debug or test, so it runs as PID 1 (root) again,
like before 0.1.0, even when USERMAP_UID/USERMAP_GID are set for perms.
Dropping to USERMAP_UID:USERMAP_GID is now opt-in with
IGNITY_CMD_DROP_PRIVILEGES=1.

Also fix gen-accounts accepting non-numeric ids such as 1000:0 (eltest -ge
lets them through), which could inject gid 0 in the generated passwd. The
test only passed because the CMD drop failed afterwards.
@amannocci
amannocci merged commit 46ae356 into main Oct 23, 2026
9 checks passed
@amannocci
amannocci deleted the feat/cmd-root-by-default branch October 23, 2026 10:11
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.

1 participant