Commit graph

136 commits

Author SHA1 Message Date
Achilleas Koutsou
83ce9aa4ef grub2: new grub2 stage options constructor for Unified configs
New constructor for unified grub2 setups [0].  Having this separate
constructor lets us have different logic for unified and non-unified
cases and also have fewer function parameters.

[0] https://fedoraproject.org/wiki/Changes/UnifyGrubConfig

Co-Authored-By: Christian Kellner <christian@kellner.me>
2022-02-23 22:42:59 +01:00
Achilleas Koutsou
a7c702c4ae osbuild2: remove redundant option set condition
The Legacy stage option is always set to the value from the function
argument unconditionally.  This condition is useless.

Co-Authored-By: Christian Kellner <christian@kellner.me>
2022-02-23 22:42:59 +01:00
Christian Kellner
2c6e726c94 disk: add new GenImageKernelOptions helper
This creates the needed kernel options for an image, if any,
based on the partition table.

Co-Authored-By: Achilleas Koutsou <achilleas@koutsou.net>
2022-02-22 19:23:41 +00:00
Christian Kellner
85e2a53606 osbuild2: add new GenImage{Prepare,Finish}Stages
Add new helper functions that will return the necessary stages to
prepare a disk image, i.e. take care of creating the raw image
file, partitioning it, creating the devices on it (LUKS2, LVM2),
and formatting all the file systems: `GenImageStagesPrepare`.
Additionally, some partition layouts require some post-processing,
e.g. LVM2 where the volume group needs to be renamed "offline".
For this the `GenImageFinishStages` was added.

Co-Authored-By: Achilleas Koutsou <achilleas@koutsou.net>
2022-02-22 19:23:41 +00:00
Christian Kellner
670b936e6b osbuild2: new GenDeviceFinishStages method
This should be called at the end of the pipeline that creates an
image, to add stages that are needed to finish up the image.
Currently the only stage that will be added is the `lvm2.metadata`
stage in the case the partition layout contains LVM2.

Co-Authored-By: Achilleas Koutsou <achilleas@koutsou.net>
2022-02-22 19:23:41 +00:00
Christian Kellner
3c6e34aeb3 osbuild2: LVM2Metadata: only validate CreationTime if not empty
It is ok to not pass the creation time to osbuild, i.e. it can be
empty. If so, don't validate it.

Co-Authored-By: Achilleas Koutsou <achilleas@koutsou.net>
2022-02-22 19:23:41 +00:00
Christian Kellner
2314ca37d7 osbuild2: NewLVM2MetadataStage takes map of devices
Instead of just passing in a single device, pass in a `Devices`
type, i.e. a map of devices, since the LVM can be located on a
LUKS2 container which is located inside a partition so multiple
devices are needed to access it.

Co-Authored-By: Achilleas Koutsou <achilleas@koutsou.net>
2022-02-22 19:23:41 +00:00
Christian Kellner
d48d6f22e1 osbuild2: GenCopyFSTreeOptions takes filename not device
The only thing we needed from the passed in device was the filename,
so just pass in that directly.

Co-Authored-By: Achilleas Koutsou <achilleas@koutsou.net>
2022-02-22 19:23:41 +00:00
Christian Kellner
a2e1fcc451 osbuild2: basic checks for GenDeviceCreationStages
Verify that we get the necessary "luks2.format" and "lvm2.create"
stages for a partition table that has LVM2 on top of LUKS2.

Co-Authored-By: Achilleas Koutsou <achilleas@koutsou.net>
2022-02-22 19:23:41 +00:00
Christian Kellner
d1b1e32b6e disk: Partition.Payload is now an Entity
Partition.Payload now supports every type of disk.Entity which enables
creating PartitionTables with LUKS, LVM, and Btrfs. \o/

Co-Authored-By: Achilleas Koutsou <achilleas@koutsou.net>
2022-02-22 19:23:41 +00:00
Achilleas Koutsou
6b3802739b osbuild2: deduplicate ziplInstStageOptions()
Use single NewZiplInstStageOptions() from osbuild2 instead of
implementing in each distro.
2022-02-22 19:23:41 +00:00
Christian Kellner
153f9b46fd osbuild2: deduplicate grub2StageOptions() and grub2InstStageOptions()
Use single NewGrub2StageOptions() and NewGrub2InstStageOptions()
functions from osbuild2 instead of implementing them in distros.

A small option flip is required outside the function for RHEL 8.5 and
RHEL 8.6 to maintain the old behaviour.

Co-Authored-By: Christian Kellner <christian@kellner.me>
2022-02-22 19:23:41 +00:00
Christian Kellner
68cc50591f osbuild2: generator method to create device creation stages
Add a new method to create all necessary stages to create the
devices for a given `PartitionTable`.

Co-Authored-By: Achilleas Koutsou <achilleas@koutsou.net>
2022-02-22 19:23:41 +00:00
Christian Kellner
44b5142234 osbuild2: lvm2 create stage constructor takes device map
This is needed so we can have LVM be contained inside a LUKS
container, which is inside a partition; i.e. multiple devices
are needed to get to the target device.

Co-Authored-By: Achilleas Koutsou <achilleas@koutsou.net>
2022-02-22 19:23:41 +00:00
Achilleas Koutsou
602111dedd osbuild2: generalise copy stage option generation
Use entity based method `ForEachMountable` and `getDevices` to generate
all mounts and devices in a generic way, which then allows for mounts on
arbitrarily nested devices.

Update manifests and image info:
- New device names generated by `pathdot()` to avoid basename
  collisions.
- Some partitions are generated in a different order now which changes
  the order they appear in the manifest and their UUIDs.

Co-Authored-By: Christian Kellner <christian@kellner.me>
2022-02-22 19:23:41 +00:00
Achilleas Koutsou
16a975fe6f obsuild2: generalise mkfs stage device option generation
Refactor GenMkfsStages to work with entity based methods so that it is
now able to handle all generic cases of arbitrarily nested devices.

Co-Authored-By: Christian Kellner <christian@kellner.me>
2022-02-22 19:23:41 +00:00
Christian Kellner
8a73ab5980 osbuild2: fix LVM device constructor arguments
NewLVM2LVDevice should take `LVM2LVDeviceOptions`. Also add a parent
argument to be able to specify the parent device for the LVM2 device.

Co-Authored-By: Christian Kellner <christian@kellner.me>
2022-02-22 19:23:41 +00:00
Achilleas Koutsou
5de4276c9c osbuild2/device: add Parent field to Device
osbuild, starting with version 31, supports for nesting of devices,
i.e. any device can have a parent device. See osbuild commit 45d0594

Co-Authored-By: Christian Kellner <christian@kellner.me>
2022-02-22 19:23:41 +00:00
Achilleas Koutsou
b871a77f09 osbuild2: deduplicate copyFSTreeOptions() function
Use a single GenCopyFSTreeOptions() function from osbuild2 instead of
implementing it multiple times in distros.

Co-Authored-By: Christian Kellner <christian@kellner.me>
2022-02-22 19:23:41 +00:00
Achilleas Koutsou
86118960b9 osbuild2: deduplicate mkfsStages() function
Use a single GenMkfsStages() function from osbuild2 instead of
implementing it multiple times in distros.

Co-Authored-By: Christian Kellner <christian@kellner.me>
2022-02-22 19:23:41 +00:00
Achilleas Koutsou
3110ae4629 disk: move stage option generation functions to osbuild1,2
Co-Authored-By: Christian Kellner <christian@kellner.me>
2022-02-22 19:23:41 +00:00
Achilleas Koutsou
46a0ad77f9 osbuild2: add LUKS2 format stage and device
Co-Authored-By: Christian Kellner <christian@kellner.me>
2022-02-22 19:23:41 +00:00
Tomas Hozza
657b7a5833 Move ostreePullStageInputs() from distros to osbuild2
Move the `ostreePullStageInputs()` function duplicated in all
distro definitions to the `osbuild2` package as
`NewOstreePullStageInputs()`.

Delete `stage_inputs.go` from all distro definitions.

Signed-off-by: Tomas Hozza <thozza@redhat.com>
2022-02-18 09:26:35 +01:00
Tomas Hozza
d946199441 Move bootISOMonoStageInputs() from distros to osbuild2
Move the `bootISOMonoStageInputs()` function duplicated in all
distro definitions to the `osbuild2` package as
`NewBootISOMonoStagePipelineTreeInputs()`.

Signed-off-by: Tomas Hozza <thozza@redhat.com>
2022-02-18 09:26:35 +01:00
Tomas Hozza
069423ea67 Move rpmStageInputs() from distros to osbuild2
Move the `rpmStageInputs()` function duplicated in all
distro definitions to the `osbuild2` package as
`NewRpmStageSourceFilesInputs()`.

Signed-off-by: Tomas Hozza <thozza@redhat.com>
2022-02-18 09:26:35 +01:00
Tomas Hozza
8e6826e743 Move OSBuildMetadataToRPMs and PackageMetadataToSignature to osbuild2
Move `OSBuildMetadataToRPMs()` and `PackageMetadataToSignature()`
functions from the `rpmmd` package to `osbuild2` package to prevent
import cycles while de-duplicating `rpmStageInputs()` function from
`stage_inputs.go` of distro definitions.

Rename `PackageMetadataToSignature()` to
`RPMPackageMetadataToSignature()`, since it takes specifically
`RPMPackageMetadata` type as an argument.

Adjust affected parts of code (unit tests, cloudapi, worker).

Signed-off-by: Tomas Hozza <thozza@redhat.com>
2022-02-18 09:26:35 +01:00
Tomas Hozza
0bd0f57231 Move qemuStageInputs() from distros to osbuild2
Move the `qemuStageInputs()` function duplicated in most
distro definitions to the `osbuild2` package as
`NewQemuStagePipelineFilesInputs()`.

Signed-off-by: Tomas Hozza <thozza@redhat.com>
2022-02-18 09:26:35 +01:00
Tomas Hozza
71ae94b40f Move xorrisofsStageInputs() from distros to osbuild2
Move the `xorrisofsStageInputs()` function duplicated in all
distro definitions to the `osbuild2` package as
`NewXorrisofsStagePipelineTreeInputs()`.

Signed-off-by: Tomas Hozza <thozza@redhat.com>
2022-02-18 09:26:35 +01:00
Tomas Hozza
c9b72033ee Move copyPipelineTreeInputs() from distros to osbuild2
Move the `copyPipelineTreeInputs()` function duplicated in many
distro definitions to the `osbuild2` package as
`NewCopyStagePipelineTreeInputs()`.

This will prevent creating another copy of the code in rhel-84 for
the `gce` image.

Signed-off-by: Tomas Hozza <thozza@redhat.com>
2022-02-18 09:26:35 +01:00
Tomas Hozza
a392d71da6 Move kernelCmdlineStageOptions() from distros to osbuild2
Move the `kernelCmdlineStageOptions()` function duplicated in many
distro definitions to the `osbuild2` package as
`NewKernelCmdlineStageOptions()`.

This will prevent creating another copy of the code in rhel-84 for the
`gce` image.

Signed-off-by: Tomas Hozza <thozza@redhat.com>
2022-02-18 09:26:35 +01:00
Christian Kellner
4b84a3c70f osbuild2: add 'remote' option for ostree.pull
Add support for the `remote` option of the `ostree.pull` stage.
This can be used to tie a commit to a remote while pulling the
commit.
2022-02-11 12:30:44 +01:00
Christian Kellner
bebf046f84 osbuild2: add 'remote' option for ostree.deploy
Add support for the `remote` option of the `ostree.deploy` stage.
This can be used to deploy a commit that is tied to a remote.
2022-02-11 12:30:44 +01:00
Tomas Hozza
885fe3d2b4 osbuild2: fix typo in tar stage option value
Related to https://github.com/osbuild/osbuild/pull/940

Signed-off-by: Tomas Hozza <thozza@redhat.com>
2021-12-22 10:41:22 +01:00
Tomas Hozza
35ef067396 osbuild2: support 'format' and 'root-node' Tar stage options
Bring the Tar stage implementation on par with the current osbuild
schema. Specifically add the 'format' and 'root-node' options to the
stage options structure.

Add stage options validation along with appropriate unit tests.

Signed-off-by: Tomas Hozza <thozza@redhat.com>
2021-12-21 20:40:12 +01:00
sanne
2543459a7f osbuild2: Expand dnf_config stage 2021-12-17 20:07:56 +01:00
Tomas Hozza
30f64d190d osbuild2: ensure that empty sysconfig options members are omitted
The `Kernel` and `Network` members of the sysconfig stage options
structure were previously not declared as pointers. As a result, they
always appeared in the resulting JSON object, even though they were
empty. Use pointers to ensure that the members are omitted from the
resulting JSON object, if they were not defined.

Signed-off-by: Tomas Hozza <thozza@redhat.com>
2021-12-16 20:47:28 +01:00
Tomas Hozza
96000173db osbuild2: do not use reflect in pam.limits.conf stage
Signed-off-by: Tomas Hozza <thozza@redhat.com>
2021-12-16 20:01:42 +01:00
Tomas Hozza
09cd5b3576 osbuild2: support org.osbuild.dnf-automatic.config stage
Add support for the new `org.osbuild.dnf-automatic.config` stage for
configuring DNF Automatic.

Add appropriate new unit tests for the stage implementation and modify
necessary existing unit tests.

Related to https://github.com/osbuild/osbuild/pull/936

Signed-off-by: Tomas Hozza <thozza@redhat.com>
2021-12-16 20:01:42 +01:00
Tomas Hozza
97ef7fbf28 osbuild2: support org.osbuild.yum.repos stage
Add support for the new `org.osbuild.yum.repos` stage for creating DNF /
YUM repository configuration files.

Add appropriate new unit tests for the stage implementation and modify
necessary existing unit tests.

Related to https://github.com/osbuild/osbuild/pull/932

Signed-off-by: Tomas Hozza <thozza@redhat.com>
2021-12-16 20:01:42 +01:00
Tomas Hozza
37a39743bc osbuild2: support PermitRootLogin in sshd.config stage
Add support for the `PermitRootLogin` option in the `sshd.config` stage.
Valid values can be of type `bool` or `string`. Due to this reason, a
custom interface type is defined and a custom `UnmarshalJSON()` method is
defined for the `SshdConfigConfig` structure.

Modify unit tests to test the newly added option and test
(un)marhsalling of valid values of both types.

Related to https://github.com/osbuild/osbuild/pull/917

Signed-off-by: Tomas Hozza <thozza@redhat.com>
2021-12-16 20:01:42 +01:00
Juan Abia
610db6563a gosec: G601 - Implicit memory aliasing in for loop
G601 warning doen't mean there's a vulnerabilty. But this code could
have unintended bugs. Disabling warnings locally.
2021-12-13 12:17:30 +02:00
Martin Sehnoutka
d1029fae69 osbuild2: update cloud-init stage with new options
Related to: https://github.com/osbuild/osbuild/pull/866/

Introduce new fields and move structure validation into the constructor.
This will fail faster and hopefully provide less space for programming
errors. Another advantage is simplified code with less type aliases and
lines.
2021-12-01 12:03:13 +01:00
Martin Sehnoutka
04f69db2c0 osbuild2: selinux stage - introduce force_autorelabel option
This was added in osbuild: https://github.com/osbuild/osbuild/pull/875

Introduce the same option in composer and make it optional by specifying
it as a pointer to bool value. It would work the same even if it was
there every time, but as it should be an edge case, don't use it
everywhere. Also osbuild doesn't require it to be present, so it seems
like the right thing to do.
2021-11-22 15:28:19 +01:00
Martin Sehnoutka
f4412ff07f osbuild2: update rhsm stage
The stage now allows for customizations specific to YUM or DNF. So far
it is just an alias to the same definition, meaning that composer can
use exactly the same structures for both.

Ref: https://github.com/osbuild/osbuild/pull/876
2021-11-19 10:43:58 +01:00
Achilleas Koutsou
e32f1cd697 osbuild: test Write() on nil Result receivers
Signed-off-by: Achilleas Koutsou <achilleas@koutsou.net>
2021-11-17 15:21:40 +01:00
Achilleas Koutsou
7f8a1b314a osbuild: check if result objects are nil in Write()
Before dereferencing the method receiver in Write(), check if the object
is nil and return early.

Fixes #2002

Signed-off-by: Achilleas Koutsou <achilleas@koutsou.net>
2021-11-17 15:21:40 +01:00
Tomas Hozza
029c005473 osbuild2/modprobe: extend and rework stage options validation
Rework the stage options data validation to be done in constructor
methods, instead of when being marshalled to JSON.

Add validation of values passed to constructor methods for modprobe
command structures.

Add validation of the configuration filename based on stage schema.

Related to issue #1785.

Signed-off-by: Tomas Hozza <thozza@redhat.com>
2021-11-16 21:49:38 +01:00
Tomas Hozza
801c9fadab osbuild2: support 'install' command in the modprobe stage
Add support for the 'install' modprobe command in the modprobe osbuild
stage implementation.

Extend unit tests to verify marshalling the stage options into JSON.

Related to https://github.com/osbuild/osbuild/pull/867.

Signed-off-by: Tomas Hozza <thozza@redhat.com>
2021-11-16 21:49:38 +01:00
Achilleas Koutsou
a0479a1bcf osbuild2: test result Write() function
Signed-off-by: Achilleas Koutsou <achilleas@koutsou.net>
2021-11-16 09:49:37 +01:00
Achilleas Koutsou
65f1a24ecd osbuild2: remove Prints in lvm.create stage test
Signed-off-by: Achilleas Koutsou <achilleas@koutsou.net>
2021-11-16 09:49:37 +01:00