Commit graph

430 commits

Author SHA1 Message Date
Achilleas Koutsou
102c322ec9 ostree: simplify ResolveParams arguments
No need to pass the entire image type. We just need the default ref.
This removes the distro package dependency from the ostree package,
which we will need so distro can use the ostree types and functions.
2022-02-23 11:08:24 +01:00
Achilleas Koutsou
b92754b135 ostree: rename request parameters type
It's in the ostree package, so it doesn't need to have OSTree in the
name.
2022-02-23 11:08:24 +01:00
Achilleas Koutsou
db345d75dd ostree: include ref in error message when invalid 2022-02-23 11:08:24 +01:00
Achilleas Koutsou
417d913439 weldr: use new ResolveOSTreeParams function 2022-02-23 11:08:24 +01:00
Achilleas Koutsou
4d31c8e69d weldr: change all OSTree related error IDs to OSTreeOptionsError
These will all be reported from the same validation function.
2022-02-23 11:08:24 +01:00
Achilleas Koutsou
26468315ab weldr: expand ostree parameter test cases
Adding three more combinations that weren't covered by previous tests:
- Supplying ref, parent, and URL: should result in an error
- Supplying ref and parent: OK
- Supplying parent, and URL: same as first case (ref gets default value
  from image type)

Added default OSTreeRef() to test image type to cover the cases where
the ref isn't specified but affects the validation.

Separated and commented the test cases.
2022-02-23 11:08:24 +01:00
Achilleas Koutsou
01b2b15ebc weldr: reuse api for all test cases in TestCompose 2022-02-23 11:08:24 +01:00
Brian C. Lane
c657713181 weldr: Allow cancel on waiting and running composes
Fix the cancel API to allow a waiting compose to be canceled.
This also fixes the cancel return code to be 400, the lorax-composer
behavior was a bug, and using 400 allows composer-cli to properly
display the error.
2022-02-18 09:31:07 +01:00
Brian C. Lane
a186fd4705 weldr: Check for missing undo blueprint
When the server is restarted the blueprint changes, which are only held
in memory, are lost. This checks for missing changes and returns an
error.

The test is also adjusted for the new error.

Related: rhbz#1922845
2022-02-15 10:10:21 +01:00
Brian C. Lane
aa8cf41ac2 blueprint: Make sure name is not empty
The blueprint name should never be empty, as it can cause other problems
like with the blueprints list results. Return an error if one is pushed
to the store, either as a blueprint commit or as a blueprint workspace.

Also adjusts the new test for the new error.

Related: rhbz#1922845
2022-02-15 10:10:21 +01:00
Brian C. Lane
a3b415d1df test: Add fixture support for blueprint changes
There is a problem with blueprint changes, once the server is restarted
the previous changes are all lost because they are not serialized to
disk.

This adds test fixture support so that new tests can be added before
fixing the problem. It adds store.FixtureOldChanges with blueprints
changes and empty blueprints.

Related: rhbz#1922845
2022-02-15 10:10:21 +01: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
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
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
Ondřej Budai
e668ed0ac5 weldr: return an error if host distro wasn't found in distro registry
Prevents a nil panic, see rhbz#2035956

Signed-off-by: Ondřej Budai <ondrej@budai.cz>
2022-01-03 18:05:15 +01:00
Juan Abia
8136209d17 gosec: G404 - Use of weak rng
math/rand is good enough for uuids. disabling rule locally.
2021-12-13 12:17:30 +02:00
Juan Abia
0b9372fe0a gosec: G110 - Potential DoS vulnerability
this vulnerability is already tested. Disabling issue in line
2021-12-13 12:17:30 +02:00
Achilleas Koutsou
9aef7bfc47 osbuild-worker: attach pipeline names to jobs
Pipeline names are added to each job before adding to the queue. When a
job is finished, the names are copied to the Result object as well. This
is done for both OSBuild and Koji jobs.

The pipeline names in the result are primarily used to separate package
lists into build and payload/image packages in two cases:
1. Koji builds: for reporting the build root and image package lists to
   Koji (in Koji finalize).
2. Cloud API (v1 and v2): for reporting the payload packages in the
   metadata request.

The pipeline names are also used to print the system log output in the
order in which pipelines are executed. This still isn't used when
printing the OSBuild Result (osbuild2.Result.Write()) and we still rely
on sorting by pipeline name
(see https://github.com/osbuild/osbuild-composer/pull/1330).
2021-11-16 09:49:37 +01:00
Achilleas Koutsou
2004c71f89 cloudapi: use osbuild v2 result struct to extract metadata
Reading stage metadata using osbuild's v2 result format.
For RPM stages we only want the core (OS) RPMs (not the build root
RPMs). Skip the build pipeline by name, but this should be handled
better since names are arbitrary.

Using type switch to convert metadata types instead of relying on the
type string of the stage result.

The rpmmd helper function isn't used anymore since that requires two
conversion passes (osbuild.StageMetadata -> rpmmd.RPM ->
cloudapi.PackageMetadata).

Signed-off-by: Achilleas Koutsou <achilleas@koutsou.net>
2021-11-16 09:49:37 +01:00
Martin Sehnoutka
d7d4e02c8c internal/common: introduce git revision and rpm version
The variables are set to the git revision from which the build is
triggered and rpm version from the spec file, if it is build using RPM.

This can be later used to query exact source version while
running osbuild-composer.

It is necessary to use both, because none of them is available in all
possible scenarios.

Use either git-rev (preferably) or RPM version (NEVRA) instead of the
"devel" build type. It was just a placeholder.
2021-09-24 14:13:23 +02:00
Brian C. Lane
e92424b5e3 weldr: deleting an unknown source should return an error
This adds a check to see if the source is valid and returns a 400 error
if it doesn't exist.
2021-09-22 11:24:31 +02: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
Jakub Rusz
37b14facd3 tests: update base tests for weldr-client
weldr-client returns different json structures than the original
composer-cli does. It is being replaced in RHEL-9 and these changes make
it possible to run the tests with both old composer-cli and
weldr-client.
2021-08-25 19:16:04 +02:00
Martin Sehnoutka
1ada606ed8 internal/rhsm: introduce package that handles subscriptions
The problem: osbuild-composer used to have a rather uncomplete logic for
selecting client certificates and keys while fetching data from
repositories that use the "subscription model". In this scenario, every
repo requires the user to use a client-side TLS certificate. The problem
is that every repo can use its own CA and require a different pair of
a certificate and a key. This case wasn't handled at all in composer.

Furthermore, osbuild-composer can use remote workers which complicates
things even more.

Assumptions: The problem outlined above is hard to solve in the general
case, but Red Hat Subscription Manager places certain limitations on how
subscriptions might be used. For example, a subscription must be tight to
a host system, so there is no way to use such a repository in osbuild-composer
without it being available on the host system as well.

Also, if a user wishes to use a certain repository in osbuild-composer it
must be available on both hosts: the composer and the worker. It will come
with different pair of a client certificate and a key but otherwise, its
configuration remains the same.

The solution: Expect all the subscriptions to be registered in the
/etc/yum.repos.d/redhat.repo file. Read the mapping of URLs to certificates
and keys from there and use it. Don't change the manifest format and let
osbuild guess the appropriate subscription to use.
2021-08-09 12:40:23 +02:00
Tomas Hozza
0a71054d86 Weldr API: allow globing in distro image type deny list
Allow globing patterns in distro-specific image type deny list of Weldr
API configuration. Extend unit tests to verify simple globing patterns.

Update NEWS entry.

Signed-off-by: Tomas Hozza <thozza@redhat.com>
2021-08-02 18:51:03 +02:00
Tomas Hozza
a9b676e43e Weldr API: return the actual getImageType() error in composeHandler()
Refactor the `composeHandler()` method to send the actual error
returned by `getImageType()` as an API response.

Modify tests to handle the changed error message in API calls.

Signed-off-by: Tomas Hozza <thozza@redhat.com>
2021-08-02 18:51:03 +02:00
Tomas Hozza
dc8a93b3f6 Weldr API: rename checkImageTypeDenylist() and return bool
Rename the `checkImageTypeDenylist()` method to `isImageTypeAllowed()`
and return boolean value instead of error.

Signed-off-by: Tomas Hozza <thozza@redhat.com>
2021-08-02 18:51:03 +02:00
Tomas Hozza
b150d57c18 Weldr API: make Image Type denylist distribution-specific
Change the Image Type denylist in Weldr API from being applied to all
distributions to being distribution-specific. A special name `*`
can be used in the configuration to match any distribution
or any image type.

Modify NEWS entry and unit tests to reflect this change.

Signed-off-by: Tomas Hozza <thozza@redhat.com>
2021-08-02 18:51:03 +02:00
Tomas Hozza
076bbc5456 Weldr API: introduce Image Type denylist for filtering exposed images
Extend Weldr API to accept a list of denied image types, which should
not be exposed via API for any supported distribution. This
functionality will be needed to not expose image types which can't be
successfully built outside of Red Hat VPN. Example of such images are
the official RHEL EC2 images, which include RHUI client packages not
available publicly.

Image Types are filters when listing available compose types and
creating a new compose using Weldr API.

Extend osbuild-composer configuration to allow specifying the list of
denied Image Types for Weldr API.

Add unit tests for implemented changes.

Add NEWS entry describing the newly introduced functionality.

Signed-off-by: Tomas Hozza <thozza@redhat.com>
2021-08-02 18:51:03 +02:00
Gianluca Zuccarelli
bf62f3868e weldr: add filesystem configuration support 2021-07-28 21:44:03 +01:00
Martin Sehnoutka
b950d6e062 weldr: accept rhsm parameter in sources
The system sources allow specification of the rhsm parameter, but it
isn't available in the sources configured over the Weldr API. This patch
implements support for it.
2021-07-27 15:39:36 +02:00
Brian C. Lane
b5f0400bd4 weldr: Filter the list of supported distributions
Some distributions do not have repositories and therefore cannot be
built. This filters the list of supported distributions by checking for
repos when starting up. All other requests use the api.distros list or
api.getDistro() function.
2021-07-12 08:58:42 +02:00
Brian C. Lane
963ce1d050 weldr: Use host distro name from registry list
The name of the distro you get from distros.FromHost() may not match any of
the names in the registry's list. Use the actual name of the distro
instead of the mangled name.

Also removes api.distro which is unused.
2021-07-12 08:58:42 +02:00
Brian C. Lane
b0f9d38a95 api_test: Test new source with 2nd distro 2021-07-12 08:58:42 +02:00
Brian C. Lane
f731d7a606 api_test: Test compose with 2nd distribution 2021-07-12 08:58:42 +02:00
Brian C. Lane
788daf91a4 api_test: Test projects/depsolve with 2nd distribution 2021-07-12 08:58:42 +02:00
Brian C. Lane
e010e2c421 api_test: Test modules/info with 2nd distribution 2021-07-12 08:58:42 +02:00
Brian C. Lane
2ad4b84af6 api_test: Test projects/info with 2nd distribution 2021-07-12 08:58:42 +02:00
Brian C. Lane
c9f4b1ac8b api_test: Test modules/list with 2nd distribution 2021-07-12 08:58:42 +02:00
Brian C. Lane
05f327c796 api_test: Test projects/list with 2nd distribution 2021-07-12 08:58:42 +02:00
Brian C. Lane
43171b4169 api_test: Test compose types with 2nd distribution 2021-07-12 08:58:42 +02:00
Brian C. Lane
5021ef06f7 Add 2nd distribution to the NewTestAPI function
This will help test support for multiple distributions.
2021-07-12 08:58:42 +02:00
Brian C. Lane
c1da403dc0 weldr: Use GetAllDistroSources in allRepository* functions 2021-07-12 08:58:42 +02:00
Brian C. Lane
e2b170e754 weldr: Check source POST for valid distros 2021-07-12 08:58:42 +02:00
Brian C. Lane
f79f399808 weldr: Add optional distro selection to compose/types 2021-07-12 08:58:42 +02:00
Brian C. Lane
f233f540e5 weldr: Fix PROJECTS_ERROR response 2021-07-12 08:58:42 +02:00
Brian C. Lane
881e1c5652 weldr: Add optional distro selection to projects/depsolve route 2021-07-12 08:58:42 +02:00
Brian C. Lane
2b63b3cbed weldr: Add optional distro selection to modules and projects/info route 2021-07-12 08:58:42 +02:00
Brian C. Lane
b98cf3c4f7 weldr: Add optional distro selection to modules/list route 2021-07-12 08:58:42 +02:00
Brian C. Lane
d1d2f6d491 weldr: Add optional distro selection to projects/list route 2021-07-12 08:58:42 +02:00