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

changefeedccl: more redactions in changefeed job description #75174

Merged
merged 1 commit into from Jan 20, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 17 additions & 1 deletion pkg/ccl/changefeedccl/changefeed_stmt.go
Expand Up @@ -490,10 +490,18 @@ func changefeedPlanHook(
func changefeedJobDescription(
p sql.PlanHookState, changefeed *tree.CreateChangefeed, sinkURI string, opts map[string]string,
) (string, error) {
cleanedSinkURI, err := cloud.SanitizeExternalStorageURI(sinkURI, []string{changefeedbase.SinkParamSASLPassword})
cleanedSinkURI, err := cloud.SanitizeExternalStorageURI(sinkURI, []string{
changefeedbase.SinkParamSASLPassword,
changefeedbase.SinkParamCACert,
changefeedbase.SinkParamClientCert,
})

if err != nil {
return "", err
}

cleanedSinkURI = redactUser(cleanedSinkURI)

c := &tree.CreateChangefeed{
Targets: changefeed.Targets,
SinkURI: tree.NewDString(cleanedSinkURI),
Expand All @@ -513,6 +521,14 @@ func changefeedJobDescription(
return tree.AsStringWithFQNames(c, ann), nil
}

func redactUser(uri string) string {
u, _ := url.Parse(uri)
if u.User != nil {
u.User = url.User(`redacted`)
}
return u.String()
}

// validateNonNegativeDuration returns a nil error if optValue can be
// parsed as a duration and is non-negative; otherwise, an error is
// returned.
Expand Down
3 changes: 2 additions & 1 deletion pkg/ccl/changefeedccl/changefeed_test.go
Expand Up @@ -3381,7 +3381,8 @@ func TestChangefeedDescription(t *testing.T) {
sqlDB.QueryRow(t,
`SELECT description FROM [SHOW JOBS] WHERE job_id = $1`, jobID,
).Scan(&description)
expected := `CREATE CHANGEFEED FOR TABLE foo INTO '` + sink.String() +
redactedSink := strings.Replace(sink.String(), security.RootUser, `redacted`, 1)
expected := `CREATE CHANGEFEED FOR TABLE foo INTO '` + redactedSink +
`' WITH envelope = 'wrapped', updated`
require.Equal(t, expected, description)
}
Expand Down