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

Validate gateway arguments #4376

Merged
merged 4 commits into from
Jun 8, 2017

Conversation

krishnasrinivas
Copy link
Contributor

@krishnasrinivas krishnasrinivas commented May 19, 2017

Description

gateway endpoints validation.

Motivation and Context

fixes #4355

How Has This Been Tested?

manually

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@mention-bot
Copy link

@krishnasrinivas, thanks for your PR! By analyzing the history of the files in this pull request, we identified @balamurugana, @krisis and @donatello to be potential reviewers.

@balamurugana
Copy link
Member

Do you mean when myhostname is the same server as the gateway is being run but bound to different interface? I think it is OK not to allow it because code will be complicated to allow it to run, but more importantly allowing such a setup would be an erroneous setup as there is no reason for a user to run it that way and would mean that user is doing a mistake.

As I mentioned in the issue, it is test setup, not some user is going to use it that way. I am OK if such kind of test setup is not allowed.

@balamurugana
Copy link
Member

We'll allow endpoint to be localhost (so that it is easy for testing) but same port for both gateway and server is not allowed (fixed by anis)

minio gateway --address=localhost:9000 http://myhostname:9000 is allowed to work. Expected is it should not.

@krishnasrinivas
Copy link
Contributor Author

minio gateway --address=localhost:9000 http://myhostname:9000 is allowed to work. Expected is it should not.

why @balamurugana ? I am unable to see what I am missing.

@balamurugana
Copy link
Member

minio gateway --address=localhost:9000 http://myhostname:9000 is allowed to work. Expected is it should not.

why @balamurugana ? I am unable to see what I am missing.

the case is localhost and myhostname resolve to same local host but different IPs. This is not a valid case as per your comment in the description.

@krishnasrinivas
Copy link
Contributor Author

the case is localhost and myhostname resolve to same local host but different IPs. This is not a valid case as per your comment in the description.

But if myhostname resolves to localhost then anis' patch already takes care of not allowing the setup.

@balamurugana
Copy link
Member

But if myhostname resolves to localhost then anis' patch already takes care of not allowing the setup.

Looks like its doing, but no unit tests show that. That needs to be added. TestCreateEndpoints() uses a technique to find non-loop back IPs of local host.

@harshavardhana
Copy link
Member

Can you fix the commit message typo @krishnasrinivas

Copy link
Member

@vadmeste vadmeste left a comment

Choose a reason for hiding this comment

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

Tested (on linux)

@deekoder deekoder requested review from krisis and removed request for donatello May 20, 2017 17:59
Copy link
Member

@krisis krisis left a comment

Choose a reason for hiding this comment

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

  • Please fix the typo in title of the PR.
  • PR's description looks more like a comment. You could record it as a comment here. The description should describe the changes and how it fixes the issue.

if runtime.GOOS == "darwin" {
host, port := mustSplitHostPort(serverAddr)
// On macOS, if a process already listens on LOCALIPADDR:PORT, net.Listen() falls back
// to IPv6 address ie minio will start listening on IPv6 address whereas another
Copy link
Member

Choose a reason for hiding this comment

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

s/ie/i.e

// On macOS, if a process already listens on LOCALIPADDR:PORT, net.Listen() falls back
// to IPv6 address ie minio will start listening on IPv6 address whereas another
// (non-)minio process is listening on IPv4 of given port.
// To avoid this error sutiation we check for port availability only for macOS.
Copy link
Member

Choose a reason for hiding this comment

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

s/sutiation/situation

Copy link
Member

@balamurugana balamurugana left a comment

Choose a reason for hiding this comment

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

Needs to add unit test to address case
minio gateway --address=localhost:9000 http://mylocalhostname:9000 where localhost and mylocalhostname point different IPs of local hosts.

@krishnasrinivas krishnasrinivas changed the title Validate gateway argumetns Validate gateway arguments May 22, 2017
@krishnasrinivas
Copy link
Contributor Author

PR's description looks more like a comment. You could record it as a comment here. The description should describe the changes and how it fixes the issue.

Oops, I don't know how it ended up in the description. It was intended to be a comment in the issue.

@codecov-io
Copy link

codecov-io commented May 22, 2017

Codecov Report

Merging #4376 into master will increase coverage by 0.01%.
The diff coverage is 42.3%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #4376      +/-   ##
==========================================
+ Coverage   66.49%   66.51%   +0.01%     
==========================================
  Files         178      178              
  Lines       25470    25491      +21     
==========================================
+ Hits        16937    16956      +19     
+ Misses       7395     7394       -1     
- Partials     1138     1141       +3
Impacted Files Coverage Δ
cmd/gateway-main.go 15.62% <42.3%> (+4.51%) ⬆️
cmd/fs-v1-background-append.go 78.52% <0%> (-2.69%) ⬇️
cmd/update-notifier.go 81.66% <0%> (+19.99%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 18c4e5d...9d431b4. Read the comment docs.

@krishnasrinivas
Copy link
Contributor Author

@balamurugana @krisis please check now

Copy link
Member

@balamurugana balamurugana left a comment

Choose a reason for hiding this comment

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

Test cases need a fix.

{":9000", "http://localhost:9001", true},
{"123.123.123.123:9000", "http://localhost:9000", false},
{":9000", "http://localhost:9000", false},
{":9000", nonLoopBackIP + ":9000", false},
Copy link
Member

Choose a reason for hiding this comment

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

I would recommend to validate error messages than valid bool.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

we had a discussion here about this bala with @harshavardhana , the problem with doing string comparison is the code becomes brittle, i.e if we change the error message string the test case breaks. So I have kept it as "valid bool" for now. But we can have a discussion in one of the meetings so that we can consistently follow one method

endpointAddr string
valid bool
}{
{":9000", "http://localhost:9001", true},
Copy link
Member

Choose a reason for hiding this comment

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

you could add a case where endpointAddr is a remote host. you could use example.org domains.

testCases := []struct {
serverAddr string
endpointAddr string
valid bool
errMsg stringB
Copy link
Member

Choose a reason for hiding this comment

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

stringB is invalid, compilation issue here.

@@ -62,23 +62,24 @@ func TestValidateGatewayArguments(t *testing.T) {
}
nonLoopBackIP := nonLoopBackIPs.ToSlice()[0]

errMsg := "endpoint points to the local gateway"
Copy link
Member

Choose a reason for hiding this comment

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

You can re-purpose the message like errEndpointLoop ? which is returned by the actual function and you are just using errEndpointLoop.Error() to compare. Naked strings like this can invite issues like typo etc avoids changing at multiple places.

@krishnasrinivas
Copy link
Contributor Author

I would recommend to validate error messages than valid bool.

@balamurugana had a discussion here about this with @harshavardhana , the problem with doing string comparison is the code becomes brittle, i.e if we change the error message string the test case breaks. So I have kept it as "valid bool" for now. But we can have a discussion in one of the meetings so that we can consistently follow it everywhere in our code.

harshavardhana
harshavardhana previously approved these changes May 24, 2017
}
}
err := validateGatewayArguments(serverAddr, endpointAddr)
fatalIf(err, "Unable to validate")
Copy link
Member

Choose a reason for hiding this comment

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

"Unable to validate" is not correct. We did validate and found the arguments invalid. We could say something like "Invalid arguments: custom endpoint and gateway addresses are identical."

for i, test := range testCases {
err := validateGatewayArguments(test.serverAddr, test.endpointAddr)
if test.valid && err != nil {
t.Errorf("Test %d expected not to return erro but got %s", i+1, err)
Copy link
Member

Choose a reason for hiding this comment

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

typo: s/erro/error

@@ -179,6 +180,36 @@ func parseGatewayEndpoint(arg string) (endPoint string, secure bool, err error)
}
}

// Validate gateway arguments.
func validateGatewayArguments(serverAddr, endpointAddr string) error {
if err := CheckLocalServerAddr(serverAddr); err != nil {
Copy link
Member

Choose a reason for hiding this comment

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

@krisis can you take a look.. ?

Copy link
Member

Choose a reason for hiding this comment

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

@harshavardhana yes, this addresses the problem my PR fixes. You can close my PR in favour.

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.

gateway: endpoint and address command line arguments need to properly validated
8 participants