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

Fix BuildConfig Environment Variable Modification #19532

Conversation

adambkaplan
Copy link
Contributor

@adambkaplan adambkaplan commented Apr 26, 2018

  1. Ensure build config environment vars are not modified when they are safely logged.
  2. Only redact a URL if it contains a password

Fixes bug BZ-1571349

@openshift-ci-robot openshift-ci-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Apr 26, 2018
@adambkaplan
Copy link
Contributor Author

/assign @bparees

@@ -163,8 +164,7 @@ func TestSafeForLoggingS2IConfig(t *testing.T) {
if redactedRegex.MatchString(config.ScriptDownloadProxyConfig.HTTPSProxy.String()) {
t.Errorf("credentials stripped from original scripts proxy: %v", config.ScriptDownloadProxyConfig.HTTPSProxy)
}
//checkEnvList(t, config.Environment, true)

checkEnvList(t, config.Environment, true)
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 also make sure none of the other proxy fields changed in the original, e.g. ScriptDownloadProxyConfig.HTTPProxy, etc.

}
if redactedRegex.MatchString(*proxyBuild.Spec.Source.Git.HTTPSProxy) {
t.Errorf("improperly redacted credentials in https proxy value: %s", *stripped.Spec.Source.Git.HTTPSProxy)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

ah i see you're covering that here

newUrl := *u
newUrl.User = url.User("redacted")
return &newUrl
newURL := *u
Copy link
Contributor

Choose a reason for hiding this comment

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

Even though you added a deepcopy higher in the stack, there's no guarantee every caller to SafeForLoggingURL is coming in via that path (in fact I don't think they all are, see: SafeForLoggingS2IConfig for example)

So I think it's still important to deepcopy the url arg here, we shouldn't be mutating the input to the function.

@openshift-ci-robot openshift-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Apr 27, 2018
newUrl := *u
newUrl.User = url.User("redacted")
return &newUrl
newURL, err := url.Parse(u.String())
Copy link
Contributor Author

Choose a reason for hiding this comment

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

url doesn't support DeepCopy(), so I re-parsed the string instead.

Copy link
Contributor

Choose a reason for hiding this comment

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

that seems fine

@adambkaplan adambkaplan force-pushed the bugfix/logging-modified-url branch 2 times, most recently from 9cfa978 to 6f37562 Compare April 27, 2018 14:47
@bparees
Copy link
Contributor

bparees commented Apr 27, 2018

please add an explicit unit test for SafeForLoggingURL to prove it can update urls and isn't mutating the input arg. (I know the higher level tests basically cover this, but i'd feel better having a direct unit test for it)

func TestSafeForLoggingURL(t *testing.T) {
cases := []string{
"https://user:password@hostname.com",
"https://www.redhat.com",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Explicit unit test for SafeForLoggingURL - other cases to add?

Copy link
Contributor

Choose a reason for hiding this comment

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

user w/ no password?

Copy link
Contributor

Choose a reason for hiding this comment

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

(sorry if these were here before and i missed them)

@adambkaplan
Copy link
Contributor Author

/retest

@adambkaplan
Copy link
Contributor Author

@bparees done & tests passing

@@ -188,7 +189,7 @@ func checkEnvList(t *testing.T, envs s2iapi.EnvironmentList, orig bool) {
if credsRegex.MatchString(env.Value) {
t.Errorf("credentials not stripped from env value %v", env)
}
if !redactedRegex.MatchString(env.Value) {
if isURL(env.Value) && urlStringHasPassword(env.Value) && !redactedRegex.MatchString(env.Value) {
Copy link
Contributor

Choose a reason for hiding this comment

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

isn't urlStringHasPassword always going to be false if the redaction worked, so the redactedRegex check will never happen?

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 catch. The redacted regex won't run in this case, but we are assured that the url string doesn't contain a password (may have a username)

Copy link
Contributor

Choose a reason for hiding this comment

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

just removing the redactedRegex check is probably fine. I dno't want to leave it there to potentially confuse someone in the future though.

or you can go for bonus points and fix the logic to actually invoke that check.

@bparees
Copy link
Contributor

bparees commented Apr 27, 2018

one last question

@bparees
Copy link
Contributor

bparees commented Apr 27, 2018

and go ahead and squash your commits

Copy link
Contributor Author

@adambkaplan adambkaplan left a comment

Choose a reason for hiding this comment

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

@bparees squashed & rebased. Please see my comment re: source-to-image.

if reflect.DeepEqual(url, outURL) {
t.Errorf("url %v was not properly redacted", outURL)
}
if !redactedRegex.MatchString(outURL.String()) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved explicit check for "redacted" string here.

@@ -238,17 +239,23 @@ func SafeForLoggingURL(u *url.URL) *url.URL {
if u == nil {
return nil
}
newUrl := *u
newUrl.User = url.User("redacted")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

source-to-image has a similar SafeForLoggingURL method, which parses an input string and always adds the "redacted" user (even if there is no user info on the URL). Worth adding this logic to s2i as well?

Copy link
Contributor

Choose a reason for hiding this comment

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

the logic that only manipulates the value if a password is set? I suppose, not critical, vendoring the change definitely doesn't need to be part of this PR.

@bparees
Copy link
Contributor

bparees commented Apr 30, 2018

/lgtm

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Apr 30, 2018
@bparees
Copy link
Contributor

bparees commented Apr 30, 2018

/approve

@openshift-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: adambkaplan, bparees

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci-robot openshift-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Apr 30, 2018
@adambkaplan
Copy link
Contributor Author

/retest

@adambkaplan
Copy link
Contributor Author

Encountered flakes:
#19058
#17731

@adambkaplan
Copy link
Contributor Author

/retest

@adambkaplan
Copy link
Contributor Author

/retest

New test flakes:
#19588
#19589

@adambkaplan
Copy link
Contributor Author

/retest because of known HAProxy flake

@adambkaplan adambkaplan force-pushed the bugfix/logging-modified-url branch from a8f4226 to 51b3047 Compare May 3, 2018 00:50
@openshift-ci-robot openshift-ci-robot removed the lgtm Indicates that a PR is ready to be merged. label May 3, 2018
@adambkaplan
Copy link
Contributor Author

/retest

@adambkaplan
Copy link
Contributor Author

@bparees needs lgtm - I rebased to bring in @gabemontero fix with test runs.

@bparees
Copy link
Contributor

bparees commented May 3, 2018

@adambkaplan fyi you shouldn't need to rebase for that, your PR is always merged/rebased on top of master before being tested.

/lgtm

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label May 3, 2018
@adambkaplan
Copy link
Contributor Author

/retest

@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

@adambkaplan
Copy link
Contributor Author

/retest
New flake downloading ruby gems during build process

@openshift-merge-robot openshift-merge-robot merged commit 601e070 into openshift:master May 4, 2018
@adambkaplan adambkaplan deleted the bugfix/logging-modified-url branch May 4, 2018 12:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants