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

release-23.1: settings: redact all string settings for diagnostics #134063

Merged
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
1 change: 1 addition & 0 deletions pkg/ccl/serverccl/diagnosticsccl/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ go_test(
args = ["-test.timeout=295s"],
deps = [
"//pkg/base",
"//pkg/ccl",
"//pkg/ccl/kvccl/kvtenantccl",
"//pkg/clusterversion",
"//pkg/config/zonepb",
Expand Down
2 changes: 2 additions & 0 deletions pkg/ccl/serverccl/diagnosticsccl/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"os"
"testing"

"github.com/cockroachdb/cockroach/pkg/ccl"
"github.com/cockroachdb/cockroach/pkg/ccl/kvccl/kvtenantccl"
"github.com/cockroachdb/cockroach/pkg/security/securityassets"
"github.com/cockroachdb/cockroach/pkg/security/securitytest"
Expand All @@ -20,5 +21,6 @@ func TestMain(m *testing.M) {
securityassets.SetLoader(securitytest.EmbeddedAssets)
serverutils.InitTestServerFactory(server.TestServerFactory)
kvtenantccl.InitConnectorFactory()
defer ccl.TestingEnableEnterprise()
os.Exit(m.Run())
}
16 changes: 15 additions & 1 deletion pkg/ccl/serverccl/diagnosticsccl/reporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,18 @@ func TestServerReport(t *testing.T) {
})
}

// We want to ensure that non-reportable settings, sensitive
// settings, and all string settings are redacted. Below we override
// one of each.
settingOverrides := []string{
`SET CLUSTER SETTING server.oidc_authentication.client_id = 'sensitive-client-id'`, // Non-reportable setting.
`SET CLUSTER SETTING changefeed.node_throttle_config = '{"message_rate": 0.5}'`, // String setting.
}
for _, s := range settingOverrides {
_, err := rt.serverDB.Exec(s)
require.NoError(t, err)
}

expectedUsageReports := 0

clusterSecret := sql.ClusterSecret.Get(&rt.settings.SV)
Expand Down Expand Up @@ -195,7 +207,7 @@ func TestServerReport(t *testing.T) {
// 3 + 3 = 6: set 3 initially and org is set mid-test for 3 altered settings,
// plus version, reporting and secret settings are set in startup
// migrations.
expected, actual := 6, len(last.AlteredSettings)
expected, actual := 6+len(settingOverrides), len(last.AlteredSettings)
require.Equal(t, expected, actual, "expected %d changed settings, got %d: %v", expected, actual, last.AlteredSettings)

for key, expected := range map[string]string{
Expand All @@ -204,6 +216,8 @@ func TestServerReport(t *testing.T) {
"server.time_until_store_dead": "1m30s",
"version": clusterversion.TestingBinaryVersion.String(),
"cluster.secret": "<redacted>",
"server.oidc_authentication.client_id": "<redacted>",
"changefeed.node_throttle_config": "<redacted>",
} {
got, ok := last.AlteredSettings[key]
require.True(t, ok, "expected report of altered setting %q", key)
Expand Down
10 changes: 7 additions & 3 deletions pkg/settings/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -350,11 +350,15 @@ var ReadableTypes = map[string]string{
}

// RedactedValue returns:
// - a string representation of the value, if the setting is reportable (or it
// is a string setting with an empty value);
// - "<redacted>" if the setting is not reportable;
// - a string representation of the value, if the setting is reportable;
// - "<redacted>" if the setting is not reportable, or a string;
// - "<unknown>" if there is no setting with this name.
func RedactedValue(name string, values *Values, forSystemTenant bool) string {
if k, ok := registry[name]; ok {
if k.Typ() == "s" || !k.isReportable() {
return "<redacted>"
}
}
if setting, ok := LookupForReporting(name, forSystemTenant); ok {
return setting.String(values)
}
Expand Down