Commit graph

421 commits

Author SHA1 Message Date
Brian C. Lane
5b87877109 cloudapi: Add optional blueprint schema to compose request
This adds a 'blueprint' section to the compose request. It also
restricts it so that only 'blueprint' or 'customizations' can be
included, but not both. The goal is to move to using 'blueprint' for all
customizations so that there is a single consistent interface for the
clients.

Where the openapi schemas are the same between the two they have been
shared, but a few are different. They are created with 'Blueprint*' as
their name.

This also re-adds the SSHKey schema removed by commit
bfad6d50e1, it is used by the Blueprint
Customization.
2024-01-15 11:48:35 +01:00
Ondrej Ezr
4b3b942dde cloudapi: Add module_hotfixes flag
Allow passing module_hotfixes flag through the cloudapi.
This will enable depsolving on repositories that might be affected by modularity filtering.

Refs HMS-3202
2023-12-20 09:02:06 +01:00
djach7
4870a836f3 cloudapi: enable 'fdo.di_mfg_string_type_mac_iface'
Adds implementation of the 'fdo.di_mfg_string_type_mac_iface' dracut
variable to allow simplified installer images to pass this value to the
manufacturing-client.service.
2023-12-14 22:21:09 +01:00
Miguel Martín
98847f7494 Expose the FIPS blueprint customization
Expose the FIPS blueprint customization through
the cloud API.

Signed-off-by: Miguel Martín <mmartinv@redhat.com>
2023-12-13 10:19:47 +01:00
Sanne Raymaekers
bfad6d50e1 cloudapi/v2: tweak customizations
Fix verbiage of groups customization, fields which accept an array
should be plural.

Remove the sshkey customization, sshkeys are merged into user
customizations anyway, so users should use the "users" customization
instead.

Since these customizations aren't in use yet, this edit should be fine.

See #3716
2023-12-08 15:31:56 +01:00
Sanne Raymaekers
794acd8e34 worker: add ability to track workers serverside
Unresponsive workers (>=1 hour of no status update) are cleaned up.

Several things are enabled by keeping track of workers, in future the
worker server could:
- keep track of how many workers are active
- see if a worker for a specific architecture is available
2023-12-06 17:22:36 +01:00
Achilleas Koutsou
fbf63f6a1f cloudapi: add upload targets to route handler tests 2023-11-17 16:48:16 +01:00
Achilleas Koutsou
38664d1b64 cloudapi: add GetTarget() test case for pulp.ostree 2023-11-17 16:48:16 +01:00
Gianluca Zuccarelli
b711e302ba cloudapi: add pulp upload target
Add the pulp.ostree upload target to the cloud API and enable it for
edge/iot commits.

Co-Authored-By: Achilleas Koutsou <achilleas@koutsou.net>
2023-11-17 16:48:16 +01:00
Achilleas Koutsou
5a93166f6b cloudapi: support multiple upload statuses in ComposeStatus
Add the new upload_statuses under the image_status in the result of the
ComposeStatus object.  The first status is also included in the old
top-level 'upload_status' property for backwards compatibility.

Tests are updated to match the new results.
2023-11-17 16:48:16 +01:00
Achilleas Koutsou
ba2240b578 cloudapi: test GetTargets()
Test some valid and invalid combinations for the GetTargets() upload
target selection.
Includes tests with and without the upload options for the default
target.
2023-11-17 16:48:16 +01:00
Achilleas Koutsou
9fc4551fdf cloudapi: check upload targets in request validation
It is now valid for UploadOptions to be nil but only if there is at
least one UploadTarget defined.
2023-11-17 16:48:16 +01:00
Achilleas Koutsou
5c95eb565c cloudapi: support multiple upload targets
Read the upload target types and options in the UploadTargets array of
the ImageRequest and initialise the Target array.  If the top-level
(old) UploadOptions are also specified, prepend them to the array using
the image type's default target type.

Each upload target type is checked against a support map for
compatibility.
2023-11-17 16:48:16 +01:00
Achilleas Koutsou
d7ab1f2112 cloudapi: multiple upload targets in request
Add an array of targets in the imageRequest and return an array from
ImageRequest.GetTargets() (renamed from GetTarget()).  Currently, the
function still only returns one target, the default for the image type
with the top level upload options.
2023-11-17 16:48:16 +01:00
Achilleas Koutsou
9d990ea5da cloudapi: separate target selection from initialisation
Separate the target selection in GetTarget() into two steps.  First
determine the default target name for the image type and then use the
name to initialise the target object.  This is a bit more work (and
double switching) but will be needed to support selecting targets
externally.
2023-11-17 16:48:16 +01:00
Achilleas Koutsou
8a6e0e3862 cloudapi: new error type ErrorInvalidUploadTarget 2023-11-17 16:48:16 +01:00
Achilleas Koutsou
b011b9845a cloudapi: split GetTarget() into functions
Separate the handling of each individual target type into its own
function called by GetTarget()'s case switch.  This makes the function
more readable and the target object creation reusable.

Added an empty line after each creation of irTarget to make it easier to
visually distinguish the cases that fall through.
2023-11-17 16:48:16 +01:00
Achilleas Koutsou
27beb73365 cloudapi: add multiple upload_statuses to ImageStatus
To report on the multiple upload requests, we add an upload_statuses
property to the ImageStatus response.
2023-11-17 16:48:16 +01:00
Achilleas Koutsou
24b4647a14 cloudapi: add multiple upload_targets to ImageRequest
Add an upload_targets field to the image request.  This lets the API
caller specify multiple upload targets and upload options to be used.
If the upload target type does not match the upload options, the request
is invalid.

For backwards compatibility, the upload targets field is optional.  If
it is not specified, the default upload target and upload options for
the image type are assumed, which is the same as the old behaviour.

Adding an explicit selection to the request makes it possible to support
multiple upload targets for the same image type.  We plan to support
ostree commits being uploaded to both aws.s3 and pulp.

To report on the multiple upload requests, we add an upload_statuses
field to the ImageStatus response.
2023-11-17 16:48:16 +01:00
Brian C. Lane
d0877e68dc cloudapi: Add partitioning_mode support to the API
This adds a 'partitioning_mode' field that can be set to 'auto-lvm',
'lvm' or 'raw'. It defaults to 'auto-lvm'.
2023-10-23 14:52:30 +02:00
Brian C. Lane
e3f162cd56 cloudapi: Move Services to an actual struct
This removes the need to make anonymous structs in the middle of the
Customizations request.
2023-10-13 16:02:40 +02:00
Brian C. Lane
ab56a625c4 cloudapi: Simplify the bp.Customizations code
There is a lot of repeated checks for bp.Customization != nil, this
simplifies that by creating an empty blueprint.Customizations at the
top, and checking to see if it is still empty at the bottom and setting
it back to nil.

Includes a new test for calling with an empty (not nil)
v2.Customizations set on the request.
2023-10-12 16:53:35 +02:00
Sanne Raymaekers
0a255df1ca cloudapi/v2: add all existing customizations to openapi spec 2023-10-11 17:29:56 +02:00
Sanne Raymaekers
6e4cade608 cloudapi/v2: log manifest generation errors as a warning
Sometimes invalid customisations slip through, and this will make it
easier to read the logs looking for them.
2023-10-02 23:37:26 +01:00
Tomáš Hozza
3c95ba8476 Include osbuild/images version in Manifest job result
Include the osbuild/images module version in the Manifest job result.
The module has direct impact on image definitions and the content of
produced manifest, therefore including this information in the Manifest
job result is very helpful for various purposes (debugging,
traceability).

This will enable to embed this information in the Koji build metadata.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2023-09-27 12:39:28 +02:00
Tomáš Hozza
8866391d88 Include osbuild-composer version in Manifest job result
Extend the Manifest job result structure to hold information about
osbuild-composer version, which produced the manifest. This will be
useful for other job types which depend on it and can then push this
information further as needed.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2023-09-27 12:39:28 +02:00
Tomáš Hozza
5b414a4516 Target: expose osbuild artifact information in target result
Add the information about osbuid artifact to the target result.
Specifically the name of the osbuild pipeline which was exported for the
specific target, and the filename of the exported file.

This will later enable embedding this information in Koji build metadata
to make it easy to reproduce the image build using the attached
manifest.
2023-09-27 12:39:28 +02:00
Tomáš Hozza
efbaa93eef Target/Koji: rework result options to contain more than just image info
The `KojiTargetResultOptions` previously contained information only
about the uploaded image file. And even then, some information, such as
the filename, were scattered in other structures such as
`KojiFinalizeJob` struct.

Since the plan is to start uploading also osbuild manifest and osbuild
build log to Koji, we need to extend the result options structure to
hold more information and also make it specific to which file is the
information related.

Rework the `KojiTargetResultOptions` to contain information about:
 - the built image
 - build log
 - osbuild manifest

Information about each file contains:
 - filename
 - checksum type
 - file checksum
 - file size

For now, only the built image information is set and consumed by the
worker.

Add custom JSON (un)marshaler for `KojiTargetResultOptions` to handle
backward compatibility when old version of worker or composer server
interact with each other. Cover them with unit tests.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2023-09-27 12:39:28 +02:00
Brian C. Lane
9e39080d00 lint: Fix implicit memory aliasing in for loops
Fix all instances of gosec G601: Implicit memory aliasing in for loop.
2023-09-21 16:56:54 +02:00
Brian C. Lane
eab16830aa test: Add checksum to cloudapi tests
These use 'pkg1' when depsolving, so they need an entry in the manifest
with the mocked checksum:

sha256:e50ddb78a37f5851d1a5c37a4c77d59123153c156e628e064b9daa378f45a2fe
2023-09-21 16:56:54 +02:00
Brian C. Lane
428e2c0ff2 cloudapi: Catch and log Serialize errors 2023-09-21 16:56:54 +02:00
Sanne Raymaekers
a7794dc634 cloudapi/v2: add oci image type to cloudapi 2023-09-19 22:57:06 +02:00
Gianluca Zuccarelli
0ce4ec7fc4 internal/cloudapi: add OpenSCAP tailoring
Add support to the cloudapi for generating the tailoring file used
to customize the OpenSCAP remediation. This allows users to select and
unselect rules for the remediation and the `autotailor` stage generates
the tailoring file.
2023-09-18 20:46:49 +02:00
Sanne Raymaekers
e5c4640923 cloudapi/v2: expose wsl image type 2023-08-28 14:51:01 +02:00
Brian C. Lane
139bf4dec2 cloudapi: Add ability to skip uploading and save image locally
During development it can be very useful to store the results locally
instead of uploading to a remote system. This implements a development
only option to help with that.

To use it you need to add OSBUILD_LOCALSAVE to the server's environment.
This can be done by editing /usr/lib/systemd/system/osbuild-composer.service
and adding:

Environment="OSBUILD_LOCALSAVE=1"

You can then use an 'upload_options' object to skip trying to upload to
the default service for the type of image, eg:

    "image_requests": [
    {
      "architecture": "x86_64",
      "image_type": "guest-image",
      "upload_options": {
          "local_save": true
      },
      ...
    }]

The results will be saved to /var/lib/osbuild-composer/artifacts/UUID/
using the default filename for the image type.

If local_save is used without OSBUILD_LOCALSAVE being set it will return
an error with id=36 saying 'local_save is not enabled'.
2023-08-09 16:48:46 +02:00
Tomáš Hozza
8367a4500a Cloud API: set the image boot mode in OSBuildJob options
Set the image boot mode (as a string value) in the OSBuildJob options.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2023-08-08 15:53:07 +02:00
Brian C. Lane
5821098c29 cloudapi: Add tests for refactored handler code
Add tests for GetBlueprintWithCustomizations, GetPayloadRepositories,
GetSubscription, and GetOstreeOptions methods.
2023-08-05 11:28:29 +02:00
Brian C. Lane
6a1f12c465 cloudapi: Add a test for the new size option 2023-08-05 11:28:29 +02:00
Brian C. Lane
c1e52aebc3 cloudapi: Refactor handler.go code to make testing easier
This moves some of the code from the PostCompose function in handler.go
into methods on the OpenAPI ComposeRequest and ImageRequest structs.

In compose.go I have added several methods.
GetBlueprintWithCustomizations takes the ComposeRequest customizations
and builds a Blueprint struct.

GetPayloadRepositories returns the custom payload repos.

GetSubscription returns the ImageOptions setup with optional
subscription information from the request.

In imagerequest.go I have added GetTarget which takes the upload
options and returns a Target. This moves the giant switch statement,
which may also benefit from further simplification at some point.

GetOSTreeOptions returns the OSTree ImageOptions if there are ostree
settings in the ImageRequest.

GetImageOptions returns the distro.ImageOptions with the size set.

This commit only moves the code, making PostCompose easier to read. All
tests still pass.

cloudapi: Move the size handling to a method on ImageRequest
2023-08-05 11:28:29 +02:00
Brian C. Lane
818d434303 cloudapi: Add optional image size support
This adds a 'size' parameter to the image_request object. It can be used
to specify the minimum image size in bytes

This behaves in the same way as the size parameter of the weldr API

For raw images the root partition is grown to fill the available space.
For LVM images the PV uses the available space, but the LV does not,
leaving space available for other LVs to be created after boot.

See COMPOSER-1883
2023-08-05 11:28:29 +02:00
Diaa Sami
b6d6ecf874 cloudapi: add validation where missing 2023-07-21 12:52:32 +02:00
Diaa Sami
2bdfa045c1 cloudapi: fix typo in property name 2023-07-21 12:52:32 +02:00
Simon de Vlieger
326f0cfa2f cloudapi: add live-installer
This was missing to enable `live-installer` in the CloudAPI.
2023-07-20 18:53:28 +02:00
Sanne Raymaekers
4bbfdb624c cloudapi/v2: cleanup rebase leftovers
This is a review oversight from osbuild/osbuild-composer#3551, just
remove it.
2023-07-10 23:51:08 +02:00
Achilleas Koutsou
0e4a9e586f split: replace internal packages with images library
Remove all the internal package that are now in the
github.com/osbuild/images package and vendor it.

A new function in internal/blueprint/ converts from an osbuild-composer
blueprint to an images blueprint.  This is necessary for keeping the
blueprint implementation in both packages.  In the future, the images
package will change the blueprint (and most likely rename it) and it
will only be part of the osbuild-composer internals and interface.  The
Convert() function will be responsible for converting the blueprint into
the new configuration object.
2023-07-10 21:11:19 +02:00
Sanne Raymaekers
f303e7c233 cloudapi/v2: rearrange middlewares
The duration middleware should come after the tenant channel middleware,
otherwise the tenant in the context will be empty. The status middleware
can come beforehand because it queries the request context right before
sending a response.
2023-06-29 16:41:36 +02:00
Gianluca Zuccarelli
fa6f3ba197 cloudapi: openscap integration
Enable the openscap customizations in the cloudapi.
2023-06-29 13:42:49 +01:00
Sanne Raymaekers
2837b2a3ad prometheus: split off request timing information into separate mw
Tracks the worker api in addition to the composer api.
2023-06-28 15:08:37 +02:00
Sanne Raymaekers
9594156baf internal/worker: use TenantChannelMiddleware 2023-06-28 15:08:37 +02:00
Sanne Raymaekers
0f946e1c9e internal/auth: add TenantChannelMiddleware
Extracts the tenant from the JWT and sets it in the request context.
2023-06-28 15:08:37 +02:00