Skip to content

Commit 96bc36e

Browse files
craig[bot]kyle-a-wong
andcommitted
Merge #150364
150364: sql, settings, cli: Add sensitive, reportable columns to cluster_settings and update debug zip setting redaction logic r=kyle-a-wong a=kyle-a-wong commit 1/2: sql,settings: add sensitive, reportable to cluster_settings VTable updates the crdb_internal.cluster_settings VTable to include 2 new columns: sensitive and reportable. These two new columns expose the isSensitive and isReportable attributes from settings objects. Epic: None Release note: None --- commit 2/2: cli: updates redaction policy for cluster settings in debug zip Previously, debug zip always exposed all settings values for unredacted debug zips, and redacted all string setting types for redacted debug zips. Now, "sensitive" cluster settings will always be redacted in debug zip, and "sensitive" and "non-reportable" cluster settings will be redacted for redacted debug zips. Release note (cli change): debug zips will now always redact "sensitive" cluster settings, whether or not a redacted debug zip is requested. For redacted debug zips, both "sensitive" and "non-reportable" cluster settings are redacted. This replaces the old logic where string-type cluster settings were always redacted for redacted debug-zips. Co-authored-by: Kyle Wong <[email protected]>
2 parents 02f8de2 + 5e6492a commit 96bc36e

File tree

11 files changed

+84
-31
lines changed

11 files changed

+84
-31
lines changed

pkg/ccl/logictestccl/testdata/logic_test/crdb_internal_tenant

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,10 @@ SELECT * FROM crdb_internal.session_trace WHERE span_idx < 0
127127
----
128128
span_idx message_idx timestamp duration operation loc tag message age
129129

130-
query TTTBTTTT colnames
130+
query TTTBBBTTTT colnames
131131
SELECT * FROM crdb_internal.cluster_settings WHERE variable = ''
132132
----
133-
variable value type public description default_value origin key
133+
variable value type public sensitive reportable description default_value origin key
134134

135135
query TI colnames
136136
SELECT * FROM crdb_internal.feature_usage WHERE feature_name = ''

pkg/cli/zip_table_registry.go

Lines changed: 44 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -222,11 +222,31 @@ var zipInternalTablesPerCluster = DebugZipTableRegistry{
222222
},
223223
},
224224
"crdb_internal.cluster_settings": {
225+
customQueryUnredacted: `SELECT
226+
variable,
227+
CASE
228+
WHEN sensitive THEN '<redacted>'
229+
ELSE value
230+
END value,
231+
type,
232+
public,
233+
sensitive,
234+
reportable,
235+
description,
236+
default_value,
237+
origin
238+
FROM crdb_internal.cluster_settings`,
225239
customQueryRedacted: `SELECT
226240
variable,
227-
CASE WHEN type = 's' AND value != default_value THEN '<redacted>' ELSE value END value,
241+
CASE
242+
WHEN NOT reportable AND value != default_value THEN '<redacted>'
243+
WHEN sensitive THEN '<redacted>'
244+
ELSE value
245+
END value,
228246
type,
229247
public,
248+
sensitive,
249+
reportable,
230250
description,
231251
default_value,
232252
origin
@@ -1384,18 +1404,29 @@ var zipSystemTables = DebugZipTableRegistry{
13841404
},
13851405
},
13861406
"system.settings": {
1387-
customQueryUnredacted: `SELECT * FROM system.settings`,
1388-
customQueryRedacted: `SELECT * FROM (
1389-
SELECT *
1390-
FROM system.settings
1391-
WHERE "valueType" <> 's'
1392-
) UNION (
1393-
SELECT name, '<redacted>' as value,
1394-
"lastUpdated",
1395-
"valueType"
1396-
FROM system.settings
1397-
WHERE "valueType" = 's'
1398-
)`,
1407+
customQueryUnredacted: `
1408+
SELECT
1409+
name,
1410+
CASE
1411+
WHEN cs.sensitive THEN '<redacted>'
1412+
ELSE s.value
1413+
END value,
1414+
s."lastUpdated",
1415+
s."valueType"
1416+
FROM system.settings s
1417+
JOIN crdb_internal.cluster_settings cs ON cs.variable = s.name`,
1418+
customQueryRedacted: `
1419+
SELECT
1420+
name,
1421+
CASE
1422+
WHEN cs.sensitive THEN '<redacted>'
1423+
WHEN NOT cs.reportable THEN '<redacted>'
1424+
ELSE s.value
1425+
END value,
1426+
s."lastUpdated",
1427+
s."valueType"
1428+
FROM system.settings s
1429+
JOIN crdb_internal.cluster_settings cs ON cs.variable = s.name`,
13991430
},
14001431
"system.span_configurations": {
14011432
nonSensitiveCols: NonSensitiveColumns{

pkg/settings/common.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,15 @@ func (c common) Visibility() Visibility {
6767
return c.visibility
6868
}
6969

70-
func (c common) isReportable() bool {
70+
func (c common) IsReportable() bool {
7171
return !c.nonReportable
7272
}
7373

7474
func (c *common) isRetired() bool {
7575
return c.retired
7676
}
7777

78-
func (c *common) isSensitive() bool {
78+
func (c *common) IsSensitive() bool {
7979
return c.sensitive
8080
}
8181

@@ -150,17 +150,17 @@ type internalSetting interface {
150150

151151
init(class Class, key InternalKey, description string, slot slotIdx)
152152
isRetired() bool
153-
isSensitive() bool
153+
IsSensitive() bool
154154
getSlot() slotIdx
155155

156-
// isReportable indicates whether the value of the setting can be
156+
// IsReportable indicates whether the value of the setting can be
157157
// included in user-facing reports such as that produced by SHOW ALL
158158
// CLUSTER SETTINGS.
159159
// This only affects reports though; direct access is unconstrained.
160160
// For example, `enterprise.license` is non-reportable:
161161
// it cannot be listed, but can be accessed with `SHOW CLUSTER
162162
// SETTING enterprise.license` or SET CLUSTER SETTING.
163-
isReportable() bool
163+
IsReportable() bool
164164

165165
setToDefault(ctx context.Context, sv *Values)
166166

@@ -179,15 +179,15 @@ func TestingIsReportable(s Setting) bool {
179179
return false
180180
}
181181
if e, ok := s.(internalSetting); ok {
182-
return e.isReportable()
182+
return e.IsReportable()
183183
}
184184
return true
185185
}
186186

187187
// TestingIsSensitive is used in testing for sensitivity.
188188
func TestingIsSensitive(s Setting) bool {
189189
if e, ok := s.(internalSetting); ok {
190-
return e.isSensitive()
190+
return e.IsSensitive()
191191
}
192192
return false
193193
}

pkg/settings/internal_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func TestSensitiveSetting(t *testing.T) {
4545
sv := &Values{}
4646
sv.Init(ctx, TestOpaque)
4747

48-
require.True(t, sensitiveSetting.isSensitive())
48+
require.True(t, sensitiveSetting.IsSensitive())
4949
u := NewUpdater(sv)
5050
require.NoError(t, u.Set(ctx, sensitiveSetting.InternalKey(), EncodedValue{Value: "foo", Type: "s"}))
5151

pkg/settings/masked.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func (s *MaskedSetting) String(sv *Values) string {
3535
}
3636
isSensitive := false
3737
if st, ok := s.setting.(internalSetting); ok {
38-
isSensitive = st.isSensitive()
38+
isSensitive = st.IsSensitive()
3939
}
4040
sensitiveRedactionEnabled := redactSensitiveSettingsEnabled.Get(sv)
4141
// Non-reportable settings are always redacted. Sensitive settings are
@@ -56,6 +56,16 @@ func (s *MaskedSetting) Visibility() Visibility {
5656
return s.setting.Visibility()
5757
}
5858

59+
// IsSensitive returns whether the underlying setting is sensitive.
60+
func (s *MaskedSetting) IsSensitive() bool {
61+
return s.setting.IsSensitive()
62+
}
63+
64+
// IsReportable returns whether the underlying setting is reportable.
65+
func (s *MaskedSetting) IsReportable() bool {
66+
return s.setting.IsReportable()
67+
}
68+
5969
// InternalKey returns the key string for the underlying setting.
6070
func (s *MaskedSetting) InternalKey() InternalKey {
6171
return s.setting.InternalKey()

pkg/settings/protobuf.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,10 @@ func (s *ProtobufSetting) Validate(sv *Values, p protoutil.Message) error {
109109
return s.validateFn(sv, p)
110110
}
111111

112+
func (s *ProtobufSetting) IsSensitive() bool {
113+
return s.sensitive
114+
}
115+
112116
// Override sets the setting to the given value, assuming it passes validation.
113117
func (s *ProtobufSetting) Override(ctx context.Context, sv *Values, p protoutil.Message) {
114118
sv.setValueOrigin(ctx, s.slot, OriginOverride)

pkg/settings/registry.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@ func LookupForReportingByKey(key InternalKey, forSystemTenant bool) (Setting, bo
494494
if !forSystemTenant && s.Class() == SystemOnly {
495495
return nil, false
496496
}
497-
if !s.isReportable() {
497+
if !s.IsReportable() {
498498
return &MaskedSetting{setting: s}, true
499499
}
500500
return s, true
@@ -531,7 +531,7 @@ func LookupForDisplayByKey(
531531
if !forSystemTenant && s.Class() == SystemOnly {
532532
return nil, false
533533
}
534-
if s.isSensitive() && !canViewSensitive {
534+
if s.IsSensitive() && !canViewSensitive {
535535
return &MaskedSetting{setting: s}, true
536536
}
537537
return s, true
@@ -565,7 +565,7 @@ var ReadableTypes = map[string]string{
565565
// - "<unknown>" if there is no setting with this name.
566566
func RedactedValue(key InternalKey, values *Values, forSystemTenant bool) string {
567567
if k, ok := registry[key]; ok {
568-
if k.Typ() == "s" || k.isSensitive() || !k.isReportable() {
568+
if k.Typ() == "s" || k.IsSensitive() || !k.IsReportable() {
569569
return "<redacted>"
570570
}
571571
}

pkg/settings/setting.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ type Setting interface {
7777
// retrieving all settings.
7878
Visibility() Visibility
7979

80+
IsSensitive() bool
81+
82+
IsReportable() bool
83+
8084
// IsUnsafe returns whether the setting is unsafe, and thus requires
8185
// a special interlock to set.
8286
IsUnsafe() bool

pkg/settings/settings_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -718,12 +718,12 @@ func TestIsReportable(t *testing.T) {
718718
if v, ok, _ := settings.LookupForLocalAccess(
719719
"bool.t", settings.ForSystemTenant,
720720
); !ok || !settings.TestingIsReportable(v) {
721-
t.Errorf("expected 'bool.t' to be marked as isReportable() = true")
721+
t.Errorf("expected 'bool.t' to be marked as IsReportable() = true")
722722
}
723723
if v, ok, _ := settings.LookupForLocalAccess(
724724
"sekretz", settings.ForSystemTenant,
725725
); !ok || settings.TestingIsReportable(v) {
726-
t.Errorf("expected 'sekretz' to be marked as isReportable() = false")
726+
t.Errorf("expected 'sekretz' to be marked as IsReportable() = false")
727727
}
728728
}
729729

pkg/sql/crdb_internal.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2025,6 +2025,8 @@ CREATE TABLE crdb_internal.cluster_settings (
20252025
value STRING NOT NULL,
20262026
type STRING NOT NULL,
20272027
public BOOL NOT NULL, -- whether the setting is documented, which implies the user can expect support.
2028+
sensitive BOOL NOT NULL, -- whether the setting is sensitive and should not be exposed to users without the appropriate privileges
2029+
reportable BOOL NOT NULL, -- whether the setting is reportable
20282030
description STRING NOT NULL,
20292031
default_value STRING NOT NULL,
20302032
origin STRING NOT NULL, -- the origin of the value: 'default' , 'override' or 'external-override'
@@ -2070,6 +2072,8 @@ CREATE TABLE crdb_internal.cluster_settings (
20702072
tree.NewDString(strVal),
20712073
tree.NewDString(setting.Typ()),
20722074
tree.MakeDBool(tree.DBool(isPublic)),
2075+
tree.MakeDBool(tree.DBool(setting.IsSensitive())),
2076+
tree.MakeDBool(tree.DBool(setting.IsReportable())),
20732077
tree.NewDString(desc),
20742078
tree.NewDString(defaultVal),
20752079
tree.NewDString(origin),

0 commit comments

Comments
 (0)