We recommend that CockroachDB Cloud Console users log in with , optionally with two-factor authentication (2FA) enabled for the SSO provider. This prevents potential attackers from using stolen credentials to access or tamper with your critical data.CockroachDB Cloud supports SSO with GitHub, Google, and Microsoft. provides additional configuration and flexibility, and includes support for OIDC or SAML protocols, autoprovisioning, and limiting the email domains that can use a given authentication method.Visit your CockroachDB Cloud Console’s account settings page and switch to SSO to improve the security of your cluster.
Provision a PKI hierarchy for SQL authentication in your cluster
There are many ways to create, manage, and distribute digital security certificates. Cockroach Labs recommends using a secure secrets server such as HashiCorp Vault, which can be used to securely generate certificates without revealing the CA private key. Refer to: Alternatively, you can generate certificates command or . However, generating certificates this way and manually handling cryptographic material comes with considerable additional risk and room for error. PKI cryptographic material related to your CockroachDB Cloud organizations, particularly in any production systems, should be handled according to a considered policy appropriate to your security goals.Initialize your Vault workstation
- Install Vault on your workstation. Your workstation must be secure to ensure the security of the PKI hierarchy you are establishing. Consider using a dedicated secure jumpbox, as described in .
-
Obtain the required parameters to target and authenticate to Vault.
- Option 1: If using a development Vault server ( suitable only for tutorial/testing purposes ), start the Vault development server and obtain your admin token locally on your CA admin jumpbox by running
vault server --dev. - Option 2: If using HashiCorp Cloud Platform (HCP):
- Go to the HCP console, choose Vault from the Services menu and then select your cluster.
- Find the Public Cluster URL for your Vault cluster. This will be set as the
VAULT_ADDRenvironment variable, in the following step. - Generate an admin token by clicking Generate token. This will be set as the
VAULT_TOKENenvironment variable, in the following step.
- Option 3: If using a Vault deployment internal to your organization, contact your Vault administrator for a token and the appropriate endpoint.
- Option 1: If using a development Vault server ( suitable only for tutorial/testing purposes ), start the Vault development server and obtain your admin token locally on your CA admin jumpbox by running
-
Initialize your shell for Vault.
-
Authenticate with your admin token.
Create the certificate authority (CA) certificate
This CA certificate will be used to configure your cluster’s Trust Store. Any client certificate signed by the CA identified by this certificate will be trusted and can authenticate to your cluster.-
Create a PKI secrets engine to serve as your client CA.
-
Generate a root credential pair for the CA. Certificates created with this CA/secrets engine will be signed with the private key generated here and held within Vault; this key cannot be exported, safeguarding it from being leaked and used to issue fraudulent certificates. The CA public certificate is downloaded in the resulting JSON payload.
Refer to: Vault documentation - PKI Secrets Engine: Setup and Usage
The public certificate can be found in the JSON file created by Vault at
.data.certificate. You can extract it, for example, using thejqutility:
On macOS, you can install
jq from Homebrew: brew install jq-
Format a public certificate JSON for upload.
Create a JSON file that includes your certificate as the value for the
x509_pem_certkey. You will use this JSON file to upload the certificate to CockroachDB Cloud. In this example, replace the certificate with the contents of your certificate.
Create a PKI role and issue credentials for the client
You can authenticate to a cluster using the private key and public certificate previously signed by the CA as long as the cluster’s trust store includes the corresponding CA.-
Define a client PKI role in Vault:
-
Create a PKI private key and public certificate for the
rootuser.
CockroachDB takes the name of the SQL user to be authenticated from the
common_name field.-
Extract the client key and certificate pair from the payload.
-
Ensure that the key file is owned by and readable only by the current user. CockroachDB will reject requests to authenticate using keys with overly-permissive permissions.
Upload a certificate authority (CA) certificate for a CockroachDB Advanced cluster
Add a CA certificate to your cluster’s trust store for client authentication. Client certificates signed using the private key corresponding to this certificate will be accepted by your cluster for certificate-based client authentication. Refer to-
Submit the asynchronous request, supplying your cluster ID, API key, and the path to the certificate JSON with your CA certificate, as described in Create the certificate authority (CA) certificate.
A
200successful response code indicates that the asynchronous request was successfully submitted, but does not guarantee that the operation (configuring the CA certificate) successfully completed. You must confirm success with a follow-upGETrequest, as described in the next step. -
Confirm success of the operation with the following
GETrequest.PENDINGindicates that the operation is still in process.IS_SETindicates that the operation completed successfully, confirming the configured public CA cert.
cockroach_client_ca_cert resource block to your Terraform template and apply the change:
Update the CA certificate for a cluster
Clients must be provisioned with client certificates signed by the cluster’s CA prior to the update, or their new connections will be blocked.
-
Submit the asynchronous request, supplying your cluster ID, API key, and the path to the certificate JSON with your CA certificate, as described in Create the certificate authority (CA) certificate.
A
200successful response code indicates that the asynchronous request was successfully submitted, but does not guarantee that the operation (configuring the CA certificate) successfully completed. You must confirm success with a follow-upGETrequest, as described in the next step. -
Confirm success of the operation with the following
GETrequest.PENDINGindicates that the operation is still in process.IS_SETindicates that the operation completed successfully, confirming the configured public CA cert.
cockroach_client_ca_cert resource block in your Terraform template, then run terraform apply.
Delete the certificate authority (CA) certificate for a cluster
This section shows how to remove the configured CA certificate from the cluster.After this operation is performed, clients can no longer authenticate with certificates signed by this CA certificate.
-
Submit the asynchronous
DELETErequest, supplying your cluster ID, API key, and the path to the certificate JSON with your CA certificate, as described in Create the certificate authority (CA) certificate. A200successful response code indicates that the asynchronous request was successfully submitted, but does not guarantee that the operation (configuring the CA certificate) successfully completed. You must confirm success with a follow-upGETrequest, as described in the next step. -
Confirm success of the operation with the following
GETrequest.PENDINGindicates that the operation is still in process.NOT_SETindicates that the operation completed successfully, confirming that no CA cert is currently set.
cockroach_client_ca_cert resource block from your Terraform template, then run terraform apply.
Authenticate a SQL client using certificate authentication
To use certificate authentication for a SQL client, you must include the filepaths to the client’s private key and public certificate. The public certificate must be signed by a CA that the cluster has been configured to trust. Refer to Upload a certificate authority (CA) certificate for a CockroachDB Advanced cluster.-
From your cluster’s overview page,
https://cockroachlabs.cloud/cluster/{ your cluster ID }, click the Connect button. - Copy the command listed under Download CA Cert and run it locally to download the required public certificate, which your client will use to verify the identity of the cluster.
-
Obtain your choice of connection string or CLI connection command for your cluster from the UI. This connection string is designed for password authentication and must be modified.
- Remove the placeholder password from the connection string.
-
Construct the full connection string by providing the paths to
sslrootcert(the cluster’s public CA certificate),sslcert(the client’s public certificate, which must be signed by the CA specified insslrootcert), andsslkey(the client’s private key). Refer to: Provision a PKI hierarchy for SQL authentication in your cluster.
-
Connect using the
cockroach sqlcommand or the SQL client of your choice:

