Commit graph

569 commits

Author SHA1 Message Date
Simon de Vlieger
2141168e44 test(stages/skopeo): schema validation
Minor schema validation test.
2023-12-12 23:08:19 +01:00
Ondřej Budai
852a76cc5c stages/skopeo: document the defaults in the schema 2023-12-12 23:08:19 +01:00
Ondřej Budai
9e612822d0 stages/skopeo: add support for OCI destination
The skopeo stage is updated to accommodate two types of
destinations: 'containers-storage' and 'oci'. Now, it can
copy a container image to either a container store or
a directory as per 'Open Container Image Layout
Specification'.
2023-12-12 23:08:19 +01:00
Michael Vogt
4e3fc6a625 osbuild: pytoml is deprecated, replace with toml
Pytoml is no longer being maintained: https://github.com/avakar/pytoml
The author suggest switching to toml.

We already use the
```
try:
    import toml
except ModuleNotFoundError:
    import pytoml as toml
```
pattern in stages/org.osbuild.containers.storage.conf so use it in the tests too to prefer "toml" instead of pytoml.
2023-12-12 14:06:50 -08:00
Brian C. Lane
77d775b2ba test: Add a test for the org.osbuild.zstd stage 2023-12-12 19:45:04 +01:00
Brian C. Lane
5dd6fb7c4c test: Add a test for the org.osbuild.xz stage 2023-12-12 19:45:04 +01:00
Brian C. Lane
9eb9f7f7f2 test: Move make_fake_input_tree to testutil
This is useful for other stage tests, move it and add a test.
2023-12-12 19:45:04 +01:00
Alexander Larsson
891bbcec17 Add test for org.osbuild.containers.storage.conf stage 2023-12-12 09:54:38 +01:00
Alexander Larsson
2d12ef478e org.osbuild.containers.storage.conf: Add pull_options
These are used to enable zstd::chunked and composefs, so they are important.
2023-12-12 09:54:38 +01:00
Alexander Larsson
4c3a81033f org.osbuild.containers.storage.conf: Add transient_store option
This is used by the automotive project, but is also useful for edge.
2023-12-12 09:54:38 +01:00
Alexander Larsson
c5a353b718 org.osbuild.containers.storage.conf: Use existing storage options definition
A bunch of the options in storage were not enabled because the
"storage" definition was not used.
2023-12-12 09:54:38 +01:00
Simon de Vlieger
1b5ab0ee03 stages(kickstart): mutual exclusive ostree options
These options are mutually exclusive, this updates the schema and test
case to ensure this is detected at schema validation time.
2023-12-08 14:29:52 +01:00
Simon de Vlieger
20d8d3a9a8 stages(kickstart): add ostreecontainer
Add support for the `ostreecontainer` kickstart command, see:
https://pykickstart.readthedocs.io/en/latest/kickstart-docs.html#ostreecontainer
2023-12-08 14:29:52 +01:00
Michael Vogt
0767ebccc1 stages(autotailor): add small unit test
Small unit test for PR#1407.
2023-12-04 14:34:17 +01:00
Gianluca Zuccarelli
6d9c6e0bde stages:oscap.autotailor: add key/value overrides
This commit extends the current support for OpenSCAP
tailoring by accepting an array of key/value overrides.
Users will be able to specify override values for specific
rules that will update the value when remediating the
image.
2023-12-04 08:49:47 +01:00
Michael Vogt
d4a0837cf0 stages(erofs): add tests and fix small bug in options handling
This adds tests for the erofs stage. The tests are slightly different
from the existing tests that run the filesystem utils inside the
stages. Depending on what exactly we want to test we may still need
a run inside the stages. However running this inside a container
should be good enough if we just want to validate that the options
are passed correctly and the file is created.
2023-12-01 10:36:06 +01:00
Ondřej Budai
a2ea0b2265 stages: add org.osbuild.erofs
Erofs is "a lightweight read-only file system"[1]. Imagine squashfs, but with
faster reads.

This commit adds support for creating it. The new stage is heavily inspired by
the squashfs one. I've decided to add all features of mkfs.erofs that looked
useful: All compression types and most of extended options (excluding the
compatibility ones, we can always add them later).

[1]: https://en.wikipedia.org/wiki/EROFS
2023-12-01 10:36:06 +01:00
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