-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
98251: sql: add schema.sql and stats.sql back to redacted statement bundles r=msirek,rharding6373 a=michae2 **sql: add create_redactable column to crdb_internal.create_statements** Add a new `create_redactable` column to the `crdb_internal.create_statements` virtual table which provides the `CREATE` statement for the table or view with all constants and literals surrounded by redaction markers. Combined with the `crdb_internal.redact` function this can be used to obtain a redacted `CREATE` statement for any table. Part of: #68570 Epic: CRDB-19756 Release note: None **sql: add WITH REDACT option to SHOW CREATE** Add a new `WITH REDACT` option to `SHOW CREATE` statements which reads from `create_redactable` instead of `create_statement` when delegating `SHOW CREATE` to `crdb_internal.create_statements`. (The `WITH REDACT` syntax is intended to allow for additional options in the future (if we want them) such as `REDACTABLE`) Part of: #68570 Epic: CRDB-19756 Release note (sql change): Add a new `WITH REDACT` option to the following statements: - `SHOW CREATE` - `SHOW CREATE TABLE` - `SHOW CREATE VIEW` which, when used, replaces constants and literals in the printed `CREATE` statement with the redacted marker, '‹×›'. **sql: add schema.sql and stats.sql back to redacted statement bundles** Use `SHOW CREATE ... WITH REDACT` to generate `CREATE` statements for schema.sql in redacted statement diagnostics bundles. Also use statistics without histograms in redacted bundles. Part of: #68570 Epic: CRDB-19756 Release note: None 98290: sql: avoid panic by not applying AvoidBuffering to InternalExecutor r=rafiss a=stevendanna The InternalExecutor creates a streamingCommandResult, which does not support DisableBuffering. Here, we skip calling DisableBuffering() if the request is from an internal executor. Fixes: #98204 Release note (bug fix): Fixes a bug in which `SET avoid_buffering = true` could produce a crash on subsequent operations. 98800: sql: add name resolver to constraint validator for legacy schema changer r=chengxiong-ruan a=chengxiong-ruan Fixes #91697 Previously, in legacy schema changer, when adding a constraint with expression containing OID datum, it panics because we didn't give the validator a proper name resolver to resolve sequence names when deserializing constraint expressions. The funny logic of deserialization is that it tries to resolve anything that is a OID datum, even it's just a scalar in which case we could fail to find a sequence and we skip it well. Release note (sql change): this commit fixes a bug where check constraint on a OID type column panics in legacy schema changer. Co-authored-by: Michael Erickson <[email protected]> Co-authored-by: Steven Danna <[email protected]> Co-authored-by: Chengxiong Ruan <[email protected]>
- Loading branch information
Showing
46 changed files
with
1,066 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
show_create_stmt ::= | ||
'SHOW' 'CREATE' object_name | ||
'SHOW' 'CREATE' object_name opt_show_create_format_options | ||
| 'SHOW' 'CREATE' 'ALL' 'SCHEMAS' | ||
| 'SHOW' 'CREATE' 'ALL' 'TABLES' | ||
| 'SHOW' 'CREATE' 'ALL' 'TYPES' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
// Copyright 2023 The Cockroach Authors. | ||
// | ||
// Licensed as a CockroachDB Enterprise file under the Cockroach Community | ||
// License (the "License"); you may not use this file except in compliance with | ||
// the License. You may obtain a copy of the License at | ||
// | ||
// https://github.com/cockroachdb/cockroach/blob/master/licenses/CCL.txt | ||
|
||
package sqlccl | ||
|
||
import ( | ||
"context" | ||
"strconv" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/cockroachdb/cockroach/pkg/internal/sqlsmith" | ||
"github.com/cockroachdb/cockroach/pkg/sql/tests" | ||
"github.com/cockroachdb/cockroach/pkg/testutils/serverutils" | ||
"github.com/cockroachdb/cockroach/pkg/util/leaktest" | ||
"github.com/cockroachdb/cockroach/pkg/util/log" | ||
"github.com/cockroachdb/cockroach/pkg/util/randutil" | ||
"github.com/cockroachdb/errors" | ||
"github.com/cockroachdb/redact" | ||
) | ||
|
||
// TestShowCreateRedactableValues tests that ShowCreateTable and ShowCreateView | ||
// do not leak PII when called with RedactableValues set to true. | ||
func TestShowCreateRedactableValues(t *testing.T) { | ||
defer leaktest.AfterTest(t)() | ||
defer log.Scope(t).Close(t) | ||
|
||
ctx := context.Background() | ||
rng, seed := randutil.NewTestRand() | ||
t.Log("seed:", seed) | ||
|
||
params, _ := tests.CreateTestServerParams() | ||
s, sqlDB, _ := serverutils.StartServer(t, params) | ||
defer s.Stopper().Stop(ctx) | ||
defer sqlDB.Close() | ||
|
||
// To check for PII leaks, we inject a single unlikely string into some of the | ||
// query constants produced by SQLSmith, and then search the redacted SHOW | ||
// CREATE statement for this string. | ||
pii := "allosaurus" | ||
containsPII := func(create, createRedactable string) error { | ||
createRedacted := string(redact.RedactableString(createRedactable).Redact()) | ||
lowerCreateRedacted := strings.ToLower(createRedacted) | ||
if strings.Contains(lowerCreateRedacted, pii) { | ||
return errors.Newf( | ||
"SHOW CREATE output contained PII (%q):\noriginal:\n%s\nredactable:\n%s\nredacted:\n%s\n", | ||
pii, create, createRedactable, createRedacted, | ||
) | ||
} | ||
return nil | ||
} | ||
|
||
// Check all redactable SHOW CREATE statements at once by using | ||
// crdb_internal.create_statements. | ||
checkAllShowCreateRedactable := func() { | ||
rows, err := sqlDB.QueryContext( | ||
ctx, "SELECT create_statement, create_redactable FROM crdb_internal.create_statements", | ||
) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
for rows.Next() { | ||
var create, createRedactable string | ||
if err := rows.Scan(&create, &createRedactable); err != nil { | ||
t.Fatal(err) | ||
} | ||
if err := containsPII(create, createRedactable); err != nil { | ||
t.Error(err) | ||
continue | ||
} | ||
} | ||
} | ||
|
||
// Perform a few random initial CREATE TABLEs and check for PII leaks. | ||
setup := sqlsmith.RandTablesPrefixStringConsts(rng, pii) | ||
setup = append(setup, "SET statement_timeout = '5s';") | ||
for _, stmt := range setup { | ||
t.Log(stmt) | ||
if _, err := sqlDB.ExecContext(ctx, stmt); err != nil { | ||
// Ignore errors. | ||
t.Log("-- ignoring error:", err) | ||
continue | ||
} | ||
} | ||
checkAllShowCreateRedactable() | ||
|
||
// Perform a few random ALTERs (and additional CREATE TABLEs) and check for | ||
// PII leaks. | ||
alterSmith, err := sqlsmith.NewSmither(sqlDB, rng, | ||
sqlsmith.PrefixStringConsts(pii), | ||
sqlsmith.DisableEverything(), | ||
sqlsmith.EnableAlters(), | ||
) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
defer alterSmith.Close() | ||
for i := 0; i < 5; i++ { | ||
alter := alterSmith.Generate() | ||
t.Log(alter) | ||
if _, err := sqlDB.ExecContext(ctx, alter); err != nil { | ||
// Ignore errors. | ||
t.Log("-- ignoring error:", err) | ||
continue | ||
} | ||
} | ||
checkAllShowCreateRedactable() | ||
|
||
// Perform a few random CREATE VIEWs and check for PII leaks. | ||
smith, err := sqlsmith.NewSmither(sqlDB, rng, | ||
sqlsmith.PrefixStringConsts(pii), | ||
sqlsmith.DisableMutations(), | ||
sqlsmith.DisableWith(), | ||
) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
defer smith.Close() | ||
for i := 0; i < 5; i++ { | ||
view := "CREATE VIEW v" + strconv.Itoa(i) + " AS " + smith.Generate() | ||
t.Log(view) | ||
if _, err := sqlDB.ExecContext(ctx, view); err != nil { | ||
// Ignore errors. | ||
t.Log("-- ignoring error:", err) | ||
continue | ||
} | ||
} | ||
checkAllShowCreateRedactable() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.