Commit graph

135 commits

Author SHA1 Message Date
Ondřej Budai
d2d70c1e95 cloudapi: add multi-tenancy test
This commit adds a very in-depth test for multi-tenancy. It queues several
composes and then runs all jobs belonging to them while checking that
they are run by the correct tenant.

Signed-off-by: Ondřej Budai <ondrej@budai.cz>
2022-03-08 12:07:00 +01:00
Ondřej Budai
ffbbd022e3 cloudapi/test: make newV2Server return also the queue
We will need this for the multi-tenancy test.

Signed-off-by: Ondřej Budai <ondrej@budai.cz>
2022-03-08 12:07:00 +01:00
Ondřej Budai
bafb613a43 cloudapi/test: add option to enable JWT
Signed-off-by: Ondřej Budai <ondrej@budai.cz>
2022-03-08 12:07:00 +01:00
Ondřej Budai
4a9812be2e cloudapi/test: add option to specify depsolve channels to test server
Signed-off-by: Ondřej Budai <ondrej@budai.cz>
2022-03-08 12:07:00 +01:00
Ondřej Budai
cfb756b9ba api/{cloud,worker}: used channel name based on JWT claims for new jobs
This commit implements multi-tenancy. A tenant is defined based on a value
from JWT claims. The key of this value must be specified in the configuration
file. This allows us to pick different values when using multiple SSOs.

Let me explain more in depth how this works:

Cloud API gets a new compose request. Firstly, it extracts a tenant name from
JWT claims. The considered claims are configured as an array in
cloud_api.jwt.tenant_provider_fields in composer's config file. The channel
name for all jobs belonging to this compose is created by `"org-" + tenant`.

Why is the channel prefixed by "org-"? To give us options in the future. I can
imagine the request having a channel override. This basically means that
multiple tenants can share a channel. A real use-case for this is multiple
Fedora projects sharing one pool of workers.

Why this commit adds a whole new cloud_api section to the config? Because the
current config is a mess and we should stop adding new stuff into the koji
section. As the Koji API is basically deprecated, we will need to remove it
soon nevertheless.

Signed-off-by: Ondřej Budai <ondrej@budai.cz>
2022-03-08 12:07:00 +01:00
Ondřej Budai
c1dc58eba4 worker: NewServer: move config parameters to a new Config struct
We will have more parameters soon so let's make this prettier sooner rather
than later.

Signed-off-by: Ondřej Budai <ondrej@budai.cz>
2022-03-08 12:07:00 +01:00
Ondřej Budai
9feb7b59d6 clouadpi: NewServer: move awsBucket parameter to a new ServerConfig struct
We will have more parameters soon so let's make this prettier sooner rather
than later.

Signed-off-by: Ondřej Budai <ondrej@budai.cz>
2022-03-08 12:07:00 +01:00
Ondřej Budai
7bfcee36f8 jobqueue: introduce the concept of channels
Channels are a concept similar to job types. Callers must specify a channel
name when queueing a new job. A list of channels is also specified when
dequeueing a job. The dequeued job's channel will always be from one of the
specified channel. Of course, the job types are also respected. The dequeued
job will also always be from one of the specified type.

Currently, all calls to jobqueue were changed so all queue operations use
an empty channel name and all dequeue operations use a list containing
an empty channel.

Thus, this is a non-functional change.

Signed-off-by: Ondřej Budai <ondrej@budai.cz>
2022-03-08 12:07:00 +01:00
Ondřej Budai
5e291bd98f cloudapi/test: remove dependency on rpmmd_mock
rpmmd_mock fixture are complex and unneeded in the context of cloudapi, let's
just copy 3 lines from them and drop the dependency.

Signed-off-by: Ondřej Budai <ondrej@budai.cz>
2022-03-02 16:20:11 +01:00
Ondřej Budai
c29a1fa9da cloudapi: drop unused rpmmdMetadata parameter & struct member
cloudapi no longer calls dnf-json directly so we can clean some code, yay!

Signed-off-by: Ondřej Budai <ondrej@budai.cz>
2022-03-02 16:20:11 +01:00
Christian Kellner
f91d8c6292 distro/rhel86: add support for azure marketplace
Add support for building images for the Azure marketplace: add a
new image type "azure-rhui" that can be used to build images
tailored to the Azure marketplace.
Add two sample manifests for 8.5 and 8.6, but note that even the
8.5 is using the 8.6 distro definitions. Also no image-info is
included since `image-info` cannot (yet) handle LVM setups and
the azure marketplace images use the LVM setup.
2022-02-27 22:03:36 +01:00
Sanne Raymaekers
e9daacd1dd internal/cloudapi: Allow bp.Customizations being nil
Customizations being nil isn't the same as an empty object. The
edge-installer types require customizations equalling nil.

This partially reverts bb486bcccb.
2022-02-23 11:24:27 +00:00
Achilleas Koutsou
459a07d101 cloudapi/v2: update tests to match new ostree parameter rules
- Create test servers that serve a commit ref for ostree compose
  requests.
- Adapt test cases t new rules.
2022-02-23 11:08:24 +01:00
Achilleas Koutsou
3839a7d0dc cloudapi/v2: catch ParameterComboError from ostree param validation 2022-02-23 11:08:24 +01:00
Achilleas Koutsou
9e0af86775 ostree: rename errors and introduce ParameterComboError
Shorter and clearer error types.
- InvalidParameterError is now RefError.  It is returned when a ref (the
  new ref or the parent ref) is invalid.
- The ResolveRefError is not renamed.  It is returned when a ref can't
  be resolved (e.g., ref not found at URL).

New error type ParameterComboError.  It is returned when a parent ref is
specified but no URL, which is an invalid parameter combination.
2022-02-23 11:08:24 +01:00
Achilleas Koutsou
134a84ac23 cloudapi/v2: test ostree url + parent error conditions
Supplying both a URL and a parent ID (regardless of ref) is currently an
error, just like in the existing Weldr API.
2022-02-23 11:08:24 +01:00
Achilleas Koutsou
bfaf0c073b cloudapi/v2: support specifying parent ref for ostree requests 2022-02-23 11:08:24 +01:00
Achilleas Koutsou
24b70837c1 cloudapi/v2: validate ostree params using common validation function
Use the ostree package error types to keep the existing distinction
between Ref- and URL-related errors.
Introduce a new error condition for a general InvalidOSTreeParams
failure.
2022-02-23 11:08:24 +01:00
Achilleas Koutsou
923850ff1b cloudapi/v2: test ostree params and error conditions 2022-02-23 11:08:24 +01:00
Achilleas Koutsou
f885de4c68 distro: remove OSTreeImageOptions type and use ostree.RequestParams 2022-02-23 11:08:24 +01:00
Sanne Raymaekers
d589317dcb internal/cloudapi: Log error in manifest job 2022-02-22 14:06:05 +01:00
Tom Gundersen
bb486bcccb cloudapi/v2/compose: don't overwrite customizations struct
The customizations struct contains different kinds of customizations,
such as users and filesystems. If both filesystems and users are
configured, the current code overwrites the user configuration.

Change this by unconditionally allocating the customizations struct
when creating the empty blueprint, and ammending it for each
customization we find.

This means that the customizations will be non-nil, also when it is
empty, which was not the case in the past. This should not change
the behavior of the code.
2022-02-19 11:13:55 +00:00
Chloe Kaubisch
0619ffa588 cloudapi: expose filesystem customizations 2022-02-19 11:13:55 +00: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
Achilleas Koutsou
346486cd3f cloudapi: test repository config conversion function 2022-02-14 17:38:41 +01:00
Achilleas Koutsou
679028bb8e cloudapi: copy all Repository fields to RepoConfig 2022-02-14 17:38:41 +01:00
Achilleas Koutsou
2d0755b924 cloudapi: test new repository collection function 2022-02-14 17:38:41 +01:00
Achilleas Koutsou
3320f2c57d cloudapi: separate repositories based on package_sets
- Any repository without package_sets is added to the general `Repos`
  field of the DepsolveJob, just like before.
- Repositories with package_sets are added to the `PackageSetsRepos`
  map, indexed by the package set names.
- Repositories defined in the customizations as `PayloadRepositories`
  are considered to be associated only with the `PayloadPackageSets`
  names from the image type and are added to the `PackageSetsRepos`
  under the payload sets.

The repository collection and conversion of repository structs (from
Repository to RepoConfig) has been moved to a separate function.
2022-02-14 17:38:41 +01:00
Achilleas Koutsou
2dde6d7e33 cloudapi: add tags to repositories in image request
Tags is an array of strings that associates repositories with package
sets.  A repository tagged with a package set name will be used only for
the named package sets.
2022-02-14 17:38:41 +01:00
Achilleas Koutsou
82eedf5b82 DepsolveJob: rename struct field for consistency
We have two fields, `Repos` and `PackageSets`.  Renaming
`PackageSetsRepositories` to `PackageSetsRepos` for consistency.
The struct is for internal use only so the rename has no impact as long
as the serialised name is the same (json tag).

Also it's shorter.

Added docstring to the struct that explains the arguments in the same
way as they are described for the `depsolve()` function.

Changing the name of the argument in the internal `depsolve()` function
for the same reasons.
2022-02-14 17:38:41 +01:00
Achilleas Koutsou
0e5bb66516 cloudapi: small comment for readability
Comment the code that reads the user-defined repositories to explaine
what's happening.
2022-02-14 17:38:41 +01:00
Ondřej Budai
631bd21ffe cloudapi/v2: add support for aws-*-rhui image types
For the brew use-case, we also need to build AWS images containing RHUI. This
commit is thus adding them.

Signed-off-by: Ondřej Budai <ondrej@budai.cz>
2022-02-10 11:26:50 +00:00
Diaa Sami
7c52db1ae1 worker/api: align & improve error handlers 2022-02-02 11:15:20 +01:00
Tom Gundersen
11e2ae4528 cloudapi/v2: add koji-specific tests
These are based on the existing tests for the koji API, making sure the coverage is the same.
2022-02-01 20:28:40 +00:00
Tom Gundersen
a3f8304ae8 cloudapi/v2: support multi-build composes
This is for now only supported for koji builds.

A lot of code moved around for this, but functionally not much changed. PostCompose() now only parses the input, and queueing of all the jobs have been factored out in separate functions. PostCompose() is mostly agnostic to koji/non-koji requests.
2022-02-01 20:28:40 +00:00
Tom Gundersen
6a9ffb2086 cloudapi/v2: make ComposeStatus handle multi-build composes
This brings parity with the koji API.
2022-02-01 20:28:40 +00:00
Tom Gundersen
c81d0d08ec cloudapi/v2: support logs/manifests endpoints
For now these only work for koji builds.
2022-02-01 20:28:40 +00:00
Tom Gundersen
b32ab36e1d worker/server: typesafe Job and JobStatus
Replace Job() and JobStatus() with typesafe versions, and introduce JobType()
for the rare instances where we don't know the type up front.

Additionally, catch a few more error cases:
 - if OSBuildResult is nil, then we failed to invoke osbuild
 - make sure the same JobResult handling is done for osbuild-koji, as for osbuild
2022-02-01 20:28:40 +00:00
Tom Gundersen
9fba2dcc5d cloudapi/v2: introduce multi build composes
This only extends the API, the backend can still only deal with composes of a single build.

I aimed to keep the API practically backwards compatible, i.e., no current consumer of it should notice the change. I hope I didn't mess that up.

fixup: image statuses
2022-02-01 20:28:40 +00:00
Tom Gundersen
c1dc9d7284 cloudapi/v2: introduce compose status
In addition to individual image status, have an
overall status that captures success or failure
of the compose as a whole.

This is not as fine grained, and only distinguishes
between "pending", "failure" and "success".

This captures other jobs than the image builds, which
is relevant for the koji composes, which consists also
of koji-init and koji-finalize, in addition to the build
jobs.
2022-02-01 20:28:40 +00:00
Tom Gundersen
c892ccfde0 cloudapi/v2: make upload request optional
For now upload requests are required if and only if we are not
using koji. When using the koji integration the produced artifacts
are uploaded to koji only. In the future we may want to support
also uploading to the cloud providers.
2022-02-01 20:28:40 +00:00
Tom Gundersen
92c7fc2534 cloupapi/v2: add koji support
Extend the compose endpoints to have minimal koji support.

This is intended to replace the current koji API so that it
can be consumed through api.openshift.com.
2022-02-01 20:28:40 +00:00
Gianluca Zuccarelli
88b5529cc4 osbuild-worker: test error backwards compatability
Since the workers will use structured error messages
going forward, it is necessary to maintain backwards
compatability for there errors in composer. Tests have
been added to the various apis to ensure that each api
checks for both kinds of errors, old and new.
2022-01-27 16:45:14 +01:00
Gianluca Zuccarelli
cc981b887a osbuild-worker: implement structured errors
Implement the structured errors as defined by the worker client.
Every error for each of the job types now returns a structured
error with a reason and a specific error code.  This will make
it possible to differentiate between 4xx errors and 5xx errors.

This commit refactors the way errors are implemented in the workers,
but maintains backwards compatability in composer by checking for
both kinds of errors.
2022-01-27 16:45:14 +01:00
sanne
a83cf95d5b go.mod: Update oapi-codegen and kin-openapi 2022-01-12 11:35:06 +01:00
Ondřej Budai
d967790ea5 api/cloud: drop v1 API
It's deprecated and not used anywhere, let's just drop it.

Signed-off-by: Ondřej Budai <ondrej@budai.cz>
2022-01-04 16:38:50 +01:00
Djebran Lezzoum
c93ea748a2 distro/depsolve/cloudapi: Add 3rd-party repository support.
Allow 3rd-party repositories to be supported and custom packages installed.
Fixes #COMPOSER-1273
2021-12-15 20:12:49 +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
Achilleas Koutsou
500e484799 cloudapi: add new image types to tests
Signed-off-by: Achilleas Koutsou <achilleas@koutsou.net>
2021-12-03 16:49:09 +00:00
Achilleas Koutsou
b840f452ea cloudapi: extend supported image types
Add support for:
- qcow2: guest iamge
- vmdk: vmware image
- image-installer: installer ISO

Signed-off-by: Achilleas Koutsou <achilleas@koutsou.net>
2021-12-03 16:49:09 +00:00