Commit Graph
6455 Commits
Author SHA1 Message Date
Luca Boccassi e5a5656b55 machined: do not allow unprivileged users to shell into the root namespace via varlink
Forbid non-root from shelling into a machine that is running in
the root user namespace.

Follow-up for adaff8eb35
2026-03-04 13:03:44 +00:00
Frantisek Sumsal acf00ba7b5 test: don't register short-living containers with machined, again
Otherwise we might try to register the same scope again before the
previous instance gets a chance to be cleaned up:

[   54.378392] systemd-nspawn[2554]: ░ Spawning container TEST-13-NSPAWN.defaultinaccessiblepaths.nxs on /var/lib/machines/TEST-13-NSPAWN.default_inaccessible_paths.nxs.
[   54.382202] systemd-nspawn[2554]: Failed to allocate scope: Unit TEST-13-NSPAWN.defaultinaccessiblepaths.nxs.scope was already loaded or has a fragment file.
[   54.411211] systemd[1]: TEST-13-NSPAWN.service: Main process exited, code=exited, status=1/FAILURE
[   54.411413] systemd[1]: TEST-13-NSPAWN.service: Failed with result 'exit-code'.
[   54.411885] systemd[1]: Failed to start TEST-13-NSPAWN.service - TEST-13-NSPAWN.

This is basically the same change as in
6a05abb9b4 but for the newly added tests.

Follow-up for 83b8daa032.

Resolves: #40945
2026-03-04 13:03:15 +00:00
Zbigniew Jędrzejewski-Szmek a22ad0efcc portable: Add ExtensionImages drop-in for any extension (#40911)
The diff seems big, but it's just removing and if and deleting the
indentation. With `git show -w` you can see clearly that is just one
line. In the files tab, in github, you can click "hide whitespaces" and
it is clear too.

I don't know if there is some better way, but when using a portable
service with an extension image that just overlays files I need to
manually add the `ExtensionImages=`. And that is added automatically for
other extension images that provide a service unit.

So, this patch just makes sure we add the `ExtensionImages=` for any
extension.

Any thoughts?

Below the commit msg for more details:

---

    Before this patch, when running:
    
            portablectl attach --extension ext.raw ./base.raw
    
No drop-in is added for the "ExtensionImages" if there aren't units from
    the extension loaded.
    
But the extension can just overlay files, as in my case. So before this
patch, I also need to manually add a drop-in with "ExtensionImages=" for
    it to really be loaded.
    
Let's just always add the drop-in for extensions. This way, it works for
    extensions that just overlay files too.
    
Please note this commit just removes the if (simpler to view the diff
    with git show -w). Also, the if checked for m->image_path being not
NULL, but removing it shouldn't cause a NULL pointer dereference.
Because
m->image_path is not used inside the if (it was needed just for the if
itself) and image_path is asserted at the beginning of the function to
    be non-NULL too.
    
    This was like this since the beginning of time in 907952bbc9
    ("portabled: add --extension parameter for layered images support")
2026-03-04 11:44:00 +01:00
Lennart Poettering 9c8a2e53d3 test: add superficial testcase for tpm2 identification 2026-03-04 08:28:46 +01:00
Rodrigo Campos 9c56f3020d test/portable: Ensure ExtensionImages is set for any dep
The previous commit made portablectl attach add a drop-in for any
extension image. Let's add a test for that too.
2026-03-03 09:38:36 +01:00
Frantisek Sumsal 83b8daa032 nspawn: actually mask certain files under /proc/
/run/systemd/inaccessible/ exists only on host - in the container we have
/run/host/inaccessible/, and since all the inaccessible mounts have
MOUNT_IN_USERNS we need to use the latter one, otherwise the masking
gets silently skipped:

~# SYSTEMD_LOG_LEVEL=debug systemd-nspawn -q --directory=foo ls -la /proc/kallsyms
...
Bind-mounting /run/systemd/inaccessible/reg on /proc/kallsyms (MS_BIND "")...
Failed to mount /run/systemd/inaccessible/reg (type n/a) on /proc/kallsyms (MS_BIND ""): No such file or directory
Changing mount flags /proc/kallsyms (MS_RDONLY|MS_NOSUID|MS_NODEV|MS_NOEXEC|MS_REMOUNT|MS_BIND "")...
Failed to mount n/a (type n/a) on /proc/kallsyms (MS_RDONLY|MS_NOSUID|MS_NODEV|MS_NOEXEC|MS_REMOUNT|MS_BIND ""): Invalid argument
Bind-mounting /run/systemd/inaccessible/reg on /proc/kcore (MS_BIND "")...
Failed to mount /run/systemd/inaccessible/reg (type n/a) on /proc/kcore (MS_BIND ""): No such file or directory
Changing mount flags /proc/kcore (MS_RDONLY|MS_NOSUID|MS_NODEV|MS_NOEXEC|MS_REMOUNT|MS_BIND "")...
Failed to mount n/a (type n/a) on /proc/kcore (MS_RDONLY|MS_NOSUID|MS_NODEV|MS_NOEXEC|MS_REMOUNT|MS_BIND ""): Invalid argument
...
Inner child finished, invoking payload.
-r--r--r--. 1 root root 0 Feb 25 13:19 /proc/kallsyms
2026-03-02 20:22:06 +01:00
Luca Boccassi 756f39c239 test: delete one more test artifact on shutdown
Hopefully fixes:

[  154.500726] TEST-13-NSPAWN.sh[4351]: + tar -C /var/tmp/mangletest/ -cvzf /var/tmp/mangletest.tar.gz mangletest-0.1
[  154.504485] TEST-13-NSPAWN.sh[5402]: mangletest-0.1/
[  154.506908] TEST-13-NSPAWN.sh[5402]: mangletest-0.1/usr/
[  154.508713] TEST-13-NSPAWN.sh[5402]: mangletest-0.1/usr/lib/
[  154.509208] TEST-13-NSPAWN.sh[5402]: mangletest-0.1/usr/lib/os-release
[  154.509877] TEST-13-NSPAWN.sh[4351]: + run0 --pipe -u testuser importctl -m --user import-tar /var/tmp/mangletest.tar.gz
[  154.693870] TEST-13-NSPAWN.sh[5405]: Enqueued transfer job 9. Press C-c to continue download in background.
[  154.696371] TEST-13-NSPAWN.sh[5405]: Image 'mangletest' already exists.

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

Follow-up for 4248b02c44
2026-02-25 20:12:18 +00:00
Daan De Meyer 101f03bedb Additions to nsresourced and vmspawn required for making use of the foreign UID range in mkosi (#40415) 2026-02-25 13:49:19 +01:00
Luca Boccassi 1012c6ce76 userdbd: avoid sending gshadow hash to unprivileged callers via varlink
Reported on yeswehack as YWH-PGM9780-59

Follow-up for d093b62c94
2026-02-25 02:52:37 +01:00
Daan De Meyer 838528104b nsresourced: Optionally map foreign UID range
Whenever delegating UID ranges to a user namespace, it can also be
useful to map the foreign UID range, so that the container running in
the user namespace with delegated UID ranges can download container
images and unpack them to the foreign UID range.

Let's add an option mapForeign to make this possible. Note that this option
gives unprivileged users full access to the any foreign UID range owned directory
that they can access. Hence it is recommended (and already was recommended) to
store foreign UID range owned directories in a 0700 directory owned by the
owner of the tree to avoid access and modifications by other users.

This is already the case for the main users of the foreign UID range,
namely /var/lib/machines, /var/lib/portables and /home/<user> which all
use 0700 as their mode.

Users will also be able to create foreign UID range owned inodes in any
directories their own user can write to (on most systems this means /tmp,
/var/tmp and /home/<user>).
2026-02-24 18:29:37 +01:00
Daan De Meyer 95d05079bf nsresourced: Add support for self mappings with delegations
mkosi does all of its environment setup in an unprivileged user
namespace with an identity mapping. When it invokes nspawn and nspawn
tries to get a transient userns from nsresourced, this fails as no
transient ranges are mapped into mkosi's unprivileged userns (as doing
so would require privileges).

To fix this problem, let's allow allocating unprivileged self user
namespaces in nsresourced, similar to what the kernel allows, except that
we also support delegations for these. This means that mkosi can get its
unprivileged userns as before from nsresourced, but it can also request a
delegated 64K range inside that userns as well, which nsresourced can then
allocate to nspawn later when it asks for one.

Similar to the kernel, we disallow setgroups for self mappings. However,
instead of doing this via /proc/self/setgroups, which applies to the current
user namespace and all its child user namespaces, we use the BPF LSM to deny
setgroups instead, so that it can still be allowed for child user namespaces.
We need this because as soon as a container launches in a child user namespace
using one of the delegated mappings, it has to be able to do setgroups() to be
able to function properly.

To allow mapping the root user, we need to add the CAP_SETFCAP capability to
nsresourced.
2026-02-24 18:29:37 +01:00
Daan De Meyer 025439faaa nsresourced: Add support for delegated ranges
We want to support the scenario where we bind mount the nsresourced
varlink socket into a container to allow nested containers where the
outer container runs in its own transient range from nsresourced but
can still allocate transient ranges for its own nested containers.

To support this use case let's add support for delegation. Delegated
ranges are allocated when allocating the primary range and are propagated
1:1 to the user namespace. We track delegated ranges in ".delegate" files
in the userns registry so that they can't be used for other range allocations.

We make one exception for delegated ranges though, if we get a request from
a user namespace that is a child of the user namespace that owns the delegated
ranges, we allow allocating from the delegated range. The parent userns already
has full ownership over the child userns, so it doesn't matter that the parent
userns and the child userns share the same range. This allows making use of
delegated ranges without having to run another copy of nsresourced inside the
parent userns to hand out from the delegated range.

To support recursive delegations, we keep track of the previous owners of the
delegated range and restore ownership to the last previous owner when the current
owner is freed.
2026-02-24 18:29:37 +01:00
Luca Boccassi d70a73c05b resolved: Add ifindex=0 support for BrowseServices to browse all mDNS interfaces (#40133)
With v259, resolved can be used to replace Avahi for mDNS service
discovery and announcement. One key difference in the API is that Avahi
by default browses on all available interfaces by passing a special
`AVAHI_IF_UNSPEC` (-1) interface index value. With this change, passing
ifindex value `0` can be used to achieve the same , so this will work:
```
# Browse on all available interfaces
varlinkctl call --more unix:/run/systemd/resolve/io.systemd.Resolve \
    io.systemd.Resolve.BrowseServices \
    '{"domain":"local","type":"_display._tcp","ifindex":0,"flags":0}'
```
Not having to iterate through all interfaces on the client side then
also makes it more straight forward to build a resolve-avahi-compat
library for painlessly replacing Avahi with systemd-resolved.

A PoC compat lib requiring this change is available at
https://github.com/LorbusChris/resolve-avahi-compat
2026-02-24 11:53:47 +00:00
Zbigniew Jędrzejewski-Szmek 04d2a86e66 manager: add needs-stop/needs-start (#40709)
Intend to use these in the deb packaging scriptlets

Fixes: #19755
2026-02-24 00:36:06 +01:00
Lennart Poettering ab83c7489d sysupdated: Split Update() into Acquire() and Install() D-Bus methods (#40628)
These mirror the `sysupdate acquire` and `sysupdate install` verbs,
which are themselves a split of `sysupdate update` into downloading and
installing stages.

I have dropped the existing `Update()` method in the final commit, as
per the suggestion on
https://gitlab.gnome.org/GNOME/gnome-software/-/merge_requests/2004#note_2145880.
If the D-Bus API for `sysupdated` is considered stable now, though, I
can drop that commit.

CC @AdrianVovk

Fixes https://github.com/systemd/systemd/issues/34814
2026-02-23 22:08:37 +01:00
Philip Withnall 7537717aed test: Expand sysupdate test to test updatectl update
This further expands the sysupdate test to run the suite a fourth time,
testing that `updatectl update` behaves the same as `sysupdate update`
and `sysupdate acquire; sysupdate update --offline`.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2026-02-23 16:35:15 +00:00
Philip Withnall b0ca987cd9 updatectl: Expose partial/pending updates in the updatectl list output
And expand the tests to catch if any more JSON fields are added to the
sysupdated output in future without being added to `updatectl`’s parser.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
Helps: https://github.com/systemd/systemd/issues/34814
2026-02-23 16:35:10 +00:00
Luca Boccassi f3a34fcc3a manager: add 'needs-stop/needs-start' markers
Useful for packaging scripts, when units are removed.
When multiple markers are assigned without +/-, the last one wins.
When using +/-, the job merging logic is followed to the extent possible.
2026-02-23 13:05:23 +00:00
Christian Glombek 1fcd11d56c resolved: Add test for ifindex=0 BrowseServices functionality
Add integration tests for the new ifindex=0 support
in BrowseServices that allows browsing all mDNS interfaces.

Integration test (in TEST-89-RESOLVED-MDNS.sh):
- testcase_browse_all_interfaces_ifindex_zero: Test with ifindex=0

Assisted-by: Claude Opus 4.5 (Preview)
2026-02-23 02:55:38 +01:00
Lennart Poettering 3a7486c9fc journalctl: add new varlink GetEntries endpoint (#40650)
journalctl: add new varlink read service to get entries

We already have some varlink support for the journal to perform
some actions like `Rotate`. It would be nice to be able to query
the journal via varlink too so this commit adds a new varlinkctl
based journal service that exposes a single GetEntries() call
to retrieve journal entries. Basic filtering is supported and
we can expand the API as needed.

This is a separate `io.systemd.JournalControl` [1] service from the
existing `io.systemd.Journald` to decouple read and write (thanks
to Lennart for suggesting this).

This also extracts some shared helper so that we do not duplicate
code when generating the json or when adding the filters.

[1] The name mirrors the bootctl->io.systemd.BootControl naming.
2026-02-22 15:14:09 +01:00
Luca Boccassi 05f5156ad1 core: validate ref_uid before checking in AttachProcesses method
ref_uid is initialized to invalid, and is only set in some
circumstances. The AttachProcesses will attempt to check it,
and assert that it is valid. Check beforehand.

Reported as YWH-PGM9780-89

Follow-up for 59857b672c
2026-02-22 15:13:02 +01:00
Michael Vogt a109189fab journalctl: add new varlink read service to get entries
We already have some varlink support for the journal to perform
some actions like `Rotate`. It would be nice to be able to query
the journal via varlink too so this commit adds a new varlinkctl
based journal service that exposes a single GetEntries() call
to retrieve journal entries. Basic filtering is supported and
we can expand the API as needed.

This is a separate `io.systemd.JournalControl` [1] service from the
existing `io.systemd.Journald` to decouple read and write (thanks
to Lennart for suggesting this).

This also extracts some shared helper so that we do not duplicate
code when generating the json or when adding the filters.

[1] The name mirrors the bootctl->io.systemd.BootControl naming.
2026-02-21 13:02:38 +01:00
Lennart Poettering 9277393d7b report: install systemd-report binary to /usr/lib/systemd/ for now
The tool should not be considered stable, and those things we usually
place in /usr/lib/systemd, and not in $PATH.

We can move that to $PATH once we are confident it's gonna stay the way
it is.
2026-02-20 08:25:12 +01:00
Lennart Poettering f3aff0c20a ci: add proper CI test for systemd-report 2026-02-20 08:25:12 +01:00
Lennart Poettering 5046a12fbc report: switch to "verbs" command line interface, and add 'describe-metrics'
Let's prepare for a future where the "systemd-report" tool can do more
than enumerate metrics: let's introduce our usual "verbs" style
interface.

Let's also add a second command right-away: "describe-metrics" shows the
description of the metrics.
2026-02-20 08:23:11 +01:00
Lennart Poettering c86a72af04 ci: drop 'Ex' suffix from transient props
The "Ex" is mostly internal, and our parsers will append it
automatically when needed
2026-02-19 15:08:20 +01:00
Lennart Poettering e31ee582fc ci: add test for OCI downloading 2026-02-19 15:08:20 +01:00
Luca Boccassi 9204838724 test: skip dnf signature checks in TEST-88-UPGRADE
Fixes failure on Rawhide:

TEST-88-UPGRADE.sh[512]: Transaction failed: Rpm transaction failed.
TEST-88-UPGRADE.sh[512]: Warning: skipped OpenPGP checks for 15 packages from repository: @commandline
TEST-88-UPGRADE.sh[512]:   - package systemd-shared-260~devel-20260218150812.fc45.x86_64 does not verify: no signature
2026-02-18 21:41:49 +00:00
Luca Boccassi af9a5121a1 test: cover both verity verification mechanisms in TEST-70-TPM2-nvpcr
Follow-up for 521a523ce0
2026-02-18 16:20:33 +00:00
Luca Boccassi b9813d6c95 test: move check for verity kernel keyring support to util.sh 2026-02-18 16:11:34 +00:00
Luca Boccassi 7112e4755e test: do not fail TEST-86-MULTI-PROFILE-UKI if full TPM2 support not available
On a mkosi run on GHA:

[    9.547863] TEST-86-MULTI-PROFILE-UKI.sh[458]: + /usr/lib/systemd/systemd-measure --current
[    9.552790] TEST-86-MULTI-PROFILE-UKI.sh[463]: Measuring boot phases: enter-initrd, enter-initrd:leave-initrd, enter-initrd:leave-initrd:sysinit, enter-initrd:leave-initrd:sysinit:ready
[    9.553086] TEST-86-MULTI-PROFILE-UKI.sh[463]: Found container virtualization none.
[    9.553308] TEST-86-MULTI-PROFILE-UKI.sh[463]: Reading EFI variable /sys/firmware/efi/efivars/LoaderTpm2ActivePcrBanks-4a67b082-0a4c-41cf-b6c7-440b29bb8c4f.
[    9.553486] TEST-86-MULTI-PROFILE-UKI.sh[463]: Loaded shared library 'libtss2-esys.so.0' via dlopen().
[    9.553676] TEST-86-MULTI-PROFILE-UKI.sh[463]: Loaded shared library 'libtss2-rc.so.0' via dlopen().
[    9.553867] TEST-86-MULTI-PROFILE-UKI.sh[463]: Loaded shared library 'libtss2-mu.so.0' via dlopen().
[    9.554050] TEST-86-MULTI-PROFILE-UKI.sh[463]: Sorry, system lacks full TPM2 support.
[FAILED] Failed to start TEST-86-MULTI-PROFILE-UKI.service - TEST-86-MULTI-PROFILE-UKI.
2026-02-18 15:39:13 +00:00
Zbigniew Jędrzejewski-Szmek ba67af7efb Bump minimum version of python to 3.9 (#40711) 2026-02-18 13:33:29 +01:00
Jörg Behrmann 761f1ef2f3 Bump minimum version of python to 3.9
This was announced in fd8c620751 and every
still-supported distributo release provides at least 3.9, as tracked by #38608.
2026-02-18 18:47:15 +09:00
Yaping Li 23c639be6d metrics: add networkd related metrics 2026-02-18 17:58:33 +09:00
Yu Watanabe 6109cf8b61 meson,test: sort unit files 2026-02-18 17:57:17 +09:00
Lennart Poettering 521a523ce0 ci: add simple test that ensures the verity nvpcr measurements are made 2026-02-17 22:00:14 +01:00
Zbigniew Jędrzejewski-Szmek f9dbf6fd5a core: add SetProperties varlink method (#40356)
Start with Markers as a property, more can be added in the future as
needed
2026-02-17 10:57:09 +01:00
r-vdp e271497d97 dns-delegates: add support for setting a firewall mark
This makes it possible to have DNS requests for certain domains routed
differently than normal requests, which is for instance useful when
using policy routing to route traffic over a VPN but DNS requests for
the VPN endpoint itself, should be routed differently.

It doesn't make much sense to configure a firewall mark at the level of
a network interface, but at the level of a DNS delegate it can be very
useful.
2026-02-16 11:09:48 +01:00
Daan De Meyer 4e77671be7 mkosi: Remove some packages from the image
Let's slim down the image size a bit. None of the removed packages
should be required.
2026-02-15 12:51:00 +00:00
Yu Watanabe a1c8e5e338 Allow non-system users/groups in networkd and udevd again (#40612) 2026-02-14 05:41:01 +09:00
Luca Boccassi 0e1c4de235 core: add SetProperties varlink method
Initial support for 'Markers' only
2026-02-13 19:16:13 +00:00
Daan De Meyer 71de0a22ff core/service: support credentials refreshing on reload (#40093)
Closes https://github.com/systemd/systemd/issues/21099
Closes https://github.com/systemd/systemd/issues/35227
2026-02-13 10:21:44 +01:00
Yu Watanabe 559dabbbde Two portabled fixes (#40664) 2026-02-13 16:53:29 +09:00
Daan De Meyer 48f0f1fd81 TEST-72-SYSUPDATE: Use some very long partition names
To catch issues like https://github.com/systemd/systemd/issues/40658.
The commit that fixes that issue can make the name even longer to ensure
we don't regress again in this regard.
2026-02-13 15:46:52 +09:00
Luca Boccassi 03f6a8b9d9 portable: do not apply extension image policy if not attaching image
Image policy is only for images, so skip for other types

Follow-up for d059615492
2026-02-12 23:20:47 +00:00
Luca Boccassi d07aa23c87 portable: fix --force flag combination with directory extension
The check for image type uses the wrong variable, so it's applied
when it shouldn't.

Follow-up for 06768b90a3
2026-02-12 23:20:47 +00:00
DaanDeMeyer ba37ed9634 dissect: Introduce --copy-ownership= to configure chown behavior
Currently, if we're copying a file, we won't copy the owner UID/GID
from the source. If we're copying a directory, we will copy the owner
UID/GID from the source. Let's give users a bit more control over this
behavior by introducing --copy-ownership= which will default to the
current behavior but allows users to explicitly enable/disable copying
of ownership.
2026-02-12 09:45:13 +01:00
Zbigniew Jędrzejewski-Szmek 5c05a339c6 udev-rules: downgrade error about non-system user/group in OWNER=/GROUP=
This reverts (in sprit) commit f5cdf9515a,
"udev-rules: ignore non-system user/group in OWNER=/GROUP=".

The original change was done to clean up a situation where we added a
new group, but the group could already have been used for some other
purposes, and now the some unexpected entity would own the device.
Unfortunately, this check doesn't really address the issue, since the
existing account might as well be a system account, which might be
equally bad. In addition, this change is a big compatiblity break,
causing existing rules to stop working. Since quite a lot of systems
have local configuration to assign devices to users for various
purposes, this is very noticable to users. In a way, the original change
to add a new group was the compat break, and follow-up patch to cahnge
the rule parsing evolved a small compat break into a much bigger one.
There is merit to the change though, since device nodes shouldn't be
owned by users and groups and different mechanisms should be used
instead. To avoid breaking users systems, and since the original goal
cannot be achieved by this patch, let's downgrade this to a warning
to guide users towards different solutions.
2026-02-11 11:24:37 +01:00
Mike Yuan 7d551b00e3 TEST-54-CREDS: add test cases for credential refreshing 2026-02-10 23:21:11 +01:00
Philip Withnall 6015c6cd6f test: Expand sysupdate test to cover split acquire/install updates
This essentially means the sysupdate tests are now run twice: once with
a monolithic update (`sysupdate update`) and once with a split update
(`sysupdate acquire; sysupdate install`).

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2026-02-09 12:05:20 +00:00