Skip to content

Commit 8f5e8eb

Browse files
committed
server: fix SetAcceptSQLWithoutTLS for shared-process deployments
We expose `SetAcceptSQLWithoutTLS` method on the test servers which allows us to tweak whether SQL clients can authenticate without TLS on a secure cluster. Previously, this method was incorrect for shared-process deployments, and this is now fixed. The notable distinction between this mode and single-tenant and external-process modes is that even though the shared-process tenant has its own copy of `base.Config` (where `AcceptSQLWithoutTLS` is stored), it does _not_ have its own pre-serve handler. In other words, before the authentication is performed, the connection is handled by the _system_ tenant, so for things to work we need to propagate the update of the boolean to the system tenant. Release note: None
1 parent 7d8dc7e commit 8f5e8eb

File tree

4 files changed

+15
-6
lines changed

4 files changed

+15
-6
lines changed

pkg/server/server_controller_new_server.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,10 @@ func makeSharedProcessTenantServerConfig(
238238
baseCfg.Config.Insecure = kvServerCfg.Config.Insecure
239239
baseCfg.Config.User = kvServerCfg.Config.User
240240
baseCfg.Config.DisableTLSForHTTP = kvServerCfg.Config.DisableTLSForHTTP
241+
// Note that since the shared-process tenant doesn't have its own pre-serve
242+
// handler, only AcceptSQLWithoutTLS of the _system_ tenant matters, so this
243+
// particular inherited value is meaningless, but we choose to keep it for
244+
// consistency with the system tenant.
241245
baseCfg.Config.AcceptSQLWithoutTLS = kvServerCfg.Config.AcceptSQLWithoutTLS
242246
baseCfg.Config.RPCHeartbeatInterval = kvServerCfg.Config.RPCHeartbeatInterval
243247
baseCfg.Config.RPCHeartbeatTimeout = kvServerCfg.Config.RPCHeartbeatTimeout

pkg/server/testserver.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1556,6 +1556,11 @@ func (t *testTenant) SetReady(ready bool) {
15561556
// SetAcceptSQLWithoutTLS is part of the serverutils.ApplicationLayerInterface.
15571557
func (t *testTenant) SetAcceptSQLWithoutTLS(accept bool) {
15581558
t.Cfg.AcceptSQLWithoutTLS = accept
1559+
// If we're running in a shared-process mode, the pre-serve handler has its
1560+
// own copy of base.Config (that is shared with the system tenant), so we
1561+
// must propagate the updated value there too. (For other deployments this
1562+
// call is redundant with the update above but otherwise harmless.)
1563+
t.pgPreServer.TestingSetAcceptSQLWithoutTLS(accept)
15591564
}
15601565

15611566
// PrivilegeChecker is part of the serverutils.ApplicationLayerInterface.

pkg/sql/pgwire/auth_test.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -860,12 +860,6 @@ func TestSSLSessionVar(t *testing.T) {
860860
t.Fatal(err)
861861
}
862862

863-
// Set the system layer to accept SQL without TLS in the event of a shared
864-
// process virtual cluster.
865-
srv.SystemLayer().SetAcceptSQLWithoutTLS(true)
866-
867-
// TODO(herko): What effect should this have on a shared process virtual
868-
// cluster? See: https://github.com/cockroachdb/cockroach/issues/112961
869863
s.SetAcceptSQLWithoutTLS(true)
870864

871865
pgURLWithCerts, cleanupFuncCerts := s.PGUrl(t,

pkg/sql/pgwire/pre_serve.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,12 @@ func (s *PreServeConnHandler) AnnotateCtxForIncomingConn(
172172
return logtags.AddTag(ctx, tag, conn.RemoteAddr().String())
173173
}
174174

175+
// TestingSetAcceptSQLWithoutTLS updates the config to tweak whether SQL clients
176+
// can authenticate without TLS on a secure cluster, in tests.
177+
func (s *PreServeConnHandler) TestingSetAcceptSQLWithoutTLS(accept bool) {
178+
s.cfg.AcceptSQLWithoutTLS = accept
179+
}
180+
175181
// tenantIndependentMetrics is the set of metrics for the
176182
// pre-serve part of connection handling, before the connection
177183
// is routed to a specific tenant.

0 commit comments

Comments
 (0)