Commit graph

623 commits

Author SHA1 Message Date
David Rheinsberg
eb4d90cf94 test: avoid shadowing globals
Lets not use `input` as variable name, since it shadows the python
global `input`. Use a different variable name and make pylint happy.
2020-04-20 18:58:26 +02:00
David Rheinsberg
72be939521 test: fix minor pylint warnings
This fixes a bunch of minor pylint warnings:
  * Drop unused imports.
  * Fix "inline-JSON" formatting.
  * Fix space before/after brackets.
  * Use `_` for unused variables.
  * Break overlong lines.
  * Mark unittest as `no-self-use` if applicable.
  * Drop spurious newline at end of file.
2020-04-20 18:58:26 +02:00
David Rheinsberg
617ed6ed29 test: fix pylint coding-style warnings
This fixes 3 things:
  * Drop an unused argument from the http server handler.
  * Break an overlong `with:` statement.
  * Fix indentation where it is wrong.
2020-04-20 18:58:26 +02:00
David Rheinsberg
f50f9d912f test: fix import order
Python mandates global imports before local imports (pylint should warn
about this). Fix the test to import locals late.
2020-04-20 18:58:26 +02:00
David Rheinsberg
7d2e895d26 test: avoid import-aliasing for trivial case
This drops the `server` alias for `http.server`. There is only a single
caller, so lets just be explicit so the callsite is easier to
understand.

As a side effect, this unifies all the imports, no cherrypicking
anymore.
2020-04-20 18:58:26 +02:00
Major Hayden
8464e8d1dc 🐎 Use more CPUs for xz with qemu
Signed-off-by: Major Hayden <major@redhat.com>
2020-04-17 18:39:42 +02:00
Major Hayden
cab71e5b18 🐎 Allow xz to use all available CPUs
By default, xz only uses one CPU core even if multiple cores are
available. If xz compression is chosen, allow xz to use all of the
cores available.

Signed-off-by: Major Hayden <major@redhat.com>
2020-04-17 14:01:07 +00:00
Christian Kellner
bc4fd565d6 stages/yum: drop stage
This stage has been replaced by the org.osbuild.rpm stage. The
latter does not need access to network due inside the container
due to its use of the osbuild sources API.
2020-04-16 11:08:25 +02:00
Christian Kellner
f036c10759 12
This completes the development of osbuild version 12.
2020-04-15 20:19:36 +02:00
David Rheinsberg
6377d328c6 samples: convert links to kernel.org
This converts all fedora links in our samples to `mirrors.kernel.org`.
This mirror works best from around the world, so lets avoid the wild
mix of local mirrors and instead use kernel.org.

This mirror is also well-managed and properly funded, so we should not
run into too many problems with it.
2020-04-15 19:38:00 +02:00
Christian Kellner
22110ffb68 spec: ship ostree specific files in sub-package
Ship the stages, assembler and source that are necessary to build
images with OSTree support in the osbuild-ostree sub-package.
2020-04-15 19:37:20 +02:00
David Rheinsberg
f60f4f22f8 NEWS: add v12 entry
Add a NEWS entry for all major changes since v11, but exclude anything
not relevant to packagers and users.
2020-04-15 18:21:03 +02:00
David Rheinsberg
dce4155d80 build: fix makefile comments
Comments must not be indented in makefiles, otherwise they might end up
being interpreted as rules. Simply drop the indentation and move it into
the comments itself.
2020-04-15 18:21:03 +02:00
David Rheinsberg
080768872e NEWS: convert tabs
Convert some tab usage to whitespace to avoid reliance on 4ch indents.
2020-04-15 18:21:03 +02:00
Tom Gundersen
c2243aee6a stage: add org.osbuild.first-boot
This stage runs a given command only on the first boot of the image,
useful for doing instantiation tasks that can only be done in the
target environment, or that should be done per-instance, rather
than per image.

Ideally we would use systemd's ConditionFirstBoot for this, but that
requires images to ship without an /etc/machine-id, and currently
we only support shipping images with an empty /etc/machine-id.
Changing this would mean dropping /etc/fstab in favor of mounting
the rootfs rw from the initrd. This is likely the right thing to
do regardless, but we would have to audit what other first-boot
services we would end up with pulling in in this case.

Instead we introduce our own flag file /etc/osbuild-first-boot,
and use ConditionPathExists.

Signed-off-by: Tom Gundersen <teg@jklm.no>
2020-04-15 16:07:34 +02:00
David Rheinsberg
551faf2d61 osbuild: add --output-directory=DIR
Add a new output-directory argument which specifies where to store
result objects. For now, this is purely optional and simply copies from
the old `output_id` into the specified directory. This allows a
backwards compatible transition towards removing any external access to
the osbuild cache.

Note that this has still lots of room for improvements:

  * We only support assembler-output for now, but we could also easily
    support entire trees as output, in case no assembler was selected.
    Alternatively, we could introduce a "copy" assembler, that just
    outputs the input tree.

  * This parameter is optional, but should really be mandatory. There
    is little reason to have the default behavior just dropping any
    generated content. This would be a breaking change, though.

  * We could move data out of a temporary object-store entry, rather
    than copy it. But again, for backwards-compatibility, we leave the
    latest store-object intact and do not move things out of it.

  * We could now transition towards never committing anything to the
    store, not even output IDs, unless explicitly checkpointed.
2020-04-15 15:40:17 +02:00
Christian Kellner
ef3f601d05 samples/f31-ostree-image.json: enable hybrid boot
That was mostly prepared already, the one last missing piece was
to use the default grub2 stage (previous commit) and now, with
this commit, to actually install the grub2 legacy bootloader via
the qemu assembler.
2020-04-15 15:39:45 +02:00
Christian Kellner
9020a0b372 samples: add f31-ostree-image.json example
An example that takes an ostree commit and creates a qcow2 image
that is bootable. NB: the commit ids and the corresponding source
will need to be adjusted after having run the pipeline that will
create the ostree commit.
2020-04-15 15:39:45 +02:00
Christian Kellner
09d73066ed samples: add f31-ostree-commit.json example
This is a Fedora 31 based example that results in a ostree repo
with a ostree commit. The latter was composed from the file system
tree that was created via the given osbuild stages.
2020-04-15 15:39:45 +02:00
Christian Kellner
4d0e18eb24 stages/grub2: opt-out option for /etc/default/grub
The file `/etc/defaults/grub` sets the defaults that are used by
grub2-mkconfig to (re-)generate the grub config (grub.cfg). This
command is not run by any scripts but by the user directly. On
modern installations (without the grubby-deprecated package)
the kernel is configured via Bootloader Specification snippets
and thus the grub config should not need to be touched at all
under normal circumstances. In the new future the grub2-mkconfig
will be updated to not require GRUB_ENABLE_BLSCFG which should
make the existence `/etc/defaults/grub` even more superfluous.
Additionally, in the future, some images might not contain
the grub2 packages at all.
2020-04-15 15:39:45 +02:00
Christian Kellner
c15b3e6cf4 stages/grub2: option to install EFI data
Add support for copying EFI data from the build root. If
`uefi.install` is set to `true`, `BOOT` and `uefi.vendor`
directories will be copied from the build root. This is
useful for example on OSTree based systems where boot/efi/EFI
is not being populated by an RPM package; but it can be used
also on other systems where it is not desirable to deliver
the EFI data via packages.
2020-04-15 15:39:45 +02:00
Christian Kellner
8d28b094eb buildroot: also bind mount /boot
Add /boot to be mounted from the build tree into the build root,
because the EFI binaries for grub are stored in there and for
ostree grub2 support those need to be copied too.
2020-04-15 15:39:45 +02:00
Christian Kellner
fd5efd0d29 stages/ostree: fix SELinux labels after deployment
Deploying an OSTree commit leads to creation of hardlinks from
the repository to the check out. These will have the correct
SELinux labels, since the files in the repository will have the
correct SELinux labels[1]. But new files are generated in '/etc'
of the new deployment, due to the 3-way configuration merge[2].
Also a new kernel, initramfs and the corresponding Bootloader
Specification entries are created in the global '/boot' dir.

In theory, ostree will set the correct SELinux labels by loading
the SELinux config from the deployment and then setting the
correct security contexts via ostree_sepolicy_setfscreatecon().
But it does so conditionally on is_selinux_enabled(2)[3], which
in our container is FALSE Therefore we have to do the same dance
as ostree does, at least for now, and manually re-label the
affected paths.

[1] Assuming they had the correct label when the commit was made
[2] https://ostree.readthedocs.io/en/latest/manual/deployment/
[3] via ostree_sepolicy_setfscreatecon in ostree-sepolicy.c
    line 640 of commit 2c1658538f8fde5813e95e7408d65662a489be91
2020-04-15 15:39:45 +02:00
Christian Kellner
7be1fa7ac5 stages/ostree: option to specify remotes
Add the ability to specify one ore more remotes for the system
repository. The required options for a single remote are its
`name` and the `url`. Optionally one or more branch can be passed
via `branches`. GPG keys can be given via `gpgkeys`; if none are
specified, no gpg verification will be done.
2020-04-15 15:39:45 +02:00
Christian Kellner
4cfcd44480 stages/ostree: mode support for mount points
The list of mount points is changed from a list of strings to a
list of objects containing `path` and an optional `mode` value.
The latter can be used to set the mode of the mount point that
will be created in the file system tree. It defaults to 0755,
or 493 in decimal, because JSON does not support octal values.
2020-04-15 15:39:45 +02:00
Christian Kellner
4d9a99562e stages/ostree: uuid or label option for rootfs
Instead of taking a raw string for the root file system kernel
option, convert the `rootfs` option to an object that must have
either `uuid` or `label` set. This will then be translated into
the proper kernel command line argument.
2020-04-15 15:39:45 +02:00
Christian Kellner
3eea0668f9 stages/ostree: add ref support
Add a new optional `ref` option. When set, a references for the
commit that was pulled with the value of `ref` will be created
in the system ostree repo. It will also be used when deploying
the commit and thus will be set as the origin for it. This is
necessary for updates to work.
2020-04-15 15:39:45 +02:00
Christian Kellner
cc01eb3a0e stages: add org.osbuild.ostree stage
Initializes the filesystem via ostree and then pulls a specified
commit and deploys that. Options are `commit`, which is the id
of the commit to pull and deploy, `osname`, which is the name
to be used for the operating system root. The `roofs` together
with `kernel_opts` options are used to build the kernel command
line for the deployment.
Additionally, a `mounts` parameter can be supplied that indicates
file system boundaries. This is needed because ostree uses a hard
link farm, which must not link across said file system boundaries.
2020-04-15 15:39:45 +02:00
Christian Kellner
b8b6619d39 sources/ostree: verify signature on local pull
Instead of verifying the gpg signature when pull from the actual
remote source into the local cache, verify the commit when it is
being pulled from the local cache into the output directory. This
ensures that the signatures are checked against the provided keys
even when the commit was already in the cache and at that time
the key might have been different.
NB: ostree expects the signature to be present on the remote at
the *target* repository, i.e. in our case the output repository.
The keys are therefore attached to a temporary remote that is
created at the output repository with the same name/id that is
used for the actual remote.
2020-04-15 15:39:45 +02:00
Christian Kellner
e1b2803ae0 sources/ostree: support gpg verification
Add a new `gpgkeys` option that, if set, must contain a list of
public keys. These keys will then be used by ostree to verify
signed commits when pulling from the remote. If the `gpgkeys`
option is missing, no verification will be attempted.
2020-04-15 15:39:45 +02:00
Christian Kellner
d5cce89fd8 sources: add org.ostree.ostree source
This source can be used to fetch ostree commits. The commits are
accessed via their commit is. The only option currently is `url`,
given for each commit, that will be used as the location of the
remote. A cache repository, that will be created if necessary,
acts as an intermediary, so remotes will be added with `name` as
the identifier to it and commits are pulled into that. In the
output directory another repository will be created as 'repo' and
the requested commit pulled into that from the cache repository via
a local pull.
2020-04-15 15:39:45 +02:00
Christian Kellner
e424e40aae assembler: add org.osbuild.ostree.commit
Add a new assembler that takes a file system tree that is already
conforming to the ostree system layout[1], creates a new repository
in archive mode and commits the file system tree to it. Afterwards,
a reference is created with the value supplied in `ref`.

The repository is located at the `/repo` directory and additional
metadata is /compose.json which contain the compose information.

Currently uses rpm-ostree to do the actual committing. In the future
this might change to plain ostree.

[1] https://ostree.readthedocs.io/en/stable/manual/adapting-existing/
2020-04-15 15:39:45 +02:00
Christian Kellner
c05112ee94 stages: add new org.osbuild.rpm-ostree stage
A stage that uses rpm-ostree compose to do post-processing of the
tree. Among other things the main steps are:
  - moves /etc to /usr/etc
  - move /boot to /usr/lib/ostree-boot
  - potentially moving /var/lib/rpm
  - re-creates the initramfs (dracut)
  - stores the treefile at /usr/share/rpm-ostree/treefile.json
  - adds altfiles module to nss
  - Recompiles SELinux policy (semodule -nB)
  - Migrates /usr/etc/{passwd, group} to /usr/lib/
  - Postprocess SELinux policy
  - Convert /var to tmpfiles.d
  - Prepares symlinks
    - /usr/local -> /var/usrlocal
    - /var/lib/alternatives -> /usr/lib/alternatives
    - /var/lib/vagrant -> /usr/lib/vagrant
  - copies the rpmdb

Based on commit 1cf0d557ae8059e689b1fed670022727e9842288 (rpm-ostree)
2020-04-15 15:39:45 +02:00
Christian Kellner
c435bb359e ci: run selinux and ostree unit tests
Add the new ostree and selinux unit tests to the github action CI
2020-04-15 15:39:45 +02:00
Christian Kellner
40c2545f74 util/selinux: add simple setfiles wrapper
Add a small wrapper around the setfiles(8) utility that can be used
to set the security context fields on one or multiple provided paths,
given a specification. The root of the file system tree can be given
via `root` and all elements of `paths` will be interpreted as
relative to that root.
2020-04-15 15:39:45 +02:00
Christian Kellner
50beb4ffb5 util: add selinux config file related helpers
Add a helper, `parse_config`, to parse a selinux configuration file,
see selinux(8), and return a dictionary containing the configuration
data in key, value pairs. This, in turn, can be fed into the other
helper method, `config_get_policy`, to get the effective policy or
`None` if SELinux is disabled or the policy type is not configured.
Add a new test suite that checks the basic functionality of the
helpers above.
2020-04-15 15:39:45 +02:00
Christian Kellner
47412e1bb7 util: new ostree module with TreeFile helper
When using rpm-ostree compose, a Treefile[1] controls various
aspects of its behaviour. Since rpm-ostree will, at least in
the beginning, be used to post-process and committing the tree
add a helper class to ease the creation of correct Treefiles.
The docstring of the Treefile contains the information in which
phases ('install', 'postprocess', 'commit') the option is used,
as of rpm-ostree commit 1cf0d557ae8059e689b1fed670022727e9842288

Add basic checks for the ostree.Treefile helper. Some of the
tests require rpm-ostree to be installed.

[1] https://rpm-ostree.readthedocs.io/en/stable/manual/treefile/
2020-04-15 15:39:45 +02:00
Tom Gundersen
8ad791be13 runners: drop ca certificate handling
Now that stages no longer access the network, drop CA certificate
setup.

In the future, we may want to restrict all network access to the
container, but that requires more work.

Signed-off-by: Tom Gundersen <teg@jklm.no>
2020-04-15 15:29:52 +02:00
Tom Gundersen
b7bbcaa3a2 runners/fedora27: drop support
We no longer attempt to support fedora before f30.

Signed-off-by: Tom Gundersen <teg@jklm.no>
2020-04-15 15:29:52 +02:00
Tom Gundersen
892342b978 stages/dnf: drop stage
This has now been entirely replaced by the rpm stage in all its
users. The dnf stage does not fit very nicely into the osbuild
module, in particular it requires direct network access, which
we would like to avoid.

Signed-off-by: Tom Gundersen <teg@jklm.no>
2020-04-15 15:29:52 +02:00
Tom Gundersen
7e80ca9bbe sources: drop unused sources.json
External sources are no longer supported by osbuild, and is no longer
used in any of the samples.

Signed-off-by: Tom Gundersen <teg@jklm.no>
2020-04-15 15:29:52 +02:00
Tom Gundersen
e96f2a6a0b samples: convert from dnf- to rpm-based pipelines
Similarly to how the tests were converted in 26f5135a5f.

Signed-off-by: Tom Gundersen <teg@jklm.no>
2020-04-15 15:29:52 +02:00
Tom Gundersen
89e549cc58 samples/rawfs: fix bug in dnf stage
The 'bl' is not a valid hash.

Signed-off-by: Tom Gundersen <teg@jklm.no>
2020-04-15 15:29:52 +02:00
Tom Gundersen
fe95d9317c samples: replace base-qcow2.json with the rpm version
Going forward we only want rpm-based pipelines, so drop the
dnf-based one.

Signed-off-by: Tom Gundersen <teg@jklm.no>
2020-04-15 15:29:52 +02:00
Tom Gundersen
afd94b1017 test/pipelines: drop sources.json
This was unused, as the test pipelines now contains the sources
inline.

Signed-off-by: Tom Gundersen <teg@jklm.no>
2020-04-15 15:29:52 +02:00
Tom Gundersen
9d79d5fcc3 stages/grub2: default to disabling legacy support
For the sake of backwards compatibility, legacy support was enabled
by default. Flip this around, so that leaving the parameter out
means disabling it.

This is more intuitive, and will pave the way for dropping support
for the value being a bool in the future.

`osbuild-composer` always passes the argumnet explicitly, though
still always as a boolean.

Signed-off-by: Tom Gundersen <teg@jklm.no>
2020-04-14 23:47:08 +02:00
Ondřej Budai
de7227965f assembler/qemu: add support for vhdx format
VHDX is the best format for uploading to AWS, thus this commit adds the
support for it. Pros over other formats supported by AWS:
- vmdk - doesn't work, qemu-img probably needs some special options
- vhd - the image size gets round up (I can get only a >=7GB volume from
  a 6GB image)
- ova - just a wrapper over vmdk/vhd/vhdx adding some metadata
- raw - no compression, the images are huge

Also, the format specification is open, therefore I can't see any issues
with it.
2020-04-14 21:56:30 +02:00
Major Hayden
b53de35b0a 🤏 Add a little bit more testing
Test a deployment of osbuild along with osbuild-composer for each PR.
More testing could be stacked on top.

Signed-off-by: Major Hayden <major@redhat.com>
2020-04-09 16:35:08 +02:00
Christian Kellner
5acc68cdc3 pipeline: explicitly import importlib.util
Causes a problem with ostree-osbuild on CI (travis) otherwise:

Traceback (most recent call last):
  File "osbuild-ostree", line 345, in <module>
    sys.exit(main())
  File "osbuild-ostree", line 337, in main
    return build(args)
  File "osbuild-ostree", line 257, in build
    output_id, commit_id = build_commit(builddir, args)
  File "osbuild-ostree", line 162, in build_commit
    r = pipeline.run(store.store,
  File "/home/travis/build/gicmo/ostree-osbuild-demo/osbuild/osbuild/pipeline.py", line 358, in run
    r = self.assemble(object_store,
  File "/home/travis/build/gicmo/ostree-osbuild-demo/osbuild/osbuild/pipeline.py", line 314, in assemble
    r = self.assembler.run(input_dir,
  File "/home/travis/build/gicmo/ostree-osbuild-demo/osbuild/osbuild/pipeline.py", line 148, in run
    osbuild_module_path = os.path.dirname(importlib.util.find_
2020-04-08 13:42:46 +02:00
David Rheinsberg
71e481f0d9 test: prune cache after each stage-test
Make sure we prune the caches after each stage-test to keep our disk
footprint small. This does considerably increase build-times since we
no longer share cached entries. However, the current CI builds simply
run out of disk-space.

Once we use separate output-directories we will be able to drop the
automatic checkpointing from the tests, and thus effectively get the
same behavior. Until then, lets prune the caches explicitly.
2020-04-07 18:20:42 +02:00