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

Sanitize password from couchbase metric #1680 #3033

Merged
merged 4 commits into from
Jul 31, 2017

Conversation

dsalbert
Copy link
Contributor

@dsalbert dsalbert commented Jul 19, 2017

Fix issue #1680

  • In cluster tag, use information provided by CouchDB API instead of getting it from telegraf server configuration where user is able to provide credentials.
  • Adjust Unit Tests to new values.

Required for all PRs:

  • Signed CLA.
  • Associated README.md updated.
  • Has appropriate unit tests.

@danielnelson
Copy link
Contributor

I looked at the example output on https://developer.couchbase.com/documentation/server/3.x/admin/REST/rest-node-get-info.html, and it looks like couchApiBase contains the origin of the node, and not the cluster origin. These seems like it changes this field to be more like hostname, am I understanding correctly?

@dsalbert
Copy link
Contributor Author

dsalbert commented Jul 20, 2017

You are right, I was more about to replace address from server configuration section with something more secure, than provide a real cluster name. According to this document, there is a name value in root of JSON object. I do not see this key/value as something provided by package couchbase. Maybe, by creating a custom query we can obtain this value.

@danielnelson
Copy link
Contributor

What about rebuilding the cluster url from the servers option list without the userinfo section?

@danielnelson danielnelson changed the title fix issue #1680 Sanitize password from couchbase metric #1680 Jul 21, 2017
@dsalbert
Copy link
Contributor Author

Good idea. Just trim/cut string to remove those sensitive data. I'll work on it. Thanks!

Add simple sanitization method to cut from `servers` configuration variable information about username and password from URI.
This variable later is used as cluster tag.
@@ -22,7 +22,7 @@
### couchbase_node

Tags:
- cluster: whatever you called it in `servers` in the configuration, e.g.: `http://couchbase-0.example.com/`
- cluster: sanitized and scheme less string from `servers` configuration field e.g.: `http://user:password@couchbase-0.example.com:8091/endpoint` -> `couchbase-0.example.com:8091/endpoint`
Copy link
Contributor

Choose a reason for hiding this comment

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

Why remove the scheme?

Copy link
Contributor Author

@dsalbert dsalbert Jul 25, 2017

Choose a reason for hiding this comment

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

I think it is better to use scheme less name for displaying and creating dashboard. In other hand, it may cause problems in case when there will be 2+ elements in servers array that will be differ from each other only by used protocol (scheme). If you wish I can also add scheme into this string, just let me know.

Thanks!

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree about the concern on multiple servers differing by scheme only, but sympathize with respect to your style concerns. That said, we should keep the scheme if only to preserve backwards compatibility.

Copy link
Contributor

@danielnelson danielnelson left a comment

Choose a reason for hiding this comment

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

Sorry about the delay reviewing, just a few minor things:

// it also removes schema name from URI
func sanitizeURI(uri string) (result string, err error) {

re, err := regexp.Compile("(\\S+:\\/\\/)?(\\S+\\:\\S+@)")
Copy link
Contributor

Choose a reason for hiding this comment

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

Move to package scope and use MustCompile, this way it only will be compiled once. Personally I would use backtick strings so you don't need to double escape, also you don't need to escape / or :. This would leave you with

`(\S+://)?(\S+\:\S+@)`

This is a nitpick, but it would be nicer if there was less vertical whitespace in this function.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point. In this case I think I can simplify those whole thing by removing function (MustCompile is gonna panic anyway).

}

if len(sanitizedAddress) <= 1 {
log.Printf("I! WARNING: Cluster address tag \"'%s'\" is too short.", sanitizedAddress)
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure it's possible to hit this line, if it is can you add a testcase?

You can use "W!" to prefix the log message to indicate a warning.

Copy link
Contributor Author

@dsalbert dsalbert Jul 28, 2017

Choose a reason for hiding this comment

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

This line should be hit when server variable/record is empty, but you are right, it should be filtered by configuration parser.

@danielnelson danielnelson merged commit 5e95367 into influxdata:master Jul 31, 2017
maxunt pushed a commit that referenced this pull request Jun 26, 2018
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