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 NodeNames, Address and Tags fields #612

Merged
merged 12 commits into from
Aug 24, 2020
Merged

Conversation

schristoff
Copy link
Contributor

@schristoff schristoff commented Aug 20, 2020

We've been seeing an issue where NodeNames will start to get very long and filled with junk.
Fields have been added to validate memberinfo in messages are within certain restrictions.

A configuration flag titled ValidateNodeNames has been added to give users the option of restricting nodename length.

The Address field in the memberinfo in messages must adhere to an IP:Port structure.
The Tags field in memberinfo in messages must adhere to the 512 max (which is placed elsewhere too)
ValidateNodeNames restricts NodeNames to alphanumeric and 128 characters.

Copy link
Contributor

@kyhavlov kyhavlov left a comment

Choose a reason for hiding this comment

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

I left some comments - looking good so far.

cmd/serf/command/agent/config.go Outdated Show resolved Hide resolved
cmd/serf/command/agent/config.go Outdated Show resolved Hide resolved
serf/config.go Outdated Show resolved Hide resolved
serf/merge_delegate.go Outdated Show resolved Hide resolved
serf/merge_delegate.go Outdated Show resolved Hide resolved
cmd/serf/command/agent/config.go Outdated Show resolved Hide resolved
serf/config.go Outdated Show resolved Hide resolved
serf/config.go Outdated Show resolved Hide resolved
serf/config.go Outdated Show resolved Hide resolved
@schristoff schristoff changed the title WIP: Verify NodeNames Verify NodeNames Aug 24, 2020
@schristoff schristoff changed the title Verify NodeNames Validate NodeNames, Address and Tags fields Aug 24, 2020
err = fmt.Errorf("NodeName is %v characters. "+
"Valid length is between 1 and 128 characters", len(result.NodeName))
return nil, err
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This logic for validating the name is getting repeated 3 times - we should pull it into a function for reuse. We can also avoid doing it in this serf/command/agent code at all and do it here instead: https://github.com/hashicorp/serf/blob/master/serf/serf.go#L235

serf.Create will get called on startup for Consul as well, where the code in this package is only used in the Serf binary.

serf/merge_delegate.go Outdated Show resolved Hide resolved
Copy link
Contributor

@kyhavlov kyhavlov left a comment

Choose a reason for hiding this comment

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

A few last small things and I think this is good to merge.

serf/serf_test.go Outdated Show resolved Hide resolved
@@ -363,7 +367,9 @@ func containsKey(keys []string, key string) bool {
func MergeConfig(a, b *Config) *Config {
var result Config = *a

// Copy the strings if they're set
//TODO(schristoff): do i need to check nodename
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we can remove this todo (since we're verifying the final config that gets passed to Create() anyway)

serf/serf.go Outdated
// then runs validations
func (s *Serf) ValidateNodeNames() error {
if s.config.ValidateNodeNames {
var InvalidNameRe = regexp.MustCompile(`[^A-Za-z0-9\-\.\\]+`)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the regexp should be [^A-Za-z0-9\-\.]+ - right now it's allowing \ characters

serf/serf.go Outdated
var InvalidNameRe = regexp.MustCompile(`[^A-Za-z0-9\-\.\\]+`)
if InvalidNameRe.MatchString(s.config.NodeName) {
return fmt.Errorf("NodeName contains invalid characters %v , Valid characters include "+
"all alpha-numerics and dashes.", s.config.NodeName)
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 specify alphanumerics, dashes and .s. Same with the comments for ValidateNodeNames above.

@schristoff schristoff merged commit d32913b into master Aug 24, 2020
@schristoff schristoff deleted the verify_nodenames branch August 24, 2020 21:13
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.

2 participants