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

Add null and empty string validation to S3 bucket #107883

Merged
merged 3 commits into from
Apr 25, 2024

Conversation

mhl-b
Copy link
Contributor

@mhl-b mhl-b commented Apr 25, 2024

Add basic validation to S3 bucket name - nullity and empty string.
It is aligned with public docs for "bucket" as required field.
We might want to add more validations based on S3 naming rules.
This PR should not be a breaking change because missing bucket
will eventually throw exception later in the code with obscure error.

I've added yaml test to modules repository_s3/10_basic.yml,
not sure if it's a right place.

Addresses #107840

@mhl-b mhl-b added >enhancement :Distributed/Snapshot/Restore Anything directly related to the `_snapshot/*` APIs Team:Distributed Meta label for distributed team v8.15.0 labels Apr 25, 2024
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-distributed (Team:Distributed)

Copy link
Contributor

@DaveCTurner DaveCTurner left a comment

Choose a reason for hiding this comment

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

Thanks @mhl-b! I'm hesitant to do this with a setting validator however. In general strengthening the validation of a setting is troublesome because of backwards compatibility: when upgrading from an older cluster, it may have metadata that it considers to be valid but which becomes invalid after the upgrade, and that typically means it will reject the whole cluster state as invalid. It's also fairly troublesome to have a setting whose default value is invalid.

That said, I think it might work in this context because of some details of how we use this particular Settings object which is quite different from other usages. But still, I'd rather we avoided using settings validation here and just checked the value in the constructor.

@mhl-b
Copy link
Contributor Author

mhl-b commented Apr 25, 2024

Thank you David, good to know that Settings can have a wider impact.

@mhl-b mhl-b requested a review from DaveCTurner April 25, 2024 16:33
Copy link
Contributor

@DaveCTurner DaveCTurner left a comment

Choose a reason for hiding this comment

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

LGTM as-is; I left some (optional) style comments too. Feel free to act on them or not, no need for another review either way.

@@ -238,6 +237,10 @@ public void sendResponse(RestResponse response) {
);
}

private Settings.Builder defaultRepoSettings() {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: I'd be inclined to inline this. It's only used in a small number of places, it's not really any shorter like this, and indeed it's a little bit of a distraction to the reader to wonder what exactly those default settings are. It'd be different if there were many required settings ofc.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you, I wasnt sure about it, it make sense to inline since it just a single setting. Will update code.

).put(S3Repository.CHUNK_SIZE_SETTING.getKey(), new ByteSizeValue(chunk, ByteSizeUnit.MB).getStringRep()).build();
}

private Settings.Builder defaultRepoSettings() {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: likewise here. Indeed extracting this method kinda messes up the otherwise-quite-nicely-formatted chain of .put calls in bufferAndChunkSettings().

reason: "contains is a newly added assertion"
features: contains
- do:
cluster.state: { }
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: cleaning up stuff like whitespace in YAML tests is ok but I'd generally prefer them in a separate PR - it makes git bisect easier to use and avoids cluttering up git annotate output etc.

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 will keep it mind in next PR's. I applied project formatting to entire file, it's relatively small one.

@mhl-b mhl-b added the auto-merge Automatically merge pull request when CI checks pass (NB doesn't wait for reviews!) label Apr 25, 2024
@elasticsearchmachine elasticsearchmachine merged commit e3c84af into elastic:main Apr 25, 2024
14 checks passed
@mhl-b mhl-b deleted the s3-bucket-validation branch June 17, 2024 17:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto-merge Automatically merge pull request when CI checks pass (NB doesn't wait for reviews!) :Distributed/Snapshot/Restore Anything directly related to the `_snapshot/*` APIs >enhancement Team:Distributed Meta label for distributed team v8.15.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants