-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Mask password discovered via module autodiscover hint #15616
Merged
ycombinator
merged 16 commits into
elastic:master
from
ycombinator:mb-ad-hints-passwd-mask
Jan 17, 2020
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
883dbbd
Mask password is string representation of config
ycombinator c44b87b
Rename method
ycombinator 227d69b
Adding unit test
ycombinator 86d4a21
Use const for module config password setting name
ycombinator 83543e9
Using common.DebugString
ycombinator 96da7dc
Simplifying
ycombinator b3900ed
Removing now-invalid unit test
ycombinator 2105597
Removing now-unnecessary const
ycombinator f115372
Refactoring: moving debug-related var and func to common file
ycombinator 790578b
Refactoring: rename from black list to mask list
ycombinator 184b64f
Implement fmt.Formatter for common.MapStr
ycombinator e485617
Reintroduce debug statement
ycombinator 3501706
Make MarshalLogObject always filter MapStr object for logging purposes
ycombinator fbd3122
Refactoring: renaming to be bit more generic
ycombinator 68667f0
Forgot to add license header to new file
ycombinator 5e8b53a
Fixing verb syntax
ycombinator File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// Licensed to Elasticsearch B.V. under one or more contributor | ||
// license agreements. See the NOTICE file distributed with | ||
// this work for additional information regarding copyright | ||
// ownership. Elasticsearch B.V. licenses this file to you under | ||
// the Apache License, Version 2.0 (the "License"); you may | ||
// not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
package common | ||
|
||
var maskList = MakeStringSet( | ||
"password", | ||
"passphrase", | ||
"key_passphrase", | ||
"pass", | ||
"proxy_url", | ||
"url", | ||
"urls", | ||
"host", | ||
"hosts", | ||
) | ||
|
||
func applyLoggingMask(c interface{}) { | ||
switch cfg := c.(type) { | ||
case map[string]interface{}: | ||
for k, v := range cfg { | ||
if maskList.Has(k) { | ||
if arr, ok := v.([]interface{}); ok { | ||
for i := range arr { | ||
arr[i] = "xxxxx" | ||
} | ||
} else { | ||
cfg[k] = "xxxxx" | ||
} | ||
} else { | ||
applyLoggingMask(v) | ||
} | ||
} | ||
|
||
case []interface{}: | ||
for _, elem := range cfg { | ||
applyLoggingMask(elem) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, it's a pitty to loose this debug string. The object is created dynamically. If something goes wrong in
NewConfigFrom
one needs this debug output in order to tell what the input was.MapStr has a few serialization methods: String, StringToPrint, and MarshalLogObject (used by zap loggers in case MapStr is passed directly). I wonder if we should: a) always apply the blacklist in these methods (there might be other places we write this debug string), or b) provide a special function/mapping serializing MapStr to a string.
We can also add a 'mixture' of a) and b) by implementing a
fmt.Formatter
. E.g. if%v
or%s
is given we apply the blacklist. But if the+
or#
flag is passed we do not apply the blacklist. ForMarshalLogObject
I would always prefer to apply the blacklist, as this is part of the logger.@ycombinator @exekias WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this option the best.