6288 Commits

Author SHA1 Message Date
Luca Boccassi
bc019f7c06 test: add coverage for image policy and bare filesystems with verity 2025-10-16 16:22:33 +01:00
Luca Boccassi
fad01f798d dissect: add support for verity-protected bare filesystems via mountfsd
Needed to implement support for RootHashSignature=/RootVerity=/RootHash=
and friends when going through mountfsd, for example with user units,
so that system and user units provide the same features at the same
level
2025-10-16 16:22:33 +01:00
Luca Boccassi
68b476a298 core: also enable PrivateUsers= for user services when using images via mountfsd
RootDirectory= and other options already implicitly enable PrivateUsers=
since 6ef721cbc7 if they are set in user
units, so that they can work out of the box.
Now with mountfsd support we can do the same for the images settings,
so enable them and document them.
2025-10-16 12:58:59 +01:00
Luca Boccassi
1ebbb0b0f4 test: add coverage for RootImage= in user units
Follow-up for 046a1487db
2025-10-16 12:58:55 +01:00
Frantisek Sumsal
92631f1962 test: wait for signed.test's zone DS records to get pushed to the parent zone
It looks like the 4 second sleep might not be enough on some slower
machines (like the ARM GH Actions nodes) which can lead to the DS RRs
propagation to clash with the manual test zone edit, and the
signed.test zone then might end up not properly signed:

TEST-75-RESOLVED.sh[749]: + : '--- ZONE: signed.test (static DNSSEC) ---'
TEST-75-RESOLVED.sh[749]: + run_delv @ns1.unsigned.test signed.test
TEST-75-RESOLVED.sh[749]: + run delv -a /etc/bind.keys @ns1.unsigned.test signed.test
TEST-75-RESOLVED.sh[778]: + delv -a /etc/bind.keys @ns1.unsigned.test signed.test
TEST-75-RESOLVED.sh[779]: + tee /tmp/tmp.2KOIiyrgth
TEST-75-RESOLVED.sh[779]: ;; /etc/bind.keys:1: option 'managed-keys' is deprecated
TEST-75-RESOLVED.sh[779]: ;; validating signed.test/DS: no valid signature found
TEST-75-RESOLVED.sh[779]: ;; validating signed.test/A: no valid signature found
TEST-75-RESOLVED.sh[779]: ; unsigned answer
TEST-75-RESOLVED.sh[779]: signed.test.		86400	IN	A	10.0.0.10
TEST-75-RESOLVED.sh[779]: signed.test.		86400	IN	RRSIG	A 13 2 86400 20251028114356 20251014101356 39330 signed.test. oo3ca8WPusbBPRhzsEKw3bsBBqFtI8i4bckoMVNzt7lY+udGW6PlaSYj OjpQGgY9oglowVM9bteNtwJKHUbvtw==
TEST-75-RESOLVED.sh[749]: + grep -qF '; fully validated' /tmp/tmp.2KOIiyrgth
[FAILED] Failed to start TEST-75-RESOLVED.service - TEST-75-RESOLVED.

Let's explicitly wait for the DS records propagation to finish before we
start editing the test zone to avoid this.

I'm still not completely sure if this is the root cause, but it's the
best shot I currently have, so I'll let the CIs decide.
2025-10-16 11:51:03 +01:00
Zbigniew Jędrzejewski-Szmek
f0562fc819 test: minor fixlets for TEST-50-DISSECT (#39328) 2025-10-16 12:25:41 +02:00
Luca Boccassi
0ce88a9132 test: call bash with -o pipefail when piping commands in TEST-50-DISSECT
We want the tests to fail if one of the intermediate commands fails,
otherwise it is hard to spot failures
2025-10-15 22:58:19 +01:00
Luca Boccassi
c581bc8ad8 test: sign extension images used by TEST-50-DISSECT 2025-10-15 19:39:21 +01:00
Luca Boccassi
dc88805d16 test: also test verity signatures on debian testing/unstable
debian testing/unstable do not set VERSION_ID, so if missing, assume
it's testing/unstable which are new enough
2025-10-15 19:39:21 +01:00
Luca Boccassi
e8d1a26d9c test: move checks around in TEST-50-DISSECT so that they can be used from multiple subtests
Also set it up so that unprivileged tests can be done
2025-10-15 15:29:14 +01:00
Lennart Poettering
aad0d11e7c dissect-image: when autoprobing insist on vfat for XBOOTLDR
Let's reduce our attack surface by insisting that XBOOTLDR is vfat when
auto-probing, just like we do for the ESP. Given neither can
realistically be integrity protected (because firmware needs to access
them) let's insist on a vfat which has a much smaller attack surface,
and one we have to accept (for now) anyway, given that the ESP must be
VFAT.

This only applies to auto-probing of course. If people mount things
explicitly via fstab none of this matters. But we really shouldn't
automount a btrfs/xfs/ext4 partition as XBOOTLDR just because it looks
like one, as that would really defeat our otherwise possibly very strict
image policies.

This also introduces a new env var $SYSTEMD_DISSECT_FSTYPE_<DESIGNATOR>
environment variable that may override this hardcoding. This is in
particular useful in our testcases, since various actually do use ext4
as XBOOTLDR case. The tests are updated to make use of the new env var,
both as a mechanism to test this and to keep the tests working.
2025-10-15 08:32:37 +02:00
Antonio Alvarez Feijoo
2fbfbfc5fa test: enable TEST-06-SELINUX in openSUSE
openSUSE switched to SELinux by default for quite some time now, so this test is
also successful.
2025-10-14 17:56:39 +01:00
Lennart Poettering
1170cc4253 timer: rebase the next elapse timestamp only if timer didn't already run (#39296) 2025-10-14 18:30:23 +02:00
Lennart Poettering
f84d61d639 test: make sure TEST-50-DISSECT.mountfsd.sh can run standalone 2025-10-13 22:26:34 +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
57d1ceffb3 dissect-image: turn verity device sharing into opt-in
Sharing verity volumes is problematic for a veriety of reasons, for
example because it might pin the wrong backing device at the wrong time.

Let's hence turn this around: unless verity sharing is enabled, leave it
off, and turn $SYSTEMD_VERITY_SHARING into a true boolean that can be
set both ways.

The primary usecase for verity sharing is RootImage=, where it probably
makes sense to leave on, hence set the flag there.

This is crucial when putting together installers which install an OS on
a second disk: if verity sharing is always on we might mount the wrong
of the two disks at the wrong time.
2025-10-13 22:13:53 +02:00
Frantisek Sumsal
62ca845ac7 test: format the min/max timestamps in "systemd" style
Before:
  Next elapse timestamp should be Sun Oct 12 00:10:00 UTC 2025 <= Sun 2025-10-12 05:43:04 UTC <= Sun Oct 12 22:10:00 UTC

After:
  Next elapse timestamp should be Tue 2025-10-14 00:10:00 CEST <= Tue 2025-10-14 19:39:11 CEST <= Tue 2025-10-14 22:10:00 CEST
2025-10-13 17:35:02 +02:00
Frantisek Sumsal
80b4cacf1b test: temporarily skip the EnterNamespace= test w/o embedded debuginfo
The EnterNamespace= feature currently doesn't work if the debuginfo is
separated from the crashing binary. Until that's resolved, let's run the
test only if the test binary has embedded debuginfo (.debug_info
section; e.g. when systemd is built without WITH_DEBUG=1) or it contains
MiniDebugInfo (.gnu_debugdata section; default on Fedora and CentOS).

See: https://github.com/systemd/systemd/pull/39268#issuecomment-3390745718
2025-10-11 22:37:33 +02:00
Frantisek Sumsal
cfb604f8f7 test: exclude test-stacktrace(-not)?-symbolized from the coredump check
As they are expected coredumps from the EnterNamespace= feature test.
2025-10-11 22:37:33 +02:00
Frantisek Sumsal
937f609b41 test: build the crashing test binary outside of the test
So we don't have to pull in gcc and other stuff into it.

Also, make the test itself a bit more robust and debug-able.
2025-10-11 22:37:33 +02:00
Jelle van der Waa
c6ebb98e3c logind: emit PropertiesChanged when lingering is enabled/disabled
Cockpit's podman plugin needs to know the lingering status so the UI can
advertise enabling `podman-restart` (which depends on lingering to
work). Currently it relies on watching `/var/lib/systemd/linger/${user}`
but that isn't a public API.

Related: #22244
2025-10-09 09:39:45 +02:00
Lennart Poettering
e921d6d40f creds: add explicit control on whether to allow null key decryption
The ability to encrypt/authenticate encryption with a null key was
originally just a fallback concept for cases where during early boot we
have no host key, but the local system has no TPM2. Nowadays it is used
for other stuff as well, such as pcrlock data propagation (i.e. data
that needs no protection itself and required to properly to TPM key
derivation).

Let's give better, explicit control over null key usage, i.e. let's make
it a tristate both on the systemd-creds command line and in the Varlink
IPC to control three cases:

- the default that we allow it only if SecureBoot is off
- explicitly allowed
- explicitly refused (this is new)

Ideally systemd-creds --allow-null switch would take a boolean argument
to control this as a tristate. Alas, that would be a compat break, hence
I added --refuse-null instead (which also maps to the low-level flag for
this).

This also normalizes that the null key is always called "null key" in
messages, and not sometimes "empty key" or "fallback key".
2025-10-08 09:18:28 +02:00
Lennart Poettering
76d5d38fcc test: add testcase for withKey varlink option 2025-10-08 09:18:28 +02:00
Lennart Poettering
e4201d0a0e sysctl: support reading configuration from stdin and command line arguments (#39219)
This makes systemd-sysctl support following syntax, like
systemd-sysusers and systemd-tmpfiles:
```sh
$ /usr/lib/systemd/systemd-sysctl --inline 'foo.bar=42'
$ /usr/lib/systemd/systemd-sysctl - <<EOF
foo.bar=42
EOF
```
2025-10-06 16:12:11 +02:00
Jelle van der Waa
42e543408b varlinkctl: add detailed error message when --more is needed
Instead of reporting a "Invalid exchange", tell the user the `--more`
flag is missing.

Closes: #39201
2025-10-05 22:14:50 +02:00
Yu Watanabe
2de03c8e8b test: add test cases for sysctl reading configuration from stdin or positional arguments 2025-10-06 04:55:25 +09:00
Yu Watanabe
862b61a3a1 test: merge TEST-76-SYSCTL into TEST-87-AUX-UTILS-VM 2025-10-06 03:26:28 +09:00
val4oss
b8efd65975 TEST-74-AUX-UTILS: use sshd_config.d
* From the TEST-74-AUX-UTILS.ssh.sh writing directly into
  /etc/ssh/sshd_config can hide config from distro using /usr/etc.
* Using directory configuration /etc/ssh/sshd_config.d/* suits for all
  cases.

Signed-off-by: val4oss <val4oss@pm.me>
2025-10-04 23:00:31 +02:00
Zbigniew Jędrzejewski-Szmek
ea44302b29 meson: using f-strings in meson
Those were added before 0.61 which is our minimum version.

Dots were dropped from the end of some messages. Most messages did not have the
trailing dot.

0.63 added support for multi-line f-strings. We can't use those yet.
2025-10-03 21:21:52 +02:00
Frantisek Sumsal
0cb252d50f test: store and compare just the property value
Follow-up for 5730a400fd.
2025-09-29 23:01:24 +02:00
Lennart Poettering
0c3639d0f5 homectl firstboot tweaks (#39137)
This adds what #39101 and #39070 did for the regular firstboot wizard
but for the homectl firstboot part: i.e. port to the generic prompt
loop, show the "chrome" bars, and mute the console.

And then it also makes querying for aux groups and shells optional,
because quite frankly, i am not sure what to answer there.
2025-09-29 10:56:27 +02:00
Yu Watanabe
0f8706915a TEST-64-UDEV-STORAGE: do not use -f/--force option for wipefs
When -f/--force is used, wipefs does not call ioctl(BLKRRPART), hence
the partitions will remain in sysfs. Let's not use the option.

This also makes it use 'udevadm lock' for safety.
2025-09-27 00:18:53 +09:00
Lennart Poettering
aa27bec194 firstboot: optionally, don't query for keymap unless connected to a real VT
The keymap only really matters if there's local access to a system, i.e.
if there's actually a physical kbd directly connected to it, to apply it
to. If during firstboot we are not talked to via a VT (but via SSH,
container, or hypervisor console or so instead), then it's very unlikely
we ever are. Hence, don't ask for a keymap, and let#s shortcut the
questions asked at boot.
2025-09-26 16:40:14 +02:00
Lennart Poettering
bedcce1a1f firstboot: drop waiting for key when starting
We only show this blurb on the first question, but the first question is
interactive anyway, hence no need to wait for input first explicitly, we
won't progress anyway without user input.

(similar for homectl's firstboot)
2025-09-26 16:27:53 +02:00
Lennart Poettering
82a48eb1db test: add simple test case for mute-console service 2025-09-26 09:42:13 +02:00
Yu Watanabe
0f44a6c64a core: assorted fixes and cleanups for cgroup (#39094) 2025-09-26 13:56:25 +09:00
Yu Watanabe
10b2d19219 timer: fix unexpected triggering of service immediately after restart of a timer (#38868)
Fixes: #31231
Fixes: #35805
2025-09-26 09:51:36 +09:00
Yu Watanabe
8b4ee3d68d core/unit: fail earlier before spawning executor when we failed to realize cgroup
Before 23ac08115a, even if we failed to
create the cgroup for a unit, a cgroup runtime object for the cgroup is
created with the cgroup path. Hence, the creation of cgroup is failed,
execution of the unit will fail in posix_spawn_wrapper() and logged
something like the following:
```
systemd[1]: testservice.service: Failed to create cgroup /testslice.slice/testservice.service: Cannot allocate memory
systemd[1]: testservice.service: Failed to spawn executor: No such file or directory
systemd[1]: testservice.service: Failed to spawn 'start' task: No such file or directory
systemd[1]: testservice.service: Failed with result 'resources'.
systemd[1]: Failed to start testservice.service.
```

However, after the commit, when we failed to create the cgroup, a cgroup
runtime object is not created, hence NULL will be assigned to
ExecParameters.cgroup_path in unit_set_exec_params().
Hence, the unit process will be invoked in the init.scope.
```
systemd[1]: testservice.service: Failed to create cgroup /testslice.slice/testservice.service: Cannot allocate memory
systemd[1]: Starting testservice.service...
cat[1094]: 0::/init.scope
systemd[1]: testservice.service: Deactivated successfully.
systemd[1]: Finished testservice.service.
```
where the test service calls 'cat /proc/self/cgroup'.

To fix the issue, let's fail earlier when we failed to create cgroup.

Follow-up for 23ac08115a (v258).
2025-09-26 09:28:12 +09:00
Yu Watanabe
5c60d3011f integration tests: do not adjust log level in the test script
We passes log level through kernel command line. It is not necessary to
set to debug level at the beginning, and set to info at the end.
This is important when a test has several subtests. If a subtest sets
log level to info at the end, then subsequent tests may not generate any
useful logs.
2025-09-26 07:20:04 +09:00
Luca Boccassi
c5e48e3a66 machined: do not allow unprivileged users to shell into the root namespace
We intend to make self-registering machines an unprivileged operation,
but currently that would allow an unprivileged user to register a
process they own in the root namespace, and then login as any
user they like, including root, which is not ideal.

Forbid non-root from shelling into a machine that is running in
the root user namespace.
2025-09-25 22:13:05 +02:00
Frantisek Sumsal
f4c3c107d9 test: check the next elapse timer timestamp after deserialization
When deserializing a serialized timer unit with RandomizedDelaySec= set,
systemd should use the last inactive exit timestamp instead of current
realtime to calculate the new next elapse, so the timer unit actually
runs in the given calendar window.

Provides coverage for:
  - https://github.com/systemd/systemd/issues/18678
  - https://github.com/systemd/systemd/pull/27752
2025-09-25 12:55:04 +02:00
Frantisek Sumsal
5730a400fd test: restarting elapsed timer shouldn't trigger the corresponding service
Provides coverage for:
  - https://github.com/systemd/systemd/issues/31231
  - https://github.com/systemd/systemd/issues/35805
2025-09-24 09:52:36 +02:00
Frantisek Sumsal
953c347fb6 test: rename TEST-53-ISSUE-16347 to TEST-53-TIMER
And split the existing test into a separate subtest.
2025-09-24 09:52:36 +02:00
Yu Watanabe
e2c5e9c011 test: use relative paths to executables
This also makes shebang always use env command, and drops unnecessary
'bash -c' or 'sh -c' when a signle command is invoked in the shell,
like sleep or echo.
2025-09-23 15:48:53 +01:00
Lennart Poettering
347a3c925c test: add simple testcase for io.systemd.Repart.ListCandidateDevices 2025-09-23 09:25:11 +02:00
Daan De Meyer
d4da97400c test: Add tests for systemd's kernel oom kill handling 2025-09-19 13:54:54 +02:00
Daan De Meyer
9cf6ad16dd core: Expose oom kills and managed oom kills as properties
It can be useful for users to know this information so let's expose
it as properties so it can be queried.
2025-09-19 13:54:54 +02:00
Mike Yuan
afba4d4387 TEST-81-GENERATORS: libmount disallows omitting fstype
It's not well-formed to begin with. And util-linux's mount(8)
is pretty much ubiquitously employed, hence it will be rejected
elsewhere too. Just stop pretending it is valid just because
glibc parser is sloppy.
2025-09-18 20:22:42 +02:00
Yu Watanabe
aa5aac9e40 test-sysusers: show diffs in stderr
Otherwise, the diffs are eaten by 'meson test' command unless --verbose
option is specified.
2025-09-17 22:20:42 +09:00
Yu Watanabe
87a87b02b9 test-udev: pass test_env to make the test use systemd-detect-virt in build directory
Otherwise, the test fails if the running host does not have
systemd-detect-virt.
2025-09-17 22:20:42 +09:00