Skip to content

server,sql: Add new JoinToken struct, generator, feature flag#61505

Merged
craig[bot] merged 1 commit intocockroachdb:masterfrom
itsbilal:add-join-token-feature-flag
Mar 5, 2021
Merged

server,sql: Add new JoinToken struct, generator, feature flag#61505
craig[bot] merged 1 commit intocockroachdb:masterfrom
itsbilal:add-join-token-feature-flag

Conversation

@itsbilal
Copy link
Copy Markdown
Contributor

@itsbilal itsbilal commented Mar 4, 2021

This change adds a new JoinToken struct in the server
package for use in TLS auto-join (see RFC #51991).

It also adds a feature flag to hide this feature except
for opt-in use, as well as a generator function to the status
server that can be used by a future SQL statement that would
generate and return join tokens. The feature flag is also
in the SQL package so it can be used by both SQL and server.

Part of #60632.

WIP until:

  • Unit tests for server.JoinToken

Release justification: All changes are to new code paths, and
are gated behind a feature flag.
Release note: None.

@itsbilal itsbilal requested review from aaron-crl and knz March 4, 2021 21:06
@itsbilal itsbilal self-assigned this Mar 4, 2021
@itsbilal itsbilal requested a review from a team as a code owner March 4, 2021 21:06
@cockroach-teamcity
Copy link
Copy Markdown
Member

This change is Reviewable

}

// TODO(bilal): This is definitely wrong.
f, err := os.Open(certLocator.CACertPath())
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aaron-crl This likely calls for a "get me the CA cert" function inside `pkg/security, right? Is there an obvious way to get hold of a certificate manager to get this?

@itsbilal itsbilal force-pushed the add-join-token-feature-flag branch from 7be180b to 1bbe759 Compare March 4, 2021 21:30
Copy link
Copy Markdown

@aaron-crl aaron-crl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @itsbilal and @knz)


pkg/server/status.go, line 2568 at r1 (raw file):

Previously, itsbilal (Bilal Akhtar) wrote…

@aaron-crl This likely calls for a "get me the CA cert" function inside `pkg/security, right? Is there an obvious way to get hold of a certificate manager to get this?

I've got the same need in the GRPC endpoint. I'm using the below code to get it there.

Since you're in server, you should have access to loadCertificateFile, so something like this (copied from my GRPC code):

// RequestCA makes it possible for a node to request the node-to-node CA certificate.
func (s *adminServer) RequestCA(
	ctx context.Context, req *serverpb.CaRequest,
) (*serverpb.CaResponse, error) {
	cl := security.MakeCertsLocator(s.server.cfg.SSLCertsDir)
	caCert, err := loadCertificateFile(cl.CACertPath())
	if err != nil {
		return nil, errors.Wrapf(
			err,
			"failed to read inter-node cert from disk at %q ",
			cl.CACertPath(),
		)
	}

	[...]
}

itsbilal added a commit to itsbilal/cockroach that referenced this pull request Mar 4, 2021
When a join token is generated, gossip it among other connected
nodes with a short TTL. This allows that join token to be used
when connecting to any node in the cluster, and not necessarily
to the same node where the join token was generated.

Also add an isValid function to the join token to confirm (on
the receiver end) that the join token matches what was stored
in gossip.

First commit is cockroachdb#61505. Part of cockroachdb#60632.

Release justification: Changes to new code paths, gated behind
experimental feature flag.
Release note: None.
@itsbilal itsbilal force-pushed the add-join-token-feature-flag branch from 1bbe759 to 4bc6c88 Compare March 4, 2021 22:58
Copy link
Copy Markdown
Contributor Author

@itsbilal itsbilal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TFTR! Tests added.

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @knz)


pkg/server/status.go, line 2568 at r1 (raw file):

Previously, aaron-crl wrote…

I've got the same need in the GRPC endpoint. I'm using the below code to get it there.

Since you're in server, you should have access to loadCertificateFile, so something like this (copied from my GRPC code):

// RequestCA makes it possible for a node to request the node-to-node CA certificate.
func (s *adminServer) RequestCA(
	ctx context.Context, req *serverpb.CaRequest,
) (*serverpb.CaResponse, error) {
	cl := security.MakeCertsLocator(s.server.cfg.SSLCertsDir)
	caCert, err := loadCertificateFile(cl.CACertPath())
	if err != nil {
		return nil, errors.Wrapf(
			err,
			"failed to read inter-node cert from disk at %q ",
			cl.CACertPath(),
		)
	}

	[...]
}

This is done now - thanks!

Copy link
Copy Markdown

@aaron-crl aaron-crl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @itsbilal and @knz)


pkg/server/join_token_test.go, line 61 at r2 (raw file):

	caCertFile := path.Join(tempDir, security.CACertFilename())
	caCert := []byte("foobar")
	require.NoError(t, ioutil.WriteFile(caCertFile, caCert, 0666))

nit: This might eventually fall afoul of cert load tests that check permissions. Consider 0600.

@itsbilal itsbilal force-pushed the add-join-token-feature-flag branch from 4bc6c88 to 2c3b31c Compare March 4, 2021 23:14
@itsbilal itsbilal force-pushed the add-join-token-feature-flag branch from 2c3b31c to 20b6852 Compare March 4, 2021 23:16
Copy link
Copy Markdown
Contributor Author

@itsbilal itsbilal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TFTR!

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @knz)


pkg/server/join_token_test.go, line 61 at r2 (raw file):

Previously, aaron-crl wrote…

nit: This might eventually fall afoul of cert load tests that check permissions. Consider 0600.

Done.

@itsbilal itsbilal force-pushed the add-join-token-feature-flag branch from 20b6852 to df249b3 Compare March 4, 2021 23:24
@itsbilal itsbilal force-pushed the add-join-token-feature-flag branch from df249b3 to cb48e0c Compare March 4, 2021 23:31
@itsbilal itsbilal force-pushed the add-join-token-feature-flag branch from cb48e0c to 4d9cd5e Compare March 4, 2021 23:47
itsbilal added a commit to itsbilal/cockroach that referenced this pull request Mar 4, 2021
When a join token is generated, gossip it among other connected
nodes with a short TTL. This allows that join token to be used
when connecting to any node in the cluster, and not necessarily
to the same node where the join token was generated.

Also add an isValid function to the join token to confirm (on
the receiver end) that the join token matches what was stored
in gossip.

First commit is cockroachdb#61505. Part of cockroachdb#60632.

Release justification: Changes to new code paths, gated behind
experimental feature flag.
Release note: None.
This change adds a new JoinToken struct in the server
package for use in TLS auto-join (see RFC cockroachdb#51991).

It also adds a feature flag to hide this feature except
for opt-in use, as well as a generator function to the status
server that can be used by a future SQL statement that would
generate and return join tokens. The feature flag is also
in the SQL package so it can be used by both SQL and server.

Part of cockroachdb#60632.

Release justification: All changes are to new code paths, and
are gated behind a feature flag.
Release note: None.
@itsbilal itsbilal force-pushed the add-join-token-feature-flag branch from 4d9cd5e to d738ecd Compare March 5, 2021 02:58
@itsbilal
Copy link
Copy Markdown
Contributor Author

itsbilal commented Mar 5, 2021

bors r=aaron-crl

@craig
Copy link
Copy Markdown
Contributor

craig bot commented Mar 5, 2021

Build succeeded:

@craig craig bot merged commit f0c2d8a into cockroachdb:master Mar 5, 2021
itsbilal added a commit to itsbilal/cockroach that referenced this pull request Mar 5, 2021
When a join token is generated, gossip it among other connected
nodes with a short TTL. This allows that join token to be used
when connecting to any node in the cluster, and not necessarily
to the same node where the join token was generated.

Also add an isValid function to the join token to confirm (on
the receiver end) that the join token matches what was stored
in gossip.

First commit is cockroachdb#61505. Part of cockroachdb#60632.

Release justification: Changes to new code paths, gated behind
experimental feature flag.
Release note: None.
aaron-crl pushed a commit to aaron-crl/cockroach that referenced this pull request Mar 5, 2021
* removed stubs and dummy functions
* cleaned up TODOs

Release justification: low risk, feature flagged functional enhancement
Release note: None
Copy link
Copy Markdown
Contributor

@knz knz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 1 of 4 files at r1, 6 of 6 files at r3.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @itsbilal)


pkg/server/join_token.go, line 81 at r3 (raw file):

//
// The format of the text (after base64-decoding) is:
// <tokenID:uuid.Size><sharedSecret:joinTokenSecretLen><fingerprint:variable><crc:4>

I would have recommended a version byte in front, so that we can handle multiple formats of join tokens. Can you process this in a followup PR?


pkg/server/status.go, line 2549 at r3 (raw file):

// subsystem directly. The response is a base64 marshaled form of the join token
// that can be shared to new nodes that want to join this cluster.
func (s *statusServer) GenerateJoinToken(ctx context.Context) (string, error) {

Can you explain the rationale of making this a method of statusServer? I though the entire join protocol would be part of the admin interface? Or the new API v2 tree?

itsbilal pushed a commit to itsbilal/cockroach that referenced this pull request May 5, 2021
* removed stubs and dummy functions
* cleaned up TODOs

Release justification: low risk, feature flagged functional enhancement
Release note: None
itsbilal pushed a commit to itsbilal/cockroach that referenced this pull request May 6, 2021
* removed stubs and dummy functions
* cleaned up TODOs

Release justification: low risk, feature flagged functional enhancement
Release note: None
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants