-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Description
Is your feature request related to a problem? Please describe.
When creating a unit/scope with User=<uid>, if getpwuid(uid) does not return a passwd struct,
systemd refuses to proceed.
AFAICT, this is because without a passwd struct, reasonable values for the process working directory, shell,
and HOME and LOGNAME are not known.
However, with user namespaces and subuid ranges, it is increasingly common to want to execute processes
and (especially) create cgroup scopes as uids that do not have associated passwd entries.
As a concrete use case: currently, "rootless podman" creates a transient systemd unit. The cgroup is owned by the main user (say, 1000), and the uid_map of the container process is 0 1000 1 \n 1 100000 65536. So, "rootless containers" are not really properly isolated. Enabling systemd to create the transient unit with User=100000 and Delegate=true would enable fully isolated containers.
Describe the solution you'd like
Do not fail when getpwuid(uid) returns nothing. Instead, either leave values unset (where feasible) or synthesise reasonable defaults (e.g. shell = /sbin/nologin). If necessary, synthesise a username (e.g. vu-100000, with collision checks.
If thought appropriate, this behaviour could sit behind a UserCredsFlag, to be triggered by a property (e.g. IgnoreMissingUser=true).
I am happy to implement this, if we can reach agreement that it is the right way to proceed.
Describe alternatives you've considered
- systemd-machined registers "machine" subuid offset and range size. nss-systemd consults the machine registry and synthesises passwd entries for uids in the range upon demand. Registering a machine prior to creating the transient unit allows the unit to be executed properly. However this is a more intrusive change for container runtimes.
- Create a new NSS passwd module (or enhance nss-systemd) to synthesise entries for UIDs in known subuid ranges. For example, if
/etc/subuidcontainsftweedal:100000:65536then a lookup for101000could return the passwd entry with nameftweedal-101000(again subject to collision check) and sensible defaults for other fields.
The systemd version you checked that didn't have the feature you are asking for
tip of main branch (6c498f6)