Commit Graph
429 Commits
Author SHA1 Message Date
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
Matteo Croce ea9826eb94 core: add options to delegate BPFFS token creation
Add four new options BPFDelegate{Commands,Maps,Programs,Attachments}=
in order to delegate to a BPFFS instance the permission to create tokens.

The value is a list of options taken from:
https://github.com/torvalds/linux/blob/v6.14/include/uapi/linux/bpf.h#L922-L1121
The special value "any" means to allow every possible values.

More informations about BPF tokens here:
https://lwn.net/Articles/947173/
2025-07-08 22:35:29 +02:00
Matteo Croce 3a47437fc9 core: Introduce PrivateBPF= to mount a private BPFFS
Add a new option PrivateBPF= to mount a new instance of bpffs within a
namespace.
PrivateBPF= can be set to "no" to use the host bpffs in readonly mode
and "yes" to do a new mount.
The mount is done with the new fsopen()/fsmount() API because in future
we'll hook some commands between the two calls.
2025-07-08 22:33:28 +02:00
Andres Beltran a89afe1948 Add quota support for DBus 2025-07-07 17:31:03 +00:00
Zbigniew Jędrzejewski-Szmek 228d84e37a systemd-analyze: stop printing Ex transient settings
The test will fail if we ever add one again in the future by mistake.
2025-07-06 18:17:47 +02:00
Zbigniew Jędrzejewski-Szmek 41288f2daf shared/bus-unit-util: fix PrivateTmp=/PrivateUsers=/ProtectControlGroups= and Ex variants
For some fields, we perform careful parsing and verification on the sender
side. For other fields, we accept any string or strv. I think that actually
this is fine: we should optimize for the correct case, i.e. the user runs a
command that is valid. The server must perform parsing in all cases, so doing
the verification on the sender side doesn't add value. When doing parsing
locally, in case of invalid or unsupported input, we would generate the error
message locally, so we would avoid the D-Bus call, but the message itself is
not better and from the user's point of view, the result is the same. And by
doing the parsing only on the server side, we deal better with the case where
the sender has an older version of the software. By not doing verification, we
implicitly "support" new values. And when the sender has a newer version that
supports additional fields, that does not help as long as the server uses an
older version. So in case of version mismatches, parsing on the server side is
as good or better.

Resolves https://github.com/systemd/systemd/issues/37174.
2025-07-06 18:17:45 +02:00
Zbigniew Jędrzejewski-Szmek fb98c75e0e shared/bus-unit-util: tweak bus_append_exec_command to use Ex prop only if necessary
This changes little in behaviour, the conceptual part is more important. The
non-Ex variant is the actual name on the command line, and we should use the
non-Ex D-Bus property too, if it works. This increases compatibility with old
versions. But the code was mostly doing the right thing. Even the tests tested
the right thing.

Follow-up for b3d593673c and
898fc00e79.

The test is simplified by taking advantage of the fact that both names
on the commandline are supposed to behave identically.

Partially resolves https://github.com/systemd/systemd/issues/37174.
2025-07-06 18:17:43 +02:00
Zbigniew Jędrzejewski-Szmek 6f06afde59 shared/bus-unit-util: rework error messages for NFTSet=
Let's be nice to the user and print the exact reason why we won't accept
a setting.
2025-07-06 18:06:51 +02:00
Zbigniew Jędrzejewski-Szmek 95a3cfcbf6 shared/bus-unit-util: rework error messages
We generally want to have error messages with a fixed structure that convey the
important information, i.e. field name, error value, and the offending text for
options that take short values. (The text is not printed for strings encoded with
base64 and hexmem or for credentials.)

Let's use a helper that prints the message in a fixed format in the majority of
cases. In the few places where a custom message is useful, the helper is not
used. The helper:
- prints the field name, value, and error info,
- quotes the value,
- handles -ENOMEM, so we don't need to handle it separately everywhere.

When this code was originally written, parse functions would return -1
as error. Nowadays day all return a good errno, so it is fine if we print
the corresponding strerror.
2025-07-06 18:06:49 +02:00
Zbigniew Jędrzejewski-Szmek ce120ac823 shared/bus-unit-util: tweak error handling in bus_append_exec_command
exec_command_flags_to_strv() should not fail, unless we screwed up, so assert
instead of returning an error. Also, no need to strdup constant _PATH_BSHELL;
drop that so that we can get rid of the oom error handling. Finally, rename
l → cmdline for clarity.
2025-07-06 17:47:11 +02:00
Zbigniew Jędrzejewski-Szmek 8d853534ed shared/bus-unit-util: also send empty array for LogFilterPatterns=
Before, for empty input, we'd send an array with one item with an empty
pattern. Use the helper which sends an empty array instead.
bus_exec_context_set_transient_property() ignores items with an empty
pattern, so the result should be the same.

Request in review:
https://github.com/systemd/systemd/pull/37665#discussion_r2182375988.
2025-07-04 12:14:27 +02:00
Zbigniew Jędrzejewski-Szmek 892a24d42c shared/bus-unit-util: check errors before other conditions
As requested in post-merge review in
https://github.com/systemd/systemd/pull/37665#discussion_r2183755909.
2025-07-04 12:14:27 +02:00
Zbigniew Jędrzejewski-Szmek 01383af1c1 shared/bus-unit-util: stop unsing strndupa
Those are user-controlled strings, so let's use heap allocations in the usual
fashion. (Though, with strndupa_safe, the allocations were bounded anyway, so
ultimately this doesn't matter.)
2025-07-03 21:03:26 +02:00
Zbigniew Jędrzejewski-Szmek 1c1626e063 shared/bus-unit-util: add bus_dump_transient_settings() helper
bus_append_unit_property() and associated functions accept a long list of
properties. But the specific names are only available through code. But it is
useful to be able to know the specific list of properties that is supported, in
particular for shell completions. Thus, add a way to list the properties that
are supported by the code.

In the future we could also turn this into a test for the documentation. For
various reasons, the list of properties listed in the docs is a partially
overlapping set. E.g. for service type, the pull request
https://github.com/systemd/systemd/pull/37661 creates a list with 212 entries,
and this code generates 7 entries less and 184 more. I didn't check all the
differences, but in the few cases I did, the list generated here was actually
correctly supported by 'systemd-run -p'.

A smoke test is added.
2025-07-03 21:03:26 +02:00
Zbigniew Jędrzejewski-Szmek c133545430 shared/bus-unit-util: convert to a table 2025-07-03 19:58:15 +02:00
Zbigniew Jędrzejewski-Szmek b77e4fc6ce shared/bus-unit-util: add helper for TimeoutSec= 2025-07-03 19:58:15 +02:00
Zbigniew Jędrzejewski-Szmek 73ac906bec shared/bus-unit-util: add define to shorten common append pattern 2025-07-03 19:58:12 +02:00
Zbigniew Jędrzejewski-Szmek 472a1faae8 shared/bus-unit-util: add helper for AppArmorProfile=/SmackProcessLabel= 2025-07-03 19:53:40 +02:00
Zbigniew Jędrzejewski-Szmek dbd4d4cc43 shared/bus-unit-util: add helper for CPUQuotaPeriodSec=ManagedOOMMemoryPressureDurationSec= 2025-07-03 19:53:40 +02:00
Zbigniew Jędrzejewski-Szmek 5e18038da2 shared/bus-unit-util: add helper for unit deps 2025-07-03 19:53:40 +02:00
Zbigniew Jędrzejewski-Szmek a90d205af5 shared/bus-unit-util: define helper for conditions and asserts
The function has "try" in the name because it dynamically checks
if the field name matches.
2025-07-03 19:53:40 +02:00
Zbigniew Jędrzejewski-Szmek 9806468ea4 shared/bus-unit-util: define helper for SuccessActionExitStatus= and friend 2025-07-03 19:53:40 +02:00
Zbigniew Jędrzejewski-Szmek bfa7d82661 shared/bus-unit-util: add helper for TimersCalendar property 2025-07-03 19:53:40 +02:00
Zbigniew Jędrzejewski-Szmek c3c21b2bc4 shared/bus-unit-util: add helper for TimersMonotonic property 2025-07-03 19:53:40 +02:00
Zbigniew Jędrzejewski-Szmek d661a540a3 shared/bus-unit-util: add helper for Listen property 2025-07-03 19:53:38 +02:00
Zbigniew Jędrzejewski-Szmek 65ebd48e6f shared/bus-unit-util: use common helper for various strv properties 2025-07-03 19:35:33 +02:00
Zbigniew Jędrzejewski-Szmek 7673abfc2b shared/bus-unit-util: define helper for SuccessExitStatus= and friends 2025-07-03 19:35:33 +02:00
Zbigniew Jędrzejewski-Szmek 7a5eb9d03d shared/bus-unit-util: define helper for Paths property 2025-07-03 19:35:33 +02:00
Zbigniew Jędrzejewski-Szmek 9e3bc6406b shared/bus-unit-util: add helper for ProtectHostnameEx and fix naming confusion
As with grandparent commit for ImportCredentialEx=, the whole series of commits
that extended ProtectHostname was confused (6746f28854,
cf48bde7ae, e76fcd0e40),
because it added ProtectHostnameEx in places where parsing of ProtectHostname
should be have been extended.

Accept ProtectHostname=… with the new extended syntax, keep accepting
ProtectHostnameEx=… for compat with release v257. Prefer sending ProtectHostname.

Partially resolves https://github.com/systemd/systemd/issues/37174.
2025-07-03 19:35:33 +02:00
Zbigniew Jędrzejewski-Szmek 779aed7443 shared/bus-unit-util: add a helper function for directory args 2025-07-03 19:35:33 +02:00
Zbigniew Jędrzejewski-Szmek e04484ad7c shared/bus-unit-util: define helper for ExtensionImages= 2025-07-03 19:35:33 +02:00
Zbigniew Jędrzejewski-Szmek 1c202720be shared/bus-unit-util: define helper for MountImages= 2025-07-03 19:35:33 +02:00
Zbigniew Jędrzejewski-Szmek 79decd4e49 shared/bus-unit-util: define helper for RootImageOptions= 2025-07-03 19:35:33 +02:00
Zbigniew Jędrzejewski-Szmek 5517273715 shared/bus-unit-util: define helper for RootHashSignature= 2025-07-03 19:35:33 +02:00
Zbigniew Jędrzejewski-Szmek 4d92c1da45 shared/bus-unit-util: define helper for RootHash= 2025-07-03 19:35:33 +02:00
Zbigniew Jędrzejewski-Szmek 8f90f4b86f shared/bus-unit-util: define helper for TemporaryFileSystem= 2025-07-03 19:35:33 +02:00
Zbigniew Jędrzejewski-Szmek 0fdcbaf633 shared/bus-unit-util: define helper for BindPaths=/BindReadOnlyPaths= 2025-07-03 19:35:33 +02:00
Zbigniew Jędrzejewski-Szmek af677b7a25 shared/bus-unit-util: define helper for RestrictNamespaces=/DelegateNamespaces= 2025-07-03 19:35:33 +02:00
Zbigniew Jędrzejewski-Szmek c622449cb7 shared/bus-unit-util: add helper for filter lists 2025-07-03 19:35:33 +02:00
Zbigniew Jędrzejewski-Szmek 187b248e5b shared/bus-unit-util: add helper for NUMAMask= 2025-07-03 19:35:33 +02:00
Zbigniew Jędrzejewski-Szmek 85eb4381d3 shared/bus-unit-util: use common helper for NUMAPolicy= 2025-07-03 19:35:33 +02:00
Zbigniew Jędrzejewski-Szmek 6dd31c8339 shared/bus-unit-util: define helper for CPUAffinity= 2025-07-03 19:35:12 +02:00
Zbigniew Jędrzejewski-Szmek 8f0824f9db shared/bus-unit-util: define helper for CapabilityBoundingSet=/AmbientCapabilities= 2025-07-03 10:37:34 +02:00
Zbigniew Jędrzejewski-Szmek 94abee6063 shared/bus-unit-util: define helper function for rlimits
Strictly speaking, we call startswith twice now. This duplication
shall be eliminated later.
2025-07-03 10:37:34 +02:00
Zbigniew Jędrzejewski-Szmek 5c41755fe6 shared/bus-unit-util: define helper for StandardInputData= 2025-07-03 10:37:34 +02:00
Zbigniew Jędrzejewski-Szmek 6bb4420100 shared/bus-unit-util: define helper for StandardInputText= 2025-07-03 10:37:34 +02:00
Zbigniew Jędrzejewski-Szmek 375351d003 shared/bus-unit-util: define helper functions for StandardInput/Output/Error= 2025-07-03 10:37:34 +02:00
Zbigniew Jędrzejewski-Szmek 32adb97cf1 shared/bus-unit-util: define helper for LogFilterPatterns= 2025-07-03 10:37:34 +02:00
Zbigniew Jędrzejewski-Szmek 50dd808d69 shared/bus-unit-util: define helper for LogExtraFields= 2025-07-03 10:37:34 +02:00
Zbigniew Jędrzejewski-Szmek 4b98aeb6ef shared/bus-unit-util: add helper for ImportCredentialEx= and fix naming confusion
We add D-Bus properties like "*Ex" because we cannot change the D-Bus property
type without breaking backward comapatibility. But those names are only for
D-Bus, not for config file stanzas or the command-line parser. There, we can
change the type, or in other words, there is no type, just a free-form string
whose interpretation we can extend or change. Commit
831f208783 that added ProtectHostnameEx was
confused, because it added ImportCredentialEx in places where parsing of
ImportCredential should be have been extended.

On D-Bus, we send ImportCrednential in preference, and ImportCredentialEx only
when required. This way we send less bytes on the wire and support older
systems that don't understand the new property.

Partially resolves https://github.com/systemd/systemd/issues/37174.
2025-07-03 10:37:34 +02:00