Commit graph

512 commits

Author SHA1 Message Date
Christian Kellner
8f75d1e7a1 stages: add new org.osbuild.fdo stage
This stage is needed to write down the FDO DIUN pub key root certs
needed to talk to the manufacturer server to grab the device credentials
for provisioning and later onboarding

Co-Authored-By: Antonio Murdaca <runcom@linux.com>
2022-02-23 15:32:02 +00:00
Thomas Lavocat
1ceb096594 host: add support for emitting signals
Add support for emitting signals to host.Service which can be used to
transmit data back to the client during an ongoing method call. This
provides the possibility for the services to send information to their
client counterpart while running. The signal can take file descriptors
as extra parameters to send data on separate files.
2022-02-22 10:38:43 +01:00
Christian Kellner
f7af3042ca test: fix executable test
During the rework done in commit "use and require explicit exports"
with commit id 7ae4a7e78, the test got overlooked. Add an empty
list of checkpoints to the `obs.compile` invocation as to actually
trigger the osbuild invocation.

Reported-By: Thomas Lavocat <tlavocat@redhat.com>
2022-02-15 13:25:23 +00:00
Alexander Larsson
7c9944ee18 Update the skope test stage
Drop format and file options and convert the hello.img from
docker to oci format.
2022-02-10 14:43:17 +01:00
Alexander Larsson
13c0c1e59e test: Add skopeo tests
There is a source test that installs a pre-build, embeded image file
and ensure all the right files are installed. This uses the vfs driver
because then it works everywhere, including the CI (which doesn't do
overlayfs).

Then the is a source test that downloads a minimal image from
a faked registry on localhost.

For the registy API to work the "/v2" entry-point in the webserver has
to be at the root, so there is a symlink in test/data:

  v2 -> sources/org.osbuild.skopeo/data/v2

But otherwise the data is localized to sources/org.osbuild.skopeo.
2022-02-10 14:43:17 +01:00
Alexander Larsson
693e44e412 sources test: Support custom mimetypes in http server
By creating a `foo.mimetype` file you can override the mimetype returned
for the file `foo`.
2022-02-10 14:43:17 +01:00
Alexander Larsson
b6629de7b2 Add skopeo to f34-build-v2 manifest
This will be needed to test the container support.
Also update the test data
2022-02-10 14:43:17 +01:00
Alexander Larsson
b31c91d671 v2: Add source-epoch key in pipeline declaration and pass to buildroot
If this is set it is passed down to all stages and set as
SOURCE_DATE_EPOCH in the buildroot environment. This implements
the spec at:
  https://reproducible-builds.org/docs/source-date-epoch/
2022-02-09 09:58:49 +01:00
Thomas Lavocat
bb30ffa062 Add the option of compressing using lz4
Using lz4 in squashfs reduces the time to complete the stage from 446s
to 4s on my laptop while making the produced iso going from 1.6G to
2.0G.
2022-01-11 13:20:11 +01:00
Christian Kellner
26a250ca6e test/data: don't write cmdline in grub2
In the fedora-boot manifest, do not write the kernel command line
to the `grubenv` file.
2022-01-06 15:09:33 +00:00
Christian Kellner
94e9f62f63 test/osbuild: check devices, mounts schema
Also check that the schema is valid for devices and mounts.
2022-01-06 15:09:33 +00:00
Jelle van der Waa
97202e53b0 stages: Respect grub_home for grub legacy boot
Additionally add a new QEMU image output target for testing
grub2/mkinitcpio stages.
2022-01-06 16:01:26 +01:00
Jelle van der Waa
0cbd7898c7 Add mkinitcpio stage
This stage generates the initrd for Arch Linux and derivates.
2021-12-21 10:44:55 +01:00
Tom Gundersen
e97f6ef34e objectstore: don't store objects by their treesum
The treesum of a filesystem tree is the content hash of all its
files, its directory structure and file metadata.

By storing trees by their treesum we avoid storing duplicates of
identical trees, at the cost of computing the hashes for every
commit to the store.

This has limited benefit as the likelihood of two trees being
identical is slim, in particular when we already have the ability
to cache based on pipeline/stage ID (i.e., we can avoid rebuilding
trees if the pipelines that built them were the same).

Drop the concept of a treesum entirely, even though I very much
liked the idea in theory...

Signed-off-by: Tom Gundersen <teg@jklm.no>
2021-12-16 16:44:07 +00:00
Achilleas Koutsou
646dd238fe stages: add new org.os.build.pacman and org.osbuild.pacman.conf stage
Pacman is the default package manager for Arch Linux and derivates, the
pacman.conf stage generate a valid pacman.conf configuration file.

Co-Authored-By: Jelle van der Waa <jvanderwaa@redhat.com>
2021-12-15 23:22:15 +01:00
Tomas Hozza
d7989a5c26 Add new stage for configuring DNF Automatic
Add a new stage `org.osbuild.dnf-automatic.config` for configuring DNF
Automatic.

The stage changes persistent DNF Automatic configuration. Currently, only
a subset of options can be set:
  - 'commands' section
    - apply_updates
    - upgrade_type

Fix #908

Signed-off-by: Tomas Hozza <thozza@redhat.com>
2021-12-15 18:49:13 +01:00
Tomas Hozza
cd4ac1c75a Add new stage for creating YUM / DNF repo files
Add a new stage `org.osbuild.yum.repos` for creating YUM / DNF `.repo`
files in `/etc/yum.repos.d`. All repo-specific options are supported but
only a subset of options which can be set for a repo as well as in the
[main] section are supported.

Add unit test for the new stage.

Fix #907

Signed-off-by: Tomas Hozza <thozza@redhat.com>
2021-12-09 18:51:51 +01:00
Sanne Raymaekers
5b3ebd7912 stages/org.osbuild.dnf.config: Edit /etc/dnf/dnf.conf
Fixes #906
2021-12-09 15:53:57 +01:00
Christian Kellner
c825c7e4fa buildroot: set container env variable
Set the container environment variable to indicate to programs
inside the build root that they are indeed running inside a
container (see also https://systemd.io/CONTAINER_INTERFACE/).
2021-12-09 13:14:27 +01:00
Christian Kellner
0c71289067 buildroot: isolate environment from the host
Create a well-defined environment with and use that for the build
root. It is not desirable to have the host's environment leak
into the container. Add a test to ensure that this works.
NB: This was probably an oversight when we switched from systemd-
nspawn to bubblewrap.
2021-12-09 13:14:27 +01:00
Christian Kellner
969a523058 test: capture full log in compile
Use the new `--monitor` and `--monitor-fd` mechanism to capture
the full log and print it as well in case of errors.
2021-12-09 00:44:21 +00:00
Christian Kellner
e62133a334 manifests/ostree-image: convert to LUKS
Wrap the LVM volume group in a LUKS container with the passphrase
`osbuild` (yes, really, super secure). NB: the kernel command line
is changed to include `luks.uuid` which is needed so that dracut
will attempt to open the luks container. This corresponds to an
crypttab entry `luks-uuid UUID`. We cannot use the /etc/crypttab
for ostree based images because the initrd is created at commit
time but they luks volume is created at deployment time, we have
to use the kernel command line instead. See the man page for the
systemd-cryptsetup-generator(8) for more information.

The `cryptsetup` package is included in the build root since it is
needed by the `org.osbuild.luks2.format` stage. All manifests that
are using the `f34-build-v2` build root change as a result.
2021-12-09 00:44:21 +00:00
Christian Kellner
0aea72e44e ci: run ostree image tests via Schutbot
OSTree tests, especially the fedora-ostree-image one, will soon
need the tight integration with the host for LVM2/LUKS support.
This we cannot run them in github action containers. Move them
to Schutzbot.
Explicitly install the new sub-package until composer gains the
needed requirement.
2021-12-09 00:44:21 +00:00
Christian Kellner
568a4ad97a loop: add new on_close callback to Loop
Add a new signal like callback to the `Loop` class which will be
invoked before the actual loop device is closed, i.e. the loop
device has an open file descriptor to the device node and it is
being closed. Can be used to perform custom cleanup tasks.
2021-12-09 00:44:21 +00:00
Christian Kellner
7e2bb524a4 devices: add custom udev rule inhibitor mechanism
Certain udev rules for block devices are problematic for osbuild.
One prominent example is LVM2 related rules that would trigger
a scan and auto-activation of logical volumes. This rules are
triggered for new block devices or when the backing file of an
loop devices changes. The rules will lead to a `lvm pvscan
--cache --activate ay` via the `lvm2-pvscan@.service` systemd
service. This will auto-activate all LVM2 logical volumes and
thus interfering with our own device handling in `devices/
org.osbuild.lvm2.lv`, where we only want to activate a single
logical volume.
Also, if the lvm2 devices get activated after the manual metadata
change done in `org.osbuild.lvm2.metadata` the volume group names
might conflict which results in all lvm2 based tooling to be very,
ver sad and also said stage to hang since the loopback device can
not be detached since the activate logical volumes keep it open.

To work-around this we therefore implement a udev rule inhibition
mechanism: on the osbuild side a lock file is created via the new
class called `UdevInhibitor` in `utils/udev.py`. A custom set of
udev rules in `10-osbuild-inhibitor.rules` is then acting on the
existence of that lock file and if present will opt-out of certain
further processing. See the udev rules file for more details.

In fact, we want this custom inhibition mechanism, for all block
devices that are under osbuild's control, since these rules are
there to provide automatisms and integrations with the host,
something we never want.

NB: this should not affect the detection of devices, since lvm2
does do a scan of devices when we call `lvdisplay` in `lvm2.lv`.
The call chain as of lvm2 git rev f773040:

  _lvdisplay_single           [tools/lvdisplay.c
    process_each_lv           [tools/toollib.c
      lvmcache_label_scan     [lib/cache/lvmcache.c
        label_scan            [ibidem, here is the device detection!
      lvdisplay_full          [lib/display/display.c
2021-12-09 00:44:21 +00:00
Tomas Hozza
0df902d6bb sshd.config stage: support PermitRootLogin option
Add support for `PermitRootLogin` option in the
`org.osbuild.sshd.config` stage.

I kept the "yes" and "no" values for consistency with other stage
options. While it will make the implementation in osbuild-composer
harder, it won't be impossible as we already have a precedence for doing
it this way (e.g. in the `org.osbuild.pam.limits.conf`).

Modify the stage unit tests to check the new option.

Remove the empty `org.osbuild.sshd.config` stage from `a.mpp.json`
since it does not add any value and it actually made the `tree-diff`
tool provide a weird tree diff results.

Fix #910

Signed-off-by: Tomas Hozza <thozza@redhat.com>
2021-12-07 15:20:50 +00:00
Christian Kellner
3958a6140c test/buildroot: test timeout at the run level
Check the timeout functionality at the `Buildroot.run` level not at
the `read_with_timeout` level, which is an implementation detail.
2021-12-07 09:47:01 +00:00
Christian Kellner
2129f3d68b test/osbuild: add order check for on_demand
Add a check that ensures the order of inputs to `depsolve` is
preserved in the result.
2021-12-03 17:09:33 +00:00
AaronH88
99c739fd60 test: test buildroot read_with_timeout function
- Added a new stage that is stuck in an infinite loop
- Added two tests that use this stage and force a timeout
2021-12-03 14:29:36 +00:00
Christian Kellner
29f2a68eeb osbuild: on-demand building of pipelines
Use the new Manifest.depsolve function to only build the pipelines that
were explicitly requested and their dependencies, taking into account
what is already present in the store.
Since now not all pipeline will be built, there wont be a result entry
for all the pipelines, thus the format version 2 result formatting was
changed to not require the pipeline to be present in result set.
2021-12-02 12:51:30 +00:00
Christian Kellner
749912c75a manifest: implement pipeline depsolving
New function that take a list of pipelines and return the list of
pipelines that need to be build, i.e. the pipelines and all their
dependencies that are not already present in the store.
Add corresponding test.
2021-12-02 12:51:30 +00:00
Christian Kellner
8770bdf10a formats/v1: remove implicit assembler export
When building a version 1 manifest, the assembler would always be
exported, even when not requested via the `--export` command line
option. This was done for backwards compatibility so to not break
tools relying on that behavior. The problem is that support for
this uses a completely different code path and might also now be
confusing behavior. Thus remove the implicit and really only ever
export what was explicitly requested by the caller.
2021-12-02 12:51:30 +00:00
Christian Kellner
80414299cd test/stages: export tree and compare that
Instead of checkpointing the tree and then accessing the generated
tree inside the store via the `map_object` function we not just
export the tree and use that. This better hides the internals of
the store and also allows us to activate on-demand building that
does not rely on checkpoints being implicitly built like exports.
2021-12-02 12:51:30 +00:00
Christian Kellner
d502157d7e test/stages: ensure we always have a tree
Ensure that all our stage tests always have at least one stage,
even it is just a `noop` stage, so that we can checkpoint and
export the `tree`.
2021-12-02 12:51:30 +00:00
Christian Kellner
7ae4a7e785 test: use and require explicit exports
Require all the tests that compile a manifest to either specify
checkpoints or exports. Convert all the tests that were relying
on implicit exports with v1 manifests to use explicit exports.
2021-12-02 12:51:30 +00:00
Christian Kellner
36356342b0 buildroot: mask /proc/cmdline
Since we bind `/proc` inside the container, we leak certain information
that comes with it. One of this is the kernel command line. None of the
decisions done by software running inside the container should depend
on the kernel command line on the host, so overwrite the kernel command
line by creating a temporary directory and mapping it inside the build-
root. For now we default to a simple `root=/dev/osbuild` fake kernel
command line.
Add a simple check for it as well.
2021-11-30 12:01:13 +01:00
Christian Kellner
4c54f7e4a6 test/buildroot: convert to pytest
Semantics should be unchanged.
2021-11-30 12:01:13 +01:00
Christian Kellner
03232f1899 test/stages: basic gunzip stage test
Add a simple check for the new `org.osbuild.gunzip` stage.
2021-11-19 00:16:04 +00:00
Christian Kellner
ac529563c3 test: use new mpp-embed in tests
This is to showcase it as much as to test its functionality. For this
the tar and xz stage tests have been converted. NB: only the mpp file
for each test is changed but the corresponding manifest is not.
The `sources/org.osbuild.inline` section has been kept otherwise the
ordering in the result manifest would change.
2021-11-18 13:41:06 +01:00
Christian Kellner
280aca8f07 test/lvm2: use LoopControl.loop_for_fd
Instead of having custom code that basically duplicates the
functionality of `LoopControl.loop_for_fd` use that instead.
Additionally, the version used in the test had a bug where
it did not re-create the Loop device in the main loop when
it was close due to an error, leading errors in subsequent
usages of the device that would often manifest in CI runs:
  fcntl.ioctl(self.fd, self.LOOP_SET_FD, fd)
  ValueError: file descriptor cannot be a negative integer (-1)
2021-11-12 17:40:00 +01:00
Tom Gundersen
f7bf23faba stages/authconfig: run authconfig
This applies the default authconfig settings to the tree.

Note that the `/backups` directory is removed. The tool creaset
this, and by default it should not exist, so this should be a
noop. However, if you run this on a tree with existing backups,
they would be lost.
2021-11-08 20:43:51 +01:00
Ondřej Budai
306fd3ed96 stages/yum.config: add an option to configure langpacks plugin
The new stage enables users to configure the langpacks plugin of YUM.
Currently, only locales option is supported.
2021-11-08 17:17:02 +01:00
Tom Gundersen
9da89de8b5 stages/pwquality.conf: set pwquality configuration
This allows the password policy to be configured.

Signed-off-by: Tom Gundersen <teg@jklm.no>
2021-11-05 16:53:54 +01:00
Tomas Hozza
58ec1c9a83 Add new org.osbuild.yum.config stage
Add a new stage for modifying YUM global configuration.

Add a unit test case for the newly added stage.

Because we test stages on Fedora, where there is no YUM, and this stage
is mostly intended for being used with RHEL-7 images, the stage does not
produce error in case the `/etc/yum.conf` file does not exist. It rather
produces a warning and creates the file. Ideally the stage would produce
an error in case the configuration file does not exist, but that would
be impossible to test on recent Fedora.

Signed-off-by: Tomas Hozza <thozza@redhat.com>
2021-11-05 12:10:33 +01:00
Achilleas Koutsou
66a1fbad9d test/cloud-init: add new options to stage test 2021-11-05 12:08:38 +01:00
Christian Kellner
12eb14378a stages: add new org.osbuild.cron.script stage
New stage to schedule a script via a /etc/cron.{hourly, daily ...}.
Currently only a simple command that will be put into an generated
script with the given name. Later more options might be added.
2021-11-05 11:53:11 +01:00
Ondřej Budai
266c3d1953 stages/grub2: add support for terminal, serial and timeout config
This commit adds options to the org.osbuild.grub2 stage to configure
terminal input and output, serial console and timeout.

The functionality and configuration schema is the same as in the legacy
grub2 stage.
2021-11-04 17:35:24 +01:00
Tom Gundersen
36176ab377 stages/waagent.conf: set WALinuxAgent configuration
This is requried to comply with Azure marketplace best
practices. The WALinuxAgent should not handle formating or
swap, as that is done by cloud-init.

Signed-off-by: Tom Gundersen <teg@jklm.no>
2021-11-03 18:32:40 +01:00
Tom Gundersen
304f1e3f9f stages/sshd.config: set sshd configuration
This is required for images to be importable to the AWS
marketplace. Both PasswordAuthentication and
ChallengeResponseAuthentication must be disabled.

Signed-off-by: Tom Gundersen <teg@jklm.no>
2021-11-03 18:32:40 +01:00
Tomas Hozza
daacf002fe Support 'install' command in org.osbuild.modprobe stage
Add support for new 'install' command in the org.osbuild.modprobe stage.

Extend the unit test coverage to test the new command.

Signed-off-by: Tomas Hozza <thozza@redhat.com>
2021-11-03 16:11:54 +00:00