]> git.ipfire.org Git - thirdparty/mkosi.git/log
thirdparty/mkosi.git
2 years agoRemove scaffolding for DistributionInstaller possibly being None 1217/head
Joerg Behrmann [Thu, 24 Nov 2022 16:14:40 +0000 (17:14 +0100)] 
Remove scaffolding for DistributionInstaller possibly being None

2 years agoSplit Alma and Rocky out of Centos
Joerg Behrmann [Thu, 24 Nov 2022 15:57:56 +0000 (16:57 +0100)] 
Split Alma and Rocky out of Centos

2 years agoRemove unused code
Joerg Behrmann [Thu, 24 Nov 2022 14:48:03 +0000 (15:48 +0100)] 
Remove unused code

2 years agoMove CentOS family to DistributionInstaller
Joerg Behrmann [Thu, 24 Nov 2022 13:54:35 +0000 (14:54 +0100)] 
Move CentOS family to DistributionInstaller

2 years agoMove OpenMandriva to DistributionInstaller
Joerg Behrmann [Thu, 24 Nov 2022 13:17:09 +0000 (14:17 +0100)] 
Move OpenMandriva to DistributionInstaller

2 years agoMove Mageia to DistributionInstaller
Joerg Behrmann [Thu, 24 Nov 2022 12:02:56 +0000 (13:02 +0100)] 
Move Mageia to DistributionInstaller

2 years agoMove Fedora to DistributionInstaller
Joerg Behrmann [Thu, 24 Nov 2022 11:54:34 +0000 (12:54 +0100)] 
Move Fedora to DistributionInstaller

This doubles basically all rpm/dnf functions with copies in
mkosi.distributions.fedora, but this let's us keep the split bisectable without
having to do a big refactor of what these functions look like.

2 years agoMove detect_distribution and dependents to mkosi.backend
Joerg Behrmann [Thu, 24 Nov 2022 11:52:52 +0000 (12:52 +0100)] 
Move detect_distribution and dependents to mkosi.backend

2 years agoMove unlink_try_hard and dependents into mkosi.remove
Joerg Behrmann [Thu, 24 Nov 2022 11:50:24 +0000 (12:50 +0100)] 
Move unlink_try_hard and dependents into mkosi.remove

Similar to mkosi.install but for removing things.

2 years agotests: appease pyright
Joerg Behrmann [Thu, 24 Nov 2022 11:09:20 +0000 (12:09 +0100)] 
tests: appease pyright

2 years agoMove Gentoo to DistributionInstaller
Joerg Behrmann [Wed, 23 Nov 2022 13:57:06 +0000 (14:57 +0100)] 
Move Gentoo to DistributionInstaller

2 years agoci: drop pyright version restriction
Joerg Behrmann [Tue, 22 Nov 2022 16:57:35 +0000 (17:57 +0100)] 
ci: drop pyright version restriction

2 years agoMove OpenSuse to DistributionInstaller
Joerg Behrmann [Tue, 22 Nov 2022 16:15:38 +0000 (17:15 +0100)] 
Move OpenSuse to DistributionInstaller

2 years agoMake all imports absolute
Joerg Behrmann [Tue, 22 Nov 2022 15:47:27 +0000 (16:47 +0100)] 
Make all imports absolute

2 years agoMove Debian and Ubuntu to DistributionInstaller
Joerg Behrmann [Tue, 4 Oct 2022 16:06:38 +0000 (18:06 +0200)] 
Move Debian and Ubuntu to DistributionInstaller

2 years agoMake install_skeleton_tree independent of Distribution enum
Joerg Behrmann [Tue, 4 Oct 2022 15:57:51 +0000 (17:57 +0200)] 
Make install_skeleton_tree independent of Distribution enum

Note for bisecting: This breaks skeleton tree on Debian-based distributions.

2 years agoAdd remove_packages method to DistributionInstaller
Joerg Behrmann [Tue, 4 Oct 2022 15:51:30 +0000 (17:51 +0200)] 
Add remove_packages method to DistributionInstaller

This should probably live in PackageType, but there is a strong dependence
between package type and distribution and I haven't figured out a good way to do
this without cyclical imports.

2 years agoStart moving functions that copy files into the image into a new install module
Joerg Behrmann [Sun, 18 Sep 2022 15:20:54 +0000 (17:20 +0200)] 
Start moving functions that copy files into the image into a new install module

2 years agoMove Arch install functions to distributions.arch
Joerg Behrmann [Tue, 4 Oct 2022 15:38:03 +0000 (17:38 +0200)] 
Move Arch install functions to distributions.arch

2 years agoMove functions out off __init__
Joerg Behrmann [Fri, 16 Sep 2022 17:30:13 +0000 (19:30 +0200)] 
Move functions out off __init__

Some are moved to backend for lack of a better place for now, most mount-related
functions are moved to a new mounts module, though some are left in __init__ for
later, when the dust settles and cyclic imports may become easier to avoid.

2 years agoHook up DistributionInstaller
Joerg Behrmann [Fri, 16 Sep 2022 16:33:33 +0000 (18:33 +0200)] 
Hook up DistributionInstaller

2 years agoAdd DistributionInstaller and hook it into MkosiState
Joerg Behrmann [Tue, 4 Oct 2022 14:52:44 +0000 (16:52 +0200)] 
Add DistributionInstaller and hook it into MkosiState

2 years agoMake Distribution enum string-based
Joerg Behrmann [Tue, 4 Oct 2022 14:51:00 +0000 (16:51 +0200)] 
Make Distribution enum string-based

2 years agoMerge pull request #1249 from keszybz/verb-parameters
Jörg Behrmann [Mon, 21 Nov 2022 10:15:10 +0000 (11:15 +0100)] 
Merge pull request #1249 from keszybz/verb-parameters

Add missing descriptions of verbs which take parameters

2 years agomkosi: rework --help to print command syntax 1249/head
Zbigniew Jędrzejewski-Szmek [Fri, 28 Oct 2022 16:46:13 +0000 (18:46 +0200)] 
mkosi: rework --help to print command syntax

Command list and syntax is the most interesting part of the output.
But because of how argparse works, we were showing this part very
briefly and buried in other options. Instead of relying on the autogenerated
description, let's reuse the list from the man page.
Because a literal text is added, the lines for verbs and --help
and --version are suppressed.

I changed "Distribution" to "Distribution options" and so on for each
option group. The additional word connects the synopsis (which says
"[options…]" with the list below.

Output:
$ bin/mkosi --help| head -n 20
usage:
       mkosi [options...] summary
       mkosi [options...] build [script parameters...]
       mkosi [options...] shell [command line...]
       mkosi [options...] boot [nspawn settings...]
       mkosi [options...] qemu [qemu parameters...]
       mkosi [options...] ssh [command line...]
       mkosi [options...] clean
       mkosi [options...] serve
       mkosi [options...] bump
       mkosi [options...] genkey
       mkosi [options...] help
       mkosi -h | --help
       mkosi --version

Build Bespoke OS Images

Distribution options:
  -d, --distribution {fedora,debian,...

When printed on the console, summary/build/shell/… are bold.

2 years agomkosi: drop ArgumentParserMkosi.fromfile_prefix_chars
Zbigniew Jędrzejewski-Szmek [Wed, 2 Nov 2022 14:03:42 +0000 (15:03 +0100)] 
mkosi: drop ArgumentParserMkosi.fromfile_prefix_chars

mkosi is not usable as a library (all APIs are internal). So there is no need
to use a global variable for this. If we ever want to change it (and it's unlikely
that we ever would), we can just replace the character in the few places. The
code is much more readable without the indirection.

2 years agoAdd missing documentation about cmdlines for various verbs
Zbigniew Jędrzejewski-Szmek [Fri, 28 Oct 2022 16:27:38 +0000 (18:27 +0200)] 
Add missing documentation about cmdlines for various verbs

The error message is changed to be more direct. If somebody doesn't know that
the parameters are passed to the command, "additional" would be unclear.

In the man page the verbs are listed by the order one would normally use them,
i.e. summary, then build, then qmeu/shell/boot/…, then clean, and the less
frequently used verbs last.

Descriptions are added to the commands which take parameters that they do that
and how those parameters are interpreted. In paricular, for 'boot' we accept
kernel commandline options, and for 'qemu' we only take qemu options. (Which is
understandable, given that we don't do a direct kernel boot, but not obvious.)

Fixes #1210.

2 years agoman: regenerate man page
Zbigniew Jędrzejewski-Szmek [Fri, 28 Oct 2022 16:22:06 +0000 (18:22 +0200)] 
man: regenerate man page

2 years agodebian/ubuntu: Configure apt chroot with APT_CONFIG
Georges Discry [Tue, 15 Nov 2022 10:19:42 +0000 (11:19 +0100)] 
debian/ubuntu: Configure apt chroot with APT_CONFIG

When invoking apt switched from running inside the container to running
on the host, apt stopped reading the configuration files present in the
container. Because of this, it is not possible anymore to configure apt
by dropping a file in `mkosi.skeleton/etc/apt/apt.conf.d/`.

apt first loads its configuration files and then parse the command-line
options (so that they can override the options set in the files). While
setting `-o Dir=<container-root>` on the command-line has some impact on
the configuration of apt, it will not read the files in
`<container-root>/etc/apt/apt.conf.d/`, as apt has already read its
configuration files from the host with the configuration `Dir "/"`.

Rather than using the command-line, the APT_CONFIG environment variable
should be used to point to a file with the chroot configuration. When
set, that file is processed before anything else. By setting `Dir` this
way, apt will read the configuration files from the container and not
from the host.

As the host configuration is not read anymore, there is no more need to
mask `/etc/apt` on the host by bind-mounting an empty directory over it.

2 years agoUse the right python when mkosi is a symlink
Georges Discry [Tue, 15 Nov 2022 11:22:31 +0000 (12:22 +0100)] 
Use the right python when mkosi is a symlink

When the `mkosi` on the `PATH` is a symlink to the script installed
inside a virtualenv, the script fails to find the python executable
inside the virtualenv and falls back to the main python3. This is
notably the case when installing mkosi with pipx.

By first following the symlink inside the virtualenv, the script can
find the corresponding python executable.

2 years agoMerge pull request #1267 from DaanDeMeyer/fix-passing-nspawn-args
Daan De Meyer [Mon, 14 Nov 2022 17:24:04 +0000 (18:24 +0100)] 
Merge pull request #1267 from DaanDeMeyer/fix-passing-nspawn-args

Fix passing extra options to systemd-nspawn

2 years agoLook in both the config file and the cwd for dropin files 1267/head
Daan De Meyer [Mon, 14 Nov 2022 15:18:39 +0000 (16:18 +0100)] 
Look in both the config file and the cwd for dropin files

A project might have multiple config files in subdirectories that
they use with --default but have shared configuration in the root
of the repository. When loading such a config file with --default,
we should still load shared dropins from the shared location.

2 years agoFix reading dropin files
fedora Cloud User [Mon, 14 Nov 2022 15:27:38 +0000 (15:27 +0000)] 
Fix reading dropin files

When using iterdir() we don't have to join the paths anymore

2 years agoFix passing extra options to systemd-nspawn
Daan De Meyer [Mon, 14 Nov 2022 15:10:25 +0000 (16:10 +0100)] 
Fix passing extra options to systemd-nspawn

systemd-nspawn ignores all options after the first argument so when
we're passing kernel command line arguments, we need to make sure
we pass the nspawn options first, otherwise they'll get ignored.

2 years agoImplement --repository-key-check=no for dnf-based distros
reuben olinsky [Mon, 14 Nov 2022 07:10:00 +0000 (23:10 -0800)] 
Implement --repository-key-check=no for dnf-based distros

2 years agoPass KERNEL_INSTALL_BYPASS through to the places where it is used
Joerg Behrmann [Tue, 8 Nov 2022 12:46:04 +0000 (13:46 +0100)] 
Pass KERNEL_INSTALL_BYPASS through to the places where it is used

The idea of using KERNEL_INSTALL_BYPASS is to not run kernel-install twice
unnecessarily, since we run it later anyway, but a user reported a regression of
kernel-install not being run at all, although it apparently was in
earlier. Passing the environment variable through will at most run
kernel-install twice, this might be a workaround.

Fixes: #1263
2 years agoMake sure parse_args_file_group() looks in the right directory
Daan De Meyer [Mon, 7 Nov 2022 10:32:12 +0000 (11:32 +0100)] 
Make sure parse_args_file_group() looks in the right directory

We should look for dropins in the same directory as where we look
for the main config file.

2 years agoImplement clean_package_manager_metadata for pacman
LaserEyess [Sun, 6 Nov 2022 17:09:08 +0000 (12:09 -0500)] 
Implement clean_package_manager_metadata for pacman

2 years agoFlush files after copying
reuben olinsky [Thu, 3 Nov 2022 15:55:04 +0000 (08:55 -0700)] 
Flush files after copying

This resolves an issue where qemu sees an incomplete image when
--ephemeral is used.

2 years agoFix path traversal in tar extraction
Joerg Behrmann [Mon, 31 Oct 2022 09:40:58 +0000 (10:40 +0100)] 
Fix path traversal in tar extraction

This fixes CVE-2007-4559 [1], which was reported in an automated closing
campaign in PR #1253.

Crafted members of a tarfile with .. in their paths could resolve to paths
outside of the target directory to which the members would be extracted to.

[1] https://github.com/advisories/GHSA-gw9q-c7gh-j9vm

Closes: #1253
2 years agoAllow uncompressed squashfs images
reuben olinsky [Fri, 28 Oct 2022 02:51:41 +0000 (19:51 -0700)] 
Allow uncompressed squashfs images

The argument parsing was blocking this but the logic invoking
mksquashfs already supported it.

2 years agoFix input check for valid base image
Michael A Cassaniti [Tue, 1 Nov 2022 06:51:50 +0000 (17:51 +1100)] 
Fix input check for valid base image

2 years agotests: do not hardcode x86_64 as the architecture
Luca Boccassi [Sun, 30 Oct 2022 11:17:13 +0000 (11:17 +0000)] 
tests: do not hardcode x86_64 as the architecture

Otherwise tests will fail when run on other architectures.

2 years agoAdd more Debian architecture mappings
Luca Boccassi [Sat, 29 Oct 2022 13:50:41 +0000 (14:50 +0100)] 
Add more Debian architecture mappings

2 years agoMerge pull request #1246 from keszybz/print-summary-to-stdout,use-colour
Zbigniew Jędrzejewski-Szmek [Fri, 28 Oct 2022 15:22:42 +0000 (17:22 +0200)] 
Merge pull request #1246 from keszybz/print-summary-to-stdout,use-colour

Print summary to stdout, use colour

2 years agoMake load_args sideeffect free
Joerg Behrmann [Fri, 28 Oct 2022 09:00:42 +0000 (11:00 +0200)] 
Make load_args sideeffect free

It is unnecessary for the find_foo functions in load_args to generate and chown
directories, since for output and build directory this is already done by the
make_foo_dir functions in build_stuff. At a similar function for the cache
directory.

Having the find_foo functions make the directories has the downside of leading
to permission errors, when the tests are run with fakeroot as done by many
distro buildsystems.

2 years agoNEWS: more markup
Zbigniew Jędrzejewski-Szmek [Thu, 27 Oct 2022 16:12:37 +0000 (18:12 +0200)] 
NEWS: more markup

2 years agoVersion 14 v14
Zbigniew Jędrzejewski-Szmek [Thu, 27 Oct 2022 16:04:37 +0000 (18:04 +0200)] 
Version 14

2 years agomkosi: put various script-related status lines together 1246/head
Zbigniew Jędrzejewski-Szmek [Thu, 27 Oct 2022 13:13:31 +0000 (15:13 +0200)] 
mkosi: put various script-related status lines together

For some reason the build script was described quite far from the
other scripts. Since 19a989fdafe3b50b7c6629efa64e6e4b1fa0c31a the same
environment is used for all scripts, so the "Script Environment" line
is now under all scripts, since it applies to all of them.

2 years agomkosi: verify scripts after parsing config, show status in summary
Zbigniew Jędrzejewski-Szmek [Thu, 27 Oct 2022 13:01:55 +0000 (15:01 +0200)] 
mkosi: verify scripts after parsing config, show status in summary

We would refuse a script if not found or not executable immediately when
parsing the argument. But only the last specified script matters, so it's
better to delay the check: in initial parsing store the path, and later check
that it exists and matches the relevant criteria, at the time when we also
check the outputs.

Similarly for tree inputs: they are checked at this time too.
This fixes #1167.

Instead of trying to generate error messages, just reuse normal Python
exceptions: i.e. os.access() is replaced by open(). This way we don't need to
come up with error messages for various conditions and possibly get them wrong.

Rework status command to show status of inputs and scripts:

$ bin/mkosi --extra-tree={./missing,/root/inaccessible} --{prepare,build,finalize,postinst}-script=/etc/fstab summary
COMMANDS:
                      verb: summary
                   cmdline:
...
CONTENT:
               Extra Trees: /home/zbyszek/src/mkosi/missing (No such file or directory)
                            /root/inaccessible (Permission denied)
            Skeleton Trees: none
...
              Build Script: /etc/fstab (Not executable)
...
        Postinstall Script: /etc/fstab (Not executable)
            Prepare Script: /etc/fstab (Not executable)
           Finalize Script: /etc/fstab (Not executable)
...

Colors are used to draw the eye to the problematic lines.

2 years agomkosi: use normal print stmts for summary
Zbigniew Jędrzejewski-Szmek [Thu, 27 Oct 2022 10:03:18 +0000 (12:03 +0200)] 
mkosi: use normal print stmts for summary

This is simpler and writes to stdout as we should, not stderr.

2 years agoMerge pull request #1151 from qdeslandes/map_permissions
Jörg Behrmann [Thu, 27 Oct 2022 11:01:44 +0000 (13:01 +0200)] 
Merge pull request #1151 from qdeslandes/map_permissions

Implement support for generated files ownership management.

2 years agoMerge pull request #1243 from keszybz/argparse-tweaks
Daan De Meyer [Thu, 27 Oct 2022 10:55:16 +0000 (12:55 +0200)] 
Merge pull request #1243 from keszybz/argparse-tweaks

Disallow option abbreviations and stop dumping usage information on error

2 years agoUpdate NEWS.md 1151/head
Quentin Deslandes [Thu, 27 Oct 2022 09:54:30 +0000 (11:54 +0200)] 
Update NEWS.md

2 years agoUse nspawn's rootidmap option for --bind mount
Quentin Deslandes [Tue, 18 Oct 2022 17:11:42 +0000 (19:11 +0200)] 
Use nspawn's rootidmap option for --bind mount

Bind-mount directories with nspawn's rootidmap option to prevent files
ownership discrepancies: files (and directories) created from within the
container in the mounted directory will be owned by the owner of the
directory on the backing filesystem.

This means, mkosi-generated directories and owner by any other user that
root won't be polluted by root-owned files and folders once the
container is stopped.

2 years agochown mkosi-generated directories
Quentin Deslandes [Tue, 18 Oct 2022 17:10:32 +0000 (19:10 +0200)] 
chown mkosi-generated directories

Change the owner of directories created by mkosi, unless --no-chown is
used. Directories owner will be set to SUDO_UID or PKEXEC_UID if
defined, or to current UID otherwise.

2 years agoAdd --noplugins when calling dnf
Daan De Meyer [Thu, 27 Oct 2022 08:09:45 +0000 (10:09 +0200)] 
Add --noplugins when calling dnf

Let's isolate image builds using dnf from the host a bit more by
disabling all plugins. For example, plugins such as versionlock
can interfere with the version of packages installed in the image
which we want to avoid.

2 years agomkosi: supress printing of argparse help on error 1243/head
Zbigniew Jędrzejewski-Szmek [Thu, 27 Oct 2022 08:39:11 +0000 (10:39 +0200)] 
mkosi: supress printing of argparse help on error

We build a precise error message, but then bury it under a wall of text
produced by print_usage(). The printing of help (or some subset of it) on
parsing error is just useless. Most likely the user made a typo in an option,
and printing a few dozen lines (and more in the future) of unhelpful
semi-related information is counterproductive.

I'm surprised that argparse doesn't make this configurable, but looking at the
code, it seems that the behaviour is hardcoded. Docs and stackoverflow also
yield no hints.

2 years agomkosi: disallow parameter abbreviations
Zbigniew Jędrzejewski-Szmek [Thu, 27 Oct 2022 08:31:37 +0000 (10:31 +0200)] 
mkosi: disallow parameter abbreviations

For interactive use, we have both short options and tab-completion.
Abbreviated options are problematic because of forward-compatibility:
if we add more options in the future, an older abbreviation might become
non-unique and stop working.

2 years agomkosi: do not build a temporary dictionary for kwargs
Zbigniew Jędrzejewski-Szmek [Thu, 27 Oct 2022 08:27:19 +0000 (10:27 +0200)] 
mkosi: do not build a temporary dictionary for kwargs

Let's use the usual method for passing mixed inherited and local keyword args.
We don't need to put the argument names in quotes so this looks nicer. Also,
if we were to make a mistake and pass the same kwargs in two places, previously
the local assignment would silently override the other value. But that seems
inverted because now the base class overwrites something specified by the daughter
class. Anyway, it's better to throw an error, which we now will do:

TypeError: argparse.ArgumentParser.__init__() got multiple values for keyword argument '…'

2 years agoRevert "mkosi: Always use the embedded default version when no release is specified"
Zbigniew Jędrzejewski-Szmek [Wed, 26 Oct 2022 21:16:56 +0000 (23:16 +0200)] 
Revert "mkosi: Always use the embedded default version when no release is specified"

This reverts commit 093d48a97b8211ff549f78f2b3b2ef77fcd45573.

I used mkosi without any explicit distro/version parameters and was surprised
that it built for Fedora 36 after successfully detecting that it's running on
Fedora 37. Using the host version is more likely to be what users expect, and
also avoids the awkward issue that when we hardcode some default version, this
version is likely to be "wrong" (not the latest) until both the distro and we
make a release.

Looking at this more generally, if we have some constant config that doesn't
specify the distro version, we have three possible source of the version
default: host distro version, latest version that was known was mkosi was
released, and actual latest released distro version. It is nice to use the
first option, because that is what users generally expect, and also this makes
mkosi "stable", i.e. we may upgrade it at any time and users will not observe
unexpected changes in defaults. This makes mkosi closer to guidelines for
upgrades in stable distros, see
https://docs.fedoraproject.org/en-US/fesco/Updates_Policy/#stable-releases.

093d48a97b8211ff549f78f2b3b2ef77fcd45573 was aiming for "consistent results",
but this gives consistency with the wrong thing. For a normal user, the host
distro version would never change "unexpectedly", and in fact it is expected
that the defaults of programs change when the host distro is upgraded and not
at any other time. Mkosi itself should provide stable and backwards-compatible
behaviour over releases.

2 years agocode: split out the handling of exceptions to a helper
Zbigniew Jędrzejewski-Szmek [Tue, 13 Sep 2022 15:58:13 +0000 (16:58 +0100)] 
code: split out the handling of exceptions to a helper

This is a bit of error-handling logic that shouldn't obscure the
main logic of the program.

2 years agoAdding custom retry amount to Machine.run()
gsegatti [Wed, 19 Oct 2022 02:56:18 +0000 (23:56 -0300)] 
Adding custom retry amount to Machine.run()

This PR aims to introduce a variable "retry_amount" passed via Machine's constructor.
This variable will define how many times a command will attempt to run when using a VM.
Default value remain as 30 if not explicitly set.

2 years agossh: fix copy_file for authorized_keys
William Roberts [Wed, 26 Oct 2022 15:46:21 +0000 (10:46 -0500)] 
ssh: fix copy_file for authorized_keys

When attempting to copy the public key to the remote images
authorized_keys file, the parent path does not exist and the following
exception is thrown[1]:
‣  Generating SSH key pair…
‣  (Unmounting image)
‣  (Detaching /dev/loop17)
Traceback (most recent call last):
  File "/home/wcrobert/workspace/mkosi/mkosi/__init__.py", line 7357, in setup_ssh
    copy_file(f"{f.name}.pub", authorized_keys)
  File "/home/wcrobert/workspace/mkosi/mkosi/__init__.py", line 614, in copy_file
    with open_close(newpath, os.O_WRONLY | os.O_CREAT | os.O_EXCL, st.st_mode) as newfd:
  File "/usr/lib/python3.8/contextlib.py", line 113, in __enter__
    return next(self.gen)
  File "/home/wcrobert/workspace/mkosi/mkosi/__init__.py", line 571, in open_close
    fd = os.open(path, flags | os.O_CLOEXEC, mode)
FileNotFoundError: [Errno 2] No such file or directory: '/var/tmp/mkosi-_0v_4emp/root/root/.ssh/authorized_keys'

The path only existed up to "/var/tmp/mkosi-_0v_4emp/root", thus a mkdir
with -p semantics is required to create the full path, add that in.

[1] Note line numbers are off due to having some print's scattered
through the code for debugging.

Fixes: #1238
Signed-off-by: William Roberts <william.c.roberts@intel.com>
2 years agofedora: move rpmdb content before replacing with symlink
Luke Asgill [Fri, 26 Aug 2022 02:39:57 +0000 (12:39 +1000)] 
fedora: move rpmdb content before replacing with symlink

Fixes #1113: building a Fedora 36 image using mkosi 13 on Fedora 35 results in
circular symlinks between /var/lib/rpm and /usr/lib/sysimage/rpm.

Co-authored-by: Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
2 years agoMake inserted root or /usr partition at least as big as RootSize
Michael A Cassaniti [Thu, 28 Jul 2022 12:02:09 +0000 (22:02 +1000)] 
Make inserted root or /usr partition at least as big as RootSize

When using SquashFS in particular, the size of the partition inserted will
always be the size of the SquashFS image. This change allows the partition
size to be set which allows for future growth.

2 years agomkosi: add new "pcrphase" tool to dracut initrds
Lennart Poettering [Wed, 21 Sep 2022 10:04:56 +0000 (12:04 +0200)] 
mkosi: add new "pcrphase" tool to dracut initrds

And lets sort the list of dracut additions again.

This is a companion to https://github.com/systemd/systemd/pull/24771,
and should probably be merged only after that got merged.

(If it's merged before it doesn't have any ill effects, but it's pretty
useless...)

2 years agoMerge pull request #1227 from DaanDeMeyer/fixes
Daan De Meyer [Mon, 17 Oct 2022 06:38:33 +0000 (08:38 +0200)] 
Merge pull request #1227 from DaanDeMeyer/fixes

Don't cache bootloader installation

2 years agoStreamline basic config installation 1227/head
Daan De Meyer [Fri, 14 Oct 2022 20:05:24 +0000 (22:05 +0200)] 
Streamline basic config installation

Let's do our basic config installation a little earlier in the build
to allow users the opportunity to override it if needed. Also, rename
all the functions for more consistency.

2 years agoDon't cache bootloader installation
Daan De Meyer [Fri, 14 Oct 2022 19:41:41 +0000 (21:41 +0200)] 
Don't cache bootloader installation

bootctl might configure itself differently depending on what's on
the rest of the system. If we run it as part of the cached image
build, we're doing the installation with files missing that might
influence the end result, so let's not do the installation as part
of the cached image build.

2 years agoMerge pull request #1213 from behrmann/automeasure
Daan De Meyer [Thu, 13 Oct 2022 15:12:30 +0000 (17:12 +0200)] 
Merge pull request #1213 from behrmann/automeasure

Rename --measure option and add a special value auto

2 years agoCopy also .git file for submodules
Fabian Wiesel [Mon, 10 Oct 2022 11:51:53 +0000 (11:51 +0000)] 
Copy also .git file for submodules

To properly get the commit history of a submodule,
we need the .git file pointing to the submodule
in the top-level git directory

2 years agoChunk partition insert using sendfile because sendfile has a maximum transfer size
Michael A Cassaniti [Fri, 7 Oct 2022 06:14:39 +0000 (17:14 +1100)] 
Chunk partition insert using sendfile because sendfile has a maximum transfer size

2 years agoinitrd can be versioned in Debian
Luca Boccassi [Sun, 9 Oct 2022 20:09:31 +0000 (21:09 +0100)] 
initrd can be versioned in Debian

In Bookworm the initrd is installed with the same version suffix
as the directory, for reasons. Check for both.

2 years agoBuild bootable images into directory
Pyfisch [Sun, 9 Oct 2022 09:04:38 +0000 (11:04 +0200)] 
Build bootable images into directory

closes #1214

2 years agoSpecify RPM dbpath when recording packages
Malte Poll [Fri, 30 Sep 2022 19:27:42 +0000 (21:27 +0200)] 
Specify RPM dbpath when recording packages

Workaround for Debian based hosts shipping a patch to store the rpmdb under ~/.
The rpmdb is moved to where the guest expects it
(/usr/lib/sysimage/rpm or /var/lib/rpm)
So rpm on Debian has to be told to search in that location.

2 years agorefactor mount_cache for better readability
Joerg Behrmann [Fri, 16 Sep 2022 16:15:11 +0000 (18:15 +0200)] 
refactor mount_cache for better readability

2 years agoMake SignExpectedPCR tri-valued 1213/head
Joerg Behrmann [Mon, 3 Oct 2022 14:55:57 +0000 (16:55 +0200)] 
Make SignExpectedPCR tri-valued

This makes SignEpectedPCR a tri-valued option using aspecial value "auto" in
addition to boolean values, where it will check whether cryptography is
importable and systemd-measure in the PATH and value True in that case and False
else.

For a True value it checks both conditions and fails hard if they are not met.

The checks are kept in the CLI definition so that what comes out stays a clean
boolean value and doesn't leak any decisions into layers further down. This
unfortunately necesitates a custom default value in the tests, so that they are
robust against what's installed on the system they run on and also needs to use
a function for the argparse type=, since actions are not called for every value.

2 years agorename --measure to --sign-expected-pcr
Joerg Behrmann [Mon, 3 Oct 2022 14:23:38 +0000 (16:23 +0200)] 
rename --measure to --sign-expected-pcr

2 years agoFix crash in setup_package_cache
Pyfisch [Sun, 2 Oct 2022 20:22:58 +0000 (22:22 +0200)] 
Fix crash in setup_package_cache

Otherwise mkosi crashes if config.cache_path is None.

2 years agoMerge pull request #1200 from behrmann/postswtmp2
Daan De Meyer [Fri, 30 Sep 2022 12:57:08 +0000 (14:57 +0200)] 
Merge pull request #1200 from behrmann/postswtmp2

Guard cryptography imports

2 years agoMerge pull request #1208 from behrmann/runnoexec
Daan De Meyer [Fri, 30 Sep 2022 12:56:21 +0000 (14:56 +0200)] 
Merge pull request #1208 from behrmann/runnoexec

Use run instead of execvp in genkey command

2 years agoMake generate_secure_boot_key use run instead of os.execvp 1208/head
Joerg Behrmann [Fri, 30 Sep 2022 09:52:38 +0000 (11:52 +0200)] 
Make generate_secure_boot_key use run instead of os.execvp

2 years agouse os.fspath instead of str to stringify run arguments
Joerg Behrmann [Fri, 30 Sep 2022 09:51:49 +0000 (11:51 +0200)] 
use os.fspath instead of str to stringify run arguments

str and bytes pass through it as is, but things supporting the __fspath__
protocol, like pathlib.Path, will use that.

2 years agoubuntu: Replace platform.machine() check with args.architecture check
Marek Vasut [Sun, 25 Sep 2022 04:39:39 +0000 (06:39 +0200)] 
ubuntu: Replace platform.machine() check with args.architecture check

Test args.architecture instead when selecting the ports.ubuntu.com .
The args.architecture will default to "aarch64" if running on a aarch64
machine and respect command line --architecture switch as well. This is
necessary in case the mkosi is generating foreign architecture container
(e.g. mkosi on amd64 generates arm64 container).

Fix security.ubuntu.com URL, which has to point to ubuntu-ports for
aarch64 machines.

2 years agoarchlinux: Replace platform.machine() check with args.architecture check
Marek Vasut [Sun, 25 Sep 2022 23:12:08 +0000 (01:12 +0200)] 
archlinux: Replace platform.machine() check with args.architecture check

Test args.architecture instead when selecting the mirror.archlinuxarm.org .
The args.architecture will default to "aarch64" if running on a aarch64
machine and respect command line --architecture switch as well. This is
necessary in case the mkosi is generating foreign architecture container
(e.g. mkosi on amd64 generates arm64 container).

Fix Architecture parameter passed into pacman.conf to permit generation
of foreign architecture containers.

The test on debian/sid amd64 used to generate archlinuxarm aarch64
container looks something like this:
1) Setup pacman
```
$ pacman-key --init
```
- Download http://mirror.archlinuxarm.org/aarch64/core/archlinuxarm-keyring-20140119-2-any.pkg.tar.xz
- Verify the download
- Extract keys into /usr/share/keyrings
```
$ pacman-key --populate
$ pacman-key --populate archlinuxarm
$ pacman-key --refresh-keys
```
2) Run `mkosi --architecture aarch64 ...`

2 years agomake measuring an option 1200/head
Joerg Behrmann [Thu, 22 Sep 2022 15:44:28 +0000 (17:44 +0200)] 
make measuring an option

2 years agoguard cryptography imports
Joerg Behrmann [Thu, 22 Sep 2022 08:37:05 +0000 (10:37 +0200)] 
guard cryptography imports

2 years agoFix undefined PIPE issue
Daan De Meyer [Thu, 22 Sep 2022 08:08:23 +0000 (10:08 +0200)] 
Fix undefined PIPE issue

2 years agoMerge pull request #1198 from DaanDeMeyer/swtpm
Lennart Poettering [Wed, 21 Sep 2022 20:25:07 +0000 (22:25 +0200)] 
Merge pull request #1198 from DaanDeMeyer/swtpm

swtpm followups

2 years agoAdd Fedora 38 and Fedora 39 signing key
Malte Poll [Wed, 21 Sep 2022 15:49:57 +0000 (17:49 +0200)] 
Add Fedora 38 and Fedora 39 signing key

2 years agomkosi: pre-calculate expected PCR 11 values, and sign them, and include in unified...
Lennart Poettering [Wed, 21 Sep 2022 10:05:16 +0000 (12:05 +0200)] 
mkosi: pre-calculate expected PCR 11 values, and sign them, and include in unified kernel image

2 years agoSoothe some CodeQL warnings
Joerg Behrmann [Wed, 21 Sep 2022 15:02:47 +0000 (17:02 +0200)] 
Soothe some CodeQL warnings

2 years agoRename run_..._cmdline() functions to run_..._setup() 1198/head
Daan De Meyer [Wed, 21 Sep 2022 16:41:20 +0000 (18:41 +0200)] 
Rename run_..._cmdline() functions to run_..._setup()

Better name since these functions end up doing more than just
constructing the command line to be used.

2 years agoStart swtpm from within run_qemu_cmdline()
Daan De Meyer [Wed, 21 Sep 2022 16:38:24 +0000 (18:38 +0200)] 
Start swtpm from within run_qemu_cmdline()

Let's always start swtpm when we're going to run a qemu machine.
To avoid callers having to do the setup themselves, let's start
swtpm from within run_qemu_cmdline(). We can reuse the context
stack inside run_qemu_cmdline() to manage the start_swtpm()
context.

2 years agomkosi: invoke qemu with swtpm, it's 2022!
Lennart Poettering [Wed, 21 Sep 2022 10:40:32 +0000 (12:40 +0200)] 
mkosi: invoke qemu with swtpm, it's 2022!

If we find swtpm around we'll use it, otherwise not.

Fixes: #1191
2 years agoci: use CodeQL instead of LGTM
Frantisek Sumsal [Wed, 14 Sep 2022 09:33:51 +0000 (11:33 +0200)] 
ci: use CodeQL instead of LGTM

As LGTM is going to be shut down by EOY[0], let's move the code scanning to
CodeQL as recommended. Thanks to GH integration the results from such
scans will be shown both in the respective PR and in the Security ->
Code Scanning tab[1].

[0] https://github.blog/2022-08-15-the-next-step-for-lgtm-com-github-code-scanning/
[1] https://github.com/systemd/mkosi/security/code-scanning

2 years agoMerge pull request #1190 from DaanDeMeyer/drop-nspawn-executable
Jörg Behrmann [Wed, 21 Sep 2022 09:12:13 +0000 (11:12 +0200)] 
Merge pull request #1190 from DaanDeMeyer/drop-nspawn-executable

Allow single files to be used with --extra-search-paths

2 years agoDrop MKOSI_NSPAWN_EXECUTABLE 1190/head
Daan De Meyer [Wed, 21 Sep 2022 07:01:09 +0000 (09:01 +0200)] 
Drop MKOSI_NSPAWN_EXECUTABLE

Now that --extra-search-paths supports single files, there's no
need anymore for MKOSI_NSPAWN_EXECUTABLE so let's drop it.

2 years agoAllow single files to be used with --extra-search-paths
Daan De Meyer [Wed, 21 Sep 2022 07:25:26 +0000 (09:25 +0200)] 
Allow single files to be used with --extra-search-paths

Sometimes we just want to use one file from a directory of files
with --extra-search-paths. Let's make sure we support this by putting
a symlink to the file in a temporary directory and adding that directory
to PATH.