Commit graph

65 commits

Author SHA1 Message Date
Sanne Raymaekers
7bfcac30dd cloudapi: support worker server target artifact retrieval
In order to get the artifact location from the cloudapi, add a helper
function in the worker server.
2025-01-24 15:26:15 +01:00
Sanne Raymaekers
d2f50a4224 internal/target: add Azure image HyperV generation 2024-11-21 11:22:20 +01:00
Tomáš Hozza
c109265abb Target/koji: extend the result struct with SBOM docs
Extend the Koji target result struct with an optional slice for uploaded
SBOM documents.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2024-09-20 17:02:09 +02:00
Tomáš Hozza
d7e59e6eec Worker: move GCE image guest OS features to upload target options
Previously, the worker was determining the GCE image guest OS Features
on its own, based on the OS name. This caused problems, in case the
osbuild-composer was of a newer version than the worker.

Example:
osbuild-composer contained support for c10s GCE image type and its
implementation also contained the proper guest OS Features list for it.
However, when the worker got the osbuild job, it built it and tried to
fetch the guest OS Features for the distro. Since its implementation was
too old, it didn't contain the code that added the actual support for
c10s GCE images and got no guest OS features list (which is the default
for unsupported distros). The image was successfully uploaded and
shared, but it does not boot in GCP, because it does not know that it
should use UEFI to boot it.

This behavior could be considered a bug. The worker should be dumb. It
should not be making decisions about the image features, but instead it
should take them from the upload target options. And composer should be
the authoritative source of truth for this. Because otherwise, we
basically have two components that need to be updated in sync to add
support for GCE images on a new distro.

Move the GCE image guest OS features to the GCP upload target options.
The worker will just take what is specified there and use it when
importing the image to GCP. As a compatibility layer for the case when
the composer would be older than the worker (unlikely, but still),
worker will try to determine the image guest OS features in case the
list in the upload target options is empty.

Extend the GCP functional tests to check that the imported image has at
least some guest OS features set.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2024-08-29 17:37:48 +02:00
Michael Vogt
573b349f16 clienterrors: rename WorkerClientError to clienterrors.New
The usual convention to create new object is to prefix `New*` so
this commit renames the `WorkerClientError`. Initially I thought
it would be `NewWorkerClientError()` but looking at the package
prefix it seems unneeded, i.e. `clienterrors.New()` already
provides enough context it seems and it's the only error we
construct.

We could consider renaming it to `clienterror` (singular) too
but that could be a followup.

I would also like to make `clienterror.Error` implement the
`error` interface but that should be a followup to make this
(mechanical) rename trivial to review.
2024-07-31 17:04:58 +02:00
Achilleas Koutsou
503fbfb312 target: add the pulp.ostree target to the marshal functions 2023-10-18 21:14:46 +02:00
Achilleas Koutsou
752040d10f target: add pulp ostree target and options 2023-10-18 21:14:46 +02:00
Tomáš Hozza
285cd30af2 Worker/osbuild: include Manifest info in Koji target result
Copy the Manifest info data from the Manifest job result to the Koji
target result, so that this information can be then imported to Koji
build metadata by the koji-finalize job.

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
Sanne Raymaekers
067366ed6a internal/target: add OCI object storage target
Uploads an OCI image to OCI object storage, and generates a
pre-authenticated request for the object, which can be used to import it
into custom images.
2023-09-19 22:57:06 +02:00
Sanne Raymaekers
8a8607cdf6 internal/vmware: add support for the GOVC_FOLDER option
When importing the ova it also creates a VM, and users don't always have
permission to register in the default folder.
2023-05-25 10:14:32 +02:00
Tomáš Hozza
403b1e4692 AWS: extend target options with the AMI boot mode
Add an optional `BootMode` field to the AWS target options.
This allows to signal to worker the intended boot mode to use when
registering the AMI in AWS. If not specified, the default behavior is
preserved, specifically that the boot mode will be determined by the
default boot mode of the instance provisioned from the AMI.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2023-05-19 13:24:39 +02:00
Tomáš Hozza
417a941a1e internal/target/azure_image: mark Location as optional
Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2022-10-27 19:33:43 +02:00
Tomáš Hozza
ad34043087 internal/target/gcp: make Bucket optional
The Bucket can now be set also in the worker configuration.
2022-10-11 13:23:18 +02:00
Ondřej Budai
54e2c2304c worker: add an option to upload public objects to aws.s3 target
If the object is marked as public, its direct download URL will be returned
instead of the presigned one.

Signed-off-by: Ondřej Budai <ondrej@budai.cz>
2022-09-19 22:56:36 +02:00
Sanne Raymaekers
111feda1f5 worker: Remove ellipsis operator from clienterrors.Error
The ellipsis operator was used as a hack to not need to pass any details
as an argument, but it makes what the end object will actually look like
less obvious. It also makes it impossible to pass an array to details
without getting a nested array.

Fixes #2874
2022-08-03 13:51:52 +02:00
Ygal Blum
3231aabbc0 cloudapi: add support for uploading to a container registry
Worker
------
Add configuration for the default container registry.
Use the default container registry if not provided as part
of the image name.
When using the default registry use the configured values
Return the image url as part of the result.

Composer Worker API
-------------------
Add `ContainerTargetResultOptions` to return the image url

Composer API
------------
Add UploadOptions to allow setting of the image name and tag
Add UploadStatus to return the url of the uploaded image

Co-Developed-By: Christian Kellner <christian@kellner.me>
2022-08-01 21:50:03 +01:00
Tomas Hozza
776a54135f worker: move osbuild exports from OSBuildJob to target
The osbuild export is specific to the upload target and different
targets may require using a different export. While osbuild-composer
still does not support multiple exports for osbuild jobs, this prepares
the ground for such support in the future.

The backward compatibility with older implementations of the composer
and workers is kept on the JSON (Un)mashaling level, where the JSON
message is always a super-set of the old and new way of providing the
exports to osbuild job.
2022-07-01 18:55:01 +01:00
Tomas Hozza
a12827865d target: add explicit target for uploading back to worker server
The uploading of artifacts back to the worker server for the on-premise
(Weldr) use case was signaled to the worker by setting the `ImageName`
in the `OSBuildJob` definition. The code also relies on the osbuild
exports being specified in the `OSBuildJob`, instead of in the target
(this is not implemented yet).

Prepare the ground for moving osbuild export definition from
`OSBuildJob` to `Target` by introducing an explicit `Worker Server"
upload target. This target will signal to the worker that it should
upload the image back to the worker server. The new target is not yet
used by any API implementation.

Extend the worker osbuild job implementation to handle the new upload
target.
2022-07-01 18:55:01 +01:00
Tomas Hozza
6f464949f5 target: move Filename from target options to Target
The filename of the image as produced by osbuild for a given export is
currently set in each target options type in the `Filename` struct
member. However, the value is not really specific to any target type,
but to the specific export used for the target. For this reason move the
value form target type options to the `Target` struct inside a new
struct `OsbuildArtifact` under the name`ExportFilename`.

The backward compatibility with older implementations of the composer
and workers is kept on the JSON (Un)mashaling level, where the JSON
object is always a super-set of the old and new way of providing the
export filename in the Target.
2022-07-01 18:55:01 +01:00
Tomas Hozza
7bfd3aec71 target/oci: OCITargetOptions.FileName -> OCITargetOptions.Filename
The `Filename` is defined in each and every target options. Modify its
name in the OCI target to be consistent with all other targets.
2022-07-01 18:55:01 +01:00
Tomas Hozza
40abb32dec target: deprecate local target and don't use it anywhere
Completely remove the use of `local` target from all code, which is not
required to keep backward compatibility. The target has not been used in
composer for some time already, but some unit tests still used its data
structures. Mark the target as deprecated and adjust all unit tests that
depended on it.

The backward compatibility is kept mostly to enable long running
osbuild-composer instances, which were upgraded to still read old jobs
from the store.

While a target with the same intention will be reintroduced, the current
`local` target data structures contain many fields which would not be
relevant for the new target.

In addition, while the "local" target will be ever used only by Weldr
API, the name would be a bit misleading. Although the worker usually
runs on the same system when using Weldr API, there is no hard
requirement enforcing this setup. In reality, the worker will be
uploading the image back to the worker server, so there is room for a
better name.
2022-07-01 18:55:01 +01:00
Tomas Hozza
93fd5e3821 target: ensure that each used target has NewXXXTargetResult defined
Ensure that `UnmarshalTargetResultOptions()` is called only when there
are any options to unmarshal in the JSON object.

Since results of some Targets don't have any options defined, mark
`TargetResult.Options` as optional in the JSON tag.
2022-07-01 18:55:01 +01:00
Tomas Hozza
6f13db5b92 target: extend TargetResult with TargetError
This will enable reporting of target-specific errors from jobs, once
they'll support multiple targets.

Target errors are currently reported via `JobResult.JobError`.
2022-07-01 18:55:01 +01:00
Tomas Hozza
c63bfe6d83 target: use constants for target names, instead of string literals 2022-07-01 18:55:01 +01:00
Christian Kellner
986f076276 container: add support for uploading to registries
Add a new generic container registry client via a new `container`
package. Use this to create a command line utility as well as a
new upload target for container registries.

The code uses the github.com/containers/* project and packages to
interact with container registires that is also used by skopeo,
podman et al. One if the dependencies is `proglottis/gpgme` that
is using cgo to bind libgpgme, so we have to add the corresponding
devel package to the BuildRequires as well as installing it on CI.

Checks will follow later via an integration test.
2022-06-29 10:02:46 +02:00
Tomas Hozza
fd82174469 worker/osbuild: consolidate Koji target options values meaning
When the Koji target support was added to the osbuild job, based on the
osbuild-koji job, the meaning of target option values got messed up.

The side effect of the issue is that when Koji composes are
submitted via Cloud API the resulting image is currently always uploaded
back to the worker server.

`OsBuildKoji` job
-----------------
- `OSBuildKojiJob.ImageName` is set to the filename of the image as
  exported by osbuild.
- `OSBuildKojiJob.KojiFilename` is set to the desired filename which
  should be used when uploading the image to Koji.

`OsBuild` job + `KojiTargetOptions` before
------------------------------------------
- `OSBuildJob.ImageName` is set to the filename of the image as exported
  by osbuild. This is done only by the Cloud API code for Koji composes.
  Cloud API does not set this for regular composes and any other target.
  The variable is set in common case only by Weldr API code with the
  same meaning and it is used by the `OsBuild` job implementation as an
  indication that the image should be uploaded back to the worker server.
- `Target.ImageName` is not set at all. Other targets use it for the
  desired filename which should be used when uploading the image to the
  target environment.
- `KojiTargetOptions.Filename` is set to the desired filename which
  should be used when uploading the image to Koji. All other target
  types use `Filename` variable in their options for the filename of the
  image as exported by osbuild.

`OsBuild` job + `KojiTargetOptions` after
-----------------------------------------
- `OSBuildJob.ImageName` is still set to the filename of the image as
  exported by osbuild. This is kept for a backward compatibility of new
  composer with older workers.
- `Target.ImageName` is set to the desired filename which should be used
  when uploading the image to Koji.
- `KojiTargetOptions.Filename` is set to the filename of the image as
  exported by osbuild.

This change is backward incompatible, meaning that old worker won't be
able to handle Koji compose requests submitted via Cloud API using a new
composer and also a new worker won't be able to handle Koji compose
requests submitted by a new composer. This is intentional, because after
discussion with Ondrej Budai, the Cloud API Koji integration is
currently not used anywhere in production.
2022-06-17 17:37:15 +02:00
Tomas Hozza
da78a76751 target/koji: delete unused fields from KojiTargetOptions
Delete unused fields from the `KojiTargetOptions` structure.
2022-06-10 14:48:18 +01:00
Tomas Hozza
42d623b743 worker/osbuild: support Koji target
Add Koji as a separate upload target to the osbuild job implementation.
2022-06-10 14:48:18 +01:00
Tomas Hozza
c7126e3c70 target: add KojiTargetResultOptions
Add `KojiTargetResultOptions` which contains the values contained in
`OSBuildKojiJobResult`, but not in `OSBuildJobResult`.
2022-06-10 14:48:18 +01:00
Ygal Blum
feb357e538 Support Generic S3 upload in Composer API
Use case
--------
If Endpoint is not set and Region is - upload to AWS S3
If both the Endpoint and Region are set - upload the Generic S3 via Weldr API
If neither the Endpoint and Region are set - upload the Generic S3 via Composer API (use configuration)

jobimpl-osbuild
---------------
Add configuration fields for Generic S3 upload
Support S3 upload requests coming from Weldr or Composer API to either AWS or Generic S3
Weldr API for Generic S3 requires that all connection parameters but the credentials be passed in the API call
Composer API for Generic S3 requires that all conneciton parameters are taken from the configuration
Adjust to the consolidation in Target and UploadOptions

Target and UploadOptions
------------------------
Add the fields that were specific to the Generic S3 structures to the AWS S3 one
Remove the structures for Generic S3 and always use the AWS S3 ones

Worker Main
-----------
Add Endpoint, Region, Bucket, CABundle and SkipSSLVerification to the configuration structure
Pass the values to the Server

Weldr API
---------
Keep the generic.s3 provider name to maintain the API, but unmarshel into awsS3UploadSettings

tests - api.sh
--------------
Allow the caller to specifiy either AWS or Generic S3 upload targets for specific image types
Implement the pieces required for testing upload to a Generic S3 service
In some cases generalize the AWS S3 functions for reuse

GitLab CI
---------
Add test case for api.sh tests with edge-commit and generic S3
2022-06-02 16:12:53 +03:00
Ygal Blum
8407c97d96 Upload to HTTPS S3 - Support self signed certificate
API
---
Allow the user to pass the CA public certification or skip the verification

AWSCloud
--------
Restore the old version of newAwsFromCreds for access to AWS
Create a new method newAwsFromCredsWithEndpoint for Generic S3 which sets the endpoint and optionally overrides the CA Bundle or skips the SSL certificate verification

jobimpl-osbuild
---------------
Update with the new parameters

osbuild-upload-generic-s3
-------------------------
Add ca-bunlde and skip-ssl-verification flags

tests
-----
Split the tests into http, https with certificate and https skip certificate check
Create a new base test for S3 over HTTPS for secure and insecure
Move the generic S3 test to tools to reuse for secure and insecure connections
All S3 tests now use the aws cli tool
Update the libvirt test to be able to download over HTTPS
Update the RPM spec

Kill container with sudo
2022-05-26 13:46:00 +03:00
Tomas Hozza
ee285e5e8a Weldr: support GCP upload target
Add support for importing the GCE image into GCP using Weldr API. The
credentials to be used can be specified in the upload settings and will
be then used by the worker to authenticate with GCP.

The GCP target credentials are passed to Weldr API as base64 encoded
content of the GCP credentials JSON file. The reason is that the JSON
file contains many values and its format could change in the future.
This way, the Weldr API does not rely on the credentials file content
format in any way.

Add a new test case for the GCP upload via Weldr and run it in CI.

Signed-off-by: Tomas Hozza <thozza@redhat.com>
2022-04-14 19:07:31 +01:00
Ygal Blum
bee14bf392 OSBuild - add support for generic S3 services
jobimpl-osbuild
---------------
Add GenericS3Creds to struct
Add method to create AWS with Endpoint for Generic S3 (with its own credentials file)
Move uploading to S3 and result handling to a separate method (along with the special VMDK handling)
adjust the AWS S3 case to the new method
Implement a new case for uploading to a generic S3 service

awscloud
--------
Add wrapper methods for endpoint support
Set the endpoint to the AWS session
Set s3ForcePathStyle to true if endpoint was set

Target
------
Define a new target type for the GenericS3Target and Options
Handle unmarshaling of the target options and result for the Generic S3

Weldr
-----
Add support for only uploading to AWS S3
Define new structures for AWS S3 and Generic S3 (based on AWS S3)
Handle unmarshaling of the providers settings' upload settings

main
----
Add a section in the main config for the Generic S3 service for credentials
If provided pass the credentials file name to the osbuild job implementation

Upload Utility
--------------
Add upload-generic-s3 utility

Makefile
------
Do not fail if the bin directory already exists

Tests
-----
Add test cases for both AWS and a generic S3 server
Add a generic s3_test.sh file for both test cases and add it to the tests RPM spec
Adjust the libvirt test case script to support already created images
GitLabCI - Extend the libvirt test case to include the two new tests
2022-04-07 15:01:01 +02:00
Tomas Hozza
c98b3afcc4 Add comments to some values in target.go 2022-04-02 08:47:02 +01:00
Roy Golan
bee932e222 Add support for OCI upload provider
Signed-off-by: Roy Golan <rgolan@redhat.com>
2022-01-28 15:16:47 +01:00
Diaa Sami
c35097fd52 Support for temporary credentials
Handle session token so that temporary credentials are supported
2021-09-02 15:13:42 +02:00
Achilleas Koutsou
e5b28c0bb3 New upload target: AWS S3
Uploads an artifact to an S£ bucket and returns a presigned URL to allow
the user to download the file.

Although it uses a lot of common code with the AWS AMI upload target,
it's treated as a completely separate target.
2021-06-18 14:02:09 +01:00
Ondřej Budai
7ae557ea22 target/azure: document what it does
Signed-off-by: Ondřej Budai <ondrej@budai.cz>
2021-03-06 15:40:48 +00:00
Ondřej Budai
2e39d629a9 worker: add azure image upload target
This commit adds and implements org.osbuild.azure.image target.

Let's talk about the already implemented org.osbuild.azure target firstly:
The purpose of this target is to authenticate using the Azure Storage
credentials and upload the image file as a Page Blob. Page Blob is basically
an object in storage and it cannot be directly used to launch a VM. To achieve
that, you need to define an actual Azure Image with the Page Blob attached.

For the cloud API, we would like to create an actual Azure Image that is
immediately available for new VMs. The new target accomplishes it.
To achieve this, it must use a different authentication method: Azure OAuth.
The other important difference is that currently, the credentials are stored
on the worker and not in target options. This should lead to better security
because we don't send the credentials over network. In the future, we would
like to have credential-less setup using workers in Azure with the right
IAM policies applied but this requires more investigation and is not
implemented in this commit.

Signed-off-by: Ondřej Budai <ondrej@budai.cz>
2021-03-06 15:40:48 +00:00
Tomas Hozza
319400c280 cloudapi: implement GCP target results and include UploadOptions
Return GCP-specific target results form the worker, similar as it is
done for AWS.

Extend Cloud API to allow GCP-specific upload Options.

Modify Cloud API to return UploadOptions as part of the UploadStatus.

Modify Cloud API integration test to check returned upload Options and
upload Type.

Signed-off-by: Tomas Hozza <thozza@redhat.com>
2021-03-04 15:44:04 +01:00
Chloe Kaubisch
f091af55d8 cloudapi: add targetresults
Add the TargetResult struct to OSBuildJobResult. Include the 'options'
interface on TargetResult to contain target-specific information,
for example amiID and region from AWS. Expose 'options' on a status
call as an UploadStatus field. Add logic to support AWS within this
format, which can be used as a template for other targets.
2021-03-02 13:22:11 +01:00
Tomas Hozza
94d399f010 cloudapi: Add support for GCP as upload target
Add support for GCP as an upload target to the internal API.

Extend the cloudapi to allow GCP as an upload target in the compose
request. Regenerate the cloudapi go code. Added GCP-specific upload
result component in the API definition, similar to AWS. It is not yet
used, but it will be once returning a target-specific result from
worker is supported.

Add support for GCP upload target to the worker job implementation.

Signed-off-by: Tomas Hozza <thozza@redhat.com>
2021-02-25 18:44:21 +00:00
Jozef Mikovic
08cfc08805 weldr: add vmware upload target to api
Extend Weldr API to allow user to specify option to upload built image to VMWare,
makes use of previously define upload target.
2021-02-16 19:06:01 +00:00
Jozef Mikovic
1a81489ef1 osbuild-worker: add target for upload to vmware
New upload target for VMWare, similar to the ones for AWS and Azure,
allowing users to set credentials for their vSphere instance.
Commit also includes function that performs the actual upload.
2021-02-16 19:06:01 +00:00
Sanne Raymaekers
22c9f6af61 cloudapi: Share an ec2 snapshot/ami with an account 2020-11-26 13:08:18 +00:00
Ondřej Budai
befeef34a5 koji: use nvra as the filename for images
We have the same thing for AWS. The AWS target also specifies under what name
should be the image available in EC2.

As requested by Brew maintainers Tomáš Kopeček and Lubomír Sedlář.
2020-10-27 19:01:30 +00:00
Tom Gundersen
e52830f530 upload/koji: don't pass task_id to cg_init_build
Contrary to our assumption, we cannot initialize the build with the
link to the task. We can only update the link once the build has
completed.

This seems like a bug in koji, but we keep it like this for now.
2020-09-16 00:15:02 +01:00
Tom Gundersen
f446613d4a upload/koji: use CGInitBuild and clarify metadata structs
Move to requiring CGInitBuild to be called before CGImport. In the
future we could make the former optional again, but for now we want to
allow the caller to have done CGInitBuild and for composer only to do
the CGImport using the passed in build_id and token.

Also rename and document some struct fields in the metadata struct to
make them more specific to our use-case and hopefully easier to read.

Signed-off-by: Tom Gundersen <teg@jklm.no>
2020-09-16 00:15:02 +01:00