Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cloudapi: make ImageRequests tied to their UploadOptions #3018

Closed

Conversation

ondrejbudai
Copy link
Member

Previously, one could pass GCPUploadOptions to an aws image request because the spec technically allows that. I haven't found any validation in our code, so I presume that the result would be pretty undefined.

A real-life example: If someone wanted an aws image but didn't specify share_with_accounts, this is valid according to AWSS3UploadOptions. Composer doesn't perform any additional checks, so it would just proceed to building such an image, and uploading it to our account where no one can use access it.

This commit makes ImageRequest be one of AWSEC2ImageRequest, AzureImageRequest etc. XYZImageRequest always requires its upload_options to be XYZUploadOptions. As all of these ImageRequests contain some common fields, I created AbstractImageRequest to deduplicate them.

One thing that I don't like is that image types called AWSEC2ImageRequestImageTypeAws are long, and in most cases we need to cast them to string, which loses a bit of type safety.

What I like is that the API spec is now more self-explanatory and helpful for composer's users.

I also had to adjust several tests that build aws images without setting share_with_accounts.

This breaks backward compatibility but the only broken requests are non-sense ones.


This is actually a prequel to #3006. A suggestion from @thozza was to make AWSEC2UploadOptions specified like this:

oneOf:
  - required:
    - share_with_accounts
  - required:
    - public

The issue is that, the spec validator will happily validate AWSEC2UploadOptions without neither of these fields set using the AWSS3UploadOptions spec. I did not like that, so I began thinking how to make the schema more error-proof and came out with this.


I was thinking if this is fine for future extensions: One extension that I can think of is to add the ability to upload any image to an S3-like storage. I think this is fine in the spec because we just make all image requests uploadable to both their target and to S3. A bit of code-duplication can happen but with oneOf and allOf, we should be just fine.

Signed-off-by: Ondřej Budai [email protected]

This pull request includes:

  • adequate testing for the new functionality or fixed issue
  • adequate documentation informing people about the change such as
    • the API spec is now more self-explanatory

Previously, one could pass GCPUploadOptions to an aws image request because
the spec technically allows that. I haven't found any validation in our code,
so I presume that the result would be pretty undefined.

A real-life example: If someone wanted an aws image but didn't specify
`share_with_accounts`, this is valid according to AWSS3UploadOptions.
Composer doesn't perform any additional checks, so it would just proceed to
building such an image, and uploading it to our account where no one can
use access it.

This commit makes ImageRequest be one of AWSEC2ImageRequest,
AzureImageRequest etc. XYZImageRequest always requires its `upload_options`
to be XYZUploadOptions. As all of these ImageRequests contain some common
fields, I created AbstractImageRequest to deduplicate them.

One thing that I don't like is that image types called
AWSEC2ImageRequestImageTypeAws are long, and in most cases we need to
cast them to `string`, which loses a bit of type safety.

What I like is that the API spec is now more self-explanatory and helpful
for composer's users.

I also had to adjust several tests that build aws images without setting
`share_with_accounts`.

This  breaks backward compatibility but the only broken requests are non-sense
ones.

Signed-off-by: Ondřej Budai <[email protected]>
Copy link
Member

@thozza thozza left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall, this IMO makes sense and looks good 👍 .

I don't like the many occurrences of casting to string, but I don't have any better suggestion since the code is generated from the API spec. I also think that the code may get uglier if we ever decide to allow uploading images to S3, in addition to their native upload target, but that is something for our future selfs... 😅

Comment on lines +839 to +840
- edge-container
- iot-container
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure that nobody relies on uploading these also to S3? 🤔 Just checking...

Copy link
Member

@croissanne croissanne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm!

thozza added a commit to thozza/koji-osbuild that referenced this pull request Nov 2, 2022
It turned out, that the upload options for AWS EC2 or GCP with just the
required properties specified, would match both schemas. This is causing
the validation fail with `oneOf` used for `upload_options`.

This will be fixed in osbuild-composer PR#3018. However, we can't use
the same approach for koji-osbuild, while keeping the schema backward
compatible and sane.

Another discussed option would be to define `upload_options` as an empty
object with `additionalProperties` set to `True`. This would
effectively mean no validation of `upload_options`. None of the plugins
actually modify the `upload_options` in any way. It is passed as
provided to `osbuild-composer`.

I think that the change in this commit is a compromise. The validation
of the `upload_options` schema is kept, but it is relaxed to `anyOf`.

[1] osbuild/osbuild-composer#3018

Signed-off-by: Tomáš Hozza <[email protected]>
thozza added a commit to thozza/koji-osbuild that referenced this pull request Nov 11, 2022
It turned out, that the upload options for AWS EC2 or GCP with just the
required properties specified, would match both schemas. This is causing
the validation fail with `oneOf` used for `upload_options`.

This will be fixed in osbuild-composer PR#3018. However, we can't use
the same approach for koji-osbuild, while keeping the schema backward
compatible and sane.

Another discussed option would be to define `upload_options` as an empty
object with `additionalProperties` set to `True`. This would
effectively mean no validation of `upload_options`. None of the plugins
actually modify the `upload_options` in any way. It is passed as
provided to `osbuild-composer`.

I think that the change in this commit is a compromise. The validation
of the `upload_options` schema is kept, but it is relaxed to `anyOf`.

[1] osbuild/osbuild-composer#3018

Signed-off-by: Tomáš Hozza <[email protected]>
thozza added a commit to thozza/koji-osbuild that referenced this pull request Nov 15, 2022
It turned out, that the upload options for AWS EC2 or GCP with just the
required properties specified, would match both schemas. This is causing
the validation fail with `oneOf` used for `upload_options`.

This will be fixed in osbuild-composer PR#3018. However, we can't use
the same approach for koji-osbuild, while keeping the schema backward
compatible and sane.

Another discussed option would be to define `upload_options` as an empty
object with `additionalProperties` set to `True`. This would
effectively mean no validation of `upload_options`. None of the plugins
actually modify the `upload_options` in any way. It is passed as
provided to `osbuild-composer`.

I think that the change in this commit is a compromise. The validation
of the `upload_options` schema is kept, but it is relaxed to `anyOf`.

[1] osbuild/osbuild-composer#3018

Signed-off-by: Tomáš Hozza <[email protected]>
ochosi pushed a commit to thozza/koji-osbuild that referenced this pull request Nov 17, 2022
It turned out, that the upload options for AWS EC2 or GCP with just the
required properties specified, would match both schemas. This is causing
the validation fail with `oneOf` used for `upload_options`.

This will be fixed in osbuild-composer PR#3018. However, we can't use
the same approach for koji-osbuild, while keeping the schema backward
compatible and sane.

Another discussed option would be to define `upload_options` as an empty
object with `additionalProperties` set to `True`. This would
effectively mean no validation of `upload_options`. None of the plugins
actually modify the `upload_options` in any way. It is passed as
provided to `osbuild-composer`.

I think that the change in this commit is a compromise. The validation
of the `upload_options` schema is kept, but it is relaxed to `anyOf`.

[1] osbuild/osbuild-composer#3018

Signed-off-by: Tomáš Hozza <[email protected]>
ondrejbudai pushed a commit to osbuild/koji-osbuild that referenced this pull request Nov 21, 2022
It turned out, that the upload options for AWS EC2 or GCP with just the
required properties specified, would match both schemas. This is causing
the validation fail with `oneOf` used for `upload_options`.

This will be fixed in osbuild-composer PR#3018. However, we can't use
the same approach for koji-osbuild, while keeping the schema backward
compatible and sane.

Another discussed option would be to define `upload_options` as an empty
object with `additionalProperties` set to `True`. This would
effectively mean no validation of `upload_options`. None of the plugins
actually modify the `upload_options` in any way. It is passed as
provided to `osbuild-composer`.

I think that the change in this commit is a compromise. The validation
of the `upload_options` schema is kept, but it is relaxed to `anyOf`.

[1] osbuild/osbuild-composer#3018

Signed-off-by: Tomáš Hozza <[email protected]>
@thozza thozza added the blocked Issues / PRs blocked by something label May 22, 2023
@github-actions
Copy link

github-actions bot commented Sep 8, 2023

This PR is stale because it has been open 30 days with no activity. Remove "Stale" label or comment or this will be closed in 7 days.

@github-actions github-actions bot added the Stale label Sep 8, 2023
@github-actions
Copy link

This PR was closed because it has been stalled for 30+7 days with no activity.

@github-actions github-actions bot closed this Sep 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blocked Issues / PRs blocked by something Stale
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants