Commit graph

552 commits

Author SHA1 Message Date
Michael Vogt
0a2e0bb3d2 stages: add org.osbuild.machine-id stage
This is a variation of PR https://github.com/osbuild/osbuild/pull/960
that put the machine-id handling into it's own stage and adds
explicit handling what should happen with it.

For machine-id(5) we essentially want the following three states
implemented:

1. `first-boot: yes` will ensure that /etc/machine-id is
   in the "uninitialized" state. This means on boot the systemd
   `ConditionFirstBoot` is triggered and a new id in `/etc/machine-id`
   is created. This will work for systemd v247+.
2. `first-boot: no` will ensure that /etc/machine-id exists but
   is empty. This will trigger the creation of a new machine-id but
   will *not* trigger `ConditionFirstBoot`.
3. `first-boot: preserve` will just keep the existing machine-id.
   Note that it will error if there is no /etc/machine-id

Note that the `org.osbuild.rpm` will also create a
`{tree}/etc/machine-id` while it runs to ensure that postinst
scripts will not fail that rely on this file. This is an
implementation detail but unfortunately the rpm stage will
leave an empty machine-id file if it was missing. So we cannot
just remove /etc/machine-id because any following rpm stage
would re-create it again (and we cannot change that without
breaking backward compatiblity). Thanks to the special semantic
that a missing /etc/machine-id and an /etc/machine-id with
the `uninitialized` string are equivalent we don't care.

To support systemd versions below v247 we could offer an option
to remove /etc/machine-id. But the downside of this is that
it would only work if the org.osbuild.machine-id stage is after
the rpm stage.

See also the discussion in PR#960.

Thanks to Tom, Christian for the PR and the background.
2023-11-30 13:30:32 +01:00
Miguel Martín
99af178c6d runners: create fake machine id when needed
Create fake machine before executing the runner command to
avoid the "Failed to resolve specifiers in '/var/log/journal/%m'"
errors.
2023-11-28 11:50:31 +01:00
Michael Vogt
3b7471ab7c stages(kickstart): add validation for the hostname
The hostname is validated according to the rules of `hostname(7)`
and tests are added to validate them.
2023-11-27 15:10:29 +01:00
Michael Vogt
2116803e32 stages(kickstart): add validation for device
This adds basic validation for the network `device` in the kickstart
stage. There are multiple ways that a `device` can written, see
https://pykickstart.readthedocs.io/en/latest/kickstart-docs.html#network
for details.

When written as device name then this is checked by the kernel in
https://elixir.bootlin.com/linux/v6.6.1/source/net/core/dev.c#L1038
and it's very free from. Our validation is stricter, if this becomes
a problem we can relax it more.

When written as a mac address the pattern will ensure it's written
in exactly this way.
2023-11-27 15:10:29 +01:00
Michael Vogt
60e78f5084 stages(kickstart): add ipv4 related regex pattern checks
Check for valid ipv4 addresses via a regex in the schema and
add matching tests. This will ensure that only valid ipv4
addresses can be entereed in "ip", "gateway" or "nameservers".

Note that libc/kernel accept invalid ipv4 addresses and do
"interesting" things with them. So they accept `127.1` and
turn that into `127.0.0.1` or even `127.256` and turn that
into `127.0.1.0` because 256 overflows into the next segment
(thanks to Simon for poiting this out). If this becomes a
problem and customers rely on invalid ipv4 addresses we will
need to relax the rules but let's start strict and help our
users with more guardrails.

Note that no ipv6 validation via regex is done. The regex
on stackoverflow for validating ipv6 is 660 chars long
and that seems a bit too long for our schemas and putting
and error with that in front of our users.
2023-11-27 15:10:29 +01:00
Michael Vogt
3b346a6a30 stages(kickstart): add network support to kickstart
This commit adds `network`support to the kickstart stage [0].

[0] https://docs.fedoraproject.org/en-US/fedora/f36/install-guide/appendixes/Kickstart_Syntax_Reference/#sect-kickstart-commands-network
2023-11-27 15:10:29 +01:00
Michael Vogt
4884dc882d stages(ostree.post-copy): add stage unit test and comment
This commit adds a small stage unit test and most importantly
a comemnt why `devices` is part of the schema (but appears unused).

The reason "devices" is explained by Alex Larsson:
"""
The mounts don't work without devices that have the filesystems.
In sample-images for example, this is typically used like so:
```
type: org.osbuild.ostree.post-copy
devices:
  root:
    type: org.osbuild.loopback
    options:
      filename: disk.img
mounts:
- name: root
  type: org.osbuild.ext4
  source: root
  target: /
```
"""
2023-11-27 13:39:20 +01:00
Marcos Libanori Sanches
810a48d859 stage(oscap.remediation): link /proc/self/fd to /dev/fd
Remediation bash didn't work correctly without /dev/fd.
Link /proc/self/fd to /dev/fd within the tree.
2023-11-23 17:56:19 +01:00
Alexander Larsson
f982b1f61a Add org.osbuild.ostree.post-copy stage
If fs-verity is configured in ostree then ostree will (try to) enable
fs-verity on various repo files. However, in osbuild this will happen
in a separate pipeline, and these files will later be copied to the
final location on the physical filesystem, and any fs-verity status
then is lost.

To support fs-verity we need to run this stage after copying the image
to the filesystem.  It uses the ostree "admin post-copy" operation.
which it will re-enable fs-verity as needed.
2023-11-22 16:39:04 +01:00
Alexander Larsson
5cfbc5a395 Add org.osbuild.experimental.ostree.config stage with composefs option
This adds a new stage that allows you to set the experimental new
`ex-integrity.composefs` option. If set to true, it means that when
deploying from this repository a composefs image will be created.

A value of `maybe` is also supported, which means composefs will only
be created if support is built into ostree.

Support for this was added in ostree 2023.4, earlier versions ignore
this key.

This stage uses the new prefix org.osbuild.experimental. This way
users will not accidentally enable an experimental option, and allows
us (and ostree) some leeway in making changes over time to this
feature.
2023-11-22 16:39:04 +01:00
Michael Vogt
5407f1cef1 stages(kickstart): support autopart
This commit implements the `autopart` kickstart option and adds
matching tests.
2023-11-15 18:21:34 +01:00
Miguel Martín
f3d740aaf8 stages: add org.osbuild.update-crypto-policies stage
This stage calls `update-crypto-policies` to set the
policy applicable for the various cryptographic back-ends,
such as SSL/TLS libraries.

Signed-off-by: Miguel Martín <mmartinv@redhat.com>
2023-11-15 17:15:10 +01:00
Miguel Martín
5a58c35680 RPM stage: link /proc/self/fd to /dev/fd
Link "/proc/self/fd" to "/dev/fd" within the tree
to avoid "'/dev/fd/63': No such file or directory" errors

Signed-off-by: Miguel Martín <mmartinv@redhat.com>
2023-11-15 13:25:03 +01:00
Michael Vogt
c9d42865ed stages(kickstart): implement "display_mode" option(s)
This implements the display mode options `text`, `graphical`,
`cmdline` as an enum with the name `display_mode`.

See PR#1442 for the rational/discussion of this over using
three boolean options.

Thanks to Achilleas and Tom!
2023-11-15 09:34:49 +01:00
Michael Vogt
2c41bcde68 stages(kickstart): ensure no extra options under clearpart
Fix an oversight from https://github.com/osbuild/osbuild/pull/1426
2023-11-15 09:34:49 +01:00
Dusty Mabe
52adfe01f7 stages: add kernel-cmdline.bls-append stage
This adds a stage to be able to add kernel arguments on a system by
appending to the BLS [1] config directly either in the tree or in
a mount. This is useful on say systems that don't use `grubby` and
thus can't use the org.osbuild.kernel-cmdline stage.

[1] https://freedesktop.org/wiki/Specifications/BootLoaderSpec/
2023-11-14 23:58:08 +01:00
Ondřej Budai
dcb0850a2e stages/org.osbuild.keymap: create xorg.conf.d if it doesn't exist
Newer versions of Fedora don't create this directory by default. This
commit modifies the stage so it creates it if it doesn't exist.
2023-11-14 10:45:44 -08:00
Alexander Larsson
cf00c5b214 org.osbuild.ostree.sign: Support ostree sign to sign commits
This form of signatures has been (build-time-optionally) supported
since ostree 2020.4 as an alternative to the old gpg signatures. With
the current work on composefs[1] they are becomming more important, as
they will allow verification of the commit (and thus the composefs
image) during boot, giving us a full trusted boot chain all the way
into the ostree userspace.

Note: `ostree sign` used to require libsodium and was thus disabled in
e.g. the Fedora build of ostree. However, recently[2] it is also supported
with openssl, which will let it be more widely used.

[1] https://github.com/ostreedev/ostree/pull/2921
[2] https://github.com/ostreedev/ostree/pull/2922
2023-11-14 13:49:39 +01:00
Alexander Larsson
9185d8e1ce Add org.osbuild.ostree.genkey stage
This stage allows you to create new (random) ed25519 keys as used by
`ostree sign`.

The primary usecase for this is composefs. You can generate a
transient key-pair during the build (unique to the build) that binds
the initrd to the userspace tree.

You put the public key in the initrd, sign the resulting commit with
the private key and then throw away the private key. During boot of a
(secureboot trusted) initrd, we use this public key to validate that
we're booting the right commit.

This is similar to how the transient kernel module signatures work.
It similarly generates a keypair during the kernel rpm build, sign the
modules, throw away the private key and embed the public key in the
kernel binary.

Of course, this stage can also be used to generate keys used for
persistant signatures.
2023-11-14 13:49:39 +01:00
Michael Vogt
9f4bd1fc31 stages(kickstart): ensure test inputs pass schema validation
Now that inputs can be relatively easily validated against
the schema this should also be used for all the "good" test
inputs to ensure that all tests test against valid inputs.
2023-11-10 14:44:59 +01:00
Simon de Vlieger
910a4b556b stage/test: kickstart test split
Split out the kickstart tests between checking contents and validating,
this allows to skip the validation tests if ksvalidator isn't available.
2023-11-10 12:03:23 +01:00
Michael Vogt
be85b2342c stages(kickstart): ensure clearpart dict always has an option set 2023-11-10 09:23:33 +01:00
Michael Vogt
cce0eeaba4 stages(kickstart): implement "reboot" option
This commit implements the `reboot` option for kickstart files.

Note that there are two ways this can be enabled via the json.
Either via a boolean or by passing a dict with options.
```
{"reboot": true}
{"reboot": {"eject": true, "kexec": true}
```

Passing the empty dict
```
{"reboot": {}}
```
is not allowed by the schema.
2023-11-10 09:23:33 +01:00
Michael Vogt
b9ad7dd1be stages(kickstart): add test for schema validation
Add functional/regression around the schema validation for the
kickstart stage. The goal is to ensure that the regexp matching
in the schema allows the expected uses and rejects clearly
forbidden ones.
2023-11-09 11:45:11 +01:00
Michael Vogt
2c3f54dc90 stages(kickstart): add unittest test for zerombr/clearpart
Trivial followup for PR#1426 to include unit test output about
the expected kickstart file.
2023-11-09 09:41:44 +01:00
Michael Vogt
ce8bc6dc1f stages(kickstart): run ksvalidator as part of the tests
Run `ksvalidator` as part of the test_kickstart.py tests. This
ensures that the file we write is valid.
2023-11-08 18:49:35 +01:00
Michael Vogt
ed95c10530 stages: add new unit test for kickstart stage
This commit adds a simple and lightweight unit test for the new
kickstart options. It's pretty simple but also cheap and runs
fast.
2023-11-07 15:12:08 +01:00
Michael Vogt
29e7c86e5d kickstart: add support for "zerombr","clearpart"
Add support for the kickstart options:
- zerombr
- clearpart

Note that for clearpart the `drives` and `list` options have a
regexp pattern to limit the valid inputs. In theory we could only
exclude the `,` here as this is used in the kickstart config as
the list delimiter. Similarly `disklabel` also needs to exclude
` ` or one could write:
```
{"disklabel": "foo --unknown-option-that-confuses-kickstart"}
```
2023-11-07 14:05:44 +01:00
Michael Vogt
a5ebd9a06f kickstart: add lang,keyboard,timezone to the supported options
This commit adds support for the following kickstart options:
- lang
- keyboard
- timezone
2023-11-03 13:29:04 +01:00
Tomáš Hozza
15c3c0a27e stage/copy: fix exception msg when parsing mounts and inputs
Functions for parsing mounts and inputs raise an exception if the
referenced entity can't be found in the stage options. However, the
exception message always included the value of the `root` variable,
which is `None` when an exception is risen. Instead of the `root`
value, the `name` variable with the entity name should be used.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2023-11-01 15:26:05 +01:00
Ondřej Budai
23de60cd23 stages/mkdir: fix its schema
The items of an array are defined under the `items` key, not under `paths`.
Let's fix this.

Btw, this is possible because JSON Schema itself doesn't use
additionalProperties = false. This allows extending the schemas easily, but
is sadly a bit error-prone.

Sadly, since this issue effectively disabled validation of the stage options,
we also need to relax the schema a bit:

We found out that there are manifests in the wild, that use relative paths,
instead of absolute ones. Thus, this commit changes the validation regex to
allow relative paths. However, this now emits a warning and it's strongly
discouraged. The associated stage test was modified to accommodate for this.

Co-authored-by: Tomáš Hozza <thozza@redhat.com>
Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2023-10-30 13:31:15 +01:00
Alexander Larsson
0c144fc4aa Add selinux-label-version to the org.osbuild.ostree.commit stage
This is a feature that was added in rpm-ostree 2023.10 and is needed
for the new transient /etc feature to work. What it does is change the
labeling of /usr/etc to match those of /etc, so that /usr/etc can be used
directly as a bind-mount or an overlay mount when mounted on /etc.

See https://github.com/coreos/rpm-ostree/pull/4640 for details.
2023-10-28 15:37:56 -04:00
Dusty Mabe
da07300f38 stages/ostree.deploy: create ostree_commit_deploy function
This drains some of the logic out of `main()` into a
`ostree_commit_deploy()` function. Doing this will make it easier
to diff this stage with the recently added `ostree.deploy.container`
stage.

This commit also changes the `ref` in the schema to be optional,
which is a fixup for 3cc733d. We need to make the ref optional because
the ref could come from the user in the toplevel schema or it could
come from input commit in the schema.
2023-10-24 13:46:10 -04:00
Luke Yang
f9a039d068 stages: add ostree.deploy.container stage
This stage is similar to ostree.deploy, but deploys from a container
image rather than from an OSTree commit by using the `ostree container
image deploy` command. An example stage definition could look like:

```
  - type: org.osbuild.ostree.deploy.container
    options:
      osname: fedora-coreos
      target_imgref: ostree-remote-registry:fedora:quay.io/fedora/fedora-coreos:stable
      mounts:
	- /boot
	- /boot/efi
      kernel_opts:
	- rw
	- console=tty0
	- console=ttyS0
	- ignition.platform.id=qemu
	- '$ignition_firstboot'
    inputs:
      images:
	type: org.osbuild.containers
	origin: org.osbuild.source
	mpp-resolve-images:
	  images:
	    - source: quay.io/fedora/fedora-coreos
	      tag: stable
```

Co-authored-by: Dusty Mabe <dusty@dustymabe.com>
2023-10-24 13:46:10 -04:00
Dusty Mabe
49acf488af stages/ostree.deploy: add description for commits input 2023-10-24 13:46:10 -04:00
Evgeny Kolesnikov
c4de5389e7 stages/oscap.remediation: Properly utilize offline capabilities
The scanner will now properly react to the chroot environment. Also,
there are some optimizations to logs and results.
2023-10-19 12:43:57 +02:00
Michael Ho
21054b181c stages/org.osbuild.users: support multiple SSH keys
Add a new attribute, "keys", to allow specifying multiple public SSH
keys to install to a users authorized_keys file.

This maintains backwards compatibility with the existing "key" attribute
that can only specify a single SSH key to install into the file (without
using some newline hacks).

Signed-off-by: Michael Ho <michael.ho@ieee.org>
2023-10-16 18:05:27 +02:00
Dusty Mabe
3cc733d7cd stages/ostree.deploy: support an ostree input
This will allow a user to specify an input directly to the deploy
stage rather than requiring a ostree.pull stage to be called first.

Adding inputs will also be useful when we soon add support for
deploying from a container rather than just deploying from an existing
ostree commit in a repo.
2023-10-06 15:55:26 +02:00
Dusty Mabe
c6c9454f6f osbuild/util: create pull_local function in util/ostree
This is prep for sharing this functionality with other stages than
the ostree.pull stage.
2023-10-06 15:55:26 +02:00
Dusty Mabe
4e99e80c4a osbuild/util: hoist ostree code into util/ostree
Prep for sharing with other stages later.
2023-10-06 15:55:26 +02:00
Dusty Mabe
34d3471fdd stages/ostree.passwd: delete dead code ostree function
As far as I can tell this is unused in this file.
2023-10-06 15:55:26 +02:00
Dusty Mabe
0f477889be stages/ostree: add deprecation notice/warning
I've been informed that this stage is old and shouldn't be used for
newly created manifests. Let's add a comment to the top for future
explorers of this code base.
2023-10-06 15:55:26 +02:00
Maxime Ripard
7af2f1a5c1 Create additional option to setup FS geometry
Some platforms like the TI AM62 require a particular FAT geometry for
their CPU to read the file system (and thus the bootloader). Failing
that the CPU will simply not boot and keep looking for a bootloader.

Let's add some options to enforce a particular filesystem geometry
through the -g option of mkfs.fat.

Signed-off-by: Maxime Ripard <mripard@kernel.org>
2023-10-05 20:17:40 +02:00
Maxime Ripard
e58fc3d289 Consolidate the options setup for mkfs.fat
The current options building code for mkfs.fat prevents to have multiple
options at a time since it will assign the opts list to either the label
or fatsize options.

If both are set, only the last one, fatsize, will be set.

Use the occasion to rewrite the code a bit and limit the number of
lists concatenation.

Signed-off-by: Maxime Ripard <mripard@kernel.org>
2023-10-05 20:17:40 +02:00
Dusty Mabe
4e5de3808e osbuild/util: add containers_source helper
This will hoist even more code into util out of the skopeo stage.
Now a caller can call:

    with containers.container_source(image) as (image_name, image_source):
        print(f"{image_name}, {image_source}")

to process containers inputs.
2023-09-30 02:29:05 +02:00
Dusty Mabe
4cd9af47d0 osbuild/util: hoist container handling code into util/containers
This hoists container handling code from the skopeo stage into
util/containers. It is prep for adding another stage that accepts
containers as an input. The code is common so we should share it
amongst all stages that use containers as input.
2023-09-30 02:29:05 +02:00
Dusty Mabe
c88b3982e8 stages/ostree.deploy: switch to v2 schema
Prep for possibly adding inputs to the ostree.deploy stage in the
future.
2023-09-28 21:38:58 +02:00
Dusty Mabe
e31b0fe931 stages/ostree.deploy: drop requirement on rootfs option
For Fedora CoreOS we don't actually have any root= kernel command
line option in our baked images. We have services that rely on this
and set up sysroot on first boot. The code in this stage doesn't
require for this option to have been provided and actually gracefully
handles when it's not provided. Let's just change the schema to also
not require it.
2023-09-14 13:02:19 +02:00
Colin Walters
fd44af4fe7 osbuild.ostree.selinux: xref ostree issue for this
We should drop this stage entirely once we have a way to
force on selinux in ostree.
2023-08-31 14:01:12 +02:00
Brian Masney
e7fb2e1117 stages/dracut: add dracut omit drivers option
Add option to exclude specific kernel modules from the initramfs that's
generated by dracut.

Signed-off-by: Brian Masney <bmasney@redhat.com>
2023-08-28 13:25:04 +02:00