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

MGMT-14730: Validate that manifest file size does not exceed 1MB #5281

Merged
merged 1 commit into from Jun 13, 2023

Conversation

paul-maidment
Copy link
Contributor

@paul-maidment paul-maidment commented Jun 7, 2023

etcd resources in k8s are limited to 1.5 MiB as indicated here https://etcd.io/docs/v3.5/dev-guide/limit/#request-size-limit
however, one the the resource types that can be created from a manifest is a ConfigMap
which has a size limit of 1MiB as cited here https://kubernetes.io/docs/concepts/configuration/configmap
so this limit has been chosen based on the lowest permitted resource size (the size of the ConfigMap)

Presently we do not validate the maximum size during upload or edit.
This pull request addresses that by validating that the file does not exceed this limit.

List all the issues related to this PR

  • New Feature
  • Enhancement
  • Bug fix
  • Tests
  • Documentation
  • CI/CD

What environments does this code impact?

  • Automation (CI, tools, etc)
  • Cloud
  • Operator Managed Deployments
  • [] None

How was this code tested?

  • assisted-test-infra environment
  • dev-scripts environment
  • Reviewer's test appreciated
  • Waiting for CI to do a full test run
  • Manual (Elaborate on how it was tested)
  • [] No tests needed

Checklist

  • Title and description added to both, commit and PR.
  • Relevant issues have been associated (see CONTRIBUTING guide)
  • This change does not require a documentation update (docstring, docs, README, etc)
  • Does this change include unit-tests (note that code changes require unit-tests)

Reviewers Checklist

  • Are the title and description (in both PR and commit) meaningful and clear?
  • Is there a bug required (and linked) for this change?
  • Should this PR be backported?

@openshift-ci-robot openshift-ci-robot added the jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. label Jun 7, 2023
@openshift-ci-robot
Copy link

openshift-ci-robot commented Jun 7, 2023

@paul-maidment: This pull request references MGMT-14730 which is a valid jira issue.

In response to this:

Openshift does not allow a manifest size of greater than 1MB and presently we do not validate the maximum size during upload or edit. This pull request addresses that by validating that the file does not exceed this limit.

List all the issues related to this PR

  • New Feature
  • Enhancement
  • Bug fix
  • Tests
  • Documentation
  • CI/CD

What environments does this code impact?

  • Automation (CI, tools, etc)
  • Cloud
  • Operator Managed Deployments
  • [] None

How was this code tested?

  • assisted-test-infra environment
  • dev-scripts environment
  • Reviewer's test appreciated
  • Waiting for CI to do a full test run
  • Manual (Elaborate on how it was tested)
  • [] No tests needed

Checklist

  • Title and description added to both, commit and PR.
  • Relevant issues have been associated (see CONTRIBUTING guide)
  • This change does not require a documentation update (docstring, docs, README, etc)
  • Does this change include unit-tests (note that code changes require unit-tests)

Reviewers Checklist

  • Are the title and description (in both PR and commit) meaningful and clear?
  • Is there a bug required (and linked) for this change?
  • Should this PR be backported?

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@openshift-ci openshift-ci bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Jun 7, 2023
@openshift-ci
Copy link

openshift-ci bot commented Jun 7, 2023

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: paul-maidment

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jun 7, 2023
@@ -353,6 +353,10 @@ func (m *Manifests) validateAllowedToModifyManifests(ctx context.Context, cluste
}

func (m *Manifests) validateUserSuppliedManifest(ctx context.Context, clusterID strfmt.UUID, manifestContent []byte, fileName string) error {
maxFileSizeBytes := 1048576
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
maxFileSizeBytes := 1048576
maxFileSizeBytes := 1024 * 1024 * 1024

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think this should be

maxFileSizeBytes := 1024 * 1024

@@ -353,6 +353,10 @@ func (m *Manifests) validateAllowedToModifyManifests(ctx context.Context, cluste
}

func (m *Manifests) validateUserSuppliedManifest(ctx context.Context, clusterID strfmt.UUID, manifestContent []byte, fileName string) error {
maxFileSizeBytes := 1048576
if len(manifestContent) > maxFileSizeBytes {
return m.prepareAndLogError(ctx, http.StatusBadRequest, errors.Errorf("Manifest content of file %s for cluster ID %s exceeds the maximum file size of 1MB", fileName, string(clusterID)))
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
return m.prepareAndLogError(ctx, http.StatusBadRequest, errors.Errorf("Manifest content of file %s for cluster ID %s exceeds the maximum file size of 1MB", fileName, string(clusterID)))
return m.prepareAndLogError(ctx, http.StatusBadRequest, errors.Errorf("Manifest content of file %s for cluster ID %s exceeds the maximum file size of 1MiB", fileName, string(clusterID)))

@omertuc
Copy link
Contributor

omertuc commented Jun 7, 2023

Can you please link to the installer code that enforces this limit? Is this 1MiB or 1MB?

@paul-maidment paul-maidment force-pushed the MGMT-14730 branch 2 times, most recently from 813ef8e to 580d656 Compare June 7, 2023 11:04
@openshift-ci-robot
Copy link

openshift-ci-robot commented Jun 7, 2023

@paul-maidment: This pull request references MGMT-14730 which is a valid jira issue.

In response to this:

Openshift does not alloww a manifest size of greater than 1MiB because ultimately the content is stored in a ConfigMap and those have a limit of 1MiB

https://kubernetes.io/docs/concepts/configuration/configmap/

Presently we do not validate the maximum size during upload or edit.
This pull request addresses that by validating that the file does not exceed this limit.

List all the issues related to this PR

  • New Feature
  • Enhancement
  • Bug fix
  • Tests
  • Documentation
  • CI/CD

What environments does this code impact?

  • Automation (CI, tools, etc)
  • Cloud
  • Operator Managed Deployments
  • [] None

How was this code tested?

  • assisted-test-infra environment
  • dev-scripts environment
  • Reviewer's test appreciated
  • Waiting for CI to do a full test run
  • Manual (Elaborate on how it was tested)
  • [] No tests needed

Checklist

  • Title and description added to both, commit and PR.
  • Relevant issues have been associated (see CONTRIBUTING guide)
  • This change does not require a documentation update (docstring, docs, README, etc)
  • Does this change include unit-tests (note that code changes require unit-tests)

Reviewers Checklist

  • Are the title and description (in both PR and commit) meaningful and clear?
  • Is there a bug required (and linked) for this change?
  • Should this PR be backported?

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@paul-maidment
Copy link
Contributor Author

paul-maidment commented Jun 7, 2023

Can you please link to the installer code that enforces this limit? Is this 1MiB or 1MB?

Explanation added to comments about ConfigMap size limit in Kubernetes.
And this is in MiB so updated to reflect this throughout the PR

@openshift-ci-robot
Copy link

openshift-ci-robot commented Jun 7, 2023

@paul-maidment: This pull request references MGMT-14730 which is a valid jira issue.

In response to this:

Openshift does not allow a manifest size of greater than 1MiB because ultimately the content is stored in a ConfigMap and those have a limit of 1MiB

https://kubernetes.io/docs/concepts/configuration/configmap/

Presently we do not validate the maximum size during upload or edit.
This pull request addresses that by validating that the file does not exceed this limit.

List all the issues related to this PR

  • New Feature
  • Enhancement
  • Bug fix
  • Tests
  • Documentation
  • CI/CD

What environments does this code impact?

  • Automation (CI, tools, etc)
  • Cloud
  • Operator Managed Deployments
  • [] None

How was this code tested?

  • assisted-test-infra environment
  • dev-scripts environment
  • Reviewer's test appreciated
  • Waiting for CI to do a full test run
  • Manual (Elaborate on how it was tested)
  • [] No tests needed

Checklist

  • Title and description added to both, commit and PR.
  • Relevant issues have been associated (see CONTRIBUTING guide)
  • This change does not require a documentation update (docstring, docs, README, etc)
  • Does this change include unit-tests (note that code changes require unit-tests)

Reviewers Checklist

  • Are the title and description (in both PR and commit) meaningful and clear?
  • Is there a bug required (and linked) for this change?
  • Should this PR be backported?

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@codecov
Copy link

codecov bot commented Jun 7, 2023

Codecov Report

Merging #5281 (0e754ef) into master (4a22712) will increase coverage by 1.25%.
The diff coverage is 100.00%.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #5281      +/-   ##
==========================================
+ Coverage   67.47%   68.72%   +1.25%     
==========================================
  Files         221      221              
  Lines       33045    34296    +1251     
==========================================
+ Hits        22298    23571    +1273     
+ Misses       8731     8677      -54     
- Partials     2016     2048      +32     
Impacted Files Coverage Δ
internal/manifests/manifests.go 72.42% <100.00%> (+0.34%) ⬆️

... and 5 files with indirect coverage changes

@@ -353,6 +353,12 @@ func (m *Manifests) validateAllowedToModifyManifests(ctx context.Context, cluste
}

func (m *Manifests) validateUserSuppliedManifest(ctx context.Context, clusterID strfmt.UUID, manifestContent []byte, fileName string) error {
// Ultimately manifests are consumed into a ConfigMap. The max permitted size of a ConfigMap is 1MiB
Copy link
Contributor

@omertuc omertuc Jun 7, 2023

Choose a reason for hiding this comment

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

Ultimately manifests are consumed into a ConfigMap

Not sure I understand, can you explain this? consumed by who?

Copy link
Contributor

Choose a reason for hiding this comment

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

config map is not exactly a correct term. MachineConfig for example is a manifest as well but it's not a configmap, i would describe it as a etcd resource in k8s is limited to 1MB

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, I meant to say "stored in a configmap", have updated the code

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK, changed this now to say
// etcd resources in k8s are limited to 1MiB

Copy link
Contributor

Choose a reason for hiding this comment

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

What is your source that etcd resources are limited to 1MiB? All I see is docs talking about configmaps being limited

Copy link
Contributor

Choose a reason for hiding this comment

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

What is your source that etcd resources are limited to 1MiB? All I see is docs talking about configmaps being limited

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My source is this internal conversation https://redhat-internal.slack.com/archives/CUPJTHQ5P/p1686135268686879
Where it is acknowledged that the etcd max size is 1.5MiB
https://etcd.io/docs/v3.5/dev-guide/limit/#request-size-limit
However, also mentions that the effective limit is 1MiB for ConfigMaps
https://kubernetes.io/docs/concepts/configuration/configmap

Is there a massive concern to setting the manifest limit to 1MiB ? Do you want to make the distinction between different types of content and change the limit accordingly?

Should we try to find out more about what the limit should be, who should we ask?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If we set the limit to 1MiB then it would be possible to upload a manifest content of this size and that might lead to an attempt to create a config map of this size.

That's why I think we should lower it to 1MiB as this is the lowest value in common between ConfigMaps and etcd resources.

If we want to analyse manifest content to determine what size should be uploaded, I think this would get complicated quickly.

So I think it's best to set to 1 MiB

Copy link
Contributor

@omertuc omertuc Jun 8, 2023

Choose a reason for hiding this comment

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

Is there a massive concern to setting the manifest limit to 1MiB

No, I just want to understand why we are doing what we're doing

Do you want to make the distinction between different types of content and change the limit accordingly?

Not necessarily, but if we don't do that, we need to at-least acknowledge in a comment explicitly that our blanket limit of 1MiB is too conservative but is done to easily have the correct limit also for configmaps without worrying about the exact type of resource

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have updated the comments and commit message to reflect this concern

@paul-maidment paul-maidment force-pushed the MGMT-14730 branch 2 times, most recently from 53fe42a to 45519be Compare June 7, 2023 12:07
@openshift-ci-robot
Copy link

openshift-ci-robot commented Jun 7, 2023

@paul-maidment: This pull request references MGMT-14730 which is a valid jira issue.

In response to this:

Openshift does not allow a manifest size of greater than 1MiB because ultimately the content is stored etcd and these resources have a limit of 1MiB.

https://kubernetes.io/docs/concepts/configuration/configmap/

Presently we do not validate the maximum size during upload or edit.
This pull request addresses that by validating that the file does not exceed this limit.

List all the issues related to this PR

  • New Feature
  • Enhancement
  • Bug fix
  • Tests
  • Documentation
  • CI/CD

What environments does this code impact?

  • Automation (CI, tools, etc)
  • Cloud
  • Operator Managed Deployments
  • [] None

How was this code tested?

  • assisted-test-infra environment
  • dev-scripts environment
  • Reviewer's test appreciated
  • Waiting for CI to do a full test run
  • Manual (Elaborate on how it was tested)
  • [] No tests needed

Checklist

  • Title and description added to both, commit and PR.
  • Relevant issues have been associated (see CONTRIBUTING guide)
  • This change does not require a documentation update (docstring, docs, README, etc)
  • Does this change include unit-tests (note that code changes require unit-tests)

Reviewers Checklist

  • Are the title and description (in both PR and commit) meaningful and clear?
  • Is there a bug required (and linked) for this change?
  • Should this PR be backported?

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@paul-maidment paul-maidment force-pushed the MGMT-14730 branch 3 times, most recently from 0a3c68a to 49136dc Compare June 8, 2023 09:41
@openshift-ci-robot
Copy link

openshift-ci-robot commented Jun 8, 2023

@paul-maidment: This pull request references MGMT-14730 which is a valid jira issue.

In response to this:

etcd resources in k8s are limited to 1.5 MiB as indicated here https://etcd.io/docs/v3.5/dev-guide/limit/#request-size-limit
however, one the the resource types that can be created from a manifest is a ConfigMap
which has a size limit of 1MiB as cited here https://kubernetes.io/docs/concepts/configuration/configmap
so this limit has been chosen based on the lowest permitted resource size (the size of the ConfigMap)

Presently we do not validate the maximum size during upload or edit.
This pull request addresses that by validating that the file does not exceed this limit.

List all the issues related to this PR

  • New Feature
  • Enhancement
  • Bug fix
  • Tests
  • Documentation
  • CI/CD

What environments does this code impact?

  • Automation (CI, tools, etc)
  • Cloud
  • Operator Managed Deployments
  • [] None

How was this code tested?

  • assisted-test-infra environment
  • dev-scripts environment
  • Reviewer's test appreciated
  • Waiting for CI to do a full test run
  • Manual (Elaborate on how it was tested)
  • [] No tests needed

Checklist

  • Title and description added to both, commit and PR.
  • Relevant issues have been associated (see CONTRIBUTING guide)
  • This change does not require a documentation update (docstring, docs, README, etc)
  • Does this change include unit-tests (note that code changes require unit-tests)

Reviewers Checklist

  • Are the title and description (in both PR and commit) meaningful and clear?
  • Is there a bug required (and linked) for this change?
  • Should this PR be backported?

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@omertuc
Copy link
Contributor

omertuc commented Jun 8, 2023

/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Jun 8, 2023
@openshift-ci-robot
Copy link

/retest-required

Remaining retests: 0 against base HEAD bba0db7 and 2 for PR HEAD 49136dc in total

@omertuc
Copy link
Contributor

omertuc commented Jun 8, 2023

/test edge-unit-test

@openshift-ci-robot
Copy link

/retest-required

Remaining retests: 0 against base HEAD bba0db7 and 2 for PR HEAD 49136dc in total

@omertuc
Copy link
Contributor

omertuc commented Jun 8, 2023

/hold test failures

@openshift-ci openshift-ci bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jun 8, 2023
etcd resources in k8s are limited to 1.5 MiB as indicated here https://etcd.io/docs/v3.5/dev-guide/limit/#request-size-limit
however, one the the resource types that can be created from a manifest is a ConfigMap
which has a size limit of 1MiB as cited here https://kubernetes.io/docs/concepts/configuration/configmap
so this limit has been chosen based on the lowest permitted resource size (the size of the ConfigMap)

Presently we do not validate the maximum size during upload or edit.
This pull request addresses that by validating that the file does not exceed this limit.
@openshift-ci openshift-ci bot removed the lgtm Indicates that a PR is ready to be merged. label Jun 11, 2023
@paul-maidment
Copy link
Contributor Author

This should fix the failures. Will unhold when this is the case and seek another review.

One change sets the filesize the correct limit of 1024 * 1024 bytes.
The second change makes thee generation of a dummy file more efficient by using a StringBuilder.

@omertuc
Copy link
Contributor

omertuc commented Jun 12, 2023

/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Jun 12, 2023
@paul-maidment
Copy link
Contributor Author

/unhold

@openshift-ci openshift-ci bot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jun 12, 2023
@filanov filanov added do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. and removed do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. labels Jun 12, 2023
@droslean
Copy link
Member

/hold

@openshift-ci openshift-ci bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jun 12, 2023
@droslean
Copy link
Member

/hold cancel

@openshift-ci openshift-ci bot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jun 12, 2023
@droslean
Copy link
Member

/refresh

@paul-maidment
Copy link
Contributor Author

/hold

@openshift-ci openshift-ci bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jun 12, 2023
@openshift-ci
Copy link

openshift-ci bot commented Jun 12, 2023

@paul-maidment: all tests passed!

Full PR test history. Your PR dashboard.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

@paul-maidment
Copy link
Contributor Author

/unhold

@openshift-ci openshift-ci bot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jun 13, 2023
@openshift-merge-robot openshift-merge-robot merged commit cfb9b37 into openshift:master Jun 13, 2023
14 checks passed
danielerez pushed a commit to danielerez/assisted-service that referenced this pull request Oct 15, 2023
…nshift#5281)

etcd resources in k8s are limited to 1.5 MiB as indicated here https://etcd.io/docs/v3.5/dev-guide/limit/#request-size-limit
however, one the the resource types that can be created from a manifest is a ConfigMap
which has a size limit of 1MiB as cited here https://kubernetes.io/docs/concepts/configuration/configmap
so this limit has been chosen based on the lowest permitted resource size (the size of the ConfigMap)

Presently we do not validate the maximum size during upload or edit.
This pull request addresses that by validating that the file does not exceed this limit.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. lgtm Indicates that a PR is ready to be merged. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants