Skip to content

Commit 54bcb71

Browse files
craig[bot]golgeek
andcommitted
Merge #151230
151230: roachprod: default to secure clusters unless GCE cockroach-ephemeral r=herkolategan,srosenberg a=golgeek Since #147737, to ease testing for engineering teams, roachprod defaults to insecure clusters. This change has led to security impact for other entities at CRL. This patch brings smart selection of secure vs. insecure cluster depending on the Cloud project the cluster is provisionned in. If the cluster is provisionned in the engineering's ephemeral GCP project, it will default to insecure, while all other configurations will default to secure. In order to achieve that, and because this depends on the cluster's configuration that is not available at the CLI package level, the CLI now keeps track of the user's arguments (--secure, --insecure, default) and passes the information to the roachprod library. Epic: none Release note: None Co-authored-by: Ludovic Leroux <[email protected]>
2 parents 73df2d9 + c48f303 commit 54bcb71

36 files changed

+209
-95
lines changed

pkg/cmd/drt-run/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ go_library(
1818
"//pkg/cmd/roachtest/registry",
1919
"//pkg/cmd/roachtest/spec",
2020
"//pkg/roachprod",
21+
"//pkg/roachprod/install",
2122
"//pkg/roachprod/logger",
2223
"//pkg/util/randutil",
2324
"//pkg/util/syncutil",

pkg/cmd/drt-run/workloads.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"sync"
1515

1616
"github.com/cockroachdb/cockroach/pkg/roachprod"
17+
"github.com/cockroachdb/cockroach/pkg/roachprod/install"
1718
"github.com/cockroachdb/cockroach/pkg/roachprod/logger"
1819
"github.com/cockroachdb/errors"
1920
"github.com/cockroachdb/logtags"
@@ -45,7 +46,7 @@ func (w *workloadRunner) runWorkloadStep(
4546
return
4647
}
4748
pgUrl, err := roachprod.PgURL(ctx, l, w.config.ClusterName, w.config.CertsDir, roachprod.PGURLOptions{
48-
Secure: w.config.CertsDir != "",
49+
Secure: install.SimpleSecureOption(w.config.CertsDir != ""),
4950
External: true,
5051
})
5152
if err != nil {

pkg/cmd/drtprod/cli/commands/yamlprocessor.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ func setupAndExecute(
283283
) error {
284284
logger := config.Logger
285285
// Move the drtprod binary to /usr/bin to ensure it is available system-wide on the cluster.
286-
err := roachprodRun(ctx, logger, monitorClusterName, "", "", true,
286+
err := roachprodRun(ctx, logger, monitorClusterName, "", "", install.SimpleSecureOption(true),
287287
os.Stdout, os.Stderr,
288288
[]string{fmt.Sprintf("sudo cp %s /usr/bin", drtprodLocation)},
289289
install.RunOptions{FailOption: install.FailSlow})
@@ -293,7 +293,7 @@ func setupAndExecute(
293293

294294
// Enable linger for the default user, so that the cloud subprocess is not
295295
// killed when the user logs out.
296-
err = roachprodRun(ctx, logger, monitorClusterName, "", "", true,
296+
err = roachprodRun(ctx, logger, monitorClusterName, "", "", install.SimpleSecureOption(true),
297297
os.Stdout, os.Stderr,
298298
[]string{fmt.Sprintf("sudo loginctl enable-linger %s", config.SharedUser)},
299299
install.RunOptions{FailOption: install.FailSlow})
@@ -318,7 +318,7 @@ func setupAndExecute(
318318
}
319319

320320
// Run the systemd command on the remote cluster.
321-
return roachprodRun(ctx, logger, monitorClusterName, "", "", true,
321+
return roachprodRun(ctx, logger, monitorClusterName, "", "", install.SimpleSecureOption(true),
322322
os.Stdout, os.Stderr,
323323
[]string{executeArgs},
324324
install.RunOptions{FailOption: install.FailSlow})
@@ -340,7 +340,7 @@ func uploadAllDependentFiles(
340340
if strings.Contains(fl, "/") {
341341
dirLocation := filepath.Dir(fl)
342342
// Use roachprod to create the directory on the remote.
343-
err := roachprodRun(ctx, logger, monitorClusterName, "", "", true,
343+
err := roachprodRun(ctx, logger, monitorClusterName, "", "", install.SimpleSecureOption(true),
344344
os.Stdout, os.Stderr,
345345
[]string{fmt.Sprintf("mkdir -p %s", dirLocation)},
346346
install.RunOptions{FailOption: install.FailSlow})

pkg/cmd/drtprod/cli/commands/yamlprocessor_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ environment:
254254
return nil
255255
}
256256
roachprodRun = func(ctx context.Context, l *logger.Logger, clusterName,
257-
SSHOptions, processTag string, secure bool, stdout, stderr io.Writer,
257+
SSHOptions, processTag string, secure install.SecureOption, stdout, stderr io.Writer,
258258
cmdArray []string, options install.RunOptions) error {
259259
require.Equal(t, "test-monitor", clusterName)
260260
if strings.HasPrefix(cmdArray[0], "mkdir -p") {
@@ -284,7 +284,7 @@ environment:
284284
return nil
285285
}
286286
roachprodRun = func(ctx context.Context, l *logger.Logger, clusterName,
287-
SSHOptions, processTag string, secure bool, stdout, stderr io.Writer,
287+
SSHOptions, processTag string, secure install.SecureOption, stdout, stderr io.Writer,
288288
cmdArray []string, options install.RunOptions) error {
289289
require.Equal(t, "test-monitor", clusterName)
290290
return nil
@@ -311,7 +311,7 @@ environment:
311311
return nil
312312
}
313313
roachprodRun = func(ctx context.Context, l *logger.Logger, clusterName,
314-
SSHOptions, processTag string, secure bool, stdout, stderr io.Writer,
314+
SSHOptions, processTag string, secure install.SecureOption, stdout, stderr io.Writer,
315315
cmdArray []string, options install.RunOptions) error {
316316
if strings.HasPrefix(cmdArray[0], "sudo cp") {
317317
return fmt.Errorf("move command failed")
@@ -342,7 +342,7 @@ environment:
342342
return nil
343343
}
344344
roachprodRun = func(ctx context.Context, l *logger.Logger, clusterName,
345-
SSHOptions, processTag string, secure bool, stdout, stderr io.Writer,
345+
SSHOptions, processTag string, secure install.SecureOption, stdout, stderr io.Writer,
346346
cmdArray []string, options install.RunOptions) error {
347347
runCmdsLock.Lock()
348348
defer runCmdsLock.Unlock()
@@ -375,7 +375,7 @@ environment:
375375
return nil
376376
}
377377
roachprodRun = func(ctx context.Context, l *logger.Logger, clusterName,
378-
SSHOptions, processTag string, secure bool, stdout, stderr io.Writer,
378+
SSHOptions, processTag string, secure install.SecureOption, stdout, stderr io.Writer,
379379
cmdArray []string, options install.RunOptions) error {
380380
require.Equal(t, "test-monitor", clusterName)
381381
if strings.HasPrefix(cmdArray[0], "sudo systemd-run") {
@@ -409,7 +409,7 @@ environment:
409409
return nil
410410
}
411411
roachprodRun = func(ctx context.Context, l *logger.Logger, clusterName,
412-
SSHOptions, processTag string, secure bool, stdout, stderr io.Writer,
412+
SSHOptions, processTag string, secure install.SecureOption, stdout, stderr io.Writer,
413413
cmdArray []string, options install.RunOptions) error {
414414
require.Equal(t, "test-monitor", clusterName)
415415
runCmdsLock.Lock()
@@ -483,7 +483,7 @@ environment:
483483
return nil
484484
}
485485
roachprodRun = func(ctx context.Context, l *logger.Logger, clusterName,
486-
SSHOptions, processTag string, secure bool, stdout, stderr io.Writer,
486+
SSHOptions, processTag string, secure install.SecureOption, stdout, stderr io.Writer,
487487
cmdArray []string, options install.RunOptions) error {
488488
require.Equal(t, "test-monitor", clusterName)
489489
runCmdsLock.Lock()
@@ -553,7 +553,7 @@ environment:
553553
return nil
554554
}
555555
roachprodRun = func(ctx context.Context, l *logger.Logger, clusterName,
556-
SSHOptions, processTag string, secure bool, stdout, stderr io.Writer,
556+
SSHOptions, processTag string, secure install.SecureOption, stdout, stderr io.Writer,
557557
cmdArray []string, options install.RunOptions) error {
558558
require.Equal(t, "test-monitor", clusterName)
559559
runCmdsLock.Lock()

pkg/cmd/roachprod-microbench/cluster/execute.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ type RemoteExecutionFunc func(
5757
ctx context.Context,
5858
l *logger.Logger,
5959
clusterName, SSHOptions, processTag string,
60-
secure bool,
60+
secure install.SecureOption,
6161
cmdArray []string,
6262
options install.RunOptions,
6363
) ([]install.RunResultDetails, error)
@@ -156,7 +156,7 @@ func remoteWorker(
156156

157157
runResult, err := execFunc(
158158
cmdCtx, log, clusterNode, "" /* SSHOptions */, "", /* processTag */
159-
false /* secure */, command.Args, runOptions,
159+
install.SimpleSecureOption(false), command.Args, runOptions,
160160
)
161161
duration := timeutil.Since(start)
162162

pkg/cmd/roachprod-microbench/cluster/executor_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ func TestExecutionScheduling(t *testing.T) {
6969
ctx context.Context,
7070
l *logger.Logger,
7171
clusterName, SSHOptions, processTag string,
72-
secure bool,
72+
secure install.SecureOption,
7373
cmdArray []string,
7474
options install.RunOptions,
7575
) ([]install.RunResultDetails, error) {
@@ -168,7 +168,7 @@ func TestCancelGroupsBeforeExecution(t *testing.T) {
168168
ctx context.Context,
169169
l *logger.Logger,
170170
clusterName, SSHOptions, processTag string,
171-
secure bool,
171+
secure install.SecureOption,
172172
cmdArray []string,
173173
options install.RunOptions,
174174
) ([]install.RunResultDetails, error) {
@@ -226,7 +226,7 @@ func TestCancelGroupsInFlight(t *testing.T) {
226226
ctx context.Context,
227227
l *logger.Logger,
228228
clusterName, SSHOptions, processTag string,
229-
secure bool,
229+
secure install.SecureOption,
230230
cmdArray []string,
231231
options install.RunOptions,
232232
) ([]install.RunResultDetails, error) {

pkg/cmd/roachprod-microbench/executor.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ func (e *executor) listBenchmarks(
252252
// cluster by inspecting the given remote directory.
253253
func (e *executor) listRemotePackages(log *logger.Logger, dir string) ([]string, error) {
254254
ctx := context.Background()
255-
results, err := roachprod.RunWithDetails(ctx, log, e.cluster, "", "", false,
255+
results, err := roachprod.RunWithDetails(ctx, log, e.cluster, "", "", install.SimpleSecureOption(false),
256256
[]string{"find", dir, "-name", "run.sh"}, install.WithNodes(install.Nodes{1}))
257257
if err != nil {
258258
return nil, err

pkg/cmd/roachprod-microbench/roachprod_util.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func InitRoachprod() {
2626
func RoachprodRun(clusterName string, l *logger.Logger, cmdArray []string) error {
2727
// Execute the roachprod command with the provided context, logger, cluster name, and options.
2828
return roachprod.Run(
29-
context.Background(), l, clusterName, "", "", false,
29+
context.Background(), l, clusterName, "", "", install.SimpleSecureOption(false),
3030
os.Stdout, os.Stderr, cmdArray, install.DefaultRunOptions(),
3131
)
3232
}

pkg/cmd/roachprod-stress/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ func roundToSeconds(d time.Duration) time.Duration {
135135

136136
func roachprodRun(clusterName string, cmdArray []string) error {
137137
return roachprod.Run(
138-
context.Background(), l, clusterName, "", "", false,
138+
context.Background(), l, clusterName, "", "", install.SimpleSecureOption(false),
139139
os.Stdout, os.Stderr, cmdArray, install.DefaultRunOptions(),
140140
)
141141
}

pkg/cmd/roachprod/cli/commands.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -736,7 +736,7 @@ cluster setting will be set to its value.
736736
clusterSettingsOpts := []install.ClusterSettingOption{
737737
install.TagOption(tag),
738738
install.PGUrlCertsDirOption(pgurlCertsDir),
739-
install.SecureOption(isSecure),
739+
isSecure,
740740
install.UseTreeDistOption(useTreeDist),
741741
install.EnvOption(nodeEnv),
742742
install.NumRacksOption(numRacks),
@@ -773,7 +773,7 @@ Note that if the cluster is started in insecure mode, set the insecure mode here
773773
Args: cobra.ExactArgs(1),
774774
Run: Wrap(func(cmd *cobra.Command, args []string) error {
775775
clusterSettingsOpts := []install.ClusterSettingOption{
776-
install.SecureOption(isSecure),
776+
isSecure,
777777
}
778778
return roachprod.UpdateTargets(context.Background(), config.Logger, args[0], clusterSettingsOpts...)
779779
}),
@@ -857,7 +857,7 @@ environment variables to the cockroach process.
857857
clusterSettingsOpts := []install.ClusterSettingOption{
858858
install.TagOption(tag),
859859
install.PGUrlCertsDirOption(pgurlCertsDir),
860-
install.SecureOption(isSecure),
860+
isSecure,
861861
install.UseTreeDistOption(useTreeDist),
862862
install.EnvOption(nodeEnv),
863863
install.NumRacksOption(numRacks),
@@ -1723,7 +1723,7 @@ roachprod grafana-annotation grafana.testeng.crdb.io example-annotation-event --
17231723
return errors.Newf("Too many arguments for --time-range, expected 1 or 2, got: %d", len(grafanaTimeRange))
17241724
}
17251725

1726-
return roachprod.AddGrafanaAnnotation(context.Background(), args[0] /* host */, isSecure, req)
1726+
return roachprod.AddGrafanaAnnotation(context.Background(), args[0] /* host */, isSecure.DefaultSecure, req)
17271727
}),
17281728
}
17291729
initGrafanaAnnotationCmdFlags(grafanaAnnotationCmd)

0 commit comments

Comments
 (0)