Skip to content

Commit

Permalink
sql: Add crdb_internal.create_join_token sql builtin function
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
itsbilal committed Mar 29, 2021
1 parent 2e91ca3 commit 1edb088
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
2 changes: 2 additions & 0 deletions docs/generated/sql/functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -2659,6 +2659,8 @@ SELECT * FROM crdb_internal.check_consistency(true, ‘\x02’, ‘\x04’)</p>
</span></td></tr>
<tr><td><a name="crdb_internal.completed_migrations"></a><code>crdb_internal.completed_migrations() &rarr; <a href="string.html">string</a>[]</code></td><td><span class="funcdesc"><p>This function is used only by CockroachDB’s developers for testing purposes.</p>
</span></td></tr>
<tr><td><a name="crdb_internal.create_join_token"></a><code>crdb_internal.create_join_token() &rarr; <a href="string.html">string</a></code></td><td><span class="funcdesc"><p>Creates a join token for use when adding a new node to a secure cluster.</p>
</span></td></tr>
<tr><td><a name="crdb_internal.encode_key"></a><code>crdb_internal.encode_key(table_id: <a href="int.html">int</a>, index_id: <a href="int.html">int</a>, row_tuple: anyelement) &rarr; <a href="bytes.html">bytes</a></code></td><td><span class="funcdesc"><p>Generate the key for a row on a particular table and index.</p>
</span></td></tr>
<tr><td><a name="crdb_internal.force_assertion_error"></a><code>crdb_internal.force_assertion_error(msg: <a href="string.html">string</a>) &rarr; <a href="int.html">int</a></code></td><td><span class="funcdesc"><p>This function is used only by CockroachDB’s developers for testing purposes.</p>
Expand Down
7 changes: 3 additions & 4 deletions pkg/sql/join_token.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@

package sql

import "github.com/cockroachdb/cockroach/pkg/settings"
import (
"github.com/cockroachdb/cockroach/pkg/settings"
)

// FeatureTLSAutoJoinEnabled is used to enable and disable the TLS auto-join
// feature.
Expand All @@ -19,6 +21,3 @@ var FeatureTLSAutoJoinEnabled = settings.RegisterBoolSetting(
"set to true to enable tls auto join through join tokens, false to disable; default is false",
false,
)

// TODO(bilal): Implement a CREATE JOIN TOKEN statement, gated by
// FeatureTLSAutoJoinEnabled.
14 changes: 14 additions & 0 deletions pkg/sql/sem/builtins/builtins.go
Original file line number Diff line number Diff line change
Expand Up @@ -3825,6 +3825,20 @@ may increase either contention or retry errors, or both.`,
},
),

"crdb_internal.create_join_token": makeBuiltin(
tree.FunctionProperties{Category: categorySystemInfo},
tree.Overload{
Types: tree.ArgTypes{},
ReturnType: tree.FixedReturnType(types.String),
Fn: func(ctx *tree.EvalContext, args tree.Datums) (tree.Datum, error) {
// TODO(bilal): Implement this.
return nil, nil
},
Info: "Creates a join token for use when adding a new node to a secure cluster.",
Volatility: tree.VolatilityVolatile,
},
),

"crdb_internal.destroy_tenant": makeBuiltin(
tree.FunctionProperties{
Category: categoryMultiTenancy,
Expand Down

0 comments on commit 1edb088

Please sign in to comment.