Repository navigation
feat: run the CMD as root unless IGNITY_CMD_DROP_PRIVILEGES=1 - #40
Merged
Merged
Conversation
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.
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.
What is the change being made?
stage2-cmdruns the CMD as PID 1 (root) by default, even whenUSERMAP_UID/USERMAP_GIDare set. Dropping toUSERMAP_UID:USERMAP_GIDis now opt-in withIGNITY_CMD_DROP_PRIVILEGES=1(default0). When opted in, the behaviour is unchanged: no drop for0:0or a non root PID 1, supplementary groups set to the gid.gen-accountschecks thatUSERMAP_UIDandUSERMAP_GIDare digits (grep -Eqzx "[0-9]+", like theUSERcheck) instead ofeltest -ge, which let values like1000:0through.test_cmd_stays_root_with_usermap_by_default. The tests expecting the CMD to drop (test_boot.py,test_least_privilege.py) setIGNITY_CMD_DROP_PRIVILEGES=1.test_accounts_reject_non_numeric_idsalso 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 forperms. This goes back to the behaviour before 0.1.0 (#34). Users of 0.1.0 relying on the CMD drop have to setIGNITY_CMD_DROP_PRIVILEGES=1: worth a line in the release notes.The
gen-accountsbug was hidden by the drop: withUSERMAP_UID=1000:0, it wroteexploit:x:1000:0:1000::...(gid 0) in the generated passwd, andtest_accounts_reject_non_numeric_idsonly passed becauses6-applyuidgidthen failed on the CMD.How has this been tested?
uv run poe test: 72 passed, run on top offeat/split-packagesbefore moving the commit ontomain. Not rerun on this branch, CI covers it.debian:bookworm-slim):USERMAP_UID=1000:0andUSERMAP_GID=0:0are rejected ("must be numbers", exit 1),1000:1000still writes the account.How has this been documented?
README.md:IGNITY_CMD_DROP_PRIVILEGESin the parameters table and "How to customizeignitybehaviour", "How to run the CMD as a non root user", the least-privilege section (SETUIDrow, capabilities note) and the Kubernetes examples..claude/CLAUDE.md:stage2-cmdand the runtime variables.Related Issues
None.