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

Redacting password while logging connection params in import data to target #2097

Merged
merged 3 commits into from
Dec 17, 2024
Merged
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
4 changes: 3 additions & 1 deletion yb-voyager/src/tgtdb/yugabytedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,9 @@ func (yb *TargetYugabyteDB) InitConnPool() error {
SessionInitScript: getYBSessionInitScript(yb.tconf),
}
yb.connPool = NewConnectionPool(params)
log.Info("Initialized connection pool with settings: ", spew.Sdump(params))
redactedParams := params
redactedParams.ConnUriList = utils.GetRedactedURLs(redactedParams.ConnUriList)
log.Info("Initialized connection pool with settings: ", spew.Sdump(redactedParams))
return nil
}

Expand Down
3 changes: 2 additions & 1 deletion yb-voyager/src/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,8 @@ func GetRedactedURLs(urlList []string) []string {
for _, u := range urlList {
obj, err := url.Parse(u)
if err != nil {
ErrExit("invalid URL: %q", u)
Copy link
Collaborator

Choose a reason for hiding this comment

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

previously we were printing u but can we now print err ?
can the error message also have the url in it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think yes, an error can include the URL in some cases, as I see url.Parse() is including the rawURL in the error msg.

func Parse(rawURL string) (*URL, error) {
	...
	if err = url.setFragment(frag); err != nil {
		return nil, &Error{"parse", rawURL, err}
	}

Copy link
Collaborator

Choose a reason for hiding this comment

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

ok, what we can do here is instead of using ErrExit() -> log + console
We print different messages for log vs console.
console can have error message(containing url)
log should have a generic msg like you added

log.Error("error redacting connection url: invalid connection URL")
fmt.Printf("error redacting connection url: invalid connection URL: %v", u)
}
result = append(result, obj.Redacted())
}
Expand Down