Commit Graph

112 Commits

Author SHA1 Message Date
Marcus Schäfer
a7b984115d
Fixed delta_root build
The support for delta_root allows to build a delta container
image from a given base container. Due to the refactoring of
the kiwi code base using context managers no explicit deletion
of instances happens anymore. This uncovered a weakness of
the delta root code at the level of the overlay mount. At
the time of the umount there are still active temporary
mount handlers which keeps the mountpoint busy. In order to
fix this properly also the PackageManager factory is now
a context manager and the Repository factory received a
cleanup method which is called when the PackageManager goes
out of scope. This refactoring also fixes the busy state
when building deltas
2024-03-07 15:50:58 +01:00
Marcus Schäfer
f158e22ae3
Move SystemPrepare to context manager
Change the SystemPrepare class to context manager.
All code using SystemPrepare was updated to the following
with statement:

    with SystemPrepare(...) as system_prepare:
        system_prepare.some_member()

This completes the refactoring from finalizers to
context managers and Fixes #2412
2024-02-27 15:43:06 +01:00
Marcus Schäfer
4bcfa7f804
Move Repository to context manager
Change the Repository Factory to be a context manager.
All code using Repository was updated to the following
with statement:

    with Repository(...).new as repo:
        repo.some_member()

This is related to Issue #2412
2024-02-22 16:17:28 +01:00
Neal Gompa (ニール・ゴンパ)
8f62f4417f
Merge pull request #2472 from OSInside/system_mount_as_context_manager
Move ImageSystem to context manager
2024-02-19 11:32:52 -05:00
Dan Čermák
48817a6441
Refactor Command class
Command.run() currently has a bit of a confusing behavior: if raise_on_error is
False and the executable is not found, then a weird CommandT is returned (return
code is -1 and stdout+stderr is None). This makes it possible to hanlde command
not found errors separately, but it makes that needlessly verbose. So instead,
let's just return None in *this* special case.

That in turn uncovered, that in most cases when we set `raise_on_error=True`, we
actually want an error if the command is not present but no error if the command
fails to execute (e.g. because it returns -1 if you run `$cmd --version`). Hence we
introduce the flag `raise_on_command_not_found`, which causes an exception to
be raised if the command is not found. This makes it independent of the
`raise_on_error` flag.

Additionally, we add a small optimization: if command starts with /, then we
assume it's a full path and we omit the call to which (and just check whether it
exists).

Co-authored-by: Marcus Schäfer <marcus.schaefer@gmail.com>
2024-02-19 16:33:24 +01:00
Marcus Schäfer
9a8f59946e
Move ImageSystem to context manager
Change the ImageSystem class to context manager.
All code using ImageSystem was updated to the following
with statement:

    with ImageSystem(...) as image_system:
        image_system.some_member()

This is related to Issue #2412
2024-02-19 16:17:00 +01:00
Alexandre Detiste
fb69627ad3
Use unittest.mock from core python everywhere
mock was an independent module that has been merged into the Python standard library.
2024-02-18 22:15:30 +01:00
Marcus Schäfer
cd052c0558
Move OCI to context manager
Change the OCI Factory to be a context manager.
All code using OCI was updated to the following
with statement:

    with OCI(...).new as oci:
        oci.some_member()

This is related to Issue #2412
2024-02-13 22:35:52 +01:00
Marcus Schäfer
c6d8235fa6
Fixed grub terminal setup
The grub terminal setup is divided into the setting for the output
and the input console. For both settings different parameters exists.
So far kiwi did not differentiate between the two parts of the
console setup and that could lead to a wrong setting if only one
value is provided in kiwi's console= attribute which lead to the
grub setting, GRUB_TERMINAL=value. If value is set to e.g gfxterm
grub takes this for both input and output and it's obviously
wrong for the input. To make this less error prune the kiwi code
changes with this commit to set GRUB_TERMINAL_INPUT and
GRUB_TERMINAL_OUTPUT rather than GRUB_TERMINAL and also runs sanity
checks on the provided values if they are applicable. The information
for setting up the console in the schema stays untouched though.
That's because it's used for all bootloaders and also because grub
supports multiple values for the console in/out setting in one
GRUB_TERMINAL variable even though kiwi does no longer use it.
To make this clear for the users also the documentation for the
console attribute setup has been updated. If we want to wish two
distinct attributes for input and output console settings a schema
change and also differentiation between bootloaders is needed and
that I only see for the kiwi-10 branch if at all. This Fixes #2419
2024-01-08 18:02:27 +01:00
Marcus Schäfer
2a22901ddd
Make sure selinux policy is effectively applied
setup_selinux_file_contexts is now called after the config.sh
script. This makes sure that eventual policy related changes
done in the optional config.sh are covered by a late setfiles
call. In addition setup_selinux_file_contexts is called again
at the end of any chroot based script hook. So we assume that
any optional script target can change the system in a way that
a new setfiles call might be required. It can happen that
setfiles is called more often than required but as we cannot
know what custom scripts does, it's better to call it more
often compared to not often enough. This Fixes bsc#1210604
2023-12-17 15:48:08 +01:00
Marcus Schäfer
fa544b4a87
Add kiwi_live_volid variable to profile
As part of the profile environment only the kiwi_install_volid
variable existed with the default value 'INSTALL'. This information
is correct when building an oem image with installiso set to
true. The resulting .install.iso image has the configured volid
or the mentioned default 'INSTALL'. However, when building a live
ISO image the default volid value is set to 'CDROM' but the profile
environment contains kiwi_install_volid which is misleading and
in case no volid is provided in the configuration file, the
default value would also be a wrong information. This commit cleans
up the mess and provides kiwi_install_volid for install ISO media
and kiwi_live_volid for Live ISO media with their respective
default values
2023-08-15 22:23:49 +02:00
glaubway
f5c2b3281f
make alias unique in any cases 2023-06-10 17:22:47 +03:00
Marcus Schäfer
e2c727f4a1
Encode remote URLs
Special characters in a URL e.g the @ sign needs to be encoded
as part of a remote URL.
2023-04-24 23:31:29 +02:00
Marcus Schäfer
05f83e545b
Add support for config-host-overlay.sh script 2023-03-16 17:14:13 +01:00
Marcus Schäfer
41875f57ea
Add support for creating delta containers
Add new attribute delta_root="true|false" which in combination with
derived_from="OCI-base-image" allows to create a delta root tree
only containing the differences between the OCI-base-image and the
actions taken by the kiwi prepare step. Based on the delta root tree
the subsequent image creation process starts. Such an incomplete
root tree is only useful under certain circumstances which is also
the reason why the feature is only available to the oci and docker
image types.
2023-03-16 17:06:15 +01:00
Marcus Schäfer
8549db8699
Fixed wrong test assertions
Former versions of pytest did ignore invalid assertions.
Now they are reported as an error and show the mistakes
of the past
2023-01-17 16:30:09 +01:00
Marcus Schäfer
9cf96cbceb
Don't show secret parts of an URI
Using URIs of the form uri://user:pass@location should not be
logged or printed including its credential data
2022-12-14 16:58:43 +01:00
Marcus Schäfer
a344c540dc
Increase scope of kernel lookup
So far kiwi was looking up kernels only on /boot. Including
other bootloaders it's no longer required that the kernel
packages of the distributions provides the kernel in /boot
Thus kiwi's lookup needs to be extended to other places
which is done by this commit.
2022-11-15 09:04:57 +01:00
Neal Gompa (ニール・ゴンパ)
1f15e07f9f
Merge pull request #2159 from OSInside/setfiles_version_check
Handle older versions of setfiles correctly
2022-06-23 10:26:29 -04:00
Marcus Schäfer
09b9d2a491
Fixed use of CommandCapabilities
The class allows to check for data produced on stdout
and stderr. However, programs reporting data on stderr
usually fails with an exit code != 0. If the command
is not called with raise_on_error=False it will never
be possible to catch information from stderr. As we
don't know if programs returns a failed exit code
even on their e.g --usage message we should always
pass the no raise option to make this more useful
2022-06-21 21:50:59 +02:00
Neal Gompa (ニール・ゴンパ)
6748dee3cb
Merge pull request #2161 from OSInside/fix_btrfs
Fix btrfs volume mounting
2022-06-21 11:25:34 -04:00
Marcus Schäfer
1c5cd2d594
Handle older versions of setfiles correctly
In older versions of setfiles we need a two pass setup
First set the policy, second apply the security context.
This commit checks in the usage message of setfiles which
invocation syntax is required
2022-06-16 10:39:20 +02:00
David Cassany
7ea533f912
Fix volume mount path and adapt unit tests
Signed-off-by: David Cassany <dcassany@suse.com>
2022-06-15 15:37:53 +02:00
Marcus Schäfer
be4bf8a84f
Fixed error handling for setfiles policy lookup
Errors from os.scandir were not catched. In addition the path
to run scandir was not properly created
2022-06-14 18:17:00 +02:00
Marcus Schäfer
30eb1c1a5b
Correct setfiles relabeling
This change was inspired by a change done on Fedora's livecd-tools
from here: livecd-tools/livecd-tools#236. The patch corrects issues
with the setfiles SELinux relabel command. The issues become apparent
when the host and guest policies differ. Thus it becomes required
to explicitly set the policy to decouple from eventual unwanted
host settings.
2022-06-13 13:18:51 +02:00
Carlos Bederián
dd7e75f9c6
Setup SELinux on every system prepare / build (#2148)
Setup SELinux on every system prepare / build such that all image types benefit from it not only the disk (oem) type
2022-06-01 11:31:00 +02:00
Marcus Schäfer
04d966b920
Add support for group id in users setting
Allow to specify the group id in the groups list a user
should belong to. The group id can be placed as part of
the group name separated by a colon like in the following
example:

<users>
    <user groups="kiwi,admin:42,users" password="..." name="kiwi"/>
</users>

Please note kiwi checks if the provided group already
exists and only creates a group if it is not already present in
the system. As default groups are usually provided by the OS
itself including its preferred group id, you will intentionally
not be able to overwrite group id for existing groups.
This Fixes #2064
2022-05-20 19:23:22 +02:00
Marcus Schäfer
4f47b1d94b
Add support for prebuilt bootstrap package for apt
When using the apt packagemanager kiwi required the use of
debootstrap to create the initial rootfs. This works as long
as there is always a main distribution repository available
which follows the structure of the official debian mirrors.
However if such a main distribution is not present or an
alternative layout like e.g OBS repos is used, debootstrap
will refuse to work. To allow for an alternative and without
the dependency to debootstrap kiwi supports using a prebuilt
bootstrap package providing the mini rootfs to serve as
the bootstrap result. As all other package managers properly
supports installation into an empty new root, this feature
was only added when using the apt packagemanager
2022-05-18 11:19:51 +02:00
Marcus Schäfer
9be6e50ee9
Added ImageSystem class
The class responsibility is to provide access to the
image root system from the block layer of the image
scope
2022-03-01 09:02:48 +01:00
Marcus Schäfer
76fecc2300
Merge pull request #2073 from OSInside/debootstrap_logging
Added debootstrap log info to exception message
2022-02-26 20:46:04 +01:00
Marcus Schäfer
9c9250ebc4
Support nose and xunit style tests
The modifications in this commit allows the unit tests
to run on both, pytest 6.x (nose test layout) and the new
pytest 7.x (xunit test layout). This Fixes #2072 in a
much nicer way. Thanks much to @smarlowucf
2022-02-26 20:26:18 +01:00
Marcus Schäfer
1f869e7ca8
Revert "Unit test adaptions to pytest v7"
This reverts commit 0dc2e803e0.
The pytest interface from version v6 to v7 has received
changes which requires the tests to be adapted to work for
either the old or the new interface. As there are still many
distributions which uses v6 as the standard we decided to
revert back the adaptions done to support v7 and create
a version requirement to v6 in .virtualenv.dev-requirements.txt
This Fixes #2072
2022-02-26 20:19:42 +01:00
Marcus Schäfer
04e879f722
Update unit test to work in obs
Some unit tests fails if they run in an obs environment.
This is because the implementation checks the runtime
envoironment and behaves differently if the system is
an obs worker. The unit tests has to explicitly set this
condition right for the test
2022-02-26 17:20:03 +01:00
Marcus Schäfer
66e7b5bb74
Added debootstrap log info to exception message
In case debootstrap fails there is more detailed information
in a logfile written by debootstrap itself. This commit changes
the exception information to contain this log information if
present. Related to Issue #1800
2022-02-22 16:19:19 +01:00
Marcus Schäfer
c666a785c3
Add support for pre_disk_sync.sh script
The optional pre_disk_sync.sh script is executed for the
disk image type oem only and runs right before the synchronisation
of the root tree into the disk image loop file. The script hook
can be used to change content of the root tree as a last action
before the sync to the disk image is performed. This is useful
for example to delete components from the system which were
needed before or cannot be modified afterwards when syncing
into a read-only filesystem.
2022-02-15 18:18:38 +01:00
Marcus Schäfer
0dc2e803e0
Fixed unit tests
The pytest interface setup() method call has changed
in a way that an additional parameter is passed to
the method which leads to a python error at invocation
time if the setup method does not define it.
2022-02-07 21:27:39 +01:00
Marcus Schäfer
580a0d6989
Merge pull request #2046 from OSInside/selinux-setfiles-correctly
Ensure SELinux labels are set based on the policy
2022-01-25 21:18:49 +01:00
Marcus Schäfer
fb6547046c
Merge pull request #2028 from Vogtinator/machine-id
Allow "uninitialized" in /etc/machine-id instead of emptying it
2022-01-25 21:17:37 +01:00
Neal Gompa
45dc804017 Ensure SELinux labels are set based on the policy
When running kiwi from a filesystem tree that has custom labels applied
(such as when using kiwi from within a container on an SELinux-enabled
host), the filesystem labeling doesn't correctly apply on some files
and folders with a warning about the location being customized by
the administrator. This causes all kinds of strange results with
the built images and makes them unbootable.

To resolve this, tell setfiles to forcibly set files and folders
with the default context from the installed policy.
2022-01-25 13:27:43 -05:00
Fabian Vogt
0b99ba8d0b Allow "uninitialized" as content of /etc/machine-id
According to machine-id(5), an empty file does not signal that this is the
first boot of the system. Instead, the file needs to be missing or contain
the string "uninitialized". A missing file does not work if the filesystem
is initially mounted read-only, so allow "uninitialized" as well, instead
of truncating it.

Improve the documentation of the method, e.g. dracut is not involved.
2022-01-25 10:53:04 +01:00
Marcus Schäfer
334895c740
Fix the uninstall(force) on Debian based dists
Packages marked for uninstall via <package name="delete|uninstall"/>
failed to become removed for several reasons. The way this was done
in kiwi did not work because dpkg needs to be called differently
and with some nasty pre-processing in order to allow for force
deletion. In force mode we also allow to remove packages marked as
essential. In gracefull uninstall mode this commit makes sure the
environment is prepared and does not fail for false-positive
reasons.
2022-01-24 16:05:46 +01:00
Marcus Schäfer
951231867b
Allow calling podman within chroot
Added helper functions and env preparation code
to allow calling podman from within a chroot. This
allows to run podman from e.g config.sh and also
inside of OBS workers
2022-01-21 09:27:35 +01:00
Marcus Schäfer
6a53c6a606
Fixed image builds without kernel
If an image is build without a kernel kiwi fails due to
some code paths expecting the presence of kernel modules
and or kernel binaries. This commit fixes this and allows
creating an image without installing a kernel.
2022-01-14 20:08:17 +01:00
Marcus Schäfer
dd763835cf
Added debug option --debug-run-scripts-in-screen
Instead of running scripts in screen if the --debug switch is
set, we allow to explicitly switch on this behavior via
a new option. This Fixes #2010
2022-01-11 09:38:22 +01:00
Marcus Schäfer
e2f32e8c8a
Added support for collection modules
In CentOS Stream 8 and Red Hat Enterprise Linux 8, there are
Application Streams that are offered in the form of modules
(using Fedora Modularity technology). To build images that use
this content KIWI needs to support to enable/disable various
modules. This commit allows to configure collection modules
in a new element as shown below

<packages type="bootstrap">
    <collectionModule name="module" stream="stream" enable="true|false"/>
</packages>

This Fixes Issue #1999
2021-12-14 22:55:05 +01:00
Marcus Schäfer
8fea098ed2
Added support for reading metalink in info module
For resolver operations through libsolv the 'kiwi image info'
module exists. So far it could not read the repos from
metalink repo definitions. This Fixes #1890
2021-11-22 22:08:56 +01:00
Marcus Schäfer
d32661888b
Add support for custom result bundle naming
Allow to specify a bundle_format per <type> which is used
at the time of the result bundle creation to create image
output names matching the provided pattern.
This Fixes #1943
2021-10-21 11:13:49 +02:00
Marcus Schäfer
0aa490c654
Fixed use of LUKS encrypted images with empty pass
For initial provisioning of LUKS encrypted disk images an
empty passphrase key is handy to avoid interaction in the
deployment process. However, the dracut kiwi modules were
lacking the information that the luks keyfile could be an
empty passphrase key which must not be opened with the
potential risk to get prompted for input. This commit
introduces a new profile environment variable evaluated
by the dracut kiwi lib code to open the LUKS pool and
allows to distinguish the situation on key files with
or without a passphrase
2021-10-14 11:27:16 +02:00
Marcus Schäfer
cded86afec
Add support for portable result data (#1949)
In addition to the serialized Result instance kiwi.result
file this commit also creates a portable version of this
information in kiwi.result.json. Only the information that
can be expressed as json document is part of the portable
version. This is related to Issue #1918
2021-10-12 18:31:49 -04:00
Marcus Schäfer
b900264779
Fixed script calls when running in obs
kiwi is called with --debug in obs which triggers the scripts
to be called through screen. However the obs caller is not
associated with a terminal thus it fails. This commit creates
an exception for debug mode when running in obs
2021-09-23 16:54:31 +02:00