Repository navigation
UAPI.16 Manifest tooling and support in systemd-sysupdate - #44292
Conversation
|
Reviewed b8d6a06 (architecture, correctness, lifetimes, security, style, tests). All findings are resolved 🎉 Must fix
Suggestions
Nits
|
026cc93 to
f8c0450
Compare
|
I did an AI review as well: Reviewed #44292 at 8a606b2..f8c0450. Found two blockers, both reproduced: B1 [Medium] — GPT-type filtering never takes effect (sysupdate-resource.c:847). The check reads the source’s partition type, but MatchPartitionType= sets the target’s type. A usr-x86-64 manifest object was offered for a root-x86-64 target; destination selection does not reject that mismatch. Two smaller findings: C1 [Low]: The man page promises full downloads and encoded-digest verification, although unencoded ranges deliberately skip those. The acquisition commit message also incorrectly describes ranges as unsupported and compression autodetection as preserved. |
f8c0450 to
e8f433e
Compare
|
Addressed all, including the AI stuff you listed. |
|
B3 [Medium, blocker] — Valid contents sources are discarded (sysupdate-resource.c:765). C2 [Low] — The tar restriction is overstated (sysupdate.d.xml:753). The documentation excludes ranges for every url-tar source, but unencoded inline tar data supports ranges. Only downloaded tar sources require the whole file. M1 remains in the replacement helper (data-fd-util.c:248). data_fd_from_iovec() duplicates memfd_new_and_seal()’s allocation, writing and sealing. Using that constructor followed by fd_reopen(O_RDONLY) preserves empty-data handling, ownership, seals and initial position while removing the duplicate implementation. M2: copy_data_fd_full() rewinds before reopening, which already resets the position. Returning before the seek on success removes an unnecessary syscall; the fallback still needs the seek. M3: Every memfd_seal_and_reopen() caller effectively requests O_RDONLY. Its mode parameter can go; fd_reopen() supplies the optional O_CLOEXEC itself. Unresolved, speculative [Low]: Small stdin copies now require /proc/self/fd on kernels without O_EMPTYPATH. That could regress pcrlock lock-pe/lock-uki in proc-less chroots. Whether that environment is supported remains open; an old/new stdin comparison there is the next check. |
This places literal data in a sealed memfd and returns a read-only fd to it, positioned at the beginning, so that it can be passed to other processes, for example as standard input. It's a thin wrapper around memfd_new_and_seal() plus a read-only reopen. The final "seal and reopen read-only" step of memfd_clone_fd() is split out into a helper, and copy_data_fd_full() now uses it too, so that its memfd case returns an O_RDONLY fd like its temporary file cases already do, instead of a sealed O_RDWR one.
The "literal" field of a contents object may carry empty data, which encodes an empty file. iovec_is_set() returns false for that though, so such a field was considered absent, and the check that "file", "url" and "literal" are mutually exclusive did not refuse an empty "literal" next to one of the others. Add uapi16_contents_has_literal(), which checks whether the field was set instead of whether it carries data, and use it for the check.
e8f433e to
88cc258
Compare
So far we ignored the "contents" arrays of UAPI.16 file objects, and always downloaded a file by its name relative to the source URL. Let's make use of them: each entry is an alternative location of the file's data, and we now try them in the listed order until one works out. All three kinds of sources are supported: "file" entries name a file relative to Path= (also if ManifestPath= is used, which only redirects the acquisition of the manifest itself), "url" entries carry an absolute URL, and "literal" entries carry the data inline. Sources may embed the file in more data, in which case the range at the specified offset is used and checked against the file's digest. Inline data is cut in memory and handed to systemd-import via a memory fd as standard input. Downloads are passed to systemd-pull with --source-offset= and --source-size=, so that for unencoded sources only the range making up the file is downloaded. systemd-pull supports ranges for raw images only, and we cannot cut into encoded inline data, hence such sources must consist of the file and nothing else; sources that do not qualify are ignored with a warning. Everything is still run through systemd-pull or systemd-import, so that decompression, sparse file handling and sandboxing work the same for all sources. The encoding declared in the manifest is passed down to the tools via --compression= (or "none" if none is declared), so that they strictly decode with that algorithm rather than guessing from the data. If a file object carries no "contents" array, it is acquired by its name as before. For UAPI.16 manifests it is taken as is (i.e. with --compression=none), since the manifest declares encodings explicitly via "contents"; for SHA256SUMS manifests the tools keep detecting the compression on their own. Fixes: systemd#38772 Fixes: systemd#32819 Fixes: systemd#35571 Fixes: systemd#38774 Fixes: systemd#37931 (Of course, these issues are only fixed if people use UAPI.16 instead of SHA256SUMS, but I think this is an OK requirement to make)
UAPI.16 manifests carry their signatures inline, hence systemd-pull is invoked with --verify=no for them, but so far nothing else verified the signature either, i.e. with the default of Verify=yes unauthenticated manifests were trusted. Pass the X.509 certificates found in the VOA hierarchy (UAPI.11, role "manifest", context "sysupdate") to uapi16_manifest_read(), so that the manifest signature is verified while the manifest is parsed. If verification is enabled and no certificates are found, the transfer is refused.
… instances UAPI.16 file objects may carry an "extendedAttributes" field. When installing a file or directory from a source with a UAPI.16 manifest, let's apply the extended attributes in the "user" namespace listed there to the inode we create, so that they are retained on the target. This is done on a best-effort basis: if the file system does not support extended attributes, or setting them fails for other reasons, this is logged but not fatal, the instance is fully usable without them.
…systems Let's add a boolean MatchXAttr= setting to the [Source] and [Target] sections of transfer files that allows restricting individual instances to specific systems, via extended attributes attached to them. If enabled, the following extended attributes are checked: user.uapi.match_hostname → the hostname user.uapi.match_machine_id → the machine ID user.uapi.match_machine_tags → the machine tags (TAGS= in machine-info) user.uapi.match_image_id → IMAGE_ID= from os-release user.uapi.match_image_version → IMAGE_VERSION= from os-release user.uapi.match_os_id → ID= from os-release user.uapi.match_os_version → VERSION_ID= from os-release In the [Source] section it is enabled by default, so that whoever publishes instances can restrict them to specific systems without every transfer file having to opt in. In the [Target] section it is off by default, i.e. installed instances are only filtered if requested. The checks are applied to the extended attributes listed in UAPI.16 manifests (relevant for sources) as well as to the extended attributes of files and directories found on disk (relevant for targets and local sources). Instances that do not match are entirely ignored, i.e. they are neither installed nor vacuumed. Since the extended attributes listed in UAPI.16 manifests are applied to the installed instances, the restrictions are retained on the target. The local system properties (hostname, machine ID, machine tags and the relevant os-release fields) are only read when they are needed for the first time, i.e. when a candidate actually carries one of these attributes. If --root=/--image= is used they are read from there. The setting is also exposed as boolean matchXAttr field of transfers defined via the io.systemd.SysUpdate.Provider Varlink interface.
88cc258 to
b8d6a06
Compare
This adds UAPI.16 support to systemd-sysupdate, systemd-importd, systemd-repart. It also adds a new tool for generating and verifying manifests.
It also adds support for additional matches in sysupdate transfer files, against xattrs on files. This is then also replicated in vpick.
Fixes: #44448
Fixes: #38772
Fixes: #32819
Fixes: #35571
Fixes: #38774
Fixes: #37931