Skip to content

OCPBUGS-57334: Redact bearertoken in TestContext #29912

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions pkg/cmd/openshift-tests/run-test/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package run_test

import (
"fmt"
"github.com/openshift/origin/pkg/defaultmonitortests"
"os"
"strings"

"github.com/openshift/origin/pkg/defaultmonitortests"

"github.com/openshift/origin/pkg/clioptions/clusterdiscovery"
"github.com/openshift/origin/pkg/clioptions/imagesetup"
"github.com/openshift/origin/pkg/clioptions/upgradeoptions"
Expand Down Expand Up @@ -54,7 +55,10 @@ func NewRunTestCommand(streams genericclioptions.IOStreams) *cobra.Command {
if err := clusterdiscovery.InitializeTestFramework(exutil.TestContext, config, testOpt.DryRun); err != nil {
return err
}
klog.V(4).Infof("Loaded test configuration: %#v", exutil.TestContext)
// Redact the bearer token exposure
testContextString := fmt.Sprintf("%#v", exutil.TestContext)
redactedTestContext := exutil.RedactBearerToken(testContextString)
klog.V(4).Infof("Loaded test configuration: %s", redactedTestContext)

exutil.TestContext.ReportDir = os.Getenv("TEST_JUNIT_DIR")

Expand Down
5 changes: 4 additions & 1 deletion pkg/cmd/openshift-tests/run-upgrade/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,10 @@ func (o *RunUpgradeSuiteOptions) UpgradeTestPreSuite() error {
if err := clusterdiscovery.InitializeTestFramework(exutil.TestContext, config, o.GinkgoRunSuiteOptions.DryRun); err != nil {
return err
}
klog.V(4).Infof("Loaded test configuration: %#v", exutil.TestContext)
// Redact the bearer token exposure
testContextString := fmt.Sprintf("%#v", exutil.TestContext)
redactedTestContext := exutil.RedactBearerToken(testContextString)
klog.V(4).Infof("Loaded test configuration: %s", redactedTestContext)

return nil
}
Expand Down
4 changes: 3 additions & 1 deletion test/extended/util/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -965,9 +965,11 @@ func (c *CLI) start(stdOutBuff, stdErrBuff *bytes.Buffer) (*exec.Cmd, error) {

func RedactBearerToken(args string) string {
if strings.Contains(args, "Authorization: Bearer") {
// redact bearer token
re := regexp.MustCompile(`Authorization:\s+Bearer.*\s+`)
args = re.ReplaceAllString(args, "Authorization: Bearer <redacted> ")
} else if strings.Contains(args, "BearerToken") {
re := regexp.MustCompile(`BearerToken:\"[^\"]+\"`)
args = re.ReplaceAllString(args, "BearerToken: <redacted> ")
}
return args
}
Expand Down