Commit graph

1339 commits

Author SHA1 Message Date
Christian Kellner
7f50d2b57f buildroot: don't specify encoding for popen
Since low-level primitives (os.read) are used to read from the stdout
pipe, manual text decoding was necessary there anyway. The `encoding`
argument meant that we could forgo the manual decoding for the call
to `communicate`. But this meant that text handling is not uniform.
Therefore, remove the `encoding` argument from the `Popen` call and
manual decode all the text.
2021-06-09 18:37:47 +01:00
Christian Kellner
13e629ba72 test/host: test for host services
Implement basic checks for the new host service scaffolding.
2021-06-09 18:37:47 +01:00
Christian Kellner
0562f5daf8 osbuild: introduce host services
Host services are a way to provide functionality to stages that is
restricted to the host and not directly available in the container,
such as providing input to stages, devices access and mounting.
This commit introduces a `ServiceManager` class that can be used to
start and (automatically) stop host service, as well as a `Service`
base class together with a `ServiceClient` class that be used to
implement host services and communicate with them. Refer to the doc
string of the module for more information.
2021-06-09 18:37:47 +01:00
Christian Kellner
70b971b83d util/jsoncomm: add send_and_recv helper
Often, a message is being sent and followed by a call to `recv`
to wait for a reply. Create a simple helper `send_and_recv` that
does both in one method.
Add a simple check for that helper to the tests.
2021-06-09 18:37:47 +01:00
Christian Kellner
610d1c45d5 util/jsoncomm: ability to create socket from fd
Add a new constructor method that allows creating a `Socket` from
an existing file-descriptor of a socket. This might be need when
the socket was passed to a child process.
Add a simple test for the new constructor method.
2021-06-09 18:37:47 +01:00
Christian Kellner
0447b00dfc util/jsoncomm: add pair constructor method
Add a new constructor method, `Socket.new_pair`, to create a pair
of connected sockets (via `socketpair`) and wrap both sides via
`jsoncomm.Socket`.
Add a simple test to check it.
2021-06-09 18:37:47 +01:00
Christian Kellner
a8fcda8348 meta: support definitions in schema version 2
For schema version 2 of modules, the `definitions` node, as defined in
the module itself, won't be at the `options` level but at the level of
the `properties` node. Look for a `definitions` at that `properties`
level and move it to the top, if found.
2021-06-09 18:37:47 +01:00
Christian Kellner
98a82ff47e aarch64: use single qemu-img thread
Work around a bug on aarch64[1] where `qemu-img` would hang
about a third of the time when converting images. To be able 
to activate the work-around based on the environment, i.e.
only on certain distributions, introduce an environment
variable, `OSBUILD_QEMU_IMG_COROUTINES`, that is set in the
runner and then picked up in the assembler.

[1] https://bugs.launchpad.net/qemu/+bug/1805256
2021-06-09 11:57:26 +02:00
Christian Kellner
1fbe4bb31a runners/rhel82: extract code into main function
Move the code in `__main__` to a `main` function to not pollute the
global namespace.
2021-06-09 11:57:26 +02:00
Christian Kellner
7ad212dc89 runners/rhel82: fix spacing between functions
Two lines between functions, demanded by PEP-8.
2021-06-09 11:57:26 +02:00
Christian Kellner
3a85c196f7 spec: move all ostree modules to the sub-package
When new ostree related stages and the new ostree input was added
they were included in the main package since all the modules were
manually listed in the corresponding exclude/include sections.
Change that by using wildcards, since all ostree related modules
should start with the org.osbuild.ostree* pattern.
2021-06-08 22:30:51 +02:00
Christian Kellner
5707c0a5b9 meta: proper error reporting for schema parsing
When parsing the module file, parse the JSON directly from the AST
node, because the AST node contains the line number of the schema
in the  module and thus we can resolve the correct line number for
errors  within the JSON. Convert the `JSONDecodeError` to a
`SyntaxError` which results in an overall better exception message:

Before:
Traceback (most recent call last):
  File "/workspaces/osbuild/osbuild/meta.py", line 331, in get_schema
    opts = self._make_options(version)
  [...]
  File "/usr/lib64/python3.9/json/decoder.py", line 353, in raw_decode
    obj, end = self.scan_once(s, idx)
json.decoder.JSONDecodeError: Expecting property name enclosed in
                              double quotes: line 2 column 1 (char 14)

After:
Traceback (most recent call last):
  File "/usr/lib64/python3.9/runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  [...]
    raise SyntaxError(msg, detail) from None
  File "stages/org.osbuild.ostree.init-fs", line 31
    additionalProperties: False
    ^
SyntaxError: Invalid schema: Expecting property name enclosed in ...
2021-06-07 17:55:00 +02:00
Christian Kellner
91e7708d80 meta: small whitespace fixes
Remove an extra line and properly align an closing bracket.
2021-06-07 17:55:00 +02:00
Christian Kellner
475b41c49a meta: promote list of modules to class level
Define the mapping of modules and their paths at the `ModuleInfo` class
level instead of having it inline in a function. This makes it possible
to use it from other places in the code.
2021-06-07 17:55:00 +02:00
Tomas Hozza
1c3aadba20 stages/dracut: disable hostonly mode and default to reproducible images
Disable host-only mode when running dracut and generate reproducible
images by default.

Suggested-by: gicmo
Signed-off-by: Tomas Hozza <thozza@redhat.com>
2021-06-07 12:15:26 +02:00
Tomas Hozza
8d43a78918 test: update test manifests to use Fedora 34
Move from using 'zram' to 'zram-generator-defaults' in the ostree bootiso
testing manifest. More information is available in Fedora 33 Change
document [1].

Add org.osbuild.kernel-cmdline stage to fedora-boot.json manifest
because of change in how grub handles the kernel command line arguments
[2].

GRUB2 Stage 2 checksums in assemblers test are updated. The change have
been verified by building the fedora-boot.json manifest with each checked
filesystem and booting the image in QEMU with legacy mode.

[1] https://fedoraproject.org/wiki/Changes/SwapOnZRAM
[2] https://github.com/osbuild/osbuild-composer/pull/982#issuecomment-697356929

Signed-off-by: Tomas Hozza <thozza@redhat.com>
2021-06-07 12:15:26 +02:00
Martin Sehnoutka
ee3760e1ba sources/curl: Implement new way of getting RHSM secrets
The previous version covered too few use cases, more specifically a
single subscription. That is of course not the case for many hosts, so
osbuild needs to understand subscriptions.

When running org.osbuild.curl source, read the
/etc/yum.repos.d/redhat.repo file and load the system subscriptions from
there. While processing each url, guess which subscription is tied to
the url and use the CA certificate, client certificate, and client key
associated with this subscription. It must be done this way because the
depsolving and fetching of RPMs may be performed on different hosts and
the subscription credentials are different in such case.

More detailed description of why this approach was chosen is available
in osbuild-composer git: https://github.com/osbuild/osbuild-composer/pull/1405
2021-06-04 18:23:05 +01:00
Ondřej Budai
4f00e282ca readme: add IRC 2021-06-04 15:10:12 +02:00
Ondřej Budai
b5e324c874 ci: remove Fedora 32 tests
It's EOL.
2021-06-04 15:08:38 +02:00
Ondřej Budai
ef0939db9b ci: remove RHEL 8.4 tests
RHEL 8.4 is now GA, so we don't need any extra tests for it. This should also
make the CI more reliable because having two distros with the same DISTRO_CODE
caused some tests to fail randomly (they used the same intermediate
artifacts).
2021-06-04 15:08:38 +02:00
Christian Kellner
ec4d7c0c1c test/manifests: annotations for ostree container
Include the new OSTree specific annotations in the ostree container
manifest.
2021-05-26 13:17:01 +02:00
Christian Kellner
722211df00 stages/oci-archive: define ostree annotations
Define a set of pre-defined ostree related annotations that can
and should be used to indicate that a container image contains
an OSTree commit. This can be used by other tools to inspect and
extract the commit more easily.
2021-05-26 13:17:01 +02:00
Christian Kellner
65d831b2cb stages/oci-archive: support for annotations
Add support for arbitrary manifest annotations: allow anything
with the exception of the `org.osbuild` and `org.opencontainer`
prefixes. The former is reserved by us, the latter by the OCI
image specification. The latter specifies a set of pre defined
keys, which are not yet supported by osbuild but will be in the
future, partly via more generic options (creation time).
2021-05-26 13:17:01 +02:00
Christian Kellner
2dfb6a224b tools: add inline-source.py
Add a simple tool that will spit out a valid org.osbuild.inline
source entry that encodes the given file. Currently always uses
base64 as encoding and sha256 for the hashing.
2021-05-12 14:26:16 +02:00
Christian Kellner
f75cb1d56d test/sources: add checks for org.osbuild.inline
Check for the empty `items` case, an invalid checksum case and
of course a valid case.
2021-05-12 14:26:16 +02:00
Christian Kellner
2025184325 sources: introduce org.osbuild.inline
Add a new source for transporting binary data within the source
entry itself. The data is ascii encoded in the `data` property
of the inline source item, with the encoding that is used being
specified in the `encoding` property.
2021-05-12 14:26:16 +02:00
Christian Kellner
3ebfc6f657 sources/curl: use util.checksum.verify_file
Now that there is a common utility function to verify the checksum
of a file, use that.
Also fix the json schema entry for the property to have to correct
minium and maximum digest length, given the supported algorithm,
which is 32 (md5) and 128 (sha512) characters.
2021-05-12 14:26:16 +02:00
Christian Kellner
f000b8e6cb test/mod: add checks for util.test_util
Test that `checksum.verify_file` works correctly, which internally
uses the only other utility function `checksum.hexdigest_file`.
Check all algorithms currently supported by the `org.osbuild.curl`
source.
2021-05-12 14:26:16 +02:00
Christian Kellner
3236bbb8da util: add new checksum related utilities
Small convenience functions to work with checksums, specifically
working with files and their checksums.
2021-05-12 14:26:16 +02:00
Christian Kellner
89f372fa3c setup.cfg: set max line length in pycodestyle
Move the max-line-length setting to the `pycodestyle` section,
which is read by pylint but also other tools like autopep8.
2021-05-12 14:26:16 +02:00
Christian Kellner
6567b8f932 setup.cfg; move pylint settings here
Create a setup.cfg file and move the pylint settings from .pylintrc
here. This file can be used to configure other tooling as well, so
it is in general more useful as a central configuration place.
2021-05-12 14:26:16 +02:00
Christian Kellner
e97285e00a test/sources: add checks for org.osbuild.ostree
Add basic checks for the ostree source, which includes a successful
pull of a commit, an empty source entry and one where the specified
commit is non-existant. For this create a simple commit in a ostree
repo is checked in. The commit was created via:

  mkdir "/tmp/data"
  echo "Hello World" > /tmp/data/hello.txt
  ostree init --repo test/data/sources/org.osbuild.ostree/data/repo \
              --mode=archive

  ostree commit --repo test/data/sources/org.osbuild.ostree/data/ \
                --branch "test/ostree" /tmp/data \
                --timestamp="1995-05-13 12:34:56 +0000"
This should give an commit with the following commit id:
  d6243b0d0ca3dc2aaef2e0eb3e9f1f4836512c2921007f124b285f7c466464d8
2021-04-29 12:58:01 +02:00
Christian Kellner
a05a8aaed6 sources/ostree: remove export functionality
Since the `sources.SourcesServer` has been removed, nothing is
using the export functionality anymore. Inputs are now used to
make content in the store available to stages. Remove all the
export logic from org.osbuild.ostree.
2021-04-29 12:58:01 +02:00
Christian Kellner
92fad13dbf test/sources: tmpdir as fixture
Instead of creating the temporaroy directory within the unit test,
provide it to the test via a test fixture.
2021-04-29 12:58:01 +02:00
Christian Kellner
518940cfe0 sources/curls: refactor downloading code
Now that the `export` functionality is gone, the download code
can be simplified, since we are not downloading a subset of the
urls, but all of them.
2021-04-29 12:58:01 +02:00
Christian Kellner
5c19360cbe sources/curl: remove export functionality
Since the `sources.SourcesServer` has been removed, nothing is
using the export functionality anymore. Inputs are now used to
make content in the store available to stages. Remove all the
export logic from org.osbuild.curl.
2021-04-29 12:58:01 +02:00
Christian Kellner
aa19a1c4c0 sources: remove server and get method
The usage of the `sources.SourcesServer` and `sources.get` have
been removed from `Stage.run`, which was the only usage throughout
osbuild and thus it is not needed anymore and can be removed.
2021-04-29 12:58:01 +02:00
Christian Kellner
f1b406a774 pipeline: remove sources server
All sources are now pre-fetched before any pipeline and thus any
stage is being built. Additionally, in the version 1 foramt, all
stages that were using source are converted to use inputs when
the manifest is loaded. Thus, nothing should use `source.get`
and thus the sources API (`SourcesServer`) anymore.
2021-04-29 12:58:01 +02:00
Christian Kellner
fd21da3aa6 test/sources: use pytest.mark.parameterize
Parameterize `test_sources` via `pytest.mark.parameterize`, so that
now the product of source and test cases for that source is visible
to pytest and thus also the caller.
2021-04-29 12:58:01 +02:00
Christian Kellner
7a48c3b734 test/sources: check Source.download
Instead of testing the legacy `SourcesServer` and `sources.get`,
test the `Source.download` method, which is the new and exclusive
way how sources are used in osbuild. For this, the complete info
for a specific source is now included the specific test case.
For the `org.osbuild.curl` source this means that the respective
information is moved from `sources.json`, which is then unused
and thus removed. The test case that checks for an unknown
checksum is also removed because `Source.download` just fetches
everything instead of a subset.
2021-04-29 12:58:01 +02:00
Christian Kellner
3c66d1e4f5 test/sources: convert to pytest
Use `pytest`, which is a dependency of osbuild since a few versions,
instead of `unittest` for the source tests. The main reason is to be
able to use `pytest.mark.parameterize` in the near future to easily
generate a test matrix.
2021-04-29 12:58:01 +02:00
Achilleas Koutsou
1476b88dcf schutzbot: add RHEL 8.5 2021-04-19 09:12:21 +02:00
Christian Kellner
eb74ddf2ef 28
This completes the development of osbuild version 28.
2021-04-08 19:27:48 +02:00
Christian Kellner
925e205ee3 NEWS: update for osbuild version 28 2021-04-08 19:27:48 +02:00
Christian Kellner
94dedfc849 devcontainer: specify the workdir
Set the workdir to the osbuild source directory; this makes it
convenient when using docker/podman exec into the container.
2021-04-08 12:56:06 +02:00
Christian Kellner
1f86a2156d devcontainer: preserve history
Use a separate volume for /root/.local/share, which is where the
fish shell keeps its history file, in order to preserve it across
container rebuilds.
2021-04-08 12:56:06 +02:00
Christian Kellner
65cf620d4b devcontainer: install additional packages
Install more more tools and utilities that help with development
and testing of osbuild inside the dev container.
2021-04-08 12:56:06 +02:00
Christian Kellner
e7620feca4 assemblers/qemu: support for qcow2 compat version
Add a new option `qcow2_comapt` which can be used explicitly
select the compatibility level of the qcow2 file format. Qemu
version 1.1 introduced extensions to the format that became
the default with 1.7, which are not readable by qemu < 1.1.
Thus if the resulting qcow2 should be read by such older qemu
versions, the compatibility level needs to be set to 0.10.
2021-04-08 10:22:56 +02:00
Christian Kellner
d37bf0375b stages/oci-archive: write history entries
According to the OCI Image Format Specification[1] history entries
for layers in the container are optional; but when trying to push
a container quay.io via skopeo (copy oci-archive:… docker://quay)
it will fail with "Cannot convert an image with 0 history entries".
This seems to come from the containers/image[2] library when the
container is converted back from the docker distribution format
to oci-archive on quay.io. Thus it seems that when skopeo converts
the image to the docker format for the distribution it does not
fill any the history entries, which are then assumed and required
to be there when converting back.
To fix this, insert history entries for each layer that is created.

[1] https://github.com/opencontainers/image-spec/blob/master/config.md
[2] https://github.com/containers/image/
2021-04-07 19:19:16 +01:00
Christian Kellner
8429b08e79 stages/oci-archive: include limited set of xattrs
Only include a very specific set of extended attributes:
  - user.*: user specified extended attributes
  - security.ima: Integrity Measurement Architecture (IMA)
  - security.capability: Linux capabilities(7)
This follows what containers/storage[1] and containers/buildah[2]
are doing. It is important to note that we DO NOT want selinux
related extended attributes (`security.selinux`) in there, which
seems to be pulled in by some versions of `tar` even if that was
seemingly excluded via `--no-selinux`. Therefore we also exclude
selinux and xattrs explicitly from the wrapping container to
make sure they are never included.

[1] 35ebda8ae2/pkg/archive/archive.go (L399)
[2] 214e4c9335/copier/xattrs.go (L19)
2021-03-31 15:04:34 +01:00