Skip to content

Commit 8595e35

Browse files
craig[bot]angles-n-daemons
andcommitted
Merge #158085
158085: sql: set the default to allow_unsafe_internals to false r=angles-n-daemons a=angles-n-daemons The system and crdb_internal namespaces have historically been open access for anyone who wants to use them. This has caused problems in the past, as many of the objects in these namespaces were developed for internal use only, and have been discovered and misused by operators, which have created difficult to recover from failures. To avoid this in the future, and provide better visibility into use of these objects, we'll begin gating access to them, requiring customers to manually override access to these records, and auditing visibly on their usage. This PR is the final step in this process, changing the default of this already existing gate, and merging a few utilities for testing and extenuating overrides. Fixes: #149595 Epic: CRDB-55276 Release note (ops change): All queries to system and crdb_internal by default will begin failing, notifying users that they must override the access gate if they wish to use those namespaces. Co-authored-by: Brian Dillmann <brian.dillmann@cockroachlabs.com>
2 parents 1c3e1bb + a29af3b commit 8595e35

File tree

19 files changed

+82
-29
lines changed

19 files changed

+82
-29
lines changed

.github/workflows/github-actions-essential-ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ jobs:
122122
with:
123123
path: examples-orms
124124
repository: cockroachdb/examples-orms
125-
ref: 876b2d52ae2b63aa9cc1741c8d189ff0b66ab0d7
125+
ref: 4422aff128585c3e0558b530558daa31972c3a40
126126
- name: compute metadata
127127
run: echo GITHUB_ACTIONS_BRANCH=${{ github.event.pull_request.number || github.ref_name}} >> "$GITHUB_ENV"
128128
- run: ./cockroach/build/github/get-engflow-keys.sh

pkg/acceptance/compose/flyway/docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ services:
55
image: us-east1-docker.pkg.dev/crl-docker-sync/docker-io/library/ubuntu:xenial-20210804
66
command: /cockroach/cockroach start-single-node --insecure --listen-addr cockroach
77
environment:
8-
- COCKROACH_ACCEPTANCE_ALLOW_UNSAFE=true
8+
- COCKROACH_OVERRIDE_ALLOW_UNSAFE_INTERNALS=true
99
volumes:
1010
- ${COCKROACH_BINARY:-../../../../cockroach-linux-2.6.32-gnu-amd64}:/cockroach/cockroach
1111
flyway:

pkg/acceptance/compose/gss/docker-compose-python.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ services:
1313
command: /cockroach/cockroach --certs-dir=/certs start-single-node --listen-addr cockroach
1414
environment:
1515
- KRB5_KTNAME=/keytab/crdb.keytab
16-
- COCKROACH_ACCEPTANCE_ALLOW_UNSAFE=true
16+
- COCKROACH_OVERRIDE_ALLOW_UNSAFE_INTERNALS=true
1717
volumes:
1818
- ${CERTS_DIR:-../../.localcluster.certs}:/certs
1919
- keytab:/keytab

pkg/acceptance/compose/gss/docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ services:
1414
command: /cockroach/cockroach --certs-dir=/certs start-single-node --listen-addr cockroach
1515
environment:
1616
- KRB5_KTNAME=/keytab/crdb.keytab
17-
- COCKROACH_ACCEPTANCE_ALLOW_UNSAFE=true
17+
- COCKROACH_OVERRIDE_ALLOW_UNSAFE_INTERNALS=true
1818
volumes:
1919
- ${CERTS_DIR:-../../.localcluster.certs}:/certs
2020
- keytab:/keytab

pkg/cli/democluster/demo_cluster.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -964,6 +964,11 @@ func (demoCtx *Context) testServerArgsForTransientCluster(
964964
args.SSLCertsDir = demoDir
965965
}
966966

967+
// Allow access to system and crdb_internal tables in demo mode.
968+
// Demo mode is for development/testing, so we want to allow access
969+
// to these tables for debugging and introspection.
970+
serverutils.SetUnsafeOverride(&args.Knobs)
971+
967972
return args
968973
}
969974

pkg/cli/democluster/demo_cluster_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,10 @@ func TestTestServerArgsForTransientCluster(t *testing.T) {
140140
actual.StoreSpecs = nil
141141
actual.Knobs.JobsTestingKnobs = nil
142142

143+
// Copy the SQLEvalContext from actual to expected since it's set by SetUnsafeOverride
144+
// and contains function pointers that we can't predict
145+
tc.expected.Knobs.SQLEvalContext = actual.Knobs.SQLEvalContext
146+
143147
assert.Equal(t, tc.expected, actual)
144148
})
145149
}

pkg/cli/interactive_tests/common.tcl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ system "mkdir -p logs"
99
set histfile "cockroach_sql_history"
1010

1111
set ::env(COCKROACH_SKIP_ENABLING_DIAGNOSTIC_REPORTING) "true"
12-
set ::env(COCKROACH_ACCEPTANCE_ALLOW_UNSAFE) "true"
12+
set ::env(COCKROACH_OVERRIDE_ALLOW_UNSAFE_INTERNALS) "true"
1313
set ::env(COCKROACH_CONNECT_TIMEOUT) 15
1414
set ::env(COCKROACH_SQL_CLI_HISTORY) $histfile
1515
# Set client commands as insecure. The server uses --insecure.

pkg/server/server_controller_new_server.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"github.com/cockroachdb/cockroach/pkg/sql"
2323
"github.com/cockroachdb/cockroach/pkg/sql/isql"
2424
"github.com/cockroachdb/cockroach/pkg/storage/fs"
25+
"github.com/cockroachdb/cockroach/pkg/testutils/serverutils"
2526
"github.com/cockroachdb/cockroach/pkg/util"
2627
"github.com/cockroachdb/cockroach/pkg/util/admission"
2728
"github.com/cockroachdb/cockroach/pkg/util/log"
@@ -84,6 +85,16 @@ func (s *topLevelServer) newTenantServer(
8485
// Apply the TestTenantArgs, if any.
8586
baseCfg.TestingKnobs = testArgs.Knobs
8687

88+
// If we're in a test environment (the parent server has testing knobs), apply unsafe override
89+
// for dynamically started tenants to allow access to crdb_internal and system tables.
90+
// This is needed because tests might start tenants via SQL (ALTER TENANT ... START SERVICE SHARED)
91+
// without explicitly setting up test args.
92+
if s.cfg.TestingKnobs != (base.TestingKnobs{}) && baseCfg.TestingKnobs == (base.TestingKnobs{}) {
93+
// Only set unsafe override if no testing knobs were provided through testArgs.
94+
// This ensures we don't override explicitly set test knobs.
95+
serverutils.SetUnsafeOverride(&baseCfg.TestingKnobs)
96+
}
97+
8798
tenantServer, err := newTenantServerInternal(ctx, baseCfg, sqlCfg, tenantStopper, tenantNameContainer, s.db.AdmissionPacerFactory)
8899
if err != nil {
89100
return nil, err

pkg/server/tenant_delayed_id_set_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ func TestStartTenantWithDelayedID(t *testing.T) {
7373
}, nil
7474
}
7575

76+
// Allow unsafe introspection.
77+
serverutils.SetUnsafeOverride(&baseCfg.TestingKnobs)
78+
7679
go func() {
7780
sw, err := NewSeparateProcessTenantServer(
7881
ctx,

pkg/server/testserver.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -700,6 +700,7 @@ func (ts *testServer) setupTenantTestingKnobs(tenantKnobs *base.TestingKnobs) {
700700
}
701701
tenantKnobs.Server.(*TestingKnobs).StubTimeNow = ts.params.Knobs.Server.(*TestingKnobs).StubTimeNow
702702
}
703+
serverutils.SetUnsafeOverride(tenantKnobs)
703704
if ts.params.Knobs.UpgradeManager != nil {
704705
tenantKnobs.UpgradeManager.(*upgradebase.TestingKnobs).SkipSomeUpgradeSteps = ts.params.Knobs.UpgradeManager.(*upgradebase.TestingKnobs).SkipSomeUpgradeSteps
705706
}
@@ -1394,6 +1395,10 @@ func (ts *testServer) StartSharedProcessTenant(
13941395
_, err := ie.ExecEx(ctx, opName, nil /* txn */, sessiondata.NodeUserSessionDataOverride, stmt, qargs...)
13951396
return err
13961397
}
1398+
1399+
// Allow access to unsafe internals for the tenant server in test environments.
1400+
serverutils.SetUnsafeOverride(&args.Knobs)
1401+
13971402
// Save the args for use if the server needs to be created.
13981403
func() {
13991404
ts.topLevelServer.serverController.mu.Lock()
@@ -1778,6 +1783,9 @@ func (ts *testServer) StartTenant(
17781783
stopper.SetTracer(tr)
17791784
}
17801785

1786+
// Allow access to unsafe internals on this tenant.
1787+
serverutils.SetUnsafeOverride(&params.TestingKnobs)
1788+
17811789
baseCfg := makeTestBaseConfig(st, stopper.Tracer())
17821790
baseCfg.TestingKnobs = params.TestingKnobs
17831791
baseCfg.Insecure = params.ForceInsecure

0 commit comments

Comments
 (0)