15
15
package testserver
16
16
17
17
import (
18
+ "bytes"
18
19
"database/sql"
19
20
"errors"
20
21
"fmt"
@@ -36,6 +37,25 @@ func (ts *testServerImpl) isTenant() bool {
36
37
return ts .curTenantID < firstTenantID
37
38
}
38
39
40
+ // cockroachSupportsTenantScopeCert is a hack to figure out if the version of
41
+ // cockroach on the test server supports tenant scoped certificates. This is less
42
+ // brittle than a static version comparison as these tenant scoped certificates are
43
+ // subject to backports to older CRDB verions.
44
+ func (ts * testServerImpl ) cockroachSupportsTenantScopeCert () (bool , error ) {
45
+ certCmdArgs := []string {
46
+ "cert" ,
47
+ "create-client" ,
48
+ "--help" ,
49
+ }
50
+ checkTenantScopeCertCmd := exec .Command (ts .serverArgs .cockroachBinary , certCmdArgs ... )
51
+ var output bytes.Buffer
52
+ checkTenantScopeCertCmd .Stdout = & output
53
+ if err := checkTenantScopeCertCmd .Run (); err != nil {
54
+ return false , err
55
+ }
56
+ return strings .Contains (output .String (), "--tenant-scope" ), nil
57
+ }
58
+
39
59
// NewTenantServer creates and returns a new SQL tenant pointed at the receiver,
40
60
// which acts as a KV server, and starts it.
41
61
// The SQL tenant is responsible for all SQL processing and does not store any
@@ -87,7 +107,11 @@ func (ts *testServerImpl) NewTenantServer(proxy bool) (TestServer, error) {
87
107
if err := createCertCmd .Run (); err != nil {
88
108
return nil , fmt .Errorf ("%s command %s failed: %w" , tenantserverMessagePrefix , createCertCmd , err )
89
109
}
90
- if ts .version .AtLeast (version .MustParse ("v22.2.0-alpha" )) {
110
+ tenantScopeCertsAvailable , err := ts .cockroachSupportsTenantScopeCert ()
111
+ if err != nil {
112
+ return nil , fmt .Errorf ("failed to determine if tenant scoped certificates are available: %w" , err )
113
+ }
114
+ if tenantScopeCertsAvailable {
91
115
// Overwrite root client certificate scoped to the system and current tenant.
92
116
// Tenant scoping is needed for client certificates used to access tenant servers.
93
117
tenantScopedClientCertArgs := []string {
0 commit comments