Commit graph

317 commits

Author SHA1 Message Date
Lars Karlitski
64713449ce Introduce runners
We've been using a generic `osbuild-run`, which sets up the build
environment (and works around bugs) for all build roots. It is already
getting unwieldy, because it tries to detect the OS for some things it
configures. It's also about to cause problems for RHEL, which doesn't
currently support a python3 shebang without having /etc around.

This patch changes the `build` key in a pipeline to not be a pipeline
itself, but an object with `runner` and `pipeline` keys. `pipeline` is
the build pipeline, as before. `runner` is the name of the runner to
use. Runners are programs in the `runners` subdirectory.

Three runners are included in this patch. They're copies of osbuild-run
for now (except some additions for rhel82). The idea is that each of
them only contains the minimal setup code necessary for an OS, and that
we can review what's needed when updating a build root.

Also modify the `--build-pipeline` command line switch to accept such a
build object (instead of a pipeline) and rename it accordingly, to
`--build-env`.

Correspondingly, `OSBUILD_TEST_BUILD_PIPELINE` → `OSBUILD_TEST_BUILD_ENV`.
2019-11-25 13:05:22 +01:00
Lars Karlitski
616e1ecbba buildroot: run everything with osbuild-run
`osbuild-run` sets up the build root so that programs can be run
correctly in it. It should be run for all programs, not just stages and
assemblers (even though they're the only consumers right now).

Also, conceptually, `osbuild-run` belongs to the build root. We'll
change its implementation based on the build root in a future commit.

The buildroot already sets up `/run/osbuild/api`. It makes sense to have
it manage libdir as well.

A nice side benefit of this is a simplification of the Stage and
Assembler classes, which grew quite complex and contained duplicate
code.
2019-11-25 13:05:22 +01:00
Lars Karlitski
8c02636bae assemblers/rawfs: add support for xfs
This introduces the `root_fs_type` option on the org.osbuild.rawfs
assembler. It only accepts "ext4" and "xfs" values right now and
defaults to "ext4" to preserve backwards compatibility.
2019-11-24 15:12:23 +01:00
Lars Karlitski
2437bb6196 assemblers/qemu: add support for xfs
This introduces the `root_fs_type` option on the org.osbuild.qemu
assembler. It only accepts "ext4" and "xfs" values right now and
defaults to "ext4" to preserve backwards compatibility.
2019-11-24 15:12:23 +01:00
Martin Sehnoutka
a253aedbc2 remove the resize, leave only vpc support and options 2019-11-23 19:35:19 +01:00
Martin Sehnoutka
459a25bba7 Support for vpc format in qemu assembler (fixes #164) 2019-11-23 19:35:19 +01:00
Lars Karlitski
aece548644 stages/dnf: add module_platform_id option
This is needed by modular repositories.
2019-11-18 19:11:21 +01:00
Martin Sehnoutka
fbb43c1c9a Revert "Fill in the license template"
This reverts commit 6add9c387ba647e5e3e71c268843358657caa212 as I
understood the license text in a wrong way.
2019-11-18 12:23:10 +01:00
Will Woods
6164b38fb9 Add STAGE_DESC, STAGE_INFO, and STAGE_OPTS to stages
This commit adds semi-structured documentation to all osbuild stages and
assemblers. The variables added work like this:

* STAGE_DESC: Short description of the stage.
* STAGE_INFO: Longer documentation of the stage, including expected
              behavior, required binaries, etc.
* STAGE_OPTS: A JSON Schema describing the stage's expected/allowed
              options. (see https://json-schema.org/ for details)

It also has a little unittest to check stageinfo - specifically:

1. All (executable) stages in stages/* and assemblers/ must define strings named
   STAGE_DESC, STAGE_INFO, and STAGE_OPTS
2. The contents of STAGE_OPTS must be valid JSON (if you put '{' '}'
   around it)
3. STAGE_OPTS, if non-empty, should have a "properties" object
4. if STAGE_OPTS lists "required" properties, those need to be present
   in the "properties" object.

The test is *not* included in .travis.yml because I'm not sure we want
to fail the build for this, but it's still helpful as a lint-style
check.
2019-11-13 21:47:03 +01:00
Will Woods
9d4b526a25 org.osbuild.rpm: make rpm --install check signatures
It turns out that rpm will happily check signatures on `--install`,
that's just not the default behavior, because of Historical Reasons.

This commit enables RPM's signature checking and drops our manual check,
which will probably speed up the RPM stage a little bit. Fun!

Oh, also there's two bonus code cleanups: one to use f-strings harder,
and one to make sure we ignore whitespace in package checksum strings.
2019-11-13 21:11:39 +01:00
Will Woods
d6ce127a8e org.osbuild.rpm: safe tempfiles
This makes the org.osbuild.rpm stage use safe temporary files for
handling keys and the package manifest.
2019-11-13 21:11:39 +01:00
Will Woods
8b8493cf04 org.osbuild.{dnf,yum}: use safe tempfiles
As a general rule, using temporary files with predictable names is a
security risk. It probably isn't _actually_ a security risk inside
osbuild stages, since they're usually running in some kind of isolated
container environment, but it's still a better idea to use tempfiles.

This makes the dnf and yum stages put their temporary files into a
temporary directory that gets deleted after dnf/yum finishes.
2019-11-13 21:11:39 +01:00
msehnout
93a3f68a31 Fill in the license template
Fixed #159
2019-11-12 12:41:21 +01:00
Lars Karlitski
1f526477d2 5 2019-10-30 18:49:56 +01:00
Christian Kellner
6e5b838892 pipeline: use API to setup stdio inside the container
Use the new the osbuild API to setup the standard input/output
inside the container, i.e. replace stdin, stdout, and stderr with
sockets provided by the host.
2019-10-30 18:44:55 +01:00
Christian Kellner
93e1c60460 api: new host side API to be used by the container
Introduce an osbuild API that can be used by the container to talk
to the osbuild host. It currently supports one method 'setup-stdio'
which should be used by the container to setup its standard input/
output so the stages can transparently do i/o with the osbuild host
via stdio.
The input data (args) is written to a temp-file backed buffer. The
output is either the host's stdout directly or another temp-file
backed buffer; the latter is re-opened (via /proc/self/fd) to get
another file-descriptor for the container, so in theory the host
and the container could do i/o to the same buffer independently.
2019-10-30 18:44:55 +01:00
Christian Kellner
76518db26b dump_fds: add flags and address parameter
Expose the flags, address parameter of the underlying sock.sendmsg
method, in order to be able to explicitly specify the recipient of
the message; as needed in connection-less mode.
2019-10-30 18:44:55 +01:00
Christian Kellner
1c5b97afbc load_fds: use frombytes instead of fromstring
Python 3.2 renamed array.fromstring to array.frombytes, but kept
the former as an, now deprecated, alias. Use the canonical form
which indeed better describes what is going on.
2019-10-30 18:44:55 +01:00
Martin Sehnoutka
27cf84edd5 bind osbuild module from dynamically discovered path 2019-10-21 15:20:31 +02:00
Martin Sehnoutka
831459e9e9 fix execv /usr/lib/osbuild/osbuild-run does not exist
In case osbuild is invoked without libdir parameter, the osbuild files
are not propagated into the buildroot container and therefore all
pipelines containing buildroot fail.

Example:
```
$ sudo osbuild --store /var/osbuild/ qcow2-pipeline.json
...
execv(/usr/lib/osbuild/osbuild-run) failed: No such file or directory
```

Unfortunately this is only the first error. Once you fix it, you realize
that also the symlink from "assemblers" directory is missing and
therefore you cannot import osbuild because it is not available anywhere
in the path. This is why I had to bind the osbuild module from host to
the build container.
2019-10-21 15:20:31 +02:00
Ondřej Budai
ce6f77cbdc stages: add org.osbuild.chrony stage
lorax-composer supports modifying timeservers, this stage implements it.

I was concerned if I should name this stage timeservers or chrony, but
I've decided to go with chrony. If some day in future Fedora/RHEL
changes the ntp client, we can easily introduce new stage named after
the new ntp client. Additionally, this solution enables us to create
systemd-timesyncd stage, which can change timeservers when chrony is not
installed (in that case systemd-timesyncd takes over the ntp
synchronization).
2019-10-19 18:38:17 +02:00
Ondřej Budai
21d91fd6df stages: add org.osbuild.groups stage
lorax-composer supports adding groups, therefore we need it as well.
2019-10-17 16:14:20 +01:00
Ondřej Budai
d0a3f99342 stages/users: set authorized_keys file permissions to 600
Otherwise user may be unable to login. More information:
https://stackoverflow.com/questions/6377009/adding-public-key-to-ssh-authorized-keys-does-not-log-me-in-automatically
2019-10-17 16:11:01 +01:00
Ondřej Budai
dff8d6591b tests: fix ResourceWarning: unclosed file when running osbuild
We don't close osbuild's stdin when no input is given. Don't open stdin
at all when no input is specified.
2019-10-17 16:07:03 +01:00
Tom Gundersen
2457635bac assemblers/qemu: simplify mkfs
Rather than relying on the offset parameter, simply run mkfs on the
loopback device which is anyway being set up. This also allows us
not to specify the size explicitly.

Before this patch mkfs would complain (uneccesarily) about the
backing file containing a partition table. This is a false positive
as the partition table is in the region of the file before the
passed offset.

Signed-off-by: Tom Gundersen <teg@jklm.no>
2019-10-16 13:44:01 +02:00
Lars Karlitski
26d29b646b stages/rpm: whitelist checksum algorithms 2019-10-15 22:53:53 +01:00
msehnout
bd02c4d8a4 Update packit.yaml for f31
ssia
2019-10-15 14:04:57 +02:00
Lars Karlitski
2b872bbbfb stages: add org.osbuild.rpm
A new stage that downloads a list of packages and installs them using
`rpm`.
2019-10-15 00:00:13 +02:00
Tom Gundersen
06bc4996a2 test/assembler: verify the bootloader
Verify the level 1 and level 1.5 GRUB2 bootloaders are as expected.

Fixes #134.

Signed-off-by: Tom Gundersen <teg@jklm.no>
2019-10-13 12:08:08 +02:00
Tom Gundersen
ea4a6d135e assembler/qemu/grub: don't search for the root partition
We know the root partition we want, as we are setting it up. There
is no need to search for it by filesystem UUID. This simplifies the
setup and means the level 1.5 bootloader is always the same, and
not dependent on an embedded UUID.

Signed-off-by: Tom Gundersen <teg@jklm.no>
2019-10-13 12:08:08 +02:00
Tom Gundersen
d15bbaa05d test: remove redundant tests and Vagrant integration
The tests from the integration_tests directory, were superseded
by the new stage tests.

The Vagrant integration seems not to have been working since
ea68bb0c26, as a test-setup.py was
dropped there, which it relies on. Remove it for now. If we want
that back, we should consider that in a separate PR.

Signed-off-by: Tom Gundersen <teg@jklm.no>
2019-10-13 12:08:08 +02:00
Tom Gundersen
21df63ba31 stages/dnf: embed the gpgkey in the pipeline
Downloading the gpg key is fragile and kept causing our tests to fail.
In general, we want to limit the network access, so let's just embed
the gpg keys directly in the pipeline.

Fixes #133.

Signed-off-by: Tom Gundersen <teg@jklm.no>
2019-10-12 14:59:01 +02:00
Lars Karlitski
8d62bed7e4 test: give osbuild time to clean up on SIGINT
When the test runner receives SIGINT, osbuild's mounts stay around.
osbuild handles SIGING correctly, but it doesn't have time before being
killed because it's parent went away.

Fix this by waiting on it explicitly in the test runner.

Fixes #119
2019-10-11 18:02:04 +02:00
Lars Karlitski
3e00117d35 test: prefix temporary directory with osbuild-test-
This makes it easier to spot which process temporary files are coming
from.
2019-10-11 18:02:04 +02:00
Lars Karlitski
1b9305b024 travis: make unittest more verbose
This prints the name of each test before running it, which might help
with travis' limit of stopping a test when it takes longer than 10
minutes.
2019-10-10 18:08:58 +02:00
Lars Karlitski
2819d07296 test: test qemu assembler
Similar to the existing test, but uses qemu-nbd to mount the generated
image.

Using unittest.TestCase.subTest() for now, which means that the tests
aren't very independent. I think this is fine in this case, because
we're testing images independently from each other, reusing the base
tree in the store.
2019-10-10 18:08:58 +02:00
Lars Karlitski
eab8cbff5e assemblers/qemu: don't try to compress raw or vdi formats
qemu-img convert fails when passing `-c` to vdi or raw outputs.
2019-10-10 18:08:58 +02:00
Ondřej Budai
2be0530047 tests: Use one store per class instead of per test method
For stages testing it is too slow to rebuild the a image containing
@Core packages every time. Let's just reuse the a image for all tests.
This should speed up the test running time a LOT.
2019-10-08 21:39:35 +02:00
Ondřej Budai
85ebb084b5 tests: introduce stage testing
The stage testing is based on an output from the tree-diff tool. During
one test two pipelines are run and their outputs are compared using
tree-diff. The diff is then compared with expected diff included in
the repository.
2019-10-08 21:39:35 +02:00
Ondřej Budai
5edac4ee58 tools/tree-diff: strip NULL character from selinux xattr 2019-10-08 21:39:35 +02:00
Ondřej Budai
fd2a20d247 tools/tree-diff: Use hash for content diffs
We need to know the exact difference of modified files in both trees.
Outputting the whole files into a diff might make a huge diff file,
therefore only their hashes are written.
2019-10-08 21:39:35 +02:00
Ondřej Budai
9fd9270c53 tools/tree-diff: List all dirs and files inside added/deleted dirs
In my opinion it is better to dump everything and then filter out
unneeded entries elsewhere.
2019-10-08 21:39:35 +02:00
Martin Sehnoutka
0862722b03 Introduce cloud-base sample
It is similar to the official Fedora cloud base image except for few
minor differences. The reason for this divergence is that we don't want
to include all hacks that are currently present in the official
kickstart file. You can see it here as a reference:
https://pagure.io/fedora-kickstarts/blob/master/f/fedora-cloud-base.ks#_149
2019-10-07 21:25:18 +02:00
Ondřej Budai
e12f55aa21 tests: print stdout from osbuild when it fails 2019-10-07 10:10:51 +02:00
Lars Karlitski
9fbe80722b assemblers: add org.osbuild.rawfs
This assembler outputs an image file which only contains the file
system.
2019-10-07 10:10:51 +02:00
Lars Karlitski
7375e4f5dd tree-diff: change shebang to respect $PATH 2019-10-07 10:10:51 +02:00
Lars Karlitski
cb2f383601 remoteloop: make LoopClient.device a context manager 2019-10-07 10:10:51 +02:00
Lars Karlitski
0dd60b3abf remoteloop: pass filename to create_device
This makes LoopClient simpler to use in the common case.
2019-10-07 10:10:51 +02:00
Lars Karlitski
356f62058f remoteloop: remove dir_fd argument in create_device
If dir_fd wasn't passed, create_device() openend it to `/dev` and forgot
about closing it. To fix this, it would have to gain logic to only close
the fd if it wasn't passed in.

Side-step the problem by removing dir_fd, since nothing is using it
right now. We can add it back if something needs it.
2019-10-07 10:10:51 +02:00
Lars Karlitski
3d3ffda5d8 remoteloop: don't close a socket it didn't open
Closing the socket is the responsibility of whoever opened it.

Fix this in the only user (qemu assembler) by using socket() in a `with`
block, which closes the socket on exit.
2019-10-07 10:10:51 +02:00