Commit graph

502 commits

Author SHA1 Message Date
Ondřej Budai
3bbded4607 org.osbuild.mkfs.btrfs: add support for -m argument
Osbuild doesn't support creating btrfs over multiple devices, thus it should
be fine to have only single and dup in the schema (other options are for raid)
2023-08-25 12:35:56 +02:00
Ondřej Budai
724183b35c stages: add org.osbuild.btrfs.subvol
A trivial stage to create subvolume on a btrfs partition.
2023-08-25 12:35:56 +02:00
Sayan Paul
61da6124ed stages/systemd:support for user service dropin
systemd unit stage will now be able to add user unit dropin,
this is done by adding an additional field:unit-type
which is set to system by default. It also adds ability
to update the unit config with ConditionPathExists.
Relevant testing updated for the new workflow.

Signed-off-by: Sayan Paul <paul.sayan@gmail.com>
2023-08-16 13:23:16 +02:00
Sayan Paul
ed926ecc71 stages/systemd:support timer units
unit pattern updated to incoporate timer units

Signed-off-by: Sayan Paul <paul.sayan@gmail.com>
2023-08-16 13:23:16 +02:00
Simon de Vlieger
161fe789af dnf4.mark: mark packages in DNF state database
This adjustment allows the definition of the mark with the RPMs and runs
DNF after installing the RPMs to put the proper markings in the DNF
state database. See #455.

This ensures that packages don't get removed during `autoremove` leading
to broken systems.
2023-08-15 00:37:06 +02:00
Brian C. Lane
44c28c8c16 autopep8: Update with changes to make autopep8 -a -a -a happy 2023-08-10 13:04:14 +02:00
Ondřej Budai
6e254c95af stages/ostree.encapsulate: use new entrypoint on rpm-ostree >=2023.2
rpm-ostree 2023.2 dropped the `rpm-ostree container-encapsulate` entrypoint.
Instead, we have to use `rpm-ostree compose container-encapsulate`.

Adjust the code that it selects the correct entrypoint based on the rpm-ostree
version.

Since the new stage now requires python-yaml, add it to the buildroot and
regenerate all manifests.
2023-08-08 12:41:17 +02:00
Colin Walters
6f81c59894 ostree.encapsulate: It's rpm-ostree, not ostree
We have a lot of copypasta of `def ostree()` but in this
case it's actually rpm-ostree, and we should be clear about that.

(Also in the future this code will need to change
 to use the non-deprecated entrypoint, see
 https://github.com/coreos/rpm-ostree/pull/4527 )
2023-08-05 23:42:50 +02:00
Simon de Vlieger
d60690ce46 tox: add tox
`tox` is a standard testing tool for Python projects, this allows you to
test locally with all your installed Python version with the following
command:

`tox -m test -p all`

To run the tests in parallel for all supported Python versions.

To run linters or type analysis:

```
tox -m lint -p all
tox -m type -p all
```

This commit *also* disables the `import-error` warning from `pylint`,
not all Python versions have the system-installed Python libraries
available and they can't be fetched from PyPI.

Some linters have been added and the general order linters run in has
been changed. This allows for quicker test failure when running
`tox -m lint`. As a consequence the `test_pylint` test has been removed
as it's role can now be fulfilled by `tox`.

Other assorted linter fixes due to newer versions:
- use a str.join method (`consider-using-join`)
- fix various (newer) mypy and pylint issues
- comments starting with `#` and no space due to `autopep8`

This also changes our CI to use the new `tox` setup and on top of that
pins the versions of linters used. This might move into separate
requirements.txt files later on to allow for easier updating of those
dependencies.
2023-08-01 15:01:13 +02:00
Gianluca Zuccarelli
74eed6a33b stages: add openscap autotailor stage
Add a new stage to generate an OpenSCAP tailoring file. The stage
overrides a base OpenSCAP profile by enabling and disabling user
selected rules and creates a new profile name which can be used for
OpenSCAP scanning and remediation.
2023-07-18 15:29:13 -07:00
Brian C. Lane
8f6535cacc org.osbuild.rpm: Add some context to rpmkeys failure
This will hopefully help debug problems when the signature check fails.
You need to manually take the hash and look it up in the manifest
sources list to figure out what package failed since this stage doesn't
have access to sources.
2023-07-18 18:42:47 +02:00
Simon de Vlieger
f1b79c8a73 stage: anaconda, allow access to more config
Anaconda has deprecated the `kickstart_modules` directive and instead
now has `activatable_`, `forbidden_`, and `optional_modules`. This is
available starting in Fedora 35.

This change allows frontend code (`osbuild-composer`) to put version
checks in place to write the correct keys.
2023-07-18 13:41:05 +02:00
Ondřej Budai
c01caae3ac stages/squashfs: add support for zstd compression
Fedora and RHEL 9 kernels support it and since it's an interesting alternative
to other compression methods, we should support it in osbuild.

I also took the liberty of sorting the compression methods alphabetically.
2023-07-18 08:58:26 +02:00
Simon de Vlieger
36ee0d3edc stages/sysconfig: add desktop support 2023-07-17 12:15:12 +02:00
Simon de Vlieger
829183a1f3 stages/sysconfig: add livesys support 2023-07-17 12:15:12 +02:00
Ondřej Budai
dc372bbdea stages/rpm: set machine-id to 444
According to the systemd spec file, /etc/machine-id should have the 444
permissions. Thus, we need to chmod the file to 444 after it's created.

See:
 - 9c05b44a4b/f/systemd.spec (_821)
 - https://bugzilla.redhat.com/show_bug.cgi?id=2221269
 - https://issues.redhat.com/browse/COMPOSER-1992
2023-07-12 10:53:31 +02:00
Antonio Murdaca
4bfd646b0d stages: add new zstd stage
typo fix test/data/stages/README.md
add updated test-data after adding zstd to fedora-34-build-v2.mpp.json

Signed-off-by: Sarita Mahajan <sarmahaj@redhat.com>
2023-06-14 09:44:00 +02:00
Simon de Vlieger
4bd169c20e stage: add a livesys stage
This stage is necessary for the live image work being done in
`osbuild-composer` at the moment.
2023-05-31 09:30:55 +02:00
Tomáš Hozza
3e780762cb stages/sgdisk: option to not quote partition names passed to sgdisk
The partition name in the sgdisk stage was previously quoted when
passed to sgdisk as an argument. I think that this was done because
the sgdisk man page states that:

```
If you want to set a name that includes a space, enclose it in
quotation marks, as in sgdisk -c 1:"Sample Name" /dev/sdb.
```

However, this should apply only when sgdisk is run in a shell, so that
the argument is not split by shell into multiple arguments and passes
as a single string.

The stage is executing sgdisk using Python `subprocess` module, which
does not need strings with spaces to be quoted, because they are passed
to the command as separate items which are not split in any way.

The previous behavior of the stage was that these quotes became part of
the actual partition name in the partition table.

After a discussion within the team, we determined that this is a bug.
However, fixing it would result in osbuild producing a different
artifact for the same manifest, compared to osbuild version without such
fix. This is undesired.

For backward compatibility, a new `quote_partition_name` property is
added to the stage options, which can be used to make the stage not
quote the partition name when passed to `sgdisk`. As a result, the
partition name won't be quoted in the partition table.

The default stage behavior us kept.

Modify unit tests to use this option by default.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2023-05-26 08:43:52 +02:00
Eric Chanudet
267f3909bd stages/sfdisk: support changing GPT partition attribute bits
util-linux 2.38.1, at least, does not accept raw bit indexes for the
reserved bits (Bit0-2). The undefined ones are out of reach as well and
will have sfdisk throw an error. Only the GUID specific ones can be
passed as raw indexes. This can be verified with the --part-attrs
option. It replicates the format of the --dump output:

$ dd if=/dev/zero of=disk.img bs=$((4<<10)) count=$((32<<10)
$ sgdisk disk.img -n 0:0:+64M -t 0:0FC63DAF-8483-4772-8E79-3D69D8477DE4 -c 0:root
$ sgdisk disk.img -A1:set:{0,1,2,3,48}
$ sfdisk --dump disk.img
label: gpt
label-id: 7484F730-3429-47BF-8A72-3A7AE1F2D86C
device: disk.img
unit: sectors
first-lba: 34
last-lba: 262110
sector-size: 512

disk.img1 : start=        2048, size=      131072, type=0FC63DAF-8483-4772-8E79-3D69D8477DE4, uuid=404694AC-247D-43B3-9907-A468E5C038A3, name="root", attrs="RequiredPartition NoBlockIOProtocol LegacyBIOSBootable GUID:48"

$ sfdisk --part-attrs disk.img 1 0
unsupported GPT attribute bit '0'
sfdisk: disk.img: partition 1: failed to set partition attributes

While the --dump output prefixes the GUID specific bits with "GUID:",
that is not necessary for setting them, which is consistent with the
man-page.

Signed-off-by: Eric Chanudet <echanude@redhat.com>
2023-05-25 14:57:28 +02:00
Simon de Vlieger
a348fe2d49 stages/isolinux: default list
Otherwise when `opts` (which isn't `required`) is left out we fail the
stage.
2023-05-23 10:13:15 +02:00
Alexander Larsson
3343696a7b org.osbuild.mkfs.ext4: Add verity option to
This allows enabling the ext4 "verity" feature (which is currently
default to off). This will be needed in the automotive work we're
doing.

Signed-off-by: Alexander Larsson <alexl@redhat.com>
2023-05-16 00:03:16 +02:00
Sanne Raymaekers
1fbd9d975f stages/org.osbuild.ovf: support older python3 versions
`str.removesuffix` was introduced in python3.9, yet el8 uses python3.6
by default.
2023-05-09 23:54:01 +02:00
Gianluca Zuccarelli
586d6bbe43 stages/yum.repo: add sslverify field
Add `sslverify` field to the yum.repo stage.
2023-05-03 20:53:52 +02:00
Ondřej Budai
f60a4e3c84 stages/lorax-script: add missing type of path to the schema
`path` has to be a string, let's make it explicit in the schema.
2023-04-19 12:42:27 +02:00
Ondřej Budai
ce196f287c stages/lorax-script: add missing default basearch to the schema
The code uses x86_64 as a default, see:

basearch = options.get("basearch", "x86_64")

Let's declare that explicitly in the schema to prevent any confusion.
2023-04-19 12:42:27 +02:00
Sanne Raymaekers
028bf67a1d stages/org.osbuild.wsl.conf: add stage to configure WSL settings 2023-04-11 10:11:08 +02:00
Simon de Vlieger
12e4e541c3 stage/systemd.preset: be able to write a preset file
The right way to enable services is to use a preset file instead of
writing directly into /etc. This adds a new stage called
`org.osbuild.systemd.preset` to do so.
2023-04-05 14:34:39 +02:00
Sanne Raymaekers
efa038197d stages/org.osbuild.ovf: support older python3 versions
The `capture_output` option was added in python3.7, yet el8 has
python3.6 by default.
2023-04-04 20:35:57 +02:00
Achilleas Koutsou
ac2f140d4c stages/skopeo: merge manifest into image directory
When a manifest list is matched with a container image, the skopeo
stage will merge the specified manifest into the container image dir
before copying it to the registry in the OS tree.

If there is no manifest to merge, we maintain the old behaviour of
symlinking the source to work around the ":" in filename issue.
Otherwise, we copy the container directory so that we can merge the
manifest in the new location.
2023-03-31 14:57:26 +02:00
Achilleas Koutsou
dd902311c2 stages/skopeo: add manifest-lists input
Add an extra optional input type to the skopeo stage called
`manifest-lists`.  This is a list of file-type inputs that must be a
list of manifest lists, downloaded by the skopeo-index source.

The manifests are parsed and automatically associated with an image from
the required `images` inputs.  If any manifest list is specified and not
used, this is an error.

Adding manifest-lists currently has no effect.
2023-03-31 14:57:26 +02:00
Achilleas Koutsou
ce29a4af73 sources/skopeo: change local container format
Change the local storage format for containers to the `dir` format.
The `dir` format will be used to retain signatures and manifests.

The remove-signatures option is removed since the storage format now
supports them.

The final move (os.rename()) at the end of the fetch_one() method now
creates the checksum directory if it doesn't exist and moves the child
archive into it, adding to any existing archives that might exist in
other formats (from a previous version downloading a `docker-archive`).

Dropped the .tar suffix from the symlink in the skopeo stage since it's
not necessary and the target of the link might be a directory now.

The parent class exists() method checks if there is a *file* in the
sources cache that matches the checksum.  For containers, this used to
be a file called container-image.tar under a directory that matches the
checksum, so for containers it always returned False.  Added an override
for the skopeo source that checks for the new directory archive.
2023-03-31 14:57:26 +02:00
Achilleas Koutsou
5f76ec03a7 inputs/containers: change archive format to dir
The format so far was assumed to be `docker-archive` if the container
was coming from a source and `oci-archive` if it was coming from a
pipeline.  The source format will now be changed to `dir` instead of
`docker-archive`.  The pipeline format remains `oci-archive`.

With the new archive format being `dir`, the source can't be linked into
the build root and is bind mounted instead with the use of a MountGuard
created with the instance of the service, and torn down when the service
is stopped.

The _data field is removed from the map functions.  It was unused and
these functions aren't part of the abstract class so they don't need to
have consistent signatures.

Update the skopeo stage with support for the newly supported `dir`
format.
2023-03-31 14:57:26 +02:00
Sanne Raymaekers
bae4f77661 stages: add ovf stage
This stage generates an ovf descriptor and a manifest intended for
vSphere. The resulting artifacts can be tarred together with the vmdk
into an ova.
2023-03-28 23:07:38 +02:00
Antonio Murdaca
345b2a5997 stages/ignition: support multi kargs in network kcmdline
As of today the functionality is broken if somebody passes more than one
karg as the join would simply unify the strings but
ignition_network_kcmdline is unquoted and results in just the very first
karg to be consumed by the set command.

Signed-off-by: Antonio Murdaca <antoniomurdaca@gmail.com>
2023-02-27 17:39:14 +01:00
Tomáš Hozza
200c2b0129 stages/copy: add option to remove destination before copying
Extend the copy stage to optionally allow removing the destination
before copying. This allows one to not follow symlinks if the
destination is a symlink to a file. By default, `cp` would change
the file pointed to by the destination if it is symlink.

Extend the stage doc text to cover the behavior with regard to
destination being a symlink.

Add unit tests for the copy stage to also test the newly added option.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2023-02-20 10:31:06 +01:00
Achilleas Koutsou
d3229dc929 stages/shell.init: add top-level files property
Add a top level property "files" to the schema and move the rest of the
existing schema one level down.  This way we can support adding global
properties in the future if we ever need to expand the scope of the
stage.
2023-02-15 18:14:01 +01:00
Achilleas Koutsou
eb903a9596 stages/shell.init: restrict filename pattern
Old filename pattern was too wide and contained a bug in the form of
.-_, which defined a range instead of three characters.
2023-02-15 18:14:01 +01:00
Achilleas Koutsou
b848e5d9df stages/shell.init: add pattern for env var names
Pattern for valid environment variable names as defined in
The Open Group Base Specifications Issue 7, 2018 edition
IEEE Std 1003.1-2017 (Revision of IEEE Std 1003.1-2008)

https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap08.html

Updated tests to match UPPERCASE ONLY var names.
2023-02-15 18:14:01 +01:00
Achilleas Koutsou
03b467da72 stages: add shell.init stage
New stage for writing shell init files in /etc/profile.d.
Currently only supports writing environment variables as key-value
pairs.
2023-02-08 13:30:39 +01:00
Tomáš Hozza
16063fff57 Add org.osbuild.chown stage
Add a new `org.osbuild.chown` stage for setting user and group ownershop
of files. The stage runs the `chown` from the image using `chroot` to
enable it to use users and groups that exist only in the (image) tree.

Add unit test testing the stage in various scenarios.

Co-authored-by: Janine Olear <pninak@web.de>
Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2023-02-07 12:14:01 +01:00
Tomáš Hozza
db1fa5b3c3 stages/mkdir: enhance stage documentation
Explicitly mention the stage behavior with regard to setting mode on
newly created or existing directories.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2023-01-20 14:28:36 +01:00
Tomáš Hozza
d3a63cf056 Revert "stages/mkdir: explicitly set mode using os.chmod"
This reverts commit a988aacf99.

After some discussion, the original behavior was intentional. With the
added support for gracefully handling the existence of directories, the
stage would originally not set the mode of an existing directory, while
now it will. Additional issue is that `mkdir` applies the provided mode
- umask, which was intentional. Setting the same mode without taking
umask value into account is not desired.
2023-01-20 14:28:36 +01:00
Tomáš Hozza
b8e1450a35 stages/mkdir: add exist_ok option to not fail if directory exists
Add a new optional stage option to not fail if the specified directory
already exists. This will make it easier to support creation of custom
repositories via customizations in osbuild-composer. The reason is that
if a specified directory exists in an image, because it was created by
an RPM, then creating it would fail. However, the user may have
specified different mode for the directory, than it already has. Since
there is no way to know for sure if the directory already exists on the
image, without building the image itself, it is desired to handle this
case gracefully as valid in specific use cases.

The default behavior stays the same - specifying an existing directory
path will lead to an error.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2023-01-16 20:19:27 +01:00
Tomáš Hozza
a988aacf99 stages/mkdir: explicitly set mode using os.chmod
Documentation for os.mkdir() says that the mode is
ignored on some systems. Also umask value may affect
the final mode. So we set the mode explicitly.

Set the mode explicitly.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2023-01-16 20:19:27 +01:00
Achilleas Koutsou
2efdbe0277 stages/rhsm.facts: create facts file in /etc
Instead of creating the file in /usr/share and symlinking to /etc,
create it directly in /etc. This fixes an issue with SELinux labeling.
The file in /usr/share does not get labelled correctly because it
doesn't match the policy and causes issues with some tools (rhc).

See rhbz#2147450.
2023-01-03 09:27:13 +01:00
Eric Curtin
0007fc2065 ostree.config: add aboot (Android) bootloader config option
We want to add aboot to the list of possible bootloaders so we can
distinguish if we are using aboot or one of the other bootloaders.

Signed-off-by: Eric Curtin <ecurtin@redhat.com>
2022-12-15 11:27:02 +00:00
Christian Kellner
caad585907 stages: add new org.osbuild.ostree.encapsulate
Wrap OSTree commits into a oci container image.
2022-12-15 11:13:19 +01:00
Christian Kellner
e793cc0eb5 stages/users: create missing home directories
If a home directory is specified for an existing user that does
not have one, `usermod` does not create one. This case is now
detected and `mkhomedir_helper(8)` is run inside the chroot to
create the home dir. In Fedora this utility is provided by the
`pam` package so this is now installed in the corresponding
tests together with a new user that simulates the aforementioned
scenario.
Enahnce the stage description: drop an superflous line and add
a description for the home-dir scenario.
2022-12-07 17:25:30 +01:00
Christian Kellner
8ee740dff2 stages/users: don't create homedir when home is empty
Don't create a home dir if the `home` property is given, but empty.
Modify the users tests to create a user that has no home directory.
2022-12-07 17:25:30 +01:00