Commit graph

899 commits

Author SHA1 Message Date
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
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
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
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
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
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
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
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
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
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
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
Michael Vogt
f0f9d8677a test: update the test cert to expire in 100y
When generating the original test certs no `-days` paramter was
passed which resulted in a too low `notAfter` value.

This commit fixes this and uses 100y also updates the README:
```
$ openssl x509 -enddate -noout -in test/data/certs/cert1.pem
notAfter=Aug  2 10:42:40 2124 GMT
$ openssl x509 -enddate -noout -in test/data/certs/cert2.pem
notAfter=Aug  2 10:42:45 2124 GMT
```
This fixes a test failure in https://github.com/osbuild/osbuild/pull/1819
for the `test_curl_download_many_mixed_certs` test.
2024-08-27 09:39:17 +02:00
Paweł Poławski
db08c472f3 general: Fix linter issues across the codebase 2024-08-26 11:59:46 -07:00
Michael Vogt
77a61da760 osbuild: drop libdir from download() methods
The libdir is passed down for sources but it is never used in
any of our sources. As this is confusing and we want to eventually
support multiple libdirs remove this code.

It looks like the libdir for soruces was added a long time ago in 8423da3
but there is no indication if/how it is/was supposed to get used and
AFACT from going over the git history it was very used.

SourceService:dispatch() never sends "libdir" to the actual sources,
so it is not an even technically an API break.
2024-08-26 19:58:55 +02:00
Achilleas Koutsou
fe1e310f2e test: add read/write tests for util.toml
Add two unit tests for our toml util module.
- Write an object with util.toml, read it with util.toml, and compare
  written and read objects.
- Write an object directly as a string, read it with util.toml,
  comparing with an expected object.

A test that writes with util.toml, reads as string, and verifies the
read string is difficult to do in a general way, because each toml
module we support writes files in a slightly different way.
2024-08-21 19:26:31 +02:00
Achilleas Koutsou
618ec9db2c test/update-crypto-policies: update diff file
With the mounting of /dev (among others) into the chroot for the
update-crypto-policies, the leftover /dev/null is now removed.

This was created by the update-crypto-policies script, running in the
chroot, by multiple output redirects into /dev/null.  Without a /dev fs,
the file was being created in the tree and would remain on the image.
2024-08-21 18:50:05 +02:00
Tomáš Hozza
a0b44c5c72 Test/stages: check dracut stage output for environment warnings
Extend the dracut stage test case with checks for error / warning
messages complaining about unsupported / incorrect runtime environment.

Messages such as:
```
/dev/fd/63: No such file or directory
```
or
```
/proc/ is not mounted. This is not a supported mode of operation.
Please fix your invocation environment to mount /proc/ and /sys/
properly. Proceeding anyway. Your mileage may vary.
```

The stage will be fixed in the next commit.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2024-08-15 19:56:20 +02:00
Michael Vogt
88c35ea306 osbuild: make inputs map() function use fd for reply as well
We recently hit the issue that `osbuild` crashed with:
```
Unable to decode response body "Traceback (most recent call last):
  File \"/usr/bin/osbuild\", line 33, in <module>
    sys.exit(load_entry_point('osbuild==124', 'console_scripts', 'osbuild')())
  File \"/usr/lib/python3.9/site-packages/osbuild/main_cli.py\", line 181, in osbuild_cli
    r = manifest.build(
  File \"/usr/lib/python3.9/site-packages/osbuild/pipeline.py\", line 477, in build
    res = pl.run(store, monitor, libdir, debug_break, stage_timeout)
  File \"/usr/lib/python3.9/site-packages/osbuild/pipeline.py\", line 376, in run
    results = self.build_stages(store,
  File \"/usr/lib/python3.9/site-packages/osbuild/pipeline.py\", line 348, in build_stages
    r = stage.run(tree,
  File \"/usr/lib/python3.9/site-packages/osbuild/pipeline.py\", line 213, in run
    data = ipmgr.map(ip, store)
  File \"/usr/lib/python3.9/site-packages/osbuild/inputs.py\", line 94, in map
    reply, _ = client.call_with_fds(\"map\", {}, fds)
  File \"/usr/lib/python3.9/site-packages/osbuild/host.py\", line 373, in call_with_fds
    kind, data = self.protocol.decode_message(ret)
  File \"/usr/lib/python3.9/site-packages/osbuild/host.py\", line 83, in decode_message
    raise ProtocolError(\"message empty\")
osbuild.host.ProtocolError: message empty
cannot run osbuild: exit status 1" into osbuild result: invalid character 'T' looking for beginning of value
...
input/packages (org.osbuild.files): Traceback (most recent call last):
input/packages (org.osbuild.files):   File "/usr/lib/osbuild/inputs/org.osbuild.files", line 226, in <module>
input/packages (org.osbuild.files):     main()
input/packages (org.osbuild.files):   File "/usr/lib/osbuild/inputs/org.osbuild.files", line 222, in main
input/packages (org.osbuild.files):     service.main()
input/packages (org.osbuild.files):   File "/usr/lib/python3.11/site-packages/osbuild/host.py", line 250, in main
input/packages (org.osbuild.files):     self.serve()
input/packages (org.osbuild.files):   File "/usr/lib/python3.11/site-packages/osbuild/host.py", line 284, in serve
input/packages (org.osbuild.files):     self.sock.send(reply, fds=reply_fds)
input/packages (org.osbuild.files):   File "/usr/lib/python3.11/site-packages/osbuild/util/jsoncomm.py", line 407, in send
input/packages (org.osbuild.files):     n = self._socket.sendmsg([serialized], cmsg, 0)
input/packages (org.osbuild.files):         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
input/packages (org.osbuild.files): OSError: [Errno 90] Message too long
```

The underlying issue is that the reply of the `map()` call is too
big for the buffer that `jsoncomm` uses. This problem existed before
for the args of map and was fixed by introducing a temporary file
in https://github.com/osbuild/osbuild/pull/1331 (and similarly
before in https://github.com/osbuild/osbuild/pull/824).

This commit writes the return values also into a file. This should
fix the crash above and make the function more symetrical as well.

Alternative/complementary version of
https://github.com/osbuild/osbuild/pull/1833

Closes: HMS-4537
2024-08-13 13:13:24 +02:00
Michael Vogt
29f926f305 jsoncom: gracefully report EMSGSIZE errors
When `jsoncomm` fails because the message is too big it currently
does not indicate just how big the message was. This commit adds
this information so that it's easier for us to determine what to
do about it.

We could also include a pointer to `/proc/sys/net/core/wmem_defaults`
but it seems we want to not require fiddling with that so let's
not do it for now.

See also https://github.com/osbuild/osbuild/pull/1838
2024-08-13 09:38:59 +02:00
Tomáš Hozza
f9ddab52f5 Update testing c9s BaseOS repodata snapshot
Use the latest c9s BaseOS repodata snapshot, specifically so that it
contains multiple versions of the same packages. This will allow to test
the `osbuild-depsolve-dnf` 'search' command. The previous metadata
contained only single version of each package.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2024-08-08 09:58:41 +02:00
Tomáš Hozza
ffd261bfff test_dnf4_mark(): disable all plugins when inspecting markings
When subscription-manager DNF plugins are enabled (e.g. on RHEL), they
produce messages to the stdout on any DNF command execution. E.g.
"Updating Subscription Management repositories.".

Disable all plugins when inspecting package markings so prevent them
from modifying the output.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2024-08-08 09:51:37 +02:00
Tomáš Hozza
12f81e053b Test/dnf4.mark: adjust the test for markings used by DNF5
When I rolled back from using 'dnf4', to check package markings, to
using 'dnf', I didn't verify the test case on Fedora Rawhide with DNF5.
It turns out that the strings reported by DNF5 differ and make the test
case fail. This time I tested the change on Fedora Rawhide with DNF5 and
it works.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2024-08-01 10:58:58 +02:00
Michael Vogt
7b16313ce2 main,monitor: fix total steps in progress reporting
The existing code to record progress was a bit too naive. Instead
of just counting the number os pipelines in a manifest to get the
total steps we need to look at the resolved pipelines.

with this fix `bib` will report the correct number of steps left
when doing e.g. a qcow2 image build. Right now the number of
steps is incorrect because the osbuild manifest contains pipelines
for qcow2,vdmk,raw,ami and all are currently considered steps
that need to be completed. With this commit this is fixed.
2024-07-31 23:00:33 +02:00
Michael Vogt
e535877798 test: add new https_serve_directory() and test certs
This commit adds a new `https_serve_directory()` test helper
and some custom self-signed and worthless certs that are used
during testing. They are not dynamically generated to avoid the
extra compuation time during tests (but they could be).

Generated via:
```
$ openssl req -new -newkey rsa:2048  -nodes -x509  \
   -subj "/C=DE/ST=Berlin/L=Berlin/O=Org/CN=localhost"   \
   -keyout "key1.pem" -out "cert1.pem"
```

This will allow us to test `https` download URLs as well in e.g.
the curl source.
2024-07-29 16:51:48 +02:00
Tomáš Hozza
52200c581d Test/dnf4.mark: make failures to parse dnf output easier to debug
The test case still fails on RHEL-10.0 Beta, even when not using dnf5,
with:

```
            for line in r.stdout.splitlines():
>               package, mark = line.strip().split(",")
E               ValueError: not enough values to unpack (expected 2, got 1)
```

Make debugging of failures like this easier by printing the line when
the issue happens.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2024-07-29 15:01:13 +02:00
Tomáš Hozza
a8f3a1e834 Test/dnf4.mark: make the test compatible with all dnf versions
Let's revert to using plain 'dnf', add an explicit newline in the query
format and skip empty lines when processing the output. This makes the
test case compatible with all DNF versions, even with dnf5 once this
issue gets fixed.

The previous approach didn't work on c9s / el9, because there is no
'/usr/bin/dnf4 -> dnf-3' symlink.

Also see:
https://github.com/osbuild/osbuild/actions/runs/10136827918/job/28026181824

Co-authored-by: Michael Vogt <michael.vogt@gmail.com>
Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2024-07-29 15:01:13 +02:00
Tomáš Hozza
4edbe227d4 Test: fix dnf4.mark stage test with DNF5
DNF5 contains a breaking change in the repoquery --qf output,
specifically it does not include the trailing newline. This breaks the
test case e.g. on the latest Fedora Rawhide [1].

As a fix, explicitly use 'dnf4' for now, until the inconsistency is
fixed in the upstream [2].

[1] https://artifacts.dev.testing-farm.io/3a3a2898-0a6a-42eb-8792-660f03c35c3c/
[2] https://github.com/rpm-software-management/dnf5/issues/709

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2024-07-25 12:23:53 +02:00
Gianluca Zuccarelli
92bb161501 stages/oscap.autotailor: make profile id required
According to `autotailor(8)` arguments passed in via the cli take
precedence over the JSON tailoring file contents.

Make the `new_profile` a required field for the json tailoring too and
pass it as an option to the `autotailor` command. This approach has some
trade-offs. It allows us to maintain the explicitness of the manifest
that is consumed by `osbuild`. The downside is that it will override the
profile id that is set by the user in the JSON tailoring file.
2024-07-17 13:14:48 +02:00
Gianluca Zuccarelli
2a28acbc85 stages/oscap.autotailor: rename new_profile
Rename the `new_profile` option to `tailoring_profile_id` for clarity.
This also ensures that the change is backwards compatible by falling
back to the `new_profile` option if that was set instead of the
`tailoring_profile` id option.
2024-07-17 13:14:48 +02:00
Michael Vogt
f7d56b3d7e tests: update l2hash for the fc40 move
Similar to what was explained in 2e6d49fbe this commit updates
the l2hash in test_assemblers to the new values from fc40 images.

Sadly it is hard to derive them from first principles (see the
other commit) and given that this is legacy code it is probably
fine this way.
2024-07-02 09:46:45 +02:00
Tomáš Hozza
d15ce4bb11 Test/assemblers: update manifest to use Fedora 40
Fedora 38 is EOL and unfortunately so are our F38 snapshots. Lets
update the manifest to F40.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2024-07-02 09:46:45 +02:00
Florian Schüller
41f528eeb2 osbuild/monitor.py: improve naming of progress 2024-06-18 16:00:55 +02:00
Gianluca Zuccarelli
8b67b02dfa test/cases: fix users stage
Since the `/etc/shadow` file contains a timestamp we need to add a
`null` value rather than a `sha256` hash to tell the diff tool to ignore
these fields. The issue is that the timestamp will always be different
meaning the tests will pass for a day, but then fail after that.
2024-06-06 14:48:32 +01:00
Tomáš Hozza
1d0952002b Test/stages/users: fix diff.json
I'm not sure what happened, but the test case started failing on the
diff on 'main'. I didn't change anything related to this test case in my
PR. The previous changes adjusted the vars, specifically the Fedora
snapshot date used to generate the manifests, but the test passed on
it.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2024-06-04 19:39:39 +02:00
Tomáš Hozza
c06fda60b6 Test/stages: update udev.rules test case to not use F34
Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2024-06-04 19:39:39 +02:00
Gianluca Zuccarelli
8985155157 test: test autotailor json import
Add a test to ensure that json tailoring import is supported for the
`oscap.autotailor` stage.
2024-05-31 19:51:46 +01:00
Gianluca Zuccarelli
ad265a519d test: update stage diffs for snapshot 20240514
Since updating the snapshots the diffs for some stage tests have
changed. This commit updates the diffs accordingly.

I followed the same steps used in 1148a6e.
2024-05-31 19:51:46 +01:00
Gianluca Zuccarelli
3f92d91fbf manifest/fedora-vars: update snapshot
We need a minimum version of `oscap-utils-1.3.10` which is available
in the `20240508` updates snapshot.
2024-05-31 19:51:46 +01:00
Tomáš Hozza
13035e6f4e Test/manifests: use SHA256 signed GPG key for c9s
The original CentOS Stream GPG key uses SHA-1 in its signature. However,
SHA-1 is by default not allowed by the c10s / el10 crypto policy. As a
result, running the stage tests which use c9s on c10s / el10 are failing
when rpmkeys tries to import the key.

As part of CS-1616 [1], the CS GPG key has been resigned using SHA256,
however only in c10s for now. Let's use the SHA256 signed GPG key from
c10s for c9s manifests, to make tests pass also on c10s / el10.

[1] https://issues.redhat.com/browse/CS-1616

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2024-05-30 20:56:33 +02:00
Michael Vogt
ad13333f36 test: tweak test_osbuild_mount_failure_msg() for tmt/fc40
The `test_osbuild_mount_failure_msg` currently fails on fc40 when
run in tmt, see:
https://artifacts.dev.testing-farm.io/c6588a82-a2cb-46df-8ca8-85dd809465f2/

This is because the failure output is slightly different between
a container and a VM/real-machine. The test ensures that we capture
the output of mount and present to the user (for easier debugging).
So this commit updates this test once more for the error string
(that part of the error comes directly from the kernels fsconfig).

If we need another update of the string we should reconsider this
test and e.g. just use `testutil.mock_command()` for this. But
for now it's easier to just add this one more failure string.
2024-05-23 14:56:41 +02:00
Tomáš Hozza
2161798312 Test/buildroot: fix checking /var/tmp mode
The motivation for this change is to fix a failing unit test in c9s
CI. Specifically an instance of:

https://artifacts.dev.testing-farm.io/2d07b8f3-5f52-4e61-b1fa-5328a0ff1058/#artifacts-/plans/unit-tests
https://gitlab.com/redhat/centos-stream/rpms/osbuild/-/merge_requests/135

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2024-05-16 09:58:38 +02:00
Paweł Poławski
91c6352c80 tests: Update stage tests readme
Readme was pointing to the dead ling with manifest v2 documentation.
I have redirected it to the documentation presented in repo.
2024-05-13 11:19:26 -07:00
Michael Vogt
4f4bddcc75 test: add "functional" test for devices/mounts acceptance
This test ensures that the inputs of devices/mounts we generate for
bootc are actually considered valid by the schema. This is a more
blackbox style test compared to `test_get_schema_automatically_added`
which just checks that we get the expected schema but not that the
expected schema actually parses our inputs.
2024-05-03 11:26:22 +02:00
Michael Vogt
a0d4dfa575 osbuild: fix error match in mount test for fc40
Similar to 4a51baf this fixes another issue in the mount error
checking where the error message changed.
2024-05-02 12:09:44 +02:00