Commit graph

3244 commits

Author SHA1 Message Date
Michael Vogt
6cc0e584ba stages(tar): expose new transform option to tar stage
This commit adds a new `transform` option to the tar stages that
maps directly to the `--transform=` comamndline argument of tar(1).

This allows to transform the names while files/dirs are added to
a tarfile. This is useful for the `gcp` pipeline for
bootc-image-builder where we want to create a gcp tar file that
expects the disk image filename in the tar to be exactly `disk.raw`.

Note that tar allows only a single `--transform` and we leave it
to the user to construct `sed` expressions if multiple renames
are required.
2024-09-25 12:57:00 +02:00
Yaakov Selkowitz
68b6481f54 spec: use python3-libdnf5 in RHEL 11 and ELN 2024-09-25 12:44:19 +02:00
schutzbot
186cf23255 Post release version bump
[skip ci]
2024-09-25 08:29:11 +00:00
Dusty Mabe
f01a3d3c01 stages/selinux: don't require file_contexts if labels passed
With the labels option the user is specifying the exact context
they want to set on the path so it's not necessary to supply a
context here. This can be also useful in the case where you want
to set some labels and you haven't yet populated the tree yet.
2024-09-25 09:17:34 +02:00
Tomáš Hozza
ca1a21b923 Fix dependencies and test for DNF4 based osbuild-depsolve-dnf
For the DNF4 version, we actually use 'dnf' package and not 'libdnf'.
Fix the SPEC file dependencies and also the check in unit test.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2024-09-20 14:58:57 +02:00
schutzbot
b1c14ed422 schutzfile: Update snapshots to 20240918 2024-09-20 14:11:50 +02:00
Alexander Larsson
bad22ebdfb Add test for containers.unix.create stage 2024-09-19 10:37:28 +02:00
Alexander Larsson
2393299510 *.unit.create.meta.json: Fix syntax for not-required checks
not required [A, B] is not right as it means its not required to have
both. Instead we want not any-of [ required: a, required: b ]
2024-09-19 10:37:28 +02:00
Alexander Larsson
e7699e0c70 org.osbuild.systemd.unit.create: Fix case of ListenFIFO option 2024-09-19 10:37:28 +02:00
Alexander Larsson
9f0f609d31 Add org.osbuild.containers.unit.create stage
This is essentially org.osbuild.systemd.unit.create but creates
file where podman looks for quadlets instead.

For now only container, volume and network is supported.

Not all quadlet options are supported, but at least the most usef ones, and enough for the automotive sample-images.
2024-09-19 10:37:28 +02:00
Alexander Larsson
af3c70fb40 /org.osbuild.systemd.unit*: Don't use interpolation with ConfigParser
Its not uncommon for systemd unit key values to contain things like
"%t", as these are magic values expanded by systemd. We need to
disable the ConfigParser default interpolation that treats '%' as
meaning interpolation.

Otherwise you will get errors like:

```
  File "/run/osbuild/bin/org.osbuild.systemd.unit.create", line 66, in <module>
    r = main(args["tree"], args["options"])
  File "/run/osbuild/bin/org.osbuild.systemd.unit.create", line 46, in main
    config.set(section, option, str(value))
  File "/usr/lib64/python3.9/configparser.py", line 1204, in set
    super().set(section, option, value)
  File "/usr/lib64/python3.9/configparser.py", line 894, in set
    value = self._interpolation.before_set(self, section, option,
  File "/usr/lib64/python3.9/configparser.py", line 402, in before_set
    raise ValueError("invalid interpolation syntax in %r at "
ValueError: invalid interpolation syntax in '%t/asil-ipc-demo/asil_ipc.socket' at position 0
```
2024-09-19 10:37:28 +02:00
Alexander Larsson
657c42bb0d org.osbuild.systemd.unit.create: Support Socket files
This allows you to create basic socket files.

Signed-off-by: Alexander Larsson <alexl@redhat.com>
2024-09-19 10:37:28 +02:00
Jonathan Lebon
ed33869430 tools/osbuild-mpp: hash mpp-embed urls from stream
Currently if one uses `mpp-embed` with URLs, osbuild-mpp still wants to
download the full file just so it can hash it. Make this more efficient
by hashing from the stream instead, which `hashlib` natively supports.

This also makes osbuild-mpp work with large artifacts in environments
that may not have enough space to temporarily save the data.
2024-09-19 01:53:18 +02:00
schutzbot
59734733c0 Post release version bump
[skip ci]
2024-09-18 11:32:51 +00:00
Tomáš Hozza
3df75de65a Util/SBOM: add compatibility layer for old lib Hawkey
'_hawkey.Reldep' object has no attribute 'name' in the version shipped
on RHEL-8. Add code to handle this situation in case it happens.
Default to using named attributes if these are available.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2024-09-18 12:26:36 +02:00
Tomáš Hozza
02ca5722f6 Solver/dnf.py: simplify the code a bit
Since the `with_sbom` variable was used only in a single place, we can
simplify the code (and remove one extra line of it) to just directly use
the if condition.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2024-09-18 12:26:36 +02:00
Tomáš Hozza
9510e88c0f CI: determine the libdnf python version from /osb/libdnf-python-version
Instead of hard-coding the Python version that the installed
python3-dnf has been built against on the latest Fedora, read the
value from the osbuild-ci container. The container now has the version
written in /osb/libdnf-python-version.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2024-09-18 12:26:36 +02:00
Tomáš Hozza
ba70909975 Add org.osbuild.dnf4.sbom.spdx stage
Add a new stage, which allows analyzing the installed packages in a
given filesystem tree using DNF4 API and generating an SPDX v2.3 SBOM
document for it.

One can provide the filesystem tree to be analyzed as a stage input. If
no input is provided, the stage will analyze the filesystem tree of the
current pipeline.

Add tests cases for both usage variants of the stage, as well as the
unit test for stage schema validation.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2024-09-18 12:26:36 +02:00
Tomáš Hozza
1d8bd0f8a6 Support SBOM for depsolving in osbuild-depsolve-dnf
Extend osbuild-depsolve-dnf, to return JSON with SPDX SBOM that
corresponds to the depsolved package set, if it has been requested.
For now, only DNF4 is supported.

Cover the new functionality with unit test.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2024-09-18 12:26:36 +02:00
Tomáš Hozza
65ef88687e osbuild/solver: add InvalidRequestError exception
This will allow validating request arguments in the solver method in a
different way for dnf4 and dnf5 and raising an exception if needed.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2024-09-18 12:26:36 +02:00
Tomáš Hozza
33a8427dd9 Test SPDX model implementation against spec JSON schema
Verify the documents generated by the internal implementation of SPDX
v2.3 model against the upstream spec JSON schema.

The schema has been downloaded from:
https://github.com/spdx/spdx-spec/blob/development/v2.3.1/schemas/spdx-schema.json

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2024-09-18 12:26:36 +02:00
Tomáš Hozza
0b68f8123b Add initial SBOM library implementation
Add implementation of standard-agnostic model for SBOM, and simple SPDX
v2.3 model. Also add convenience functions for converting DNF4 package
set to the standard-agnostic model and for converting it to SPDX model.

Cover the functionality with unit tests.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2024-09-18 12:26:36 +02:00
Tomáš Hozza
75b6fb4abe Tests: allow site packages in tox to test code depending on 'dnf'
'dnf' Python package can't be installed using pip in the tox
environment. In order to test the code which uses it, we need to use the
system version. Our testing environment uses Fedora as the system,
therefore we can reasonably use the system version of 'dnf' only with
Python version which is on Fedora.

Enable site packages in tox for Python 3.12 when testing osbuild
internals.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2024-09-18 12:26:36 +02:00
Tomáš Hozza
67c7d63983 testutil: add helper function for depsolving pkgset with DNF4
This will be useful for testing SBOM implementations.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2024-09-18 12:26:36 +02:00
Dusty Mabe
796f1d6fa1 stages/coreos.platform: use shutil.copy
Switch from shutil.copy2 so that we don't copy over the
SELinux labels from the source file.
2024-09-18 11:06:44 +02:00
Jonathan Lebon
3c3be92016 devices/loopback: add read-only option
It's sometimes useful to set up a loop device for an already formatted
disk/filesystem image to derive new artifacts from it. In that case, we
want to make sure it's impossible to modify its contents in any way in
that process, both for our own purposes and for other stages operating
on it.

Notably, mounting some filesystems read-only still seem to touch the
disk (like XFS).
2024-09-18 08:54:34 +02:00
Michael Vogt
478fee2876 util: use Libc.memfd_create() when os.memfd_create() is missing
This provide compat for pyton versions below 3.8. This can be
removed (together with the previous commit) once we are at
python3.8+.
2024-09-17 19:27:03 +02:00
Michael Vogt
09e78c52d9 uktil: add libc.memfd_create() wrapper
This is required for python3.6 where there is no `os.memfd_create()`
yet. Can be removed once we move to python3.8+.
2024-09-17 19:27:03 +02:00
Michael Vogt
0abdfb9041 jsoncomm: transparently handle huge messages via fds
The existing jsoncomm is a work of beautiy. For very big arguments
however the used `SOCK_SEQPACKET` hits the limitations of the
kernel network buffer size (see also [0]). This lead to various
workarounds in #824,#1331,#1836 where parts of the request are
encoded as part of the json method call and parts are done via
a side-channel via fd-passing.

This commit changes the code so that the fd channel is automatically
and transparently created and the workarounds are removed. A test
is added that ensures that very big messages can be passed.

[0] https://github.com/osbuild/osbuild/pull/1833
2024-09-17 19:27:03 +02:00
Michael Vogt
d67fa48c17 stages: fix btrfs subvolume creation under subdirectories
The code currently does not support btrfs subvolumes that are not
directly under the root directory. This commit fixes this by adding
`-p` to `btrfs subvolume create` and adding an integration test.

Closes: https://github.com/osbuild/osbuild/issues/1882
2024-09-13 11:23:35 +02:00
Michael Vogt
ed95178b80 test: add test that ensures return value of chroot.run()
Small followup for https://github.com/osbuild/osbuild/pull/1854
which added the return value to `util.Chroot.run`. This commit
now adds a (super trivial) test for this.
2024-09-11 20:19:46 +02:00
schutzbot
6953ea89b4 Post release version bump
[skip ci]
2024-09-11 08:27:12 +00:00
Jonathan Lebon
66a00335c6 stages/dmverity: make device objects more generic
We need to pass loopback devices for these properties, but the schema
says that there will be a `path` property, so osbuild complains.

osbuild is right of course, but this definitely *did* work in an earlier
version, so something changed. Ideally, we'd narrow down here what
happened exactly, but at the same time this approach of just making the
property more generic matches what's done in e.g. the `zipl.inst` stage
where we also use a loopback device.

For reference, this is where we use this stage:

ba45b296ec/src/osbuild-manifests/platform.qemu.ipp.yaml (L100-L119)
2024-09-10 20:11:16 +02:00
Michael Vogt
f3188e841f osbuild: also print what export is availalble when one is not found
The current error message when an export is not found could be
improved by printing what exports are actually availalble to make
it easier for the user to e.g. spot typos.
2024-09-10 10:49:18 -07:00
Lukas Zapletal
09da4fff7b stages: add org.osbuild.pki.update-ca-trust
Adds a new stage that calls update-ca-trust tool with extract argument
to extract CA certificates. It is expected that one or more CAs are
placed in the /etc/pki/ca-trust/source/anchors directory in PEM format.
Filenames do not matter but must be unique enough. See the
update-ca-trust man page for more details on what it does.
2024-09-10 19:10:06 +02:00
Lukas Zapletal
88474fd4d9 util: run returns CompletedProcess 2024-09-10 19:10:06 +02:00
Michael Vogt
ea14713f3a osbuild add new -q, --quiet option
Current osbuild will always print some non output even
when run with `--monitor=JSONSeqMonitor` because of the
unconditional `print/sys.stdout.write()` in `main_cli.py`.

This commit adds a new `-q` option to silence this so that something
like osbuild-composer can run `osbuild -q --monitor=JSONSeqMonitor`
to get pure json-seq output during the build.

The use-case is to run `osbuild --monitor-fd` from e.g. bib and
osbuild-composer so that we get pure json from the monitor-fd
and anything that goes on std{out,err} can be logged as it is
most likely error output.
2024-09-09 18:07:54 -07:00
Michael Vogt
a221d4e68b test: checkpoint "build" stage too during test_stages.py
Quick check to see if checkpointing "build" helps with the
runtime. Note that the cache size is already 20GB, I doubled
it for good measure but we probably can go back to 20, just
want to make sure this is not the bottleneck.

Closes: https://github.com/osbuild/osbuild/issues/1874
2024-09-05 18:17:56 +02:00
schutzbot
a0828f77dc schutzfile: Update snapshots to 20240901 2024-09-05 17:39:41 +02:00
Florian Schüller
0f5db9a283 stages: fix some documentation typos to prepare for spellchecking 2024-09-04 12:17:58 +02:00
Ondřej Budai
2f84ba96c9 stages: add a new mkswap stage
A stage very similar to the existing mkfs ones (actually, I started from
the xfs one). It creates a swap area on a given device.
2024-09-02 15:27:32 +02:00
Achilleas Koutsou
83fcc8a0b1 test: compare full arg_list in chroot context test
- Add an extra call to `/bin/false` and explicitly set the `check`
  argument for both `run()` calls.
- Compare full call_args_list.  This checks that all the options are as
  expected, that the `check` argument is set properly, and that the full
  order of all the calls is as expected, including the chroot path.

Co-authored-by: Michael Vogt <michael.vogt@gmail.com>
2024-08-28 16:45:48 -07:00
Achilleas Koutsou
1093b5eeb2 util/chroot: use subprocess.run() for all commands
For consistency, use subprocess.run() with check=True for the calls that
were previously using subprocess.check_call().

Update the affected tests to match.
2024-08-28 16:45:48 -07:00
Achilleas Koutsou
73464ff119 test: add test for chroot context
Add a test for the chroot context that mocks subprocess.run() and
subprocess.check_call().  The test verifies that the functions are
called the expected number of times with the expected command (first
arg).
2024-08-28 16:45:48 -07:00
Achilleas Koutsou
3dbf389ebf util/chroot: add run() method to context class
Rename the ChrootProcDevSys class to just Chroot and add a run() method.
Calls now can be made using:

  with Chroot(root) as chroot:
      chroot.run(command)
2024-08-28 16:45:48 -07:00
Achilleas Koutsou
931e832944 test/dracut: update subprocess.run() call count 2024-08-28 16:45:48 -07:00
Achilleas Koutsou
149e3ead96 util/chroot: call unmount with check=False
If one of the chroot mounts fails to unmount, keep iterating so that we
don't stop and continue to unmount the rest.
Print an error message with the failed mounts, but don't fail the build.

Since failing to unmount doesn't fail the exiting of the context, and
the context itself doesn't know what will be running in the chroot,
do a lazy unmount.
2024-08-28 16:45:48 -07:00
schutzbot
d893e81004 Post release version bump
[skip ci]
2024-08-28 08:26:06 +00:00
Michael Vogt
b4b865fddf Revert "sources(curl): disable curl --parallel by default"
This reverts commit 9bef57d5a6.
2024-08-28 07:46:37 +02:00
Michael Vogt
a229d46b1e sources(curl): manually keep track of failed URLs
This commit keeps track of individual errors as curl will only report
the last download operation success/failure via it's exit code.

There is "--fail-early" but the downside of that is that abort all in
progress downloads too.
2024-08-28 07:46:37 +02:00