Commit Graph
1815 Commits
Author SHA1 Message Date
Daan De Meyer f102bc3e5f tree-wide: Introduce sd-forward.h and shared-forward.h headers
Let's not leak details from src/shared and src/libsystemd into
src/basic, even though you can't actually do anything useful with
just forward declarations from src/shared.

The sd-forward.h header is put in src/libsystemd/sd-common as we
don't have a directory for shared internal headers for libsystemd
yet.

Let's also rename forward.h to basic-forward.h to keep things
self-explanatory.
2025-10-16 17:00:29 +02:00
Luca Boccassi 9dd61cfbe7 Use verity sharing for user services and nspawn too (#39313)
https://github.com/systemd/systemd/pull/39168 made verity sharing
opt-in, and enabled it for system services.
Also enable it for user services for RootImage/etc, and for nspawn, for
the same reasons.
2025-10-15 11:01:57 +01:00
Lennart Poettering 9f69ff69f7 mountfsd: make MountDirectory() work with systemd-homed
systemd-homed already applies an idmap to its mounts, hence we need to
undo it before we can create our own.
2025-10-15 10:21:59 +02:00
Luca Boccassi 566a4bbbbf nspawn: enable verity sharing
Just like RootImage=, ExtensionImages= etc, nspawn can make use of
this to save a lot of time when starting containers that use an already
open image, since the default was changed to disabled.

Follow-up for 57d1ceffb3
2025-10-14 20:49:12 +01:00
Lennart Poettering e5dc514277 nspawn: register containers in both user and system machined if applicable (#39145) 2025-10-14 11:58:29 +02:00
Lennart Poettering d20dff2814 dissect-image: take policy into consideration when unlocking verity, too
Previously, we'd take the image policy only into consideration when
dissecting the mage, but for the unlock/verity step we'd go via best
effort. Change that. This means we can now enforce policies such as
activating by root hash only even if a signature exists and similar.

Also, introduce a separate error code if we try to unlock a Verity
volume but have no root hash. Previously we'd return ENOKEY for that,
exactly like we do for encrypted volumes where we have no passparse. The
interctive unlock loop dissected_image_decrypt_interactively() is
otherwise very confused and will ask for a root hash, which makes no
sense. Hence use two distinct errors for this.
2025-10-13 22:26:34 +02:00
Lennart Poettering 814db2ae79 nspawn: register containers with both the system-wide and the per-user machined instance
Let's make sure each container run by unpriv users is known by both
instances. Making it known by the host instance ensures it is resovlable
by nss-myhostname (and various other tools), but making it known by the
per-user instance means the user can fully manage it on their own.

This simplifies the code a bit too, i.e. we always allocate a scope
ourselves now, and just register it, instead of letting machined do that
under some circumstances. THere's little value in that and it simplifies
things for us quite a bit.
2025-10-07 12:33:52 +02:00
Lennart Poettering 4e75f47782 nspawn: support .nspawn files in per-user mode 2025-10-07 11:44:54 +02:00
Yu Watanabe 5fc94cc6d9 Use string tables to parse option arguments (#39173) 2025-10-04 23:16:12 +02:00
David Tardon 188049d38c tree-wide: combine DUMP_STRING_TABLE() and return 2025-10-02 16:19:03 +02:00
David Tardon 365399c4e4 nspawn: inline handle_arg_console() to its only call place 2025-10-02 16:19:03 +02:00
David Tardon 65c4347d6e nspawn: set arguments directly
There's no point in going through handle_arg_console() now that all the
checks have been moved out of it.
2025-10-02 16:19:03 +02:00
David Tardon 99df84ef23 nspawn: postpone selection of console mode
Moving it away from argument parsing code allows to simplify that.
2025-10-02 16:19:03 +02:00
David Tardon 25f1473c81 nspawn: use table to parse --console= 2025-10-02 16:18:41 +02:00
n0099 613f7f26aa nspawn: correct the option name --private-users-ownership= when it's not expected value 2025-10-02 16:06:55 +02:00
Lennart Poettering 83b6ef9b62 libselinux: turn into dlopen() dep 2025-09-26 11:12:04 +02:00
Luca Boccassi 996e6d0d89 nspawn: free D-Bus error before fallback (#39131)
Otherwise the next call fails:

Got message type=error sender=:1.5 destination=:1.470 path=n/a 
    interface=n/a member=n/a cookie=151 reply_cookie=3 signature=s
    error-name=org.freedesktop.DBus.Error.UnknownMethod
    error-message=Unknown method CreateMachineEx or interface
    org.freedesktop.machine1.Manager. Assertion
'!bus_error_is_dirty(reterr_error)' failed at
    src/libsystemd/sd-bus/sd-bus.c:2396, function sd_bus_call(). Aborting.

Follow-up for d80af3b97b
2025-09-26 14:00:48 +09:00
Lennart Poettering d9c5566c0f machined: make image locking runtime scope aware, too
We cannot create an image lock in /run if we are unpriv, hence create it
in $XDG_RUNTIME_DIR instead.
2025-09-25 22:43:59 +02:00
Lennart Poettering aaca6bd5d9 libseccomp: turn into dlopen() dependency 2025-09-26 03:30:11 +09:00
Lennart Poettering d71f2899bd meson: drop libblkid dep from components not using it directly 2025-09-24 18:11:12 +02:00
Luca Boccassi d80af3b97b machined: add PIDFD D-Bus variants for registering/creating machines
Current methods take a numeric PID, but we know that is unreliable for
the usual reasons. Add variants that take a PIDFD instead, or a
PID + PIDFDID combination for remote users.
2025-09-24 14:11:59 +01:00
Aleksandr Mezin c3d5f5f165 nspawn: don't try to connect to D-Bus when it's not necessary (#39045)
`runtime_bus` is only used if `!arg_keep_unit`.

`system_bus` is additionally used if `arg_register`.

So for `!arg_register && arg_keep_unit`, none of them should be
necessary, and nspawn should be able to work without any D-Bus
connections.

Fixes https://github.com/systemd/systemd/issues/39044

Follow-up for f2f26f1527
2025-09-22 11:59:38 +01:00
Daan De Meyer 8796164189 tree-wide: Remove unused includes (#39023) 2025-09-19 16:07:04 +02:00
Daan De Meyer 9adb4685df tree-wide: Remove unused includes 2025-09-19 14:46:55 +02:00
Yu Watanabe 7184f8366f firewall-util: drop FirewallContext
After iptables support is dropped, FirewallContext is a trivial
wrapper of sd_netlink. Let's drop it and directly use sd_netlink.
2025-09-19 15:33:17 +09:00
Yu Watanabe 9f94034ea8 nspawn: realign gperf table 2025-09-17 22:07:27 +09:00
Alan Brady 113ef23264 nspawn: add NamespacePath support for nspawn files
Commit d7bea6b6 ("nspawn: introduce an option for specifying network
namespace path") already did most of the work here enabling a command
line option for specifying the namespace path for a given container.
Someone even took care of the merging code in merge_settings as though
this already worked. All that's then needed is to add a line to the
nspawn-gperf.gperf file to actually enable being able to specify
NamespacePath from nspawn files as well.

This greatly simplifies how we configure nspawn containers by being able
to give all the options we need in .nspawn files instead of needing to
also use command line parameters.

Closes: #27188
2025-09-17 14:14:02 +02:00
DaanDeMeyer 945e1fd37b nspawn: Drop CAP_NET_BIND_SERVICE if in userns with identity mapping
Even if there's no uid shift, we still won't be able to bind to privileged
ports in the host network namespace, so drop the capability regardless of
whether we have a uid shift or not.
2025-09-05 08:24:39 +02:00
Lennart Poettering ce3b12713b nspawn: the second time on_orderly_shutdown() is called userdata is NULL (#38709)
We know that it is, because we set it to NULL in the very same
on_orderly_shutdown() call.
2025-08-25 19:08:01 +01:00
Yu Watanabe 88fce09026 nspawn: fix --link-journal=host with --private-users=pick and friends
Fixes #38611.
2025-08-20 16:17:59 +09:00
Yu Watanabe 92366b8fbc nspawn: always set TERM=dumb when running with a pipe
Otherwise, we will get unexpected OSC sequences.
2025-08-13 23:43:52 +09:00
Luca Boccassi c892e33979 nspawn: fix recursive bind mounts
Follow-up for 90fa161b5b

Fixes https://github.com/systemd/systemd/issues/38505
2025-08-08 10:53:02 +09:00
Yu Watanabe 7f6086d530 tree-wide: do not use %m with SYNTHETIC_ERRNO() 2025-07-22 03:05:54 +09:00
Yu Watanabe 5918ba9c69 tree-wide: fix log messages: "Failed VERB" -> "Failed to VERB" 2025-07-22 03:05:33 +09:00
DaanDeMeyer dbbbdde266 nspawn: Generalize parse_bind_user_shell()
Preparation for reuse in vmspawn.
2025-07-15 14:22:52 +02:00
DaanDeMeyer 852de7ed70 nspawn: Prepare --bind-user= logic for reuse in systemd-vmspawn
Aside from the usual boilerplate of moving the shared logic to shared/,
we also rework the implementation of --bind-user= to be similar to what
we'll do in systemd-vmspawn. Instead of messing with the nspawn container
user namespace, we use idmapped mounts to map the user's home directory on
the host to the mapped uid in the container.

Ideally we'd also use the "userdb.transient" credentials to provision the
user records, but this would only work for booted containers, whereas the
current logic works for non-booted containers as well.

Aside from being similar to how we'll implement --bind-user= in vmspawn,
using idmapped mounts also allows supporting --bind-user= without having to
use --private-users=.
2025-07-14 16:25:22 +02:00
DaanDeMeyer b955051244 nspawn: Don't clear idmapping if we're not doing an idmapped mount
We only need to clear the existing idmapping if we're going to be
replacing it with another idmapping. Otherwise we should keep the
existing idmapping in place.
2025-07-14 11:54:56 +01:00
Lennart Poettering aac7e892e4 machined: make registration of unpriv user's VMs/containers work (#37855)
This adds missing glue to reasonably allow unpriv users VMs/containers
to register with the system machined.

This primarily adds two things:

1. machined can now properly track VMs/containers residing in subcgroups
of units, because that's effectively what happens for per-user
VMs/containers: they are placed below the system unit `user@….service`
in some user unit.

2. machines registered with machined now have an owning UID: users can
operate on their own machines withour re-authentication, but not on
others.

Note that this is only a first step regarding machined's hookup of
nspawn/vmspawn in the long run for unpriv operation.

I think eventually we should make it so that there's both a per-user and
a per-system machined instance (so far, and even with this PR there's
still one per-system instance), and per-user containers/VMs would
registering with *both*. Having two instances makes sense I think,
because it would mean we can make machined reasonably manage the
per-user image discovery, and also do the per-system network/hostname
handling.
2025-07-11 21:10:08 +02:00
Lennart Poettering 6ef1fc6d02 nspawn: properly order include of constants.h 2025-07-11 18:16:48 +02:00
Lennart Poettering 0c250b3919 nspawn: tweak logging/notifications when processing exit requests 2025-07-11 18:15:12 +02:00
Lennart Poettering f63ca4fc14 nspawn: slightly beef up READY= logic in nspawn
Let's also send out a STATUS= message when we get READY=1 if it didn't
come with a STATUS= message itself.

Also, let's initially say the container is "started", and only once the
READY=1 is seen claim it was "running".
2025-07-11 18:15:12 +02:00
Lennart Poettering f2f26f1527 nspawn: reorganize scope allocation/registration logic
This cleans up allocation of a scope unit for the container: when
invoked in user context we'll now allocate a scope through the per-user
service manager instead of the per-system manager. This makes a ton more
sense, since it's the user that invokes things after all. And given that
machined now can register containers in the user manager there's nothing
stopping us to clean this up.

Note that this means we'll connect to two busses if run unpriv: once to
the per-user bus to allocate the scope unit, and once to the per-system
bus to register it with machined.
2025-07-11 18:15:12 +02:00
Yu Watanabe 2bdabb167b basic: rename cap-list.c -> capability-list.c
This also renames relevant files in the same way.

Addresses https://github.com/systemd/systemd/pull/37904#discussion_r2191950396
2025-07-11 18:33:43 +09:00
Yu Watanabe 543a48b653 libc-wrapper: introduce a tiny libc wrapper
Then, move syscall definitions to the wrapper, and prototypes are moved
to relevant headers.

This also adds checks for add_key() and request_key(), as one day
glibc may be going to add some of them separatedly.

The check for fspick in meson.build is dropped, as it is currently
unused in our code.

This also moves
- basic/missing_bpf.h -> include/override/linux/bpf.h,
- basic/missing_keyctl.h -> include/override/linux/keyctl.h.
2025-07-11 13:05:46 +09:00
Lennart Poettering c35ceb84e3 Introduce ERRNO_IS_FS_WRITE_REFUSED(), and use it in binfmt_mounted() (#38117)
- This introduces ERRNO_IS_FS_WRITE_REFUSED(), and apply it where
usable.
- This makes unexpected errors in access_fd() called by binfmt_mounted()
propagated to the caller.
- Renames binfmt_mounted() to binfmt_mounted_and_writable(), as it also
checks the fs is writable.
- Voidifies one disable_binfmt() call in shutdown.c.
2025-07-10 21:38:13 +02:00
DaanDeMeyer 4f54d81ace nspawn: Use in_child_chown() in one more place 2025-07-10 13:55:45 +02:00
DaanDeMeyer 6f60ce002b nspawn: Improve log message 2025-07-10 13:55:43 +02:00
Yu Watanabe e28d408c6b errno-util: introduce ERRNO_IS_NEG_FS_WRITE_REFUSED() 2025-07-10 14:02:00 +09:00
Mike Yuan 56c6d90f8c mount-util: teach open_tree_attr_fallback() our usual AT_EMPTY_PATH trick
While at it, rename it to _with_fallback following
the naming scheme we use elsewhere.
2025-07-09 10:14:00 +02:00
Matteo Croce a80c06cf02 nspawn: create mountpoint for bpffs
When we mount a tmpfs as /sys, create a mountpoint for bpf, as we
already do for cgroup
2025-07-08 18:23:46 +02:00