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

strip proxy credentials from proxy env variables when logging them #13751

Merged
merged 2 commits into from
May 11, 2017

Conversation

bparees
Copy link
Contributor

@bparees bparees commented Apr 13, 2017

@bparees
Copy link
Contributor Author

bparees commented Apr 13, 2017

[test]

@bparees
Copy link
Contributor Author

bparees commented Apr 13, 2017

[testextended][extended:core(builds)]

@bparees
Copy link
Contributor Author

bparees commented Apr 13, 2017

@openshift/devex ptal

newEnv := make([]string, len(env))
copy(newEnv, env)
for i, val := range newEnv {
newEnv[i] = re.ReplaceAllString(val, "$1$2")
Copy link
Member

Choose a reason for hiding this comment

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

Would it be better, and possibly more consistent to use the net/url package to parse the url and pick out the parts that you want to use? https://golang.org/pkg/net/url/

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah, that would be better. i'll redo the s2i change and update this pull.

@bparees bparees changed the title strip proxy credentials from proxy env variables when logging them DO_NOT_MERGE] strip proxy credentials from proxy env variables when logging them Apr 13, 2017
@bparees bparees changed the title DO_NOT_MERGE] strip proxy credentials from proxy env variables when logging them [DO_NOT_MERGE] strip proxy credentials from proxy env variables when logging them Apr 13, 2017
@bparees
Copy link
Contributor Author

bparees commented Apr 13, 2017

turns out we log this information inadvertently in a lot of different places. working on it.

@bparees bparees force-pushed the clear_proxy branch 10 times, most recently from f7e82d4 to 183f9c0 Compare April 19, 2017 23:17
@bparees bparees changed the title [DO_NOT_MERGE] strip proxy credentials from proxy env variables when logging them strip proxy credentials from proxy env variables when logging them Apr 19, 2017
@bparees
Copy link
Contributor Author

bparees commented Apr 20, 2017

flake #13829
flake #9999
flake #13067

[test]

@bparees
Copy link
Contributor Author

bparees commented Apr 20, 2017

flake #13814
[test]

@bparees
Copy link
Contributor Author

bparees commented Apr 20, 2017

@openshift/devex ptal

@bparees
Copy link
Contributor Author

bparees commented Apr 20, 2017

flake #13067
[test]

@bparees
Copy link
Contributor Author

bparees commented Apr 20, 2017

flake #13067

[test]

@bparees
Copy link
Contributor Author

bparees commented Apr 24, 2017

[test]

@openshift-bot openshift-bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Apr 24, 2017
@jim-minter
Copy link
Contributor

as half-discussed on IRC, my recommendations would be:

  1. replace user:password@host with <redacted>@host rather than just blanking out
  2. to minimise boilerplate at each code site, and maximise chances of people doing the right thing in future, for every type that needs to be redacted, e.g. proxy string, net.URL, api.Build, string containing serialised api.Build, etc., I'd recommend having a centralised dedicated pure function which returns a redacted copy of its input, such that at the call site it's just necessary to do (for example) glog.V(4).Infof("my build %#v", SafeForLoggingBuild(build)). Ideally it would be nice to implement the Stringer and/or GoStringer interface, because then no change at the call site would be necessary at all, but perhaps that might be pushing it.

@openshift-bot openshift-bot added needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. and removed needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. labels May 6, 2017
@bparees bparees force-pushed the clear_proxy branch 2 times, most recently from 81c42b8 to 41bb56e Compare May 8, 2017 21:26
@openshift-bot openshift-bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label May 8, 2017
@bparees bparees force-pushed the clear_proxy branch 2 times, most recently from 0636040 to 3c9db32 Compare May 10, 2017 04:19
@bparees
Copy link
Contributor Author

bparees commented May 10, 2017

@jim-minter ptal.

@bparees
Copy link
Contributor Author

bparees commented May 10, 2017

flake #14122
[test]

if err != nil {
return nil, fmt.Errorf("unable to serialize build: %v", err)
}
glog.V(4).Infof("redacted build: %v", string(bytes))
Copy link
Contributor

Choose a reason for hiding this comment

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

Am I right in thinking the reason you're doing this is that you want to log the (redacted) nested detail beyond what printf/%#v provides on cfg.build?
If so, it makes sense; it's just a shame that %#v doesn't go far enough, because it would be simpler.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah, the problem is printf %#v doesn't dereference nested pointers. I also tried using spew instead, but it also didn't work for me so i punted and did this. The nice part about doing it this way is the behavior should be exactly the same as it was before in terms of the format of the output.

copy(newEnv, env)
proxyRegex := regexp.MustCompile("(?i).*proxy.*")
for i, env := range newEnv {
if proxyRegex.MatchString(env.Name) {
Copy link
Contributor

Choose a reason for hiding this comment

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

(fwiw, or strings.Contains(strings.ToLower(env.Name), "proxy") - throughout patch)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fair, but this implementation will be easier to extend in the future if we decide there are other keys we want to redact (just expand the regex), so i'd rather not change it at this point.

@@ -84,3 +90,219 @@ func TestTrustedMergeEnvWithoutDuplicates(t *testing.T) {
}

}

var credsRegex = regexp.MustCompile(".*user:password.*")
var redactedRegex = regexp.MustCompile(".*redacted*")
Copy link
Contributor

Choose a reason for hiding this comment

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

missing '.' - should be (".*redacted.*"), or better strings.Contains(s, "redacted") throughout - leading and trailing .* are superfluous.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

will remove .*s

@jim-minter
Copy link
Contributor

bar the nit of the '.' in the regex, lgtm

@bparees
Copy link
Contributor Author

bparees commented May 10, 2017

.*s cleaned up.

@openshift-bot
Copy link
Contributor

Evaluated for origin testextended up to fb9a4bd

@jim-minter
Copy link
Contributor

lgtm

@openshift-bot
Copy link
Contributor

continuous-integration/openshift-jenkins/testextended SUCCESS (https://ci.openshift.redhat.com/jenkins/job/test_pull_request_origin_extended/363/) (Base Commit: 31caa0d) (Extended Tests: core(builds))

@bparees
Copy link
Contributor Author

bparees commented May 10, 2017

flake #14128
flake #14129
[test]

@openshift-bot
Copy link
Contributor

Evaluated for origin test up to fb9a4bd

@openshift-bot
Copy link
Contributor

continuous-integration/openshift-jenkins/test SUCCESS (https://ci.openshift.redhat.com/jenkins/job/test_pull_request_origin/1316/) (Base Commit: f714687)

@bparees
Copy link
Contributor Author

bparees commented May 10, 2017

[merge]

@openshift-bot
Copy link
Contributor

Evaluated for origin merge up to fb9a4bd

@openshift-bot
Copy link
Contributor

openshift-bot commented May 11, 2017

continuous-integration/openshift-jenkins/merge SUCCESS (https://ci.openshift.redhat.com/jenkins/job/merge_pull_request_origin/604/) (Base Commit: 5b5f19b) (Image: devenv-rhel7_6225)

@openshift-bot openshift-bot merged commit 2628c77 into openshift:master May 11, 2017
@bparees bparees deleted the clear_proxy branch May 18, 2017 20: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.

6 participants