Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
60627: bazel: fix up name of `forbiddenmethod` library target r=rickystewart a=rickystewart

This was moved wholesale from a directory called `descriptormarshal`,
so it retained its old library name. This isn't the normal style we're
using and I'm concerned about how Gazelle will handle this going
forward, so change it to the expected style. Also delete an accidentally
duplicated test.

Release note: None

60636: cli: Add connect command stub r=aaron-crl a=itsbilal

Adds a new command stub, `connect`, with relevant args of
`--certs-dir`, `--init-token`, and list of peers. Implementation
code for this command is yet to come, and the command is not hooked
up to the outer `cockroach` command yet.

Very first part of cockroachdb#60632.

Release note: None.

Co-authored-by: Ricky Stewart <[email protected]>
Co-authored-by: Bilal Akhtar <[email protected]>
  • Loading branch information
3 people committed Feb 18, 2021
3 parents 1a43d11 + dfa43ca + 2b4c93c commit 9171f18
Show file tree
Hide file tree
Showing 10 changed files with 60 additions and 17 deletions.
1 change: 0 additions & 1 deletion pkg/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,6 @@ ALL_TESTS = [
"//pkg/storage:storage_test",
"//pkg/testutils/keysutils:keysutils_test",
"//pkg/testutils/lint/passes/fmtsafe:fmtsafe_test",
"//pkg/testutils/lint/passes/forbiddenmethod:descriptormarshal_test",
"//pkg/testutils/lint/passes/forbiddenmethod:forbiddenmethod_test",
"//pkg/testutils/lint/passes/hash:hash_test",
"//pkg/testutils/lint/passes/nocopy:nocopy_test",
Expand Down
4 changes: 4 additions & 0 deletions pkg/base/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,10 @@ type Config struct {
// SSLCertsDir is the path to the certificate/key directory.
SSLCertsDir string

// InitToken is a shared initialization token for generating TLS certificates
// across multiple nodes.
InitToken string

// User running this process. It could be the user under which
// the server is running or the user passed in client calls.
User security.SQLUsername
Expand Down
1 change: 1 addition & 0 deletions pkg/cli/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ go_library(
"cert.go",
"cli.go",
"client_url.go",
"connect.go",
"context.go",
"cpuprofile.go",
"debug.go",
Expand Down
2 changes: 2 additions & 0 deletions pkg/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,8 @@ func init() {
startSingleNodeCmd,
initCmd,
certCmd,
// TODO(bilal): Uncomment this when the connect command does something useful.
// connectCmd,
quitCmd,

sqlShellCmd,
Expand Down
5 changes: 5 additions & 0 deletions pkg/cli/cliflags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -711,6 +711,11 @@ Instead, require the user to always specify access keys.`,
Description: `Prompt for the new user's password.`,
}

InitToken = FlagInfo{
Name: "init-token",
Description: `Shared token for initialization of node TLS certificates`,
}

CertsDir = FlagInfo{
Name: "certs-dir",
EnvVar: "COCKROACH_CERTS_DIR",
Expand Down
34 changes: 34 additions & 0 deletions pkg/cli/connect.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright 2021 The Cockroach Authors.
//
// Use of this software is governed by the Business Source License
// included in the file licenses/BSL.txt.
//
// As of the Change Date specified in that file, in accordance with
// the Business Source License, use of this software will be governed
// by the Apache License, Version 2.0, included in the file
// licenses/APL.txt.

package cli

import "github.com/spf13/cobra"

// connectCmd triggers a TLS initialization handshake and writes
// certificates in the specified certs-dir for use with start.
var connectCmd = &cobra.Command{
Use: "connect --certs-dir=<path to cockroach certs dir> --init-token=<shared secret> --join=<host 1>,<host 2>,...,<host N>",
Short: "build TLS certificates for use with the start command",
Long: `
Connects to other nodes and negotiates an initialization bundle for use with
secure inter-node connections.
`,
Args: cobra.NoArgs,
RunE: MaybeDecorateGRPCError(runConnect),
}

// runConnect connects to other nodes and negotiates an initialization bundle
// for use with secure inter-node connections.
func runConnect(cmd *cobra.Command, args []string) error {
// TODO(bilal): Implement TLS init handshake.
// https://github.com/cockroachdb/cockroach/issues/60632
return nil
}
9 changes: 9 additions & 0 deletions pkg/cli/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,15 @@ func init() {
stringSliceFlag(f, &cliCtx.certPrincipalMap, cliflags.CertPrincipalMap)
}

// Flags for the connect command.
{
f := connectCmd.Flags()
stringFlag(f, &baseCfg.SSLCertsDir, cliflags.CertsDir)
stringFlag(f, &baseCfg.InitToken, cliflags.InitToken)
varFlag(f, addrSetter{&startCtx.serverListenAddr, &serverListenPort}, cliflags.ListenAddr)
varFlag(f, &serverCfg.JoinList, cliflags.Join)
}

for _, cmd := range []*cobra.Command{
createCACertCmd,
createClientCACertCmd,
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/roachvet/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ go_library(
deps = [
"//pkg/testutils/lint/passes/errcmp",
"//pkg/testutils/lint/passes/fmtsafe",
"//pkg/testutils/lint/passes/forbiddenmethod:descriptormarshal",
"//pkg/testutils/lint/passes/forbiddenmethod",
"//pkg/testutils/lint/passes/hash",
"//pkg/testutils/lint/passes/nocopy",
"//pkg/testutils/lint/passes/returnerrcheck",
Expand Down
17 changes: 3 additions & 14 deletions pkg/testutils/lint/passes/forbiddenmethod/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")

go_library(
name = "descriptormarshal",
name = "forbiddenmethod",
srcs = [
"analyzers.go",
"forbiddenmethod.go",
Expand All @@ -17,24 +17,13 @@ go_library(
)

go_test(
name = "descriptormarshal_test",
name = "forbiddenmethod_test",
size = "small",
srcs = ["descriptormarshal_test.go"],
data = glob(["testdata/**"]),
tags = ["broken_in_bazel"],
deps = [
":descriptormarshal",
"//pkg/testutils/skip",
"@org_golang_x_tools//go/analysis/analysistest",
],
)

go_test(
name = "forbiddenmethod_test",
srcs = ["descriptormarshal_test.go"],
data = glob(["testdata/**"]),
deps = [
":descriptormarshal",
":forbiddenmethod",
"//pkg/testutils/skip",
"@org_golang_x_tools//go/analysis/analysistest",
],
Expand Down
2 changes: 1 addition & 1 deletion pkg/testutils/lint/passes/passesutil/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ go_test(
srcs = ["passes_util_test.go"],
tags = ["broken_in_bazel"],
deps = [
"//pkg/testutils/lint/passes/forbiddenmethod:descriptormarshal",
"//pkg/testutils/lint/passes/forbiddenmethod",
"//pkg/testutils/lint/passes/unconvert",
"//pkg/testutils/skip",
"@com_github_stretchr_testify//require",
Expand Down

0 comments on commit 9171f18

Please sign in to comment.