Commit graph

823 commits

Author SHA1 Message Date
Christian Kellner
7171eb2bf3 osbuild: add custom selinux policy
A usual step in creating OS file system trees is to apply the
correct SELinux labels for all files and directories. This is
done by the org.osbuild.selinux stage, which internally uses the
setfiles command in order to do so. The SELiunx policy to be
used for this operation is the one of the newly created system,
not the host one. It therefore can contain labels that are not
known on the host. The kernel will prevent setting invalid,
i.e. unknown, labels unless the caller has the CAP_MAC_ADMIN
capability. By default, setfiles is executed in the setfiles_t
domain, where it lacks that capability. Therefore a custom
osbuild SELinux policy was created, with a special transition
rule that will execute setfiles in the setfiles_mac_t
domain. All stages, sources and assemblers as well as the main
binary are label with the new osbuild_exec_t label.

Additionally, allow a transition from osbuild_t to install_t by
using `anaconda_domtrans_install`, so that ostree and
rpm-ostree, which are labeled as install_exec_t, can transition
to the install_t domain when called form osbuild.  Update the
spec file to build the policy and include it in a new
osbuild-selinux sub-package.
2020-06-10 01:35:05 +02:00
Christian Kellner
696219dab9 util/ostree: accept typing.List for List[str]
In python 3.6 the value of `__origin__` for typing.List[str] is
typing.List. This then changed to the actual `list` type in later
versions. Accept both versions.
2020-06-09 13:42:35 +02:00
Christian Kellner
7a2ad6f0f8 osbuild: replace capture_output in subprocess.run
The `capture_output` argument for subprocess.run was added in 3.7,
but want to support 3.6 as well. Change all the usages of it with
`stdout=subprocess.PIPE` that will have the same effect, at least
for stdout.
2020-06-09 13:42:35 +02:00
Lars Karlitski
d7d1d9dbbf Take care not to put large content on /tmp
Most stages and assemblers already use `/var/tmp` to store large
files or trees. Do this in the qemu assembler and copy stage as well.
2020-06-09 09:12:05 +02:00
Tom Gundersen
cf8216aea9 sources/files: don't spam stderr with error messages
Silence the errors, but include instead the error code in the returned
error message.

Signed-off-by: Tom Gundersen <teg@jklm.no>
2020-06-07 22:08:34 +02:00
Tom Gundersen
d8e0469516 sources/files: don't retry curl on the same URL
The retry logic was meant to work around issues where a round-robin
redirect of mirrors gave us random mirrors of varying quality. This was
not used in practice, rather fixed mirrors were always used (either
hard-coded as basurl, or resolved from metalink).

The retry logic meant that when we did hit very slow mirrors we would
time-out and retry, potentially failing altogether, even though the data
was coming. Each retry would not help, as the mirror was anyway the
same. As a result our CI gave us avoidable false negative test results
some of the time.

The proper solution to this is to gain support for librepo and metalinks
to adopt the same retry logic that dnf uses.

For now, improve on the retry logic by retrying until a max total time,
rather than an increasing timeout on each try. Up the given timeouts to
be one minute to connect and five minutes to complete the download. This
avoids hanging forever if the mirror is truly broken, but still gives
more time to finish the download than each iteration in the old code
did.

There are no new tests for this, as before this change the tests mostly
passed, and after it they will hopefully still mostly pass (but more
often).

Signed-off-by: Tom Gundersen <teg@jklm.no>
2020-06-07 22:08:34 +02:00
Tom Gundersen
10a9f16852 test: move all test manifests to get fedora packages from kernel mirrors
This replaces the round-robin mirror at fedoraproject.org, as that was
proving to be quite unreliable.

This is a short-term fix before add metalink support.

Signed-off-by: Tom Gundersen <teg@jklm.no>
2020-06-07 22:08:34 +02:00
Major Hayden
11c1063729
Run image tests in PSI only
AWS does not have nested virtualization.
2020-06-05 13:14:30 -05:00
Major Hayden
daec7e8234 Add CI details script
Dump data about the machine running the test very early in the job run.

Signed-off-by: Major Hayden <major@redhat.com>
2020-06-05 13:11:01 -05:00
Major Hayden
381abb354a Use S3 for CI repositories
Upload artifacts from the mock builds into S3 to allow us to burst into
AWS when needed.

Signed-off-by: Major Hayden <major@redhat.com>
2020-06-05 09:43:09 -05:00
David Rheinsberg
5c3ce5c30a ghci: merge unittest invocations
Merge all unittest invocations into a single Github-Workflow Job. This
simplifies our workflow and allows us to easily parallelize individual
jobs.
2020-06-05 09:27:40 +02:00
David Rheinsberg
06af246f38 test/assemblers: use F32 manifest
Switch to the fedora-boot.json manifest, so we automatically use the
latest fedora manifest for assembler-tests.
2020-06-05 09:27:40 +02:00
David Rheinsberg
0010514c4a test: move assembler-tests into ./test/run/
Move the last remaining test into the correct subdir. With this done,
all our tests run in one of the 3 groups:

   * `make test-src`
     Run tests against the source-code, including linters.

   * `make test-mod`
     Run unit-tests on the individual python modules. This needs no
     special permissions (unless noted in each test) or runtime
     environments. It is meant to be fast and easy to run in all
     circumstances.

   * `make test-run`
     Run tests that execute the osbuild pipeline. This requires
     superuser privileges and will likely take a while. Furthermore,
     this might produce large artifacts.
2020-06-05 09:27:40 +02:00
David Rheinsberg
55da864e0a build: align makefile targets with test-targets
Align the makefile targets with the test-targets (`module` -> `mod`,
etc.). This way, we have consistent names everywhere.

While at it, move the `make test-run` invocation closer to the others.
2020-06-05 09:27:40 +02:00
David Rheinsberg
d584a1e225 test: move stage-tests into test/run and test/data
Move the stage-tests over to the new test-infrastructure. This moves
the test invocation into `./test/run/test_stages.py`, so it is invoked
as part of the runtime-tests. Secondly, the test-data is stored in
./test/data/stages/ so the path is relative to
TestBase.locate_test_data().

While at it, this also drops the dynamic class modifications and instead
uses subTest(). This simplifies the code quite a bit and avoids
dynamically creating python code.
2020-06-05 09:27:40 +02:00
David Rheinsberg
e8445da3d9 test: move test_osbuild.py into module tests
Move the `test_osbuild.py` test into the module-test directory. This
test contains just a bunch of basic functionality tests for a selection
of osbuild modules. Hence, it can be run together with the other module
tests.
2020-06-05 09:27:40 +02:00
David Rheinsberg
3cf8b79e80 test: move test_objectstore into module-tests
Move `test_objectstore` into the module-level tests. This allows us to
run it as part of `make test-module.

Make sure to properly guard it as root-only module.
2020-06-05 09:27:40 +02:00
David Rheinsberg
9bb6123963 test: convert test_boot to runtime tests with F32
Move the `test_boot` suite into ./test/run closer to the other runtime
tests, and convert the used manifest over to an MPP based F32 manifest.
2020-06-05 09:27:40 +02:00
David Rheinsberg
6e8562f712 test: make source-tests relative to ./test/data/
This moves the `sources_tests` into ./test/data/sources/ and makes the
entire test use `locate_test_data()` to get relative paths for their
accesses.

This further improves our test cases to support running from
installments rather than local checkouts. We need access to ./test/data
guarded, so we can install packages and still have the tests access the
correct paths.

This also adjusts the HTTP-Server we use in the test to serve data
relative to a path it is handed. I now chose `./test/data`, which will
easily allow us to re-use the same HTTP-Server in the future for other
tests that require it.
2020-06-05 09:27:40 +02:00
David Rheinsberg
4b85f48b12 test: include grub2-pc in f32-build.json
We need the `grub2-pc` RPM to install grub, so make sure we provide it
in our f32-build.json manifest.
2020-06-05 09:27:40 +02:00
David Rheinsberg
240905d4a0 test: make TestBase inherit unittest.TestCase
We want to extend our base-class to support extensions to
unittest.TestCase, so make sure we inherit from it.

Adjust all callers to no longer inherit from TestCase, since this is now
done automatically by TestBase.
2020-06-05 09:27:40 +02:00
David Rheinsberg
06119f7d88 tools: move tree-diff into ./tools
Move the `tree-diff` tool into ./tools, which is our new place for tools
used by the test-suite or during development.

The only hard-coded user is the TestBase, so fix its path to the tool
so the test-suite will continue to find it.
2020-06-05 09:27:40 +02:00
David Rheinsberg
2aa9755f88 ci: regenerate test data
Run the MPP tools in the CI and verify the committed test-data did not
change and is up-to-date.

This runs `make test-data` and then simply uses `git diff --exit-code`
to trigger a CI failure if there are any differences in ./test/data.
2020-06-05 09:27:40 +02:00
David Rheinsberg
020e78d571 test: import build-pipelines
Extend the `f32-base.json` manifest to use our F32 build-root. Use the
new mpp-import-pipeline preprocessor to include `f32-build.json` as
build-root.
2020-06-05 09:27:40 +02:00
David Rheinsberg
ae8910e02c tools: add pipeline-import mpp
This adds a new MPP which supports importing pipelines from another
file. It simply looks for "mpp-import-pipeline" tags at the same
position where we would expect a "pipeline" tag. It then uses the "path"
attribute in it to find a manifest. From this manifest, the "sources"
are merged back into the original sources, and the "pipeline" is taken
verbatim to replace the "mpp-import-pipeline".

The idea is to allow importing build-pipelines from other files into our
test manifests, without duplicating the build-pipeline everywhere.
2020-06-05 09:27:40 +02:00
David Rheinsberg
a3d1e3ff50 test: import no-op test into the runtime-tests
Add a new trivial runtime-test which simply runs a no-op pipeline. This
is a fast, trivial test that simply verifies osbuild is properly setup
and accessible.

Remove the explicit no-op test from the CI, now that the test-suite has
it as well.
2020-06-05 09:27:40 +02:00
Christian Kellner
162797f206 NEWS.md: update for osbuild version 16
Major changes are the support for ignition, that assembler results
wont be automatically committed anymore, a new org.osbuild.copy
stage, the removal of the `tree_id` & `output_id` as well as full
manifest validation due to the addition of source schema validation.
2020-06-04 16:22:59 +02:00
Christian Kellner
af7ef2ec3e test/stages: replace fau.de mirror with kernel.org
Recently downloading rpms from the fau.de mirror is failing quite
often with timeouts. Replace its only usage in the rpm stages
test with the kernel.org mirror.
2020-06-04 13:50:32 +02:00
Christian Kellner
7897e662fd stages/rpm-ostree: add initramfs-args
Add a new stage option `initramfs-args`, that will in turn be set
on the Treefile that is then passed to rpm-ostree. This will pass
the options on to dracut when building the initramfs module. NB:
the `ostree` dracut module will also always be automatically
included by rpm-ostree.
2020-06-04 10:25:39 +02:00
Christian Kellner
52f33d56b7 ostree: add 'initramfs-args' option to Treefile
Add the initramfs-args Treefile option that can be used to pass
arguments to drauct via rpm-ostree. NB: the ostree module will
always be automatically be included by rpm-ostree.
2020-06-04 10:25:39 +02:00
Christian Kellner
c91333aea8 stages: add org.osbuild.ignition stage
This stage will create a file '/boot/ignition.firstboot' that will,
with the help of support in grub, trigger ignition on the first
boot. The `network` option can be used to overwrite the default
network configuration set in grub2.
2020-06-04 10:25:39 +02:00
Christian Kellner
be6358d73f stages/grub2: support for ignition
Add support for ignition[1] via a new `ignition` stage option. If
enabled, a new section is added to the main grub.cfg that will
create a 'ignition_firstboot' variable meant to be included in the
kernel command line configuration.
The grub.cfg snippet was taken from 'src/grub.cfg' of Fedora CoreOS
Assembler[2] at ec05cde20d3449fab8e4c76493ffa1ebd9b0b626 but with
PR #1373 applied to not hard-code the dhcp options.

[1] https://github.com/coreos/ignition
[2] https://github.com/coreos/coreos-assembler/
2020-06-04 10:25:39 +02:00
Christian Kellner
3f14ace5c1 stages/users: support new users w/ duplicate uids
When adding a new user with a uid that already exists, the "-o",
option needs to be added. Always do so when the uid is specified.
A use case for this is e.g. an installer iso with a `install`
user that has 0 (like root) for its uid (and gid).
2020-06-03 17:09:55 +02:00
Christian Kellner
04d3c0fc17 stages/users: fix conditionals for zero & "" strs
Support setting uids, gids with values of `0` as well as passwords
and descriptions with the empty string, by explicitly checking the
value of each against `None`, because simple `if` conditionals are
false for those.
2020-06-03 17:09:55 +02:00
Tom Gundersen
fca588d4b5 stages/rpm: make GPG signature verification opt-in
The content hash of each RPM is already verified, so verifying
signatures again is not necessary if the manifest generation is trusted,
and verifying signatures does not help if the manifest generation is
not.

Let us follow what DNF does and default to not verify signatures, but in
order to preserve features already in use we still allow opting in to
verifying signatures as before on a per RPM basis.

This will make it possible to install unsigned RPMs, or a mixed of
signed and unsigned RPMs.

Signed-off-by: Tom Gundersen <teg@jklm.no>
2020-06-03 16:36:00 +02:00
Christian Kellner
5891beab4e meta: also validate the schema for sources
When validating the manifest, now also validate the schema for
the supplied sources.
2020-06-02 09:50:14 +02:00
Christian Kellner
9930f6ebfb test/osbuild: check the schema of sources
Add 'Source' to the list of module classes that will undergo basic
schema checks, i.e. verify that their embedded schema data is valid
JSON schema.
2020-06-02 09:50:14 +02:00
Christian Kellner
bdae02a6b5 meta: ModuleInfo support for Sources
Add support for querying information about sources: add the mapping
from name to directory and accept "Source" as a module name. Adapt
the ModuleInfo schema property to handle the different styles for
stage-like schemata as well as sources now.
2020-06-02 09:50:14 +02:00
Christian Kellner
f967bf7164 sources/dnf: add documentation and schema
Since the dnf stage is not used anymore only a placeholder schema
and documentation is added.
2020-06-02 09:50:14 +02:00
Christian Kellner
42ef470740 sources/files: add documentation and schema
Add a brief documentation text and its JSON schema so that osbuild
can verify options org.osbuild.files source entries.
2020-06-02 09:50:14 +02:00
Christian Kellner
66d1dc1206 sources/ostree: add documentation and schema
Add a brief documentation text and its JSON schema so that osbuild
can verify options org.osbuild.ostree source entries.
2020-06-02 09:50:14 +02:00
Major Hayden
e7b480895f CI: Store RPMs by SHA
This commit brings over updates for mock builds from osbuild-composer.

Signed-off-by: Major Hayden <major@redhat.com>
2020-06-01 15:54:50 +02:00
Christian Kellner
f19effd70a stages/grub2: redirect cfg as template
Extract the grub.cfg redirect config as GRUB_REDIRECT_TEMPLATE,
meant to be used via python's string.Template class. Document
its intended use and also the template options.
2020-05-29 11:52:32 +02:00
Christian Kellner
06b2c8c99b stages/grub2: main configuration as a template
Extract the strings for grub.cfg into a GRUB_CFG_TEMPLATE multi-line
string and turn it into a template meant to be used via python's
string.Template class. Document it, especially the template options.
2020-05-29 11:52:32 +02:00
Christian Kellner
ff215aa77c stages/grub2: unify grub.cfg writing path
Instead of having two different places within conditionals where
the configuration is written, have only one common. In the case
of hybrid boot, in the end there will be two grub configuration
files: the canonical one in /boot/grub2/grub.cfg and a redirect
one, in the EFI directory that will redirect to the canonical.
In case of legacy only, only the canonical one in the default
location (/boot/grub2/grub.cfg) will be written.
For EFI only mode, only /boot/efi/EFI/<vendor>/grub.cfg will
be written with the main grub configuration data.
Thus the writing of the main grub configuration will now always
be written in exactly one place (now line 319).
2020-05-29 11:52:32 +02:00
Christian Kellner
823b8999a7 stages/grub2: write redirect cfg via the object
Move the write_grub_cfg_redirect to the new GrubConfig object as
write_redirect. Add a `separate_boot` property to be used by the
new write_redirect. Remove the corresponding variable and also
the `grub_fs` variable since that is now all handled by the
GrubConfig object.
2020-05-29 11:52:32 +02:00
Christian Kellner
5828729217 stages/grub2: turn write_grub_cfg into an object
The reason behind this is to combine all the necessary state in the
object instead of passing it all to the write_grub_cfg function.
The idea is that as more things will get configurable, say the
timeout or ignition support, more things need to be passed to it
and thus it is better to an object where these config options can
be set and then combined when writing the config.
2020-05-29 11:52:32 +02:00
Christian Kellner
dfd044a512 stages/ostree: 'rootfs' option is not required
Fedora CoreOS[1] uses a dracut module[2] together with a systemd
generator[3] to mount the file system, including the root one.
Thus neither '/etc/fstab' nor a `root=` kernel command line
option is needed. Support that use case by making the 'rootfs'
option optional.

[1] https://github.com/coreos/fedora-coreos-config/tree/testing-devel/
[2] overlay.d/05core/usr/lib/dracut/modules.d/40ignition-ostree
[3] overlay.d/05core/usr/lib/systemd/system-generators/coreos-boot-mount-generator
2020-05-29 11:51:57 +02:00
Christian Kellner
58db898790 stages/ostree: option to pre-populate /var
The ignition-dracut module for Fedora CoreOS and anaconda both have
code to populate '/var' via systemd-tmpfiles. In images that where
said dracut module is not used, but '/var' needs to be populate, it
can no be done by setting the `populate_var` option.
2020-05-29 11:51:57 +02:00
David Rheinsberg
4a6ee7081b test/pylint: select files via git-ls-tree
We currently run pylint on all files we find in the checkout. This is
particularly annoying when we have osbuild-stores in the checkout, which
then contain lots of python files in their stored trees.

Change the pylint test to use `git ls-tree` to find all files in the
index and then only run pylint against the subset that we are interested
in.
2020-05-29 11:07:44 +02:00