Skip to main content
This tutorial shows how to provision a for a CockroachDB CockroachDB cluster deployed in Google Cloud Platform (GCP). See also:
  • .
  • .
To create these certificates and keys, use the cockroach cert with the appropriate subcommands and flags, use openssl commands, or use a (for example, a public CA or your organizational CA).

Subcommands

SubcommandUsage
openssl genrsaCreate an RSA private key.
openssl reqCreate CA certificate and CSRs (certificate signing requests).
openssl caCreate node and client certificates using the CSRs.

Configuration files

To use openssl req and openssl ca subcommands, you need the following configuration files:
File name patternFile usage
ca.cnfCA configuration file
node.cnfServer configuration file
client.cnfClient configuration file

Certificate directory

To create node and client certificates using the OpenSSL commands, you need access to a local copy of the CA certificate and key. We recommend creating all certificates (node, client, and CA certificates), and node and client keys in one place and then distributing them appropriately. Store the CA key somewhere safe and keep a backup; if you lose it, you will not be able to add new nodes or clients to your cluster.

Required keys and certificates

Use the openssl genrsa and openssl req subcommands to create all certificates, and node and client keys in a single directory, with the files named as follows:

Node key and certificates

File name patternFile usage
ca.crtCA certificate
node.crtServer certificate
node.keyKey for server certificate

Client key and certificates

File name patternFile usage
ca.crtCA certificate.
client.<user>.crtClient certificate for <user> (for example: client.root.crt for user root).
client.<user>.keyKey for the client certificate.
Note the following:
  • The CA key should not be uploaded to the nodes and clients, so it should be created in a separate directory.
  • Keys (files ending in .key) must meet the on macOS, Linux, and other UNIX-like systems.

Examples

Step 1. Create the CA key and certificate pair

  1. Create two directories:
    • certs: Create your CA certificate and all node and client certificates and keys in this directory and then upload the relevant files to the nodes and clients.
    • my-safe-directory: Create your CA key in this directory and then reference the key when generating node and client certificates. After that, keep the key safe and secret; do not upload it to your nodes or clients.
  2. Create the ca.cnf file and copy the following configuration into it. You can set the CA certificate expiration period using the default_days parameter. We recommend using the CockroachDB default value of the CA certificate expiration period, which is 365 days.
The keyUsage and extendedkeyUsage parameters are vital for CockroachDB functions. You can modify or omit other parameters as per your preferred OpenSSL configuration and you can add additional usages, but do not omit keyUsage and extendedkeyUsage parameters or remove the listed usages.
  1. Create the CA key using the openssl genrsa command:
  2. Create the CA certificate using the openssl req command:
  3. Reset database and index files:

Step 2. Create the certificate and key pairs for nodes

In the following steps, replace the placeholder text in the code with the actual username and node address.
  1. Create the node.cnf file for the first node and copy the following configuration into it:
The subjectAltName parameter is vital for CockroachDB functions. You can modify or omit other parameters as per your preferred OpenSSL configuration, but do not omit the subjectAltName parameter.
  1. Create the key for the first node using the openssl genrsa command:
  2. Create the CSR for the first node using the openssl req command:
  3. Sign the node CSR to create the node certificate for the first node using the openssl ca command.
  4. Verify the values in the Subject Alternative Name field in the certificate:
    Sample output:

Step 3. Create the certificate and key pair for the first user

In the following steps, replace the placeholder text in the code with the actual username.
  1. Create the client.cnf file for the first user and copy the following configuration into it:
The commonName and subjectAltName parameters are vital for CockroachDB functions. You can modify or omit other parameters as per your preferred OpenSSL configuration, but do not omit the commonName parameter or modify the subjectAltName parameter.
  1. Create the key for the first client using the openssl genrsa command:
  2. Create the CSR for the first client using the openssl req command:
  3. Sign the client CSR to create the client certificate for the first client using the openssl ca command.
  4. Verify the values in the CN field in the certificate:
    Sample Output:

Step 4. Start a local cluster and connect using a connection URL

  1. Start a single-node cluster:
  2. In a new terminal window, connect to the cluster using a connection URL:
  3. Create a new SQL user:
  4. Exit the SQL shell:

Step 5. Create the certificate and key pair for a client

In the following steps, replace the placeholder text in the code with the actual username.
  1. Edit the client.cnf file for the client and copy the following configuration into it:
The commonName parameter is vital for CockroachDB functions. You can modify or omit other parameters as per your preferred OpenSSL configuration, but do not omit the commonName parameter.
  1. Create the key for the first client using the openssl genrsa command:
  2. Create the CSR for the first client using the openssl req command:
  3. Sign the client CSR to create the client certificate for the first client using the openssl ca command.
  4. Verify the values in the CN field in the certificate:
    Sample output:
  5. Connect to the SQL client using the client certificate:
For each node in your deployment, repeat Step 2 and upload the CA certificate and node key and certificate to the node. For each client, repeat Step 5 and upload the CA certificate and client key and certificate to the client. After you have uploaded all the keys and certificates to the corresponding nodes and clients, remove the .pem files in the certs directory. These files are unnecessary duplicates of the .crt files that CockroachDB requires.

See also

  • : Learn about starting a multi-node secure cluster and accessing it from a client.
  • : Learn more about the flags you pass when adding a node to a secure cluster