Commit graph

2608 commits

Author SHA1 Message Date
Alexander Larsson
891bbcec17 Add test for org.osbuild.containers.storage.conf stage 2023-12-12 09:54:38 +01:00
Alexander Larsson
eea81b660a testutils: Add assert_dict_has
This is a convenient way for tests to assert that some nested dicts
(like a parsed json) has a particular key/value somewhere in it.

For example:
  assert_dict_has(config, "toplevel.subitem.key", True)
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
Michael Vogt
4026d4dc10 test: add test that ensures mount output is part of the exception
While debugging a failure of osbuild-composer [0] on fc39 it was
noticed that a mount failure does not include the output of
the mount command:
```
  File "/usr/lib/python3.12/site-packages/osbuild/mounts.py", line 78, in mount
    path = client.call("mount", args)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/site-packages/osbuild/host.py", line 348, in call
    ret, _ = self.call_with_fds(method, args)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/site-packages/osbuild/host.py", line 384, in call_with_fds
    raise error
osbuild.host.RemoteError: CalledProcessError: Command '['mount', '-t', 'xfs', '-o', 'ro,norecovery', '--source', '/dev/rootvg/applv', '--target', '/tmp/tmpjtfmth56/app']' returned non-zero exit status 32.
   File "/usr/lib/python3.12/site-packages/osbuild/host.py", line 268, in serve
    reply, reply_fds = self._handle_message(msg, fds)
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/site-packages/osbuild/host.py", line 301, in _handle_message
    ret, fds = self.dispatch(name, args, fds)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/site-packages/osbuild/mounts.py", line 111, in dispatch
    r = self.mount(args)
        ^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/site-packages/osbuild/mounts.py", line 160, in mount
    subprocess.run(
  File "/usr/lib64/python3.12/subprocess.py", line 571, in run
    raise CalledProcessError(retcode, process.args,
```
which makes diagnostic errors harder of course. This commit adds
a test that ensures that mount output is visbile and also changes
the code to include it.

[0] https://github.com/osbuild/osbuild-composer/pull/3820
2023-12-11 11:24:17 +01:00
Simon de Vlieger
e73f4e57dd ci: update terraform hash
Some AMI went AWOL.
2023-12-08 14:29:52 +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
Jakub Rusz
36883654ce rpmbuild: add fedora-40 2023-12-06 10:11:32 +01:00
schutzbot
c53c60e694 Post release version bump
[skip ci]
2023-12-06 08:15:39 +00:00
Paweł Poławski
55a007a871 Readme: Update project build information
osbuild-composer project has build related section in the main README.
For the osbuild it was missing. Even if this is script-based project
external developers may not be aware of this just by looking at README.
Missing build related section has been added for consistency.
2023-12-05 11:46:16 +01:00
Paweł Poławski
12a9e65e2f Makefile: Update helper notes
Makefile has multiple test related targets.
* linter target has been added to the helper note.
* dead test-src target has been removed from Makefile
2023-12-05 11:46:16 +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
Ondřej Budai
7882db2543 test/data/manifests: add erofs-utils to Fedora buildroot
The next commit will add a stage test that requires erofs-utils. Let's add it
into the buildroot in a separate commit, so the history is more readable.
2023-12-01 10:36:06 +01:00
Michael Vogt
627199543f test: add erofs stage test
Add a simple stage test for the erofs stage. It uses dump.erofs
instead of mounting the file because the kernel in the GH runners
do not support mounting erofs just yet.
2023-12-01 10:36:06 +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
Tomáš Hozza
286b785af7 Packit: make COPR builds for new releases in a dedicated project
Add a new Packit "copr_build" job, which will build new upstream
releases in a dedicated COPR project "osbuild-stable". This will allow
people to consume stable builds of osbuild ASAP (including some
sub-packages on CS which are not part of the official distro builds).

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2023-11-30 14:23:15 +01:00
Simon de Vlieger
b225d1cf04 osbuild-mpp: conditional losetup
`mpp-define-images` can create an image file, using `losetup` to deal
with non-standard sector sizes requires root. Not all users run
`osbuild-mpp` as root.

While I am not a fan of "suddenly sudo" based on the input manifest this
does alleviate builds breaking for manifests with default sector sizes
when non-root.
2023-11-30 14:16:57 +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
Dusty Mabe
e191dc1d0d tools/osbuild-mpp: set part ID from name if missing
For our Fedora CoreOS disk images we set the partition labels (name)
for the partitions. This is also supported using the primitives here
in OSBuild, but it wasn't obvious that I needed to set the name in
the mpp-define-images definition. Let's set the name there, but let's
also allow osbuild-mpp to set the `id`, which is what is used later
to access that partition from the `name` too if `id` isn't set.

This means we allow something like:

   - name: BIOS-BOOT
     type: 21686148-6449-6E6F-744E-656564454649
     bootable: true
     uuid: FAC7F1FB-3E8D-4137-A512-961DE09A5549
     size: 100

rather than requiring something like:

   - id: BIOS-BOOT
     name: BIOS-BOOT
     type: 21686148-6449-6E6F-744E-656564454649
     bootable: true
     uuid: FAC7F1FB-3E8D-4137-A512-961DE09A5549
     size: 100
2023-11-29 10:37:08 +01:00
Dusty Mabe
5ad3f968e1 manifests: add example metal4k disk image for Fedora CoreOS
The created disk image would be written to 4k native disks.
2023-11-29 10:37:08 +01:00
Dusty Mabe
28c2772d42 tools/osbuild-mpp: add sector size support for image layouts
Now you can specify a sector_size in `mpp-define-images` to support
creating a 4k native disk image (sector_size=4096).

This does use a loopback device, which means osbuild-mpp also needs
to run as root, when previously that wasn't necessary.
2023-11-29 10:37:08 +01:00
Dusty Mabe
2e1f6e2553 tools/osbuild-mpp: support defining multiple image layouts
Right now you can only define a single image, lets add mpp-define-images
and accept a list.
2023-11-29 10:37:08 +01:00
Dusty Mabe
b824e1e57a manifests: fedora-coreos-container: human friendly partitioning
Let's define the partitioning for the example here in a more human
friendly way using GiB and MiB terms. This yields no change in the
generated json.
2023-11-29 10:37:08 +01:00
Dusty Mabe
5207e92cab tools/osbuild-mpp: handle corner case in mpp-format-int
If you do math in mpp-format-int it could end up getting converted
to a float. Of course if you end up with a decimal value that isn't
`.0` that's a problem for an int, but if it is `.0` let's handle it
gracefully.

For example, math like this could end up with a value with `.0`:

  mpp-format-int: "{bios_boot_size_mb * 1024 * 1024 / sector_size_bytes}"
2023-11-29 10:37:08 +01:00
Dusty Mabe
0770eb0090 devices/loopback: make setting sector_size meaningful
For the org.osbuild.loopback the user can set the sector size, but
it had no effect on the underlying loopback device. Let's make it
meaningful by passing along the given value to the underlying code.
2023-11-29 10:37:08 +01:00
Alexander Larsson
677a874115 osbuild-mpp: Print better errors if eval fails
I'm trying to debug some failures, and having no feedback as to
what file we're parsing or what code is evaluated when something
fails makes it hard to debug manifests.

This adds some nice error messages that will help.
2023-11-28 18:03:05 +01:00
Miguel Martín
bc04bfc366 runners: clean up temp files before exiting the runner
Clean up created temp files before exiting the runner.
2023-11-28 11:50:31 +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
b3c6366135 osbuild: improve monitor docstrings/signatures
This is a split out from the work around json
progress in [1].

[1] https://github.com/osbuild/osbuild/compare/main...mvo5:osbuild:json-progress-mvo?expand=1
2023-11-28 09:56:56 +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
Michael Vogt
158acaac78 osbuild: ensure loop.Loop() has the required device node
When loop.Loop() is called and a new loop device must be allocated
there is no gurantee that the correct device node is available on
the system. In containers /dev is often just a tmpfs with static
device nodes. So when /dev/loopN is not available when the
container is created the device node will be missing even if
`get_unbound()` create a new loop device for us.

This commit ensures that the device node is available. It creates
it unconditionally and ignores any EEXIST errors to ensure there
is no TOCTOU issue.

Note that the test could have passed a `Loop(dir_fd=open(tmpdir))`
instead of creating/patching loop.DEV_PATH but it seems slightly
nicer to test the flow without a custom dir_path as this is what
the real code that creates a loop device is also using.
2023-11-24 16:05:52 +01:00
Gianluca Zuccarelli
9cd8fc979b test: fix broken oscap remediation tests
The oscap remediation tests broke with 810a48d. This commit adds the
fixes to get the GitHub actions to go green again.
2023-11-24 14:28:34 +00:00
Simon de Vlieger
e7db40831f test: stage tests -> stage integration tests
Quick rename to have our wording be in-line with the new differences
between stage unit tests and stage integration tests; also being applied
to the guides.
2023-11-24 13:58:04 +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
Michael Vogt
edbf409a40 osbuild: fix missing initialization of fd in osbuild.loop.Loop
When osbuild.loop.Loop calls `__init__()` it assigns the `self.fd`
on open. However if that open call fails for whatever reason
(not found, permissions) the cleanup in `__del__` will fail in
confusing ways because `self.fd` is not initialized yet. It
also prevents the correct error from getting reported. A tiny
test is added to ensure this does not regress.
2023-11-23 14:01:53 +01:00
Michael Vogt
1374faa488 tests: remove custom tmpdir() fixtures and use tmp_path
This commit removes some unnecessary custom tmpdir() fixtures
and uses the pytest buildin tmp_path instead.

Some custom tmpdir fixtures are left in place as they configure
the tmp location to be under `/var/tmp` which is not trivial to
do with pytests `tmp_path`. Not sure or not if the is a deep
reason there for using /var/tmp. I assume it's to ensure that
the tests run on a real FS not on a potential tmpfs but I don't
have the full background so didn't want to change anything.
2023-11-23 13:09:25 +01:00
Alexander Larsson
d66b2faa41 Move org.osbuild.experimental.ostree.config to osbuild-ostree subpackage 2023-11-22 19:28:06 +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
9d7bbd674f tests: remove custom tempdir_fixture
There is no need for a handcrafted tempdir fixture, pytest already
provides a build-in `tmp_path`.
2023-11-22 12:46:19 +01:00
Michael Vogt
4b69d2e1c4 util: tweak _calculate_size() to _calculate_space()
Update the naming, docstring and tweak the tests.

Thanks to bcl and dustymabe!
2023-11-22 10:28:08 +01:00
Dusty Mabe
9121360f7b osbuild/util/fscache: calculate actual size of files
In OSBuild we'll often be operating on sparse files. Let's make the
tabulation of the size of files on disk used when determining cache
size for pruning consider the actual size of the file usage on disk
rather than the size the file reports to be.

This means using os.lstat().st_blocks * 512 versus os.lstat().st_size.

See https://stackoverflow.com/a/55203604
2023-11-22 10:28:08 +01:00