4112 Commits

Author SHA1 Message Date
Colin Walters
1dd64eb264 Release 2025.2
Signed-off-by: Colin Walters <walters@verbum.org>
2025-03-21 08:13:36 -04:00
Daiki Ueno
79470298bf sign: Support generic "spki" type of commit signatures
The current "ed25519" signing type assumes raw Ed25519 key format for
both public and private keys. This patch generalizes it by adding a
new signature type "spki" which uses the X.509 SubjectPublicKeyInfo
format for public keys. Keys in this format can easily be created with
openssl tools and provide crypto agility[1] as the format embeds
algorithm identifier.

The supposed use-case of this feature is to attach multiple signatures
with different algorithms to a single commit, so even if an algorithm
turned vulnerable, the signatures made with other algorithms can still
be used as a fallback. For instance, signer can create an Ed25519
signature along with a quantum-resistent ML-DSA signature.

The following are a couple of implementation notes:

- The private keys shall be stored in the PKCS#8 format, though future
  extensions may support other format such as opaque key handles on a
  hardware token.

- The "spki" signature type prefers the keys to be encoded in the PEM
  format on disk, while it still accepts base64 encoded keys when given
  through the command-line.

1. https://en.wikipedia.org/wiki/Cryptographic_agility

Signed-off-by: Daiki Ueno <dueno@redhat.com>
2025-03-18 16:22:16 +09:00
Daiki Ueno
1a6165e3ee sign: Add PEM reading facility
This adds a new class OstreePemReader, which reads PEM blocks from an
input stream.  This would be useful for the "x509" signing backend, as
the keys are typically stored in the PEM format.

Signed-off-by: Daiki Ueno <dueno@redhat.com>
2025-03-18 16:21:25 +09:00
Daiki Ueno
65efdf6649 sign: Factor out logic to read key blobs
This defines a new interface OstreeBlobReader, which encapsulates the
key file parsing logic. This would make it easy to support custom file
formats such as PEM.

Signed-off-by: Daiki Ueno <dueno@redhat.com>
2025-03-18 16:21:24 +09:00
Daiki Ueno
867dc0b74d sign: Use explicit_bzero to clear secret key material
Suggested in:
https://github.com/ostreedev/ostree/pull/3278#discussion_r1675696052

Signed-off-by: Daiki Ueno <dueno@redhat.com>
2025-03-18 16:21:00 +09:00
Daiki Ueno
dc1f9fb49b sign: Fix typo in error messages and comments
Signed-off-by: Daiki Ueno <dueno@redhat.com>
2025-03-18 16:21:00 +09:00
Colin Walters
1f82bdeac9
Merge pull request #3395 from cgwalters/syncfs-clarification
commit: Clarify that syncfs is of repo/tmp
2025-03-17 21:59:05 -04:00
Colin Walters
688ab1aa8e commit: Clarify that syncfs is of repo/tmp
We saw this in an error message:
```
error: Generating commit from rootfs: syncfs: Not a directory
```

I'm pretty sure it's this function call but let's be a bit
more sure by adding a bit more context.
2025-03-17 19:10:42 -04:00
Etienne Champetier
1b3ba40f13 Use fsfreeze_thaw_cycle(/boot) instead of fsync(/boot)
Grub doesn't support replaying XFS journal, so when using
XFS for /boot, fsync() or syncfs() are not enough and can
leave the system in an unbootable state.

Signed-off-by: Etienne Champetier <e.champetier@ateme.com>
2025-03-14 16:33:33 -04:00
Colin Walters
8df797d355
Merge pull request #3389 from jlebon/pr/drop-finalize-staged-path
boot: Drop ostree-finalize-staged.path
2025-03-10 15:57:54 -04:00
Jonathan Lebon
2b9912e9f9
boot: Drop ostree-finalize-staged.path
This effectively reverts ac1a919f ("boot: Add
ostree-finalize-staged.path").

A bug came in on the OCP side that demonstrates that the way things are
setup right now is racy. If a reboot is triggered quickly after staging
a deployment, the whole pipeline of:

- ostree-finalize-staged.path, which triggers
- ostree-finalize-staged.service, which triggers
- ostree-finalize-staged-hold.service,

may not fully have happened before systemd isolates to `reboot.target`
which will want to kill all pending jobs.

Just directly starting the systemd unit is less elegant but much more
explicit and gets rid of any possible race because it's directly part of
the staging operation.

Fixes: https://issues.redhat.com/browse/OCPBUGS-51150
2025-03-07 17:11:44 -05:00
Colin Walters
37961d3d9e core: canonicalize bare-user xattrs
Previously we were erroring out if xattrs were provided in
non-canonical (e.g. unsorted) form all the way down to just
the bare-user path. But for archive repos and dirmeta we
canonicalized.

Canonicalize bare-user xattrs on both read and write consistently
instead of erroring.

Signed-off-by: Colin Walters <walters@verbum.org>
2025-02-25 14:58:35 -05:00
Colin Walters
b0c4712e0d commit: Add errprefix for bareuser metadata
To aid debugging.

Signed-off-by: Colin Walters <walters@verbum.org>
2025-02-25 14:58:35 -05:00
Colin Walters
ab9a3b02a9 core: Print which xattrs are not sorted
I hit this in the rpm-ostree rechunker flow somehow
and with this change I now get:

`error: Generating commit from rootfs: Processing dir var: Writing content object: Incorrectly sorted xattr name (prev=user.Librepo.checksum.mtime, cur=security.selinux), index=2`

which is more useful, although I still need to figure out
and fix why that's happening (again?).

Signed-off-by: Colin Walters <walters@verbum.org>
2025-02-25 14:58:35 -05:00
Colin Walters
82b660b12d
Merge pull request #3382 from alyssais/private
libostree: add private dependencies to pkg-config
2025-02-14 08:34:42 -05:00
Alyssa Ross
8afde45f9a
libostree: remove unused libmount include
As far as I can tell, this hasn't been used since
9a526bba ("sysroot: Handle ro /boot but rw /sysroot").
2025-02-14 12:29:46 +01:00
Alyssa Ross
cb1d0ad0b9
libostree: add private dependencies to pkg-config
This makes it possible to use pkg-config to link against libostree as
a static library.  Unlike shared libraries, static libraries don't
encode their dependencies in the library file, so we have to
communicate them via pkg-config.
2025-02-14 12:26:11 +01:00
Colin Walters
68d70de6c6 sepolicy: Add ostree_sepolicy_set_null_log
Let's quiet the output of libselinux by default, all we
get is the pointless "regex version mismatch" warnings.
This is what e.g. systemd does.

This is exposed via the library; our binary opts in,
then we expect higher level tools like e.g. bootc to
do this too.

Signed-off-by: Colin Walters <walters@verbum.org>
2025-02-10 15:24:52 -05:00
Colin Walters
303c2a23a2
Merge pull request #3377 from cgwalters/log-require-verity
prepare-root: Log when we're mounting with verity required
2025-02-03 13:17:54 -05:00
Colin Walters
5dce6456cc
Merge pull request #3379 from nikita-dubrovskii/pvimg
zipl: remove 'sdboot' image before generating new one
2025-02-03 12:40:37 -05:00
Nikita Dubrovskii
0c25931b13 zipl: remove 'sdboot' image before generating new one 2025-02-03 13:31:17 +01:00
Colin Walters
533c8b9281 lib: Add missing Since annotations to two recent APIs
On general principle, but specfiically this is needed
to ensure the Rust binding generator correctly handles
feature flags for them.
2025-02-01 13:36:07 -05:00
Colin Walters
863890804b prepare-root: Log when we're mounting with verity required
On general principle, but specifically as I wanted to cross-check
this when debugging something else.
2025-02-01 10:23:29 -05:00
fossdd
e82bb38adf
libotutil: Remove redundant import of prctl.h
sys/prctl.h already provides prctl.h and adding both imports fails on
musl libc:

	/usr/include/sys/prctl.h:88:8: error: redefinition of 'struct prctl_mm_map'
	   88 | struct prctl_mm_map {
	      |        ^~~~~~~~~~~~
	In file included from src/libotutil/ot-unix-utils.c:33:
	/usr/include/linux/prctl.h:134:8: note: originally defined here
	  134 | struct prctl_mm_map {
	      |        ^~~~~~~~~~~~
2025-01-27 17:49:39 +01:00
Joseph Marrero Corchado
372c4444dd Release 2025.1 2025-01-15 13:11:04 -05:00
Colin Walters
20ff0865c7 Always generate composefs blob, don't enable runtime by default
Followup to 9a0acd7249

Basically our composefs enablement flag has long had a tension between
trying to do two things:

- Enable generating the composefs blob (at deployment time)
- Enable at runtime in prepare-root

And we've hit issues in "ratcheting" enabling composefs
across upgrades because of this.

This change builds on the previous one, and now it's really
simple to talk about:

- If composefs is enabled at build time, we *always*
  generate a composefs blob at deplyment time
- Configuring the prepare-root config now mostly
  only affects the runtime state.

There is one detail though: in order to handle the
verity requirement at deploy time, we do still parse
the config then.

But for the basic "is composefs enabled at all at runtime"
that is now fully keyed off the config, not the build time
or (worse) whether the deployment happened to have a composefs
blob.

For users who want composefs on, they need to do so in the base
image configuration.

Signed-off-by: Colin Walters <walters@verbum.org>
2025-01-10 08:04:50 -05:00
Colin Walters
014c965578 tree-wide: Rerun clang-format, update ci
We have drift again here because we're using an old clang-format
in CI, and some things have landed that it didn't catch.

And update clang-format to ubuntu-24.04 so we are running
against something more modern.

Signed-off-by: Colin Walters <walters@verbum.org>
2025-01-09 13:29:51 -05:00
Colin Walters
ce4e49e1f4
Merge pull request #3364 from ruihe774/geteuid
chore: Use geteuid() instead of getuid() to check privilege
2025-01-02 09:23:16 -05:00
Mary Strodl
b04cb8f40f bin/admin-upgrade: add kexec support
Adds a new `--kexec` flag to `ostree admin upgrade` which will cause
the deployment to be loaded into kexec after the upgrade completes.
It is particularly useful in conjunction with the `--reboot` flag to
perform a reboot into the new deployment without waiting for the
(often slow) firmware initialization to take place. (And in my case,
allows me to avoid a normal reboot, which can be unreliable on my
hardware).

After an image has been loaded (using the `kexec_file_load` syscall),
the `systemctl-reboot` command (which is called when the existing
`-r` flag is included) will trigger a kexec on the loaded image
rather than a normal reboot. From `systemctl(1)`:

  If a new kernel has been loaded via kexec --load, a kexec will be
  performed instead of a reboot, unless "SYSTEMCTL_SKIP_AUTO_KEXEC=1"
  has been set. If a new root file system has been set up on
  "/run/nextroot/", a soft-reboot will be performed instead of a
  reboot, unless "SYSTEMCTL_SKIP_AUTO_SOFT_REBOOT=1" has been set.

A good in-depth technical explanation of kexec can be found here:
https://web.archive.org/web/20090505132901/http://www.ibm.com/developerworks/linux/library/l-kexec.html

My implementation uses the `kexec_file_load` syscall rather than the
older `kexec_load` syscall, which allows the kernel to verify the
signatures of the new kernel. It is supported on Linux 3.17 and
newer. I assume this probably won't be an issue, but if it is, it's
not that hard to put a preprocessor directive around the kexec stuff
to disable it for older kernels. Even RHEL is new enough now to
not be an issue :)

Closes: #435
2024-12-23 13:59:37 -05:00
Misaki Kasumi
f9bf9ac560 chore: Check CAP_SYS_ADMIN in ot_util_process_privileged 2024-12-20 20:35:08 +08:00
Misaki Kasumi
1bd9aa6461 chore: Use geteuid() instead of getuid() to check privilege 2024-12-20 19:13:59 +08:00
Colin Walters
64a38aec8c
Merge pull request #3353 from jlebon/pr/composefs-maybe
libostree/deploy: enable composefs by default
2024-12-17 15:34:37 -05:00
Colin Walters
1c68410368
Merge pull request #3354 from ruihe774/cfs-verity
prepare-root: Add composefs.enabled=verity
2024-12-17 14:59:00 -05:00
Colin Walters
08395e2479
Merge pull request #3348 from qiuzhiqian/main
rofiles-fuse: when fuse execution fails, rofiles-fuse still returns exit code 0
2024-12-17 14:22:10 -05:00
Jonathan Lebon
41a7f36f8e
lib/deploy: error out if composefs enabled but unsupported
If composefs was explicitly requested (`enabled = true`) but libostree
was not compiled with composefs support, error out at deploy time. This
matches the logic in `ostree-prepare-root`.
2024-12-17 13:30:11 -05:00
Jonathan Lebon
9a0acd7249
libostree/deploy: enable composefs by default
The composefs libostree integration has been supported for a while now
and is actively in use in various ostree/bootc-based systems. Let's
turn it on by default.

This has no effect if composefs support is not compiled in. Note also
that this does not change the default value of the `composefs.enabled`
tristate to `true`. The default is still `maybe`, but the deploy API
will now also create composefs images for `maybe`.

The reason for doing it this way is so that systems upgrading from
old libostree versions (which may either not have composefs support or
may have composefs-related bugs) will still be able to upgrade and not
trip `ostree-prepare-root` in the new deployment (which allows missing
composefs images for `maybe`).

We may in the future change the default value to `true`.

See also: https://github.com/ostreedev/ostree/issues/2867
2024-12-17 13:30:08 -05:00
Misaki Kasumi
a8f75bfe35 sign-ed25519: Fix error message of validate_length 2024-12-17 15:55:08 +00:00
Misaki Kasumi
5831fb5a63 sysroot-deploy: Require fsverity when composefs.enabled=verity 2024-12-17 15:53:54 +00:00
Misaki Kasumi
881c88162a prepare-root: Add composefs.enabled=verity 2024-12-17 15:53:54 +00:00
Colin Walters
74efebdf50
Merge pull request #3346 from cgwalters/commit-label-ordering
core: Always sort incoming xattrs
2024-12-03 11:20:33 -05:00
qiuzhiqian
8346244443 rofiles-fuse: Fixed the problem that when fuse execution fails, the command returns a status code of 0
testcase:
`$ sudo rofiles-fuse a b`
fuse: bad mount point `b': No such file or directory
`$ echo $?`
0
2024-12-03 20:38:35 +08:00
Colin Walters
1858d3d300 core: Always sort incoming xattrs
When recomputing selinux attrs during commit, we weren't sorting,
which could cause various issues like fsck failures.

This is a big hammer; change things so we always canonicalize
(i.e. sort) the incoming xattrs when creating a file header
and directory metadata.

I think almost all places in the code were already keeping
things sorted, but it's better to ensure correctness first.
If we ever have some performance issue (I'm doubtful) we
could add something like `_ostree_file_header_known_canonicalized`
or so.

Closes: https://github.com/ostreedev/ostree/issues/3343

Signed-off-by: Colin Walters <walters@verbum.org>
2024-12-02 10:40:17 -05:00
Simon McVittie
67ed2acad4 composefs: Ensure buffer is suitably aligned for struct fsverity_digest
struct fsverity_digest starts with a __u16, so it will normally require
16-bit alignment, which is not guaranteed for a char array.

Resolves: https://github.com/ostreedev/ostree/issues/3339
Signed-off-by: Simon McVittie <smcv@debian.org>
2024-11-14 13:55:11 +00:00
Colin Walters
6ed1f83ab8 checkout: Only verify digest if repo requires fsverity
Fixes a regression from the previous commit; in
the case where the target repo doesn't have composefs in
signed mode there's no reason to verify the digest
at checkout time because we aren't verifying it at
boot time either.

The regression is in cases that use rpm-ostree e.g.
where as of recently we unconditionally add the composefs
digest, but for e.g. FCOS we aren't deploying with fsverity
enabled.

Closes: https://github.com/ostreedev/ostree/issues/3330

Signed-off-by: Colin Walters <walters@verbum.org>
2024-11-04 13:01:55 -05:00
Colin Walters
a6d07b6cc3 deploy: Don't recompute verity checksums if not enabled
This fixes a truly horrific performance bug when
composefs is enabled, but fsverity is not supported
by the filesystem. We'd fall back to doing *userspace*
checksumming of all files at deployment time which was absolutely
not expected or required.

There's really an immense amount of technical debt
here, such as the confusion between `ex-integity.composefs`
vs the prepare-root config, how we handle "torn" states
where some objects don't have verity enabled but some do,
etc.

The ostree composefs state has two modes:

- signed: We need to enforce fsverity
- unsigned: Best effort resilience

So we fix this by making the deploy path to make verity
"opportunistic" - if the ioctl gives us the data, then we
add it to the composefs.

However, this code path is also invoked when we're
computing the expected composefs digest to inject
as commit metadata, and *that* API must work regardless
of whether the target repo has fsverity enabled as
it may operate on a build server.

One lucky thing in all of this: When I went to add
the "checkout composefs" API I added a stub `GVariant`
for options extensibility, which we now use.

Signed-off-by: Colin Walters <walters@verbum.org>
2024-10-28 09:31:34 -04:00
Colin Walters
72202df98f deploy: Don't copy xattrs for devicetree
xref: https://github.com/coreos/fedora-coreos-tracker/issues/1808

For the kernel/initramfs that we copy to `/boot`
we use an explicit relabeling today, ignoring the source SELinux
context.

When we added handling for devicetree it reuse the `copy_dir_recurse`
we have for `etc` handling, and that copied the source xattrs.

Let's ensure that the devicetree is also `boot_t` by *not* copying
xattrs and relying on the default labeling.

Signed-off-by: Colin Walters <walters@verbum.org>
2024-10-18 11:32:42 -04:00
Colin Walters
f7018d84de
Merge pull request #3316 from ruihe774/readonly-cmdline
prepare-root: allow `sysroot.readonly=true` with kernel cmdline `ro`
2024-10-10 14:40:48 -04:00
Colin Walters
f11e6a4ae0 commit: Give a better error message for unhandled file type
xref https://github.com/ostreedev/ostree/issues/3319

It'd be useful to know what file type is being hit here; I believe
this code path should be unreachable.
2024-10-10 12:54:33 +00:00
Misaki Kasumi
5b6d208801 prepare-root: allow sysroot.readonly=true with kernel cmdline ro 2024-10-10 20:38:34 +08:00
Colin Walters
fdfeb0ba7b checkout: Add commentary around whiteout "quoting"
Signed-off-by: Colin Walters <walters@verbum.org>
2024-10-01 17:07:59 -04:00