Commit graph

622 commits

Author SHA1 Message Date
Tomáš Hozza
be1ba5be08 Stages/grub2: extend default config options
Extend the stage to allow explicitly configuring more grub2 default
config options. Preserve the defaults for options which were previously
hard-coded.

Extend the stage unit test to verify setting of the new grub2 default
config options.

Related to https://issues.redhat.com/browse/RHEL-19583

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2024-02-20 19:28:43 +01:00
Tomáš Hozza
84fc4c9903 Extend unit test for org.osbuild.grub2 stage
Test the content of the /etc/default/grub config file based on the
provided stage options.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2024-02-20 19:28:43 +01:00
Tomáš Hozza
7895424b78 Stages/grub2.legacy: extend default config options
Extend the stage to allow explicitly configuring more grub2 default
config options. Preserve the defaults for options which were previously
hard-coded.

Extend the stage unit test to verify setting of the new grub2 default
config options.

Related to https://issues.redhat.com/browse/RHEL-19583

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2024-02-20 19:28:43 +01:00
Tomáš Hozza
21ebed9305 Add unit test for org.osbuild.grub2.legacy
For now, test the content of /etc/default/grub configuration file.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2024-02-20 19:28:43 +01:00
Michael Vogt
43c83c01e6 stages(org.osbuild.systemd.unit.create): add small unit test
Small unit test for the new `org.systemd.unit.create` stage. It
will do basic schema validation checks and ensures that a simple
service definition is correctly translated to a systemd unit.
2024-02-19 15:12:55 +01:00
Evgeny Kolesnikov
46e1bc1e2b stages/oscap.remediation: Mount host's /proc and /dev earlier
We need /dev/urandom for the first pass as well.
2024-02-17 02:10:58 +01:00
Michael Vogt
90193d007f stages/bootc.install-to-fs: fix root mount handling
The bootc.install-to-filesystem code needs to run against the
root directory of a mounted tree, i.e. with /boot, /boot/efi
mounted. So change the code so that the target dir is the
the "mounts" paths. This is similar to how bootupd works and
the caller need to arrange the right mount setup there.
2024-02-16 18:05:50 +01:00
Sayan Paul
e858dc72c3 stage/systemd-unit:stage to create systemd unit file
Add systemd unit files in osbuild stage

This stage creates systemd unit file in `/usr/lib/systemd/system/`.
The stage accepts filename which must end with `.service`.Section
`Unit` , `Service` , `Install` accepts various parameters as per
the systemd documentaion.`systemd-analyze verify` is be performed
after the .service file is created to check for potential errors.

Signed-off-by: Sayan Paul <paul.sayan@gmail.com>
2024-02-16 11:55:11 +01:00
Michael Vogt
c3af3173eb stages(container-deploy): podman mount failure test/tweaks
This commit adds a test that ensures that the output of
podman mount is part of the error message. While writing
the test I also tweaked the code slightly so that we only
try to `podman umount` if we managed to successfully mount.
2024-02-12 17:41:21 -08:00
Michael Vogt
c0f670f035 test: add manifests for bootc.install-to-filesystem
This commit adds example manifests for a bootc.install-to-filesystem
system. It does not do more with them because running a full test
requires a working podman which is difficult to use inside our
GH runners that are already running inside docker.
2024-02-09 12:03:09 +01:00
Michael Vogt
af360b0d71 stages: add test for bootc.install-to-filesystem 2024-02-09 12:03:09 +01:00
Ondřej Budai
226b50eba5 stages: add new org.osbuild.bootc.install-to-filesystem
Support the `boot install to-filesystem` capability to install a
bootc image to a filesystem.
2024-02-09 12:03:09 +01:00
Luke Yang
619a64f0bd stages/org.osbuild.qemu: make qcow2 compression optional
Modify the stages/org.osbuild.qemu stage such that compression is
optional. This resolves the image size differences between an image
built with coreos assember vs osbuild, as discussed in:
https://github.com/coreos/fedora-coreos-tracker/issues/1653#issuecomment-1928342241
2024-02-07 20:31:10 -05:00
Dusty Mabe
e1cbf92673 ostree: add convenience function for using default OSTree deployment
This adds a `default: true` option for all cases where OSTree
information is specified in schemas and allows for the information
to be picked up from the filesystem.

This is a safe operation because when building disk images there is
no known case where having two deployments makes sense. In the case
there ever were a case then the osname, ref, and serial options still
exist and can be used.

Co-authored-by: Luke Yang <luyang@redhat.com>
Co-authored-by: Michael Vogt <michael.vogt@gmail.com>
2024-02-07 18:50:38 -05:00
Dusty Mabe
2021b915f1 stages(copy): allow copying from a mount or the tree
It seems like an artifical limitation to prevent copying from a mount
or from one location in the tree to another. It just so happens we need
this functionality when building CoreOS images because we want to take
a file embedded in the OSTree at a location and copy it to another
location in the tree. The particular example here is we want to copy
/usr/share/coreos-assembler/platforms.json -> /boot/coreos/platforms.json
See https://github.com/coreos/coreos-assembler/pull/3709

Allowing to copy from/to the tree we can now do something like:

```
- type: org.osbuild.copy
  options:
    paths:
      - from: tree:///usr/share/coreos-assembler/platforms.json
        to: tree:///boot/coreos/platforms.json
  mounts:
    - name: ostree.deployment
      type: org.osbuild.ostree.deployment
      options:
        deployment:
          ref: ostree/1/1/0
          osname:
            fedora-coreos
```
2024-02-07 18:38:03 -05:00
Michael Vogt
705397e7f6 test: add simple zipl_inst tests
Co-authored-by: Nikita Dubrovskii <nikita@linux.ibm.com>
2024-02-07 18:08:44 -05:00
Nikita Dubrovskii
e427289887 stages(zipl.inst): support appending kernel options
In some cases it could useful to add additional kernel options without
modifying BLS config, so any subsequent call to `zipl` would ignore them.
We are going to use this to append `ignition.firstboot` to kernel cmdline
for CoreOS on s390x.
2024-02-07 18:08:44 -05:00
Colin Walters
161c19601a container-deploy: Output stderr on failure
This stage was failing for me in bib, with this change I now
get more useful information from podman's stderr, e.g.:

```
RuntimeError: Failed to mount image (125): time="2024-02-06T14:23:06Z" level=error msg="Unmounting /var/lib/containers/storage/overlay/06456126e7c06cf1b21de024e08e64eddead2b8d03779be213e63aeeea9dec94/merged: invalid argument"
Error: creating overlay mount (...snip...)
fuse: device not found, try 'modprobe fuse' first
fuse-overlayfs: cannot mount: No such file or directory
```
2024-02-07 16:11:19 +01:00
Achilleas Koutsou
d75f43ff7b stages: add new org.osbuild.bootupd.gen-metadata stage
Runs bootupctl generate-update-metadata in the tree to transform
/usr/lib/ostree-boot into a bootupd-compatible update payload.

This stage should be run on the sysroot of an ostree deployment or
ostree-converted tree.
2024-02-07 12:10:01 +01:00
Dusty Mabe
011cf6851b stages(ostree.config): support setting sysroot.bootprefix
See https://github.com/ostreedev/ostree/pull/2705 and also
https://github.com/osbuild/osbuild/issues/1566.
2024-02-07 11:28:24 +01:00
Dusty Mabe
151b6e48ae stages(sgdisk): support label option
We only support `gpt` here so it would seem this option doesn't
make much sense to add, but it will make it so that the mpp-define-images
from osbuild-mpp can be passed in to `org.osbuild.sgdisk` just as it
can be passed in today to `org.osbuild.sfdisk`.
2024-02-06 17:44:31 +01:00
Nikita Dubrovskii
fc185dae8c support user-defined partition numbers for GPT disks
Partitions by default are indexed starting at 1, but in
some cases, such as CoreOS for IBM Z, it may be usefull
to set the 'partnum' for GPT disks explicitly, without
creating dummy partitions.

Now user can define an image:

```
    mpp-define-images:
      - id: image
        size: 10737418240
        table:
          uuid: 00000000-0000-4000-a000-000000000001
          label: gpt
          partitions:
            - name: boot
              type: 0FC63DAF-8483-4772-8E79-3D69D8477DE4
	      partnum: 3
              size: 786432
            - name: root
              type: 0FC63DAF-8483-4772-8E79-3D69D8477DE4
	      partnum: 4
              size: 4194304
```

So target disk would look like:

```
    Disklabel type: gpt
    Disk identifier: 00000000-0000-4000-A000-000000000001
    Device        Start     End Sectors  Size Type
    /dev/loop0p3   2048  788479  786432  384M Linux filesystem
    /dev/loop0p4 788480 4982783 4194304    2G Linux filesystem
```

This patch updates the osbuild-mpp tool and the sgdisk and sfdisk
stages to support this.

Co-authored-by: Dusty Mabe <dusty@dustymabe.com>
2024-02-06 17:44:31 +01:00
Sanne Raymaekers
25df4d76a6 stages(tar): add unit test 2024-02-06 12:43:53 +01:00
Sanne Raymaekers
df663ada8a stages(tar): add paths option
This adds an optional `paths` option to the tar stage. If specified, the
paths will be included in the tarball in order.

The OVA image needs to have its contents in a specific order in the
archive.
2024-02-06 12:43:53 +01:00
Djebran Lezzoum
cdc410bb00 stages(kickstart): Add missing rootpw, initlabel, nohome
In the context of specific ostree installation we are missing some kickstart options:
1. rootpw option (despite we only need rootpw --lock, implement the full spec found here https://pykickstart.readthedocs.io/en/latest/kickstart-docs.html#rootpw)
2. initlabel a property of clearpart option
3. nohome a property of autopart
FIXES: https://issues.redhat.com/browse/THEEDGE-3835
2024-02-02 18:42:58 +01:00
Luke Yang
477a21043e Create stages/org.osbuild.chattr stage
Add or remove the immutable bit to the specified mount directory.

The need we have for this right now is for the CoreOS builds where
the immutable bit being set on an OSTree deployment root doesn't
survive the `cp -a --reflink=auto` in the org.osbuild.copy stage when
being copied from the directory tree into the mounted XFS filesystem
we created on the disk image. Thus we have to workaround this loss
of attribute by applying the attribute directly on the mounted
filesystem from the disk.
2024-01-31 16:46:01 -05:00
Tomáš Hozza
2581160cfc stages/test: introduce 'stage_schema' fixture
Introduce a 'stage_schema' fixture, which will load the stage schema
by the stage name defined in the STAGE_NAME defined in the test module
and optionally provided schema version and return it. If no schema
version is specified, version "2" is assumed. Modify all stage unit
tests to use this fixture, instead of loading the stage schema on their
own.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2024-01-31 17:18:52 +01:00
Tomáš Hozza
23c8f5b432 stages/test: introduce 'stage_module' fixture
Introduce a 'stage_module' fixture, which will load the stage module by
its name defined in the test module STAGE_NAME variable. Modify all
stage unit tests to use this fixture, instead of loading the stage
module on their own.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2024-01-31 17:18:52 +01:00
Tomáš Hozza
73cb074f4b stages/cloud-init: test datasource_list dump format
Add a simple unit test, which ensures that the `datasource_list` key
is dumped in the configuration file on a single line if defined in
the stage options.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2024-01-31 17:18:52 +01:00
Tomáš Hozza
c6edc710f2 stages/cloud-init: fix dumping of datasource_list key
The stage dumps invalid cloud-init configuration, in case the
`datasource_list` key has a value assigned. The value is supposed to be
a list, but cloud-init documentation mandates that the value is always a
single line, with no newlines. This was not true in the past.

Fix #1554

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2024-01-31 17:18:52 +01:00
Michael Vogt
a3192eb7c6 stages(container-deploy): add new exclude option
This commit adds a new `exclude` option to the container-deploy
stage. This is needed when we deploy `bootc` containers that are
used for the buildroot. Here the  `/sysroot` dir needs to be
excluded because it has conflicting selinux definitions for
files there and in the normal "root" dir.

See also https://github.com/osbuild/bootc-image-builder/pull/138
2024-01-24 18:32:25 +01:00
Michael Vogt
a56afcb280 test: add new testutil.assert_jsonschema_error_contains() helper
This commit adds a new helper `assert_jsonschema_error_contains()`
to `testutil` and uses it everywhere where we check errors from
jsonschema.
2024-01-23 12:00:59 +01:00
Luke Yang
106681f41e stages/org.osbuild.mkfs.ext4: add ext4 options
Add optional flags to the org.osbuild.mkfs.ext4 stage enabling/disabling
the metadata_csum_seed and orphan_file features.
2024-01-22 13:00:52 -05:00
Dusty Mabe
d9363d4561 stages/ostree.aleph: don't manipulate image name from origin
It appears to work with the `docker://` prefix as well as the
`registry:` prefix.

```
$ ostree container image list --repo=/ostree/repo
docker://quay.io/fedora/fedora-coreos:rawhide
$
$ ostree container image metadata --repo=/ostree/repo docker://quay.io/fedora/fedora-coreos:rawhide | md5sum
aaf7fa84896358730f0a69c330db31a6  -
$ ostree container image metadata --repo=/ostree/repo registry:quay.io/fedora/fedora-coreos:rawhide | md5sum
aaf7fa84896358730f0a69c330db31a6  -
```

Let's just keep the name unmodified. This also fixes it so that
`registry:` doesn't get prepended to refs that aren't from a registry
like:

```
$ cat /ostree/deploy/rhcos/deploy/3824ff6c279d0f4ef043e80f448eeb0d24269d50e452224a5614f915ee73fb7e.0.origin
[origin]
container-image-reference=ostree-unverified-image:oci-archive:/rhcos-416.92.202401191512-0-ostree.x86_64.ociarchive
$ ostree container image metadata --repo=/ostree/repo oci-archive:/rhcos-416.92.202401191512-0-ostree.x86_64.ociarchive | wc -c
16292
```
2024-01-19 17:15:23 -05:00
Michael Vogt
84059544e4 test: fix test_schema_validation_containers_storage_conf
The test starts failing because a new version of jsonschema (4.21.0)
changed the error messages for `minProperties: 1`.

To fix this we just use a regex and check for both possible values.
As a drive-by the commit also improves the error output in case
the match is not found.
2024-01-17 13:58:22 +01:00
Luke Yang
d089b429a7 stages/org.osbuild.ostree.config: support bls-append-except-default
Support setting the sysroot.bls-append-except-default value in the
OSTree config. This is used by CoreOS to support configuration used
for GRUB password support https://github.com/coreos/fedora-coreos-tracker/issues/1333
2024-01-11 12:55:12 -05:00
Michael Vogt
73ec3122f2 stages,test: update tests for new selinux.setfiles() calling 2024-01-11 10:23:25 +01:00
Michael Vogt
467a23ffa7 stages(selinux): use osbuild.util.selinux.setfiles()
Instead of calling `setfiles` manually just reuse the existing
helper. The tests validate that there is no functional change.
2024-01-11 10:23:25 +01:00
Michael Vogt
18159eceec test: add selinux stage test 2024-01-11 10:23:25 +01:00
Dusty Mabe
8cce659ec5 stages/bootupd: support installing to a partition of a device
For ppc64le we need to pass in a partition (i.e. /dev/loop0p1) rather
than the root device (/dev/loop0) to the --device argument of bootupctl.
Let's add a partition field and find the device node based on the user
specified partition.

On ppc64le this would look something like:

```
      - type: org.osbuild.bootupd
        options:
          bios:
            device: disk
            partition:
              mpp-format-int: '{image.layout[''POWERPC-PREP-BOOT''].partnum}'
          static-configs: true
          deployment:
            osname: fedora-coreos
            ref: ostree/1/1/0
        devices:
          disk:
            type: org.osbuild.loopback
            options:
              filename: disk.img
              partscan: true
        mounts:
          - name: root
            type: org.osbuild.xfs
            source: disk
            partition:
              mpp-format-int: '{image.layout[''root''].partnum}'
            target: /
          - name: boot
            type: org.osbuild.ext4
            source: disk
            partition:
              mpp-format-int: '{image.layout[''boot''].partnum}'
            target: /boot
```
2024-01-10 01:15:18 +01:00
Michael Vogt
492dc6021c stages(bootupd): refactor test to separately test behaviors
It now tests  bind_mounts and bootupd behavior separately.
2024-01-10 01:15:18 +01:00
Michael Vogt
dacf5733ea stages(bootupd): add tests for existing behavior
Also refactor bind mounts into a helper.
2024-01-10 01:15:18 +01:00
Michael Vogt
eb657b08b3 stages(bootupd): add schema test 2024-01-10 01:15:18 +01:00
Renata Ravanelli
cdcb4598bb create org.osbuild.bootupd stage
Add the bootupd stage to install GRUB on both BIOS and UEFI systems,
ensuring that your bootloader stays up-to-date.

Signed-off-by: Renata Ravanelli <rravanel@redhat.com>
2024-01-10 01:15:18 +01:00
Michael Vogt
c03e6be52a stages(grub2): allow pulling efi binaries from alternative efi roots
The EFI binaries are currently pulled from a hardcoded path in the
buildroot. When moving to containers as buildroots this will no
longer work as they have an alternative layout. This is an easy
"fix" - make the location of the `EFI/` directory configurable.

This allows us set `efi_src_dir` to `/usr/lib/bootupd/updates/EFI/`
and keep our existing `bootc-image-builder` workflow.

Note that this may actually not be the desired solution and instead
we want the new `bootupd`: https://github.com/osbuild/osbuild/pull/1519
2024-01-09 19:43:01 +01:00
Michael Vogt
cb02d0a4bc stages(container-deploy): ensure /var/tmp is available
This commit ensures that `/var/tmp` is available. Skopeo expects
this dir but the bwrap environment starts with a very minimal
`/var` so `/var/tmp` may not be available.
2024-01-09 12:54:11 +01:00
Michael Vogt
ac5653d9f1 stages: rework container-deploy stage to not use tmp storage
This commit reworks the `org.osbuild.container-deploy` stage to
not use a tmp storage when mounting the container image. This
is needed because of [0] but it should generally be fine because
inside the stages the real /var is a tmpfs (which is why we
triggered the bug in the first place).

[0] https://github.com/containers/storage/issues/1779
2024-01-03 11:25:48 -08:00
Michael Vogt
9a8b0ddb61 test: add test for org.osbuild.container-deploy 2024-01-03 11:25:48 -08:00
Ondřej Budai
fdc5bf3b98 stages: org.osbuild.container-deploy 2024-01-03 11:25:48 -08:00
Luke Yang
5fc3b565a2 create org.osbuild.ostree.aleph stage
Similar to the aleph file created for builds of FCOS based on ostree
commit inputs, this adds an aleph file that contains information about
the initial deployment of data when the disk image was built

A new stage is preferred here as both the org.osbuild.ostree.deploy
and org.osbuild.ostree.deploy.container stages need an aleph file and
use of the aleph file may depend on the project/product. For example,
right now CoreOS is the only project that uses an aleph file, but others
may want it in the future.
2023-12-19 17:58:39 +01:00