Commit graph

3259 commits

Author SHA1 Message Date
Florian Schüller
2d1e8553d7 stages/test/test_tar: fix regex to be more robust
For usecases where for example selinux is not supported,
we should expect more errors from tar so we should also accept this
when matching the string.

Kudos go to Achilleas Koutsou <achilleas@koutsou.net> for this hint
2024-10-26 20:04:37 +02:00
Florian Schüller
a1f02113cd stages/org.osbuild.tar: implement disk-full test
this should be an example environment
for more stages to test if they return a proper error
in a "disk full scenario"
2024-10-26 20:04:37 +02:00
Florian Schüller
6fec975c30 README: document test prerequisites
The full list of packages is also listed in terraform
containers/blob/main/docker-bake.hcl#L240 ("BASE_PACKAGES")
so this README and the package list should somewhat stay in sync
2024-10-25 23:06:06 +02:00
Nikita Dubrovskii
23f01307b2 org.osbuild.mkdir: support creating dirs on mounts
This allows creating new directories on mounts:
```
- type: org.osbuild.mkdir
  options:
    paths:
      - path: mount:///boot/efi
  devices:
    disk: ...
  mounts:
    - name: boot
      target: /boot
      ...
```
2024-10-25 16:22:19 +02:00
Michael Vogt
ad7c646712 test: add integration test for Chroot.run()
This commit adds a test that is more "integration"-ish in style
to make sure that the actual return code of a command is returned
via chroot.
2024-10-24 10:06:46 +02:00
Michael Vogt
1b3e956334 testutil: switch mock_command to use bash
This change allows use the more advanced features of bash like
array operations (e.g. `${@:2}` to drop the first two arguments
or similar. On fedora/rhel this is a no-op as it is already using
sh -> bash (afaik).
2024-10-24 10:06:46 +02:00
Michael Vogt
a3e32f3823 util: drop absolute path from Chroot.run() calls
We currently use the absolute path of these binaries in the
helper. This has some advantages but given that we control the
inputs for PATH in general it seems unnecessary.

We are also slightly inconsistent about this in the codebase but
favor the non absolute path version. A quick count:
```
$ git grep '"chroot"'|wc -l
13
$ git grep '"/usr/sbin/chroot"'|grep -v test_|wc -l
8
```
for `mount` and `umount` it seems this is the only place that uses
the absolute path.

It's not an important change but it has the nice property that it
allows us to use e.g. `testutil.mock_command()` in our tests and
it would be nice to be consistent.
2024-10-24 10:06:46 +02:00
schutzbot
0cf3cf9020 Post release version bump
[skip ci]
2024-10-23 08:28:22 +00:00
Lukas Zapletal
f9873e493e sources: MTLS and proxy support for ostree 2024-10-22 22:16:35 +02:00
Renata Ravanelli
9c69bf3423 osbuild.spec: Add python3-dnf dependency for osbuild-tools
The recent change in https://github.com/osbuild/osbuild/pull/1896
removed the dnf dependency, leading to failures in osbuild-mpp with the
following error:

    ModuleNotFoundError: No module named 'dnf'

To fix it, add the python3-dnf dependency for the
osbuild-tools package.

Signed-off-by: Renata Ravanelli <rravanel@redhat.com>
2024-10-22 11:11:54 +02:00
Lukáš Zapletal
4b4b5cea95 chore: add dicussions link to README
I am keeping mailing list link, however, nobody was able to tell me how one can subscribe to it. I think it is Google Groups list now and there is no join option.
2024-10-17 11:33:33 +02:00
Michael Vogt
55106056c8 meta: use pathlib to join paths in class Index
This commit moves the joining of path fragements from f-strings
to pathlib and simplifies some of the map/filter/lambda expressions
into more standard list comprehensions.
2024-10-17 08:55:18 +02:00
Paweł Poławski
8f7a3d7234 CI: Update excluded tests list
After removal of TOML write packages on c9s and c10s some
tests using this library needs to be skipped.
2024-10-09 17:41:01 -07:00
schutzbot
6ed754946d Post release version bump
[skip ci]
2024-10-09 08:27:18 +00:00
Ondřej Budai
e5e3aad7b8 spec: remove unneeded dnf depedendency
This was added years ago in 3c19420b3e.
Back then, we were constructing the initial buildroot using dnf directly
(stages had network access at that point). We reworked this with the
introduction of the rpm stage, sources and an external depsolver. The
dnf stage itself was actually removed in
892342b978. Thus, I think we don't need
to pull dnf anymore, so this commit removes the dependency.
2024-09-26 12:11:13 +02:00
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