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 validation for newS3Config (#3410) #3414

Merged
merged 2 commits into from Nov 17, 2022
Merged

Conversation

u5surf
Copy link
Contributor

@u5surf u5surf commented Nov 9, 2022

  • endpoint has prefixed with bucket name

Signed-off-by: u5surf u5.horie@gmail.com

What this PR does

To fix the issue of 3410, we should be added the validation of endpoint which has not prefixed with bucket name.

Which issue(s) this PR fixes or relates to

Fixes #3410

Checklist

  • Tests updated
  • Documentation added
  • CHANGELOG.md updated - the order of entries should be [CHANGE], [FEATURE], [ENHANCEMENT], [BUGFIX]

@u5surf u5surf requested a review from a team as a code owner November 9, 2022 00:11
@CLAassistant
Copy link

CLAassistant commented Nov 9, 2022

CLA assistant check
All committers have signed the CLA.

Comment on lines 43 to 45
if strings.HasPrefix(cfg.Endpoint, cfg.BucketName) {
return s3.Config{}, fmt.Errorf("the endpoint must not prefixed with the bucket name: %s", cfg.BucketName)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

We should do this in the Config.Validate() method:

// Validate config and returns error on failure
func (cfg *Config) Validate() error {
if !util.StringsContain(supportedSignatureVersions, cfg.SignatureVersion) {
return errUnsupportedSignatureVersion
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@colega Thanks, reviewing. I fixed it and added change log and unit test.

@colega
Copy link
Contributor

colega commented Nov 10, 2022

Can you please move the validation to the Config.Validate() method, and also add a test and a changelog entry? Thank you.

CHANGELOG.md Outdated
@@ -4,6 +4,7 @@

### Grafana Mimir

* [CHANGE] Added Validation when S3 endpoint had a prefix of bucket name. #3414
Copy link
Contributor

Choose a reason for hiding this comment

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

I would say this is an ENHANCEMENT, since we're not adding a new restriction, we're just validating it earlier, WDYT?
Also, please move the changelog entry at the end of the category.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@colega I've fixed.

Copy link
Contributor

@colega colega left a comment

Choose a reason for hiding this comment

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

Thank you, this looks pretty good now! Just a small nitpick about the changelog entry.

CHANGELOG.md Outdated
@@ -30,6 +30,7 @@
* [BUGFIX] Updated `golang.org/x/text` dependency to fix CVE-2022-32149. #3285
* [BUGFIX] Query-frontend: properly close gRPC streams to the query-scheduler to stop memory and goroutines leak. #3302
* [BUGFIX] Ruler: persist evaluation delay configured in the rulegroup. #3392
* [ENHANCEMENT] Added Validation when S3 endpoint had a prefix of bucket name. #3414
Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry again, I mean that this should go after all the "[ENHANCEMENT]" elements.

Also could you please rehprase this as something like:
S3 bucket configuration now validates that the endpoint does not have the bucket name prefix.

(Why am I suggestion this change? This way the first words say what we're changing: S3 bucket configuration, so it's easier to visually scan for changes when something went wrong. Also lowercased the "validation word.)

@@ -37,7 +37,6 @@ func newS3Config(cfg Config) (s3.Config, error) {
if err != nil {
return s3.Config{}, err
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we can revert this file to main's version to avoid adding the unneeded change here?

Comment on lines 86 to 87
Endpoint: "mimir-blocks.s3.eu-central-1.amazonaws.com",
BucketName: "mimir-block",
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is interesting because shows a sort of flaw in the check. The bucket name is NOT the exact endpoint prefix. I think you should improve the check (strings.HasPrefix()) to also look for the dot (.) at the end of the bucket name when checking it.

* endpoint has prefixed with bucket name

Signed-off-by: u5surf <u5.horie@gmail.com>
Copy link
Collaborator

@pracucci pracucci left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@pracucci pracucci enabled auto-merge (squash) November 17, 2022 07:11
@pracucci pracucci merged commit 5d46a1a into grafana:main Nov 17, 2022
manohar-koukuntla pushed a commit to manohar-koukuntla/mimir that referenced this pull request Nov 17, 2022
* Add validation for newS3Config (grafana#3410)

* endpoint has prefixed with bucket name

Signed-off-by: u5surf <u5.horie@gmail.com>

* Update pkg/storage/bucket/s3/config.go

Signed-off-by: u5surf <u5.horie@gmail.com>
Co-authored-by: Marco Pracucci <marco@pracucci.com>
masonmei pushed a commit to udmire/mimir that referenced this pull request Dec 16, 2022
* Add validation for newS3Config (grafana#3410)

* endpoint has prefixed with bucket name

Signed-off-by: u5surf <u5.horie@gmail.com>

* Update pkg/storage/bucket/s3/config.go

Signed-off-by: u5surf <u5.horie@gmail.com>
Co-authored-by: Marco Pracucci <marco@pracucci.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bucket validation passes when S3 host starts with bucket name
4 participants