Commit graph

948 commits

Author SHA1 Message Date
Tomáš Hozza
a3428e282d sbom/spdx: use compliant license expressions
Introduce a new class `SpdxLicenseExpressionCreator`, responsible for
converting license texts extracted from packages, into an SPDX-compliant
license expressions. If the `license_expression` Python package is
available on the system, it is used to determine the license text
extracted from a package is a valid SPDX license expression. If it is,
it's returned as is back to the caller. If it is not, or of the package
is not available on the system, the license text is wrapped in a
`ExtractedLicensingInfo` instance.

The `SpdxLicenseExpressionCreator` object keeps track of all generated
`ExtractedLicensingInfo` instances and de-duplicates them based on the
license text. This means that if two packages use the same
SPDX-non-compliant license text, they will be wrapped by an
`ExtractedLicensingInfo` instance with the same `LicenseRef-` ID.

The reason for fallback when `license_expression` package is not
available is that it is not available on RHEL and CentOS Stream. This
implementation allows us to ship the functionality in RHEL and
optionally enabling it by installing `license_expression` from a 3rd
party repository. In any case, the generated SBOM document will always
contain valid SPDX license expressions.

Extend unit tests to cover the newly added functionality.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>

FIXUP: sbom/spdx: use compliant license expressions

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2025-02-27 13:31:19 +01:00
Tomáš Hozza
0174173175 test/data/spdx: add README describing each file
Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2025-02-27 13:31:19 +01:00
Tomáš Hozza
aaa6d8ec84 sbom/spdx2/model: support ExtractedLicensingInfo
Extend the SPDX v2 model to support referencing extracted licensing
information, which is either not in the SPDX license list or can't be
expressed by the SPDX-compliant license expression.

Cover the new functionality by unit tests.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2025-02-27 13:31:19 +01:00
Michael Vogt
b22cbd3298 monitor: limit the amount of data sent in JSONSeqMontior.result()
This commit limits the output in the json pipeline to a "reasonable"
length. We ran into issues (e.g. [0]) from a combination of a stage
that produce tons of output (dracut, ~256 kb, see issue#1976) and
the consumer ("images" osbuild/monitor.go) that used a golang scanner
with a max default buffer of 64kb before erroring. So limit it
here.

The stage result from via json is mostly for information and any error
will most likely at the end. Plus consumers can collect the individual
log lines on their own if desired via the "log()" messages that are
stream in "real-time" with the added benefit that e.g. timestamps
can be added to the logs etc.

[0] https://issues.redhat.com/browse/RHEL-77988
2025-02-18 10:36:59 +01:00
Dusty Mabe
4e033c305e stages: add more options to qemu vmdk disk type
The CoreOS team uses the compat6 and adapter_type options when creating
a VMDK for AWS.

e1943d6adb/src/cosalib/qemuvariants.py (L48)
2025-02-17 03:41:11 -05:00
Tomáš Hozza
2622782604 Test/manifest_tests: --osb-store -> --osbuild-store
Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2025-01-31 10:18:14 +01:00
Tomáš Hozza
0b158c3fd3 Test/manifest_tests: use temporary dir if workdir is not specified
In case the workdir is not provided to the script explicitly as an
argument, the script will use a temporary directory under /var/tmp as
its workdir. In such case, the workdir will be deleted on exit. This
should mitigate potentially confusing behavior when executing the script
multiple times with different arguments, while never specifying the
workdir.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2025-01-31 10:18:14 +01:00
Tomáš Hozza
7cef5b480a Test/cases: delete manifest-db-based manifest_tests.sh
Delete the old manifest-db-based test case script, which is no longer
used anywhere.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2025-01-31 10:18:14 +01:00
Tomáš Hozza
a244003e6e Tests: add new manifest tests using osbuild/images cache
Add new implementation of the manifest tests, which goal is to ensure
that the osbuild behavior didn't change. This is ensured by comparing
image-info report produced for image artifact built using older
(known-to-be-good) osbuild version and the latest osbuild version
(potentially from a PR).

Previously, we used the osbuild/manifest-db repository, which contained
pre-generated manifests with their corresponding image-info report.
Unfortunately, this setup prooved to be cumbersome to maintain and keep
updated.

We are already building images for known manifests in the osbuild/images
repository. These are then uploaded to AWS S3 cache. The images are
built with a pinned osbuild version, which will be always older than the
one that we would be using for image build in osbuild PR.

So the intention of this new script is to take advantage of the
osbuild/images S3 cache. As part of the test case (for a specific distro
/ arch / image_type / config):
 - download the manifest from S3
 - download the image artifact, built from the manifest, from S3
 - generate image-info report for the downloaded image
 - rebuild the downloaded manifest using current version of osbuild
 - generate image-info report for the rebuilt image
 - compare the two image-info reports. If there is no difference, the
   test case PASS, otherwise it will FAIL.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2025-01-31 10:18:14 +01:00
Michael Vogt
035781ea1c osbuild: add a mutex to the _jsonseq() writer
This commit fixes a race/threading issue with the way the monitor
works. The osbuild monitor can be called from multiple threads,
e.g. in buildroot.py:run() monitor.log() is called but also
in host.py:_stdout_ready(). This can lead to out-of-order writes
when many messages need to be processed.

We did not notice this so far because we were lucky and also
log was just used for information. But now it is used to transmit
the jsonseq data which means out-of-order communication results
in broken json.

Closes: https://github.com/osbuild/image-builder-cli/issues/110
2025-01-30 20:08:53 +01:00
Simon de Vlieger
1e70131346 data: include appstream repository metadata
The CentOS Stream 9 repository metadata contains modules; these are
necessary for testing modularity depsolving.

Note that the filelists metadata is kept empty to keep repository size
down.

Co-authored-by: Michael Vogt <michael.vogt@gmail.com>
Signed-off-by: Simon de Vlieger <supakeen@redhat.com>
2025-01-22 18:03:21 +01:00
Achilleas Koutsou
e99dabe467 test: generate container-dev-null test manifests
Generate the manifests from the mpp yaml files.
2025-01-17 10:10:47 +01:00
Achilleas Koutsou
278b9130b0 test: (mpp) manifests for container embed
Add mpp files to create manifests that will embed the container (that
contains /dev/null) in an OS tree and compose an ostree commit from it.

This used to cause the rpm-ostree compose command to fail with:

    error: Writing commit: While writing rootfs to mtree: Not a regular file or symlink: null
2025-01-17 10:10:47 +01:00
Achilleas Koutsou
e2b9d0f3ca test: update rpmrepo snapshots
Required for latest version of rpm-ostree.
2025-01-17 10:10:47 +01:00
Achilleas Koutsou
6b45c81a29 test: create a container with /dev/null
Create a container using the new script and add it to the repo for use
in testing.
2025-01-17 10:10:47 +01:00
Achilleas Koutsou
0507a9807c test: container creation script with /dev/null
Add a script that creates a container image as an oci-archive that
contains /dev/null.
2025-01-17 10:10:47 +01:00
Michael Vogt
c27c32be0e osbuild: add result error reporting for sources
This commit adds error reporting from source download errors
to the monitor. It reuses the `BuildResult` for symmetry but
we probably want to refactor this a bit to make source handling
a bit more similar to stages.
2025-01-14 14:33:28 +01:00
Michael Vogt
5ba7cadd8b monitor: include build_result in jsonseq monitor streaming
In order to avoid having to rely on the output of `osbuild --json`
when using `--progress=JSONSeqMonitor` the monitor needs to include
the `osbuild.pipeline.BuildResult` for each individual stage.

This commit adds those to the montior.
2025-01-14 14:33:28 +01:00
Michael Vogt
a36fca4b34 test: reformat json data to appease linter
This commit just ran:
```
  find -iname "*.json" -print -exec sh -c 'jq --indent 2 . {} | sponge {}' \;
```
to ensure that the new test json data from librepo is in the format
the linter expects.
2025-01-14 08:19:16 +01:00
Brian C. Lane
e4ae9ec018 test: Skip check_moduleinfo for unsupported versions
Most modules do not support both schema versions. This is masked by
module type code in get_schema() in most cases, but really should not be
tested. This skips running check_moduleinfo if the module doesn't
support the version. eg. org.osbuild.librepo only supports v2.
2025-01-14 08:19:16 +01:00
Brian C. Lane
0eb842e80c test: Validate the source test manifests
This helps prevent testing against invalid manifest data. It runs on the
source's manifest data, using the highest schema version parsed for the
source.
2025-01-14 08:19:16 +01:00
Brian C. Lane
e2345a6348 test: Add baseurl test for org.osbuild.librepo
These test:

* baseurl success
* baseurl with a bad checksum (or file) which is expected to fail
2025-01-14 08:19:16 +01:00
Brian C. Lane
6045b3ffd6 test: Add mirrorlist test for org.osbuild.librepo
These tests test downloading packages using mirrorlist:

* Using a single mirrorlist repo
* Using two mirrorlist repos
* A bad checksum (or file) from the download which is expected to fail
* Two mirrorlist paths with the first one returning a 404, expected to
  succeed with the 2nd mirrorlist path.
2025-01-14 08:19:16 +01:00
Brian C. Lane
0c340da0a2 test: Add metalink test for org.osbuild.librepo
NOTE: The metalink xml file points to a repomd.xml file which does not
exist. In practice librepo doesn't download this, it only uses the url
to construct the mirror urls, so it is not present.

These tests test downloading packages using metalink:

* Using a single metalink repo
* Using two metalink repos
* A bad checksum (or file) from the download which is expected to fail
* Two metalink paths with the first one returning a 404, expected to
  succeed with the 2nd metalink path.
2025-01-14 08:19:16 +01:00
Tomáš Hozza
2f82179268 test_util_path: extend test coverage of join_abs()
Add additional test cases for the `join_abs()` function based on a
suggestion from the PR review.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2025-01-06 11:53:46 -08:00
Tomáš Hozza
8463394d2c util/path: add join_abs() to join potentially absolute paths
It turned out that in many cases, stages need to join two absolute
paths, the pipeline tree path and the path on a booted system. However,
the standard `os.path.join()` function can't handle such situation as
just prepending the root to the subsequent paths.

Add a new helper function, which is able to join any paths together,
regardless if any of them is absolute or not. If the root is not
absolute, the result will be made absolute to the filesystem root `/`.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2025-01-06 11:53:46 -08:00
Jonathan Lebon
0331e6f313 stages: add coreos.live-artifacts.mono stage
This adds a new `org.osbuild.coreos.live-artifacts.mono` stage to build
CoreOS Live ISO/PXE artifacts. The code is heavily based on the
`cmd-buildextend-live` script from coreos-assembler [1], but a lot of
things had to be adapted:
- the stage is provided the deployed oscontainer tree, metal, and
  metal4k images as inputs
- we use chroot instead of supermin to execute some commands in the
  context of the target oscontainer
- a bunch of calls that were wrapped by libguestfs for us (e.g.
  mkfs.vfat, mksquashfs), we now have to call ourselves; to retain
  maximum compatibility, we ensured that we still effectively use the
  same args that libguestfs passed

And various other minor adjustments.

Of course, this is not really in line with the OSBuild philosophy
of having smaller-scoped stages. We have labeled this with a .mono
suffix to denote it is monolithic, similar to the existing
`org.osbuild.bootiso.mono` stage today.

Eventually we may be able to break this stage down if we find it worth
the effort. Alternatively the need for it may go away as we align more
with Image Mode.

[1] 43a9c80e1f/src/cmd-buildextend-live

Co-authored-by: Dusty Mabe <dusty@dustymabe.com>
Co-authored-by: Renata Ravanelli <renata.ravanelli@gmail.com>
2024-12-18 11:09:29 -05:00
Dusty Mabe
b7e3268ef0 manifests: updates for FCOS manifest
There have been a lot of changes to the CoreOS definitions in [1].
Let's update the test manifest here to more closely match what is
running in the field there.

[1] dcd60cfe01/src/osbuild-manifests
2024-12-18 11:09:29 -05:00
Dusty Mabe
aa11ec1ec1 test: add podman to fedora-build-v2 manifest
The org.osbuild.container-deploy stage uses podman. Including it
in the build here will allow that stage to be used with this
pipeline as the buildroot.

Include a workaround here for what I consider to be a bug [1] in that
`podman` will create `/etc/containers/networks` on first run if it
doesn't exist. That dir should just be created by an RPM. If we
don't include this workaround then the stage will fail when `podman`
attempts the `mkdir` because `/etc/containers` is mounted in from
the buildroot readonly.

[1] https://github.com/containers/common/pull/2265
2024-12-18 11:09:29 -05:00
Tomáš Hozza
139837f628 manifest_tests.py: use osbuild-image-info from osbuild package
Modify the test case to not use the image-info copy from manifest-db.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2024-12-18 12:50:32 +01:00
Tomáš Hozza
503cfb0936 CI: move the manifest_tests.sh from schutzbot/ to test/cases/
The test script should have been in the test/cases/ directory in the
first place.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2024-12-18 12:50:32 +01:00
Tomáš Hozza
7699f8134f Add org.osbuild.dnf5.sbom.spdx stage
Add DNF5 version of the `sbom.spdx` stage, which generates an SPDX SBOM
document from a given FS tree using libdnf5 API.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2024-12-18 05:46:45 +01:00
Michael Vogt
25d3656068 util,test: add test for new shlex based os-release parsing
This commit adds a tiny unit test for the new `shlex` based
os-release parsing and tweaks the error message in a small
and non-functional way (just because it's slightly nicer
for a user). The test checks for three keys NAME which is
quoted with `"`, ID which is not quoted and OSTREE_VERSION
which is quoted with `'`.
2024-12-04 14:54:00 -05:00
Renata Ravanelli
07d4f6955d util/osrelease.py: Replaced string stripping with shlex.split()
- Replaced string stripping with `shlex.split()` to properly
handle values in the os-release file;
- This ensures cleaner and more accurate key-value assignments,
follwing a broader set of shell-like parsing rules;
- Add os-release file for Fedora CoreOS 40 for testing.

Signed-off-by: Renata Ravanelli <rravanel@redhat.com>
2024-12-04 14:54:00 -05:00
Tomáš Hozza
f1c43ae5bd util/sbom/spdx: rename {,s}bom_pkgset_to_spdx2_doc()
Rename the function for consistency reason. The parent package is named
SBOM (originally BOM).

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2024-12-02 23:24:39 +01:00
Tomáš Hozza
def6a9fabd util/sbom: add support for DNF5
Add functions for transforming package sets depsolved using libdnf5 to
the SBOM standard-agnostic model. Cover the function with unit tests.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2024-12-02 23:24:39 +01:00
Tomáš Hozza
c3f3588419 test_util_sbom_spdx: fix imported module name
There was a typo in the imported module name, which caused the test to
be always skipped.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2024-12-02 23:24:39 +01:00
Tomáš Hozza
0a64f08f08 test_util_sbom_dnf: fix imported module name
There was a typo in the imported module name, which caused the test to
be always skipped.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2024-12-02 23:24:39 +01:00
Tomáš Hozza
7993b78e7c Testutil: add DNF5 helper function for depsolving
This will be used for testing the SBOM implementation with DNF5.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2024-12-02 23:24:39 +01:00
Tomáš Hozza
76a0d56690 Test/manifests: update fedora manifests to F41
Update the fedora manifest template to F41. This is a preparation for
testing a new `org.osbuild.dnf5.sbom.spdx` stage. In addition to that,
F39 is already EOL and unsupported, so moving to a newer version is
desirable.

Regenerate all testing manifests.

Notes about specific changes:
 - Remove `pcmciautils` package from ostree manifest, because it has
   been deprecated and it is not available on F41 any more.
 - Add `python3-dnf` package to the Fedora build pipeline. The reason
   is that DNF5 is installed by default since F41 and the module is
   needed to test e.g. `org.osbuild.dnf4.sbom.spdx` or
   `org.osbuild.dnf4.mark` stages.
 - Add `python3-libdnf5` package to the Fedora build pipeline. This is a
   preparation for testing a new `org.osbuild.dnf5.sbom.spdx` stage.
 - Install `pam` in `authselect` stage test manifest, because otherwise
   authselect fails on the nonexistence of /etc/pam.d.
 - Adjust the `dnf4.mark` test case to also accept `dnf5` as the marked
   package, because on F41, `dnf` is a virtual provide of it.
 - Adjust stage tests and their diffs as needed.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2024-11-28 13:29:12 +01:00
Dusty Mabe
85f3bc1f09 test/data/manifests/fedora-coreos-container: fix CI
We updated the container in the registry so we need to update this
manifest to unbreak CI.
2024-11-28 11:53:57 +01:00
Achilleas Koutsou
b9efc1f9bf test/users: modify root's home directory in stage test
Since 9071cd0abb the commands in the
org.osbuild.users stage are run using the osbuild.util.chroot.Chroot
context manager.  This includes mounting /proc into the chroot.

The `usermod` command now fails with

  usermod: user root is currently used by process N

when modifying any property of the root user that requires the user to
not be logged in (like the home directory).

Change the home directory of the root user in the stage test to check
for this issue and catch regressions.
2024-11-26 23:35:04 +01:00
Tomáš Hozza
3ac6d405b5 Fix pylint issue E0606: possibly-used-before-assignment
Fix:
assemblers/org.osbuild.qemu:310:36: E0606: Possibly using variable 'prep_type' before assignment (possibly-used-before-assignment)
inputs/org.osbuild.tree:85:15: E0606: Possibly using variable 'path' before assignment (possibly-used-before-assignment)
stages/org.osbuild.sfdisk:58:36: E0606: Possibly using variable 'prep_type' before assignment (possibly-used-before-assignment)
stages/org.osbuild.systemd.unit:23:16: E0606: Possibly using variable 'unit_dropins_dir' before assignment (possibly-used-before-assignment)
test/mod/test_meta.py:219:29: E0606: Possibly using variable 'schema_part' before assignment (possibly-used-before-assignment)

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2024-11-25 10:09:18 +01:00
Lukas Zapletal
32b1b91597 test: regenerate X509 test certs 2024-11-22 10:15:50 +01:00
Nikita Dubrovskii
6a59e740e4 parsing: treat locations without scheme as belonging to 'tree://' 2024-11-14 17:49:26 +01:00
Nikita Dubrovskii
077244e3b9 parsing: add parse_location_into_parts
New fucntion returns tuple of 'root' and relative 'file path', which could be
useful in contexts, where knowing 'root' is required, for example setting
selinux labels.
2024-11-14 17:49:26 +01:00
Lukas Zapletal
ef24311f77 sources: MTLS and proxy support for ostree 2024-11-04 16:35:53 +01:00
Simon de Vlieger
8429acf7e3 test: metadata in describe
Michael Vogt pointed out that testcases start failing when we describe
the new format. Let's add a test case and fix the describe to include
the metadata.

Metadata is freeform in the `Manifest` instance but it is stored on it
during loading (at which time its properties are validated) and returned
as-is on describe.

Signed-off-by: Simon de Vlieger <supakeen@redhat.com>
2024-10-29 08:24:33 +01:00
Simon de Vlieger
12dcf3c6d9 schema: metadata at the top level
Allows a new object under the top-level key `metadata` which contains a
`generators` property. This property is a list of all generators involved
in the creation of a manifest.

Each generator can add its name and version to this list.

Signed-off-by: Simon de Vlieger <supakeen@redhat.com>
2024-10-29 08:24:33 +01: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