Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sql: Add system table join_tokens, and create_join_tokens() builtin function #62053

Merged

Conversation

itsbilal
Copy link
Contributor

@itsbilal itsbilal commented Mar 16, 2021

This change adds a new system table, join_tokens, for the
exclusive use of storing join tokens. This is necessary as
we need guaranteed at-most-once semantics with these, which
transactions give us pretty easily. A related migration is also added
to create said table

This change also adds a new builtin function, crdb_internal.create_join_token()
that creates and persists a join token in that table.

Currently, there's no mechanism to remove expired join tokens.

See RFC #51991. Part of #60632.

Release note (general change): Add crdb_internal.create_join_token()
sql builtin function to create join tokens for use when joining
new nodes to a secure cluster. This functionality is hidden behind
a feature flag.

@itsbilal itsbilal requested review from knz, aaron-crl and a team March 16, 2021 00:05
@itsbilal itsbilal requested a review from a team as a code owner March 16, 2021 00:05
@itsbilal itsbilal requested review from dt and removed request for a team March 16, 2021 00:05
@itsbilal itsbilal self-assigned this Mar 16, 2021
@cockroach-teamcity
Copy link
Member

This change is Reviewable

@itsbilal
Copy link
Contributor Author

There are many SQL bits here so it'd rather have this get some more SQL eyes. That said, the first and third commits might have an impact on some of your work @aaron-crl , as it moves around some JoinToken stuff.

@itsbilal itsbilal force-pushed the create-jointoken-sql-move-system-table branch 3 times, most recently from 699e7c4 to 49609c2 Compare March 22, 2021 21:05
Copy link
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.

1st commit LGTM

2nd commit not quite so. I think this work does not justify a fully fledged new SQL statement. (Moreover, CREATE is someone earmarked for DDL / SQL metaschema changes.) I would recommend a SQL built-in function instead. We already have crdb_internal.create_tenant and I believe we can follow this model here.

3rd commit LGTM

4th commit code OK, but when you connect the create function to the cert manager, don't do this in the sql/sem/builtins package. Instead add a function in the sql package and make it an interface. Again, you can follow the example of create_tenant.

5th commit LGTM

Reviewed 3 of 3 files at r1, 11 of 11 files at r2, 4 of 4 files at r3, 9 of 9 files at r4, 5 of 5 files at r5.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @aaron-crl and @dt)

@itsbilal itsbilal force-pushed the create-jointoken-sql-move-system-table branch from 49609c2 to 790d72e Compare March 26, 2021 20:57
@itsbilal itsbilal changed the title sql: Add system table join_tokens, use it in CREATE JOINTOKEN sql: Add system table join_tokens, and create_join_tokens() builtin function Mar 26, 2021
@itsbilal itsbilal force-pushed the create-jointoken-sql-move-system-table branch from 790d72e to 56df4ad Compare March 26, 2021 21:06
@itsbilal
Copy link
Contributor Author

TFTR! I've moved over to a sql builtin, and updated the PR accordingly. Also folded the other PR into this one.

Copy link
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.

:lgtm: but I think you need to revisit some tests that assert table IDs.

Reviewed 26 of 26 files at r6, 4 of 4 files at r7, 4 of 4 files at r8, 13 of 13 files at r9, 5 of 5 files at r10.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @aaron-crl, @dt, and @itsbilal)


pkg/sql/join_token_test.go, line 87 at r7 (raw file):

	defer s.Stopper().Stop(context.Background())

	rows, err := sqldb.Query("CREATE JOINTOKEN;")

2nd commit: CREATE JOINTOKEN doesn't seem relevant to the PR any more. Maybe you can copy the query from the 4th commit into it.

Previously, the generation of join tokens bypassed the
certificate manager when loading CA certificates. This change
updates that code path and associated tests to use the certificate
manager, to make testing easier.

Release note: None.
Adds a create_join_token builtin function for use in TLS auto-joins.
This function, when run on a self-hosted single-tenant
Cockroach node, creates and returns a new join token. This
join token can then be copy-pasted to new nodes and used
to give them the set of certificates for secure auto TLS
initialization.

See RFC cockroachdb#51991. Part of cockroachdb#60632.

Release note: None.
As we're going with a system table based appraoch for saving join
tokens, it makes more sense to move the underlying struct to the
security package so that it can be used in the sql subsystem.
The reason why it was in server was so we could access
Gossip in the same code as the JoinToken struct itself.

Also remove the status server method added to generate/gossip
join token.

Release note: None.
@itsbilal itsbilal force-pushed the create-jointoken-sql-move-system-table branch from 56df4ad to f7b3b84 Compare March 29, 2021 15:31
@itsbilal itsbilal requested a review from a team as a code owner March 29, 2021 15:31
Copy link
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! Updated the failing tests, and fixed lint issues too.

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (and 1 stale) (waiting on @aaron-crl, @dt, and @knz)


pkg/sql/join_token_test.go, line 87 at r7 (raw file):

Previously, knz (kena) wrote…

2nd commit: CREATE JOINTOKEN doesn't seem relevant to the PR any more. Maybe you can copy the query from the 4th commit into it.

Done. Moved this entire file to the 4th commit to reduce confusion, instead of having a half-working test.

@itsbilal itsbilal removed the request for review from a team March 29, 2021 15:37
This change adds a new system table, `join_tokens`, for the
exclusive use of storing join tokens. This is necessary as
we need guaranteed at-most-once semantics with these, which
transactions give us pretty easily.

This change also updates the `create_join_token()` function to
create and store a join token in that table.

Currently, there's no mechanism to remove expired join tokens.

Release note (general change): Add `crdb_internal.create_join_token()`
sql builtin function to create join tokens for use when joining
new nodes to a secure cluster. This functionality is hidden behind
a feature flag.
This change adds a SQL migration (gated on cluster versions)
for the join_tokens table added in a previous commit.

Release note: None.
@itsbilal itsbilal force-pushed the create-jointoken-sql-move-system-table branch from f7b3b84 to 068ad3d Compare March 29, 2021 16:02
A lot of tests in the cli and sql packages assert on
system table IDs, range numbers, etc., that were failing
due to the addition of the `join_tokens` table. This change
updates all those tests to account for that table.

Release note: None.
@itsbilal itsbilal force-pushed the create-jointoken-sql-move-system-table branch from 068ad3d to 3a44b45 Compare March 29, 2021 17:58
@itsbilal
Copy link
Contributor Author

bors r=knz

@craig
Copy link
Contributor

craig bot commented Mar 29, 2021

Build succeeded:

@craig craig bot merged commit 0e70529 into cockroachdb:master Mar 29, 2021
@@ -1756,6 +1764,49 @@ var (
FormatVersion: descpb.InterleavedFormatVersion,
NextMutationID: 1,
})

// MigrationsTable is the descriptor for the migrations table. It stores facts
Copy link
Contributor

Choose a reason for hiding this comment

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

PS I think this comment could do with fixing, it's referring to the table before.

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