6437 Commits

Author SHA1 Message Date
Alexander Larsson
d47a90347b sysroot: Ensure deployment detection works when using composefs
In the case of composefs, we cannot compare the devino of the rootfs
and the deploy dir, because the root is the composefs mount, not a
bind mount. Instead we check the devino of the etc subdir of the
deploy, because this is a bind mount even when using composefs.
2023-05-31 10:57:37 +02:00
Alexander Larsson
11d7587e40 prepare-root: Support using composefs as root filesystem
This changes ostree-prepare-root to use the .ostree.cfs image as a
composefs filesystem, instead of the checkout.

By default, composefs is used if support is built in and the .ostree.cfs
file exists in the deploy dir, otherwise we fall back to the old
method. However, if the ot-composefs kernel option is specified this
can be tweaked as per:
 * off: Never use composefsz
 * maybe: Use if possible
 * on: Fail if not possible
 * signed: Fail if the cfs image is not fs-verity signed with
   a key in the keyring.
 * digest=....: Fail if the cfs image does not match the specified
   digest.

The final layout when composefs is active is:

 /        ro overlayfs mount for composefs
 /sysroot "real" root
 /etc     rw bind mount to $deploydir/etc
 /var     rw bind mount to $vardir

We also specify the $deploydir/.ostree-mnt directory as the (internal)
mountpoint for the erofs mount for composefs. This can be used to map
the root fs back to the deploy id/dir in use,

A further note: I didn't test the .usr-ovl-work overlayfs case, but a
comment mentions that you can't mount overlayfs on top of a readonly
mount. That seems incompatible with composefs. If this is needed we
have to merge that with the overlayfs that composefs itself sets up,
which is possible with the libcomposefs APIs.
2023-05-31 10:57:37 +02:00
Alexander Larsson
bba3109fe2 switchroot: Make read_proc_cmdline_ostree() take a key argument
This changes it into read_proc_cmdline_key(), as this will later be
used to read additional keys.
2023-05-31 10:57:37 +02:00
Alexander Larsson
3fcebe454e composefs deploy: Store cfs signature in .ostree.cfs.sig file
In many cases, such as when using osbuild, we are not preparing the final
deployment but rather a rootfs tree that will eventually be copied to the
final location. In that case we don't want to apply the signature directly
but when the deployment is copied in place.

To make this situateion workable we also write the signature to a file
next to the composefs image file. Then whatever mechanism that does
the final copy can apply the signature.
2023-05-31 10:57:37 +02:00
Alexander Larsson
c988ff7938 deploy: Write a .ostree.cfs composefs image in the deploy dir
This can be used as a composefs source for the root fs instead of
the checkout by pointing the basedir to /ostree/repo/objects.

We only write the file is `composefs` is enabled.

We enable ensure_rootfs_dirs when building the image which adds the
required root dirs to the image. In particular, this includes /etc
which often isn't in ostree commits in use.

We also create an (empty) .ostree.mnt directory, where composefs
will mount the erofs image that will be used as overlayfs lowerdir
for the root overlayfs mount. This way we can find the deploy
dir from the root overlayfs mount options.

If the commit has composefs digests recorded we verify those with the
created file. It also applies the fs-verity signature if it is
recorded, unless this is disabled with the
ex-integrity.composefs-apply-sign=false option.
2023-05-31 10:55:14 +02:00
Alexander Larsson
0c3d9894be Commit: Add composefs digest and sig to the commit metadata
If `composefs-apply-sig` is enabled (default no) we add an
ostree.composefs digest to the commit metadata. This can be verified
on deploy.

This is a separate option from the generic `composefs` option which
controls whether composefs is used during deploy. It is separate
because we want to not have to force use of fs-verity, etc during the
build.

If the `composefs-certfile` and `composefs-keyfile` keys in the
ex-integrity group are set, then the commit metadata also gets a
ostree.composefs-sig containing the signature of the composefs file.
2023-05-31 10:55:14 +02:00
Alexander Larsson
e2956e2c08 lib: Add (private) API for checking out commits into a composefs image
This supports checking out a commit into a tree which is then
converted into a composefs image containing fs-verity digests for all
the regular files, and payloads that are relative to a the
`repo/objects` directory of a bare ostree repo.

Some specal files are always created in the image. This ensures that
various directories (usr, etc, boot, var, sysroot) exists in the
created image, even if they were not in the source commit. These are
needed (as bindmount targets) if you want to boot from the image. In
the non-composefs case these are just created as needed in the checked
out deploydir, but we can't do that here.

This is all controlled by the new ex-integrity config section, which
has the following layout:

```
[ex-integrity]
fsverity=yes/no/maybe
composefs=yes/no/maybe
composefs-apply-sig=yes/no
composefs-add-metadata=yes/no
composefs-keyfiile=/a/path
composefs-certfile=/a/path
```

The `fsverity` key overrides the old `ex-fsverity` section if
specified.  The default for all these is for the new behaviour to be
disabled. Additionally, enabling composefs implies fsverity defaults
to `maybe`, to avoid having to set both.
2023-05-31 10:55:14 +02:00
Alexander Larsson
9ba98cd8e9 fsverity: Support passing a signature when enabling fs-verity
The composefs code will need this.
2023-05-31 10:55:14 +02:00
Alexander Larsson
c6ed5cc7b2 fsverity: Add _ostree_fsverity_sign helper
This code signs a fsverity digest (using openssl) such that the
resulting signature can be used with the FS_IOC_ENABLE_VERITY ioctl.
2023-05-31 10:55:14 +02:00
Alexander Larsson
02d24d2a38 Add ot_keyfile_get_tristate_with_default() helper
This parses keys like yes/no/maybe. The introduced OtTristate type
is compatible with the existing _OstreeFeatureSupport type.
2023-05-31 10:55:14 +02:00
Colin Walters
0dd2788410
Merge pull request #2864 from cgwalters/prepare-root-prepare-composefs
prepare-root: Move sysroot.tmp creation earlier
2023-05-30 09:15:40 -04:00
Colin Walters
f903d6af67
Merge pull request #2866 from jlebon/pr/autoprune-tweaks
lib/deploy: Use `fallocate` for early prune space check
2023-05-30 08:38:16 -04:00
Jonathan Lebon
193ef29f3f lib/deploy: Use fallocate for early prune space check
The `f_bfree` member of the `statvfs` struct is documented as the
"number of free blocks". However, different filesystems have different
interpretations of this. E.g. on XFS, this is truly the number of blocks
free for allocating data. On ext4 however, it includes blocks that
are actually reserved by the filesystem and cannot be used for file
data. (Note this is separate from the distinction between `f_bfree` and
`f_bavail` which isn't relevant to us here since we're privileged.)

If a kernel and initrd is sized just right so that it's still within the
`f_bfree` limit but above what we can actually allocate, the early prune
code won't kick in since it'll think that there is enough space. So we
end up hitting `ENOSPC` when we actually copy the files in.

Rework the early prune code to instead use `fallocate` which guarantees
us that a file of a certain size can fit on the filesystem. `fallocate`
requires filesystem support, but all the filesystems we care about for
the bootfs support it (including even FAT).

(There's technically a TOCTOU race here that existed also with the
`statvfs` code where free space could change between when we check
and when we copy. Ideally we'd be able to pass down that fd to the
copying bits, but anyway in practice the bootfs is pretty much owned by
libostree and one doesn't expect concurrent writes during a finalization
operation.)
2023-05-29 12:17:05 -04:00
Jonathan Lebon
76649127d1 lib/deploy: Rename variable for clarity
`size_to_remove` looks cryptic in contrast to
`new_new_bootcsum_dirs_total_size`. Rename it in the style of the latter
for easier reading.
2023-05-28 18:39:03 -04:00
Jonathan Lebon
a3c0d6a3fe lib/deploy: Log case when auto-pruning is hopeless
For easier diagnostics.
2023-05-28 18:38:53 -04:00
Jonathan Lebon
115d5cf073 lib/deploy: Drop unused variable
Noticed this diagnostic in my editor with clangd hooked up.
2023-05-28 18:38:38 -04:00
Jonathan Lebon
632ffa4302 lib/deploy: Initialize var to pacify gcc static analysis
Classic case of analysis getting confused by variables initialized by
a function.
2023-05-27 10:38:14 -04:00
Bartłomiej Piotrowski
99f6356b5b Use a value based on OSTREE_MAX_METADATA_SIZE 2023-05-26 12:09:13 +02:00
Bartłomiej Piotrowski
4bac96a8c8 Increase the metadata size limit to 128MB
Flathub has hit the 10MB limit in 2022, and we had to drop less popular
CPU architectures from the main summary to subsummaries, effectively
cutting off users running too old Flatpak version. Despite that, the
main summary containing only x86_64 is already at 7MB. As this is
eventually going to happen to subsummaries as well, preemptively bump
the limit 12 times.

It takes between 2 and 3 years for a change like this to roll out across
Linux distributions so the best time for this was yesterday.

fixes #2715
2023-05-25 11:49:54 +02:00
Colin Walters
c22576c41d prepare-root: Move sysroot.tmp creation earlier
Main motivation is prep for composefs in
https://github.com/ostreedev/ostree/pull/2640
In the interest of that, we add a `bool using_composefs` but
it's currently always `false`.

Co-authored-by: Alexander Larsson <alexl@redhat.com>
2023-05-24 15:50:38 -04:00
Colin Walters
50790b285e
Merge pull request #2860 from cgwalters/xshell2
tests: A bit more xshell porting
2023-05-22 13:37:10 -04:00
Joseph Marrero Corchado
b5b3ef78af
Merge pull request #2859 from jmarrero/release-2023.3
Release 2023.3
2023-05-18 17:09:04 -04:00
Colin Walters
88e8b671ce tests: A bit more xshell porting
Part of https://github.com/ostreedev/ostree/issues/2857
2023-05-18 08:14:50 -04:00
Joseph Marrero
88fe600ff8 configure: post-release version bump 2023-05-17 16:32:43 -04:00
Joseph Marrero
bf3495dbbf Release 2023.3 v2023.3 2023-05-17 16:29:04 -04:00
Colin Walters
16cb47489e
Merge pull request #2856 from cgwalters/port-to-xshell
tests/inst: Add xshell and use it in one place
2023-05-10 15:16:24 -04:00
Colin Walters
dc23b9389b tests/inst: Add xshell and use it in one place
I've deprecated sh-inline; in the end I think it is better
to minimize the amount of bash code we have.  xshell solves
the core convenience problem of taking local variables and mapping
them to command arguments.

A full port would be nontrivial; this just starts the ball
rolling.
2023-05-10 14:02:09 -04:00
Colin Walters
8a2993a9d0
Merge pull request #2565 from cgwalters/clang-format
Add .clang-format file + tree-wide: Run `clang-format`
2023-05-03 08:24:21 -04:00
Colin Walters
c1044a02b2 ci: Validate clang-format 2023-05-02 10:39:04 -04:00
Colin Walters
453aed97f6 tree-wide: Run clang-format
This is a one-time tree wide reformatting to ensure consistency
going forward.
2023-05-02 08:42:19 -04:00
Colin Walters
a917813bb8 clang-format: Don't align backslashes
This increases compatibility between clang-15 and clang-16.
Also, I don't care about the aesthetics here.
2023-05-02 08:42:19 -04:00
Colin Walters
1574f3f739 lib: Fix one include
We need all the ostree bits here.
2023-05-01 17:22:38 -04:00
Jonathan Lebon
dd70c9b78c
Merge pull request #2854 from cgwalters/clang-format-prep 2023-05-01 16:48:26 -04:00
Colin Walters
0e4768094c tree-wide: Fix various include ordering issues
This fixes the build with `clang-format`.
2023-05-01 15:37:57 -04:00
Colin Walters
abd5427c3b lib: clang-format ostree.h
In order to make this work, we need to move the autocleanup
definitions after the other headers.
2023-05-01 15:37:57 -04:00
Colin Walters
f56131976e Add clang formatting infrastructure
Prep for reformatting the codebase.
2023-05-01 15:37:56 -04:00
Colin Walters
d333f20b4a build-sys: Squash automake conditional warning re .PHONY 2023-05-01 14:21:37 -04:00
Colin Walters
919212d73b
Merge pull request #2847 from jlebon/pr/calculate-and-cleanup
lib/sysroot-deploy: Add experimental support for automatic early prune
v0.18.0 ostree-sys-v0.13.0
2023-05-01 13:25:25 -04:00
Jonathan Lebon
c561e6179e lib/sysroot-deploy: Add experimental support for automatic early prune
During the early design of FCOS and RHCOS, we chose a value of 384M
for the boot partition. This turned out to be too small: some arches
other than x86_64 have larger initrds, kernel binaries, or additional
artifacts (like device tree blobs). We'll likely bump the boot partition
size in the future, but we don't want to abandon all the nodes deployed
with the current size.[[1]]

Because stale entries in `/boot` are cleaned up after new entries are
written, there is a window in the update process during which the bootfs
temporarily must host all the `(kernel, initrd)` pairs for the union of
current and new deployments.

This patch determines if the bootfs is capable of holding all the
pairs. If it can't but it could hold all the pairs from just the new
deployments, the outgoing deployments (e.g. rollbacks) are deleted
*before* new deployments are written. This is done by updating the
bootloader in two steps to maintain atomicity.

Since this is a lot of new logic in an important section of the
code, this feature is gated for now behind an environment variable
(`OSTREE_ENABLE_AUTO_EARLY_PRUNE`). Once we gain more experience with
it, we can consider turning it on by default.

This strategy increases the fallibility of the update system since one
would no longer be able to rollback to the previous deployment if a bug
is present in the bootloader update logic after auto-pruning (see [[2]]
and following). This is however mitigated by the fact that the heuristic
is opportunistic: the rollback is pruned *only if* it's the only way for
the system to update.

[1]: https://github.com/coreos/fedora-coreos-tracker/issues/1247
[2]: https://github.com/ostreedev/ostree/issues/2670#issuecomment-1179341883

Closes: #2670
2023-05-01 12:12:03 -04:00
Joseph Marrero Corchado
8b2ba4f401
Merge pull request #2853 from cgwalters/bump-msrv
rust: Bump MSRV to 1.64
2023-04-30 13:42:43 -04:00
Colin Walters
1b43b39574 rust: Bump MSRV to 1.64
Since a dependency `winnow` bumped to this in a recent update.
2023-04-29 17:11:58 -04:00
Colin Walters
b4dcfd7ede
Merge pull request #2849 from pwithnall/request-debugging
lib/fetcher: Add some debugging messages to the libsoup request path
2023-04-26 16:46:43 -04:00
Philip Withnall
77e334e5b4 lib/fetcher: Add some debugging messages to the libsoup request path
This will help with debugging stalled requests in future, such as
issue #605.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>

Helps: #605
2023-04-26 15:44:03 -04:00
Joseph Marrero Corchado
9c548d832c
Merge pull request #2850 from cgwalters/ci-no-error-deprecated-declarations
ci: Turn off errors for deprecated-declarations
2023-04-26 10:50:50 -04:00
Colin Walters
64aa5af236 ci: Drop workaround for fedora-release-container
I think this isn't necessary anymore, and is now actively broken
with f38.
2023-04-26 09:46:57 -04:00
Colin Walters
3391d8f3f0 ci: Turn off errors for deprecated-declarations
Having `-Werror` on in CI only by default has generally worked OK,
but I don't think it's worth trying to immediately scramble to port
when they deprecate APIs.

Motivated in this case by
```
 src/libostree/ostree-fetcher-curl.c: In function 'initiate_next_curl_request':
src/libostree/ostree-fetcher-curl.c:876:3: error: 'CURLOPT_PROTOCOLS' is deprecated: since 7.85.0. Use CURLOPT_PROTOCOLS_STR [-Werror=deprecated-declarations]
  876 |   rc = curl_easy_setopt (req->easy, CURLOPT_PROTOCOLS, (long)(CURLPROTO_HTTP | CURLPROTO_HTTPS | CURLPROTO_FILE));
      |   ^~
```
2023-04-26 09:37:22 -04:00
Jonathan Lebon
fd3304e987 tests/kolainst: Add make localinstall
When hacking and testing locally with `cosa build-fast` and `kola run`,
I prefer to leave testing framework stuff within the work directory
rather than installed in my pet container. Add a `localinstall` target
for this which puts the tests in `tests/kola`. Then a simple `kola run`
will pick it up.
2023-04-14 15:19:17 -04:00
Jonathan Lebon
771deb55d1 tests/kola: delete unused .gitignore
AFAICT, I don't see how `runkola.sh` or the Makefile in `tests/kolainst`
can create files in `tests/kola` since it's geared towards installing
under `/usr`.
2023-04-14 15:19:17 -04:00
Jonathan Lebon
45772ede3e lib/sysroot-deploy: Nuke finalize-failure.stamp on successful finalization
In the unusual case where one is manually finalizing staged deployments,
as can happen in testing, we expect a successful finalization to remove
the failure stamp file.
2023-04-14 15:19:17 -04:00
Colin Walters
90f7c7bd9f
Merge pull request #2848 from jlebon/pr/calculate-and-cleanup-prep
Prep patches for automatic early prune
2023-04-14 14:44:38 -04:00