Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

document using the postgresql dynamic secret with cockroachdb

Dimitris Staratzis8b834e68ae68
diff --git a/docs/.vale/styles/config/vocabularies/Infisical/canonical/accept.txt b/docs/.vale/styles/config/vocabularies/Infisical/canonical/accept.txt
index bc249a9937..a31f158e85 100644
--- a/docs/.vale/styles/config/vocabularies/Infisical/canonical/accept.txt
+++ b/docs/.vale/styles/config/vocabularies/Infisical/canonical/accept.txt
@@ -336,6 +336,7 @@ Patroni
# --- Databases ---
PostgreSQL
MySQL
+CockroachDB
MongoDB
MongoDB Atlas
Redis
diff --git a/docs/documentation/platform/dynamic-secrets/postgresql.mdx b/docs/documentation/platform/dynamic-secrets/postgresql.mdx
index 3876426b55..1a5684082e 100644
--- a/docs/documentation/platform/dynamic-secrets/postgresql.mdx
+++ b/docs/documentation/platform/dynamic-secrets/postgresql.mdx
@@ -1,13 +1,15 @@
---
title: "PostgreSQL dynamic secrets"
sidebarTitle: "PostgreSQL"
-description: "Learn how to dynamically generate PostgreSQL database users."
+description: "Learn how to dynamically generate PostgreSQL and CockroachDB database users."
---
import DynamicSecretUsernameTemplateParamField from "/snippets/documentation/platform/dynamic-secrets/dynamic-secret-username-template-field.mdx";
The Infisical PostgreSQL dynamic secret allows you to generate PostgreSQL database credentials on demand based on configured role.
+You can also use this dynamic secret with CockroachDB, as described in [Use with CockroachDB](#use-with-cockroachdb).
+
## Prerequisite
Create a user with the required permission in your SQL instance. This user will be used to create new accounts on-demand.
@@ -66,7 +68,7 @@ Create a user with the required permission in your SQL instance. This user will
Name of the database for which you want to create dynamic secrets
</ParamField>
- <ParamField path="CA(SSL)" type="string">
+ <ParamField path="CA (SSL)" type="string">
A CA may be required if your DB requires it for incoming connections. AWS RDS instances with default settings will requires a CA which can be downloaded [here](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/UsingWithRDS.SSL.html#UsingWithRDS.SSL.CertificatesAllRegions).
</ParamField>
@@ -116,6 +118,39 @@ Create a user with the required permission in your SQL instance. This user will
</Step>
</Steps>
+## Use with CockroachDB
+
+CockroachDB accepts PostgreSQL connections, so you can follow the [PostgreSQL setup steps](#set-up-dynamic-secrets-with-postgresql) with these settings:
+
+- **Service**: select **PostgreSQL**
+- **Port**: your cluster's SQL port (`26257` by default)
+- **CA (SSL)**: your cluster's CA certificate, such as `ca.crt` from the cluster's certificates directory (required, because CockroachDB refuses unencrypted connections)
+
+### Admin user privileges
+
+Infisical uses the user you enter in **User** to create a database user for each lease and grant it access to your tables. To give that user the privileges it needs, connect to the database in **Database Name** as a CockroachDB admin and run:
+
+```sql
+ALTER USER <admin-user> WITH CREATEROLE CREATELOGIN;
+GRANT ALL ON ALL TABLES IN SCHEMA public TO <admin-user> WITH GRANT OPTION;
+```
+
+If your creation statement grants fewer privileges, such as only `SELECT`, replace `ALL` with those privileges in the `GRANT` statement.
+
+### SQL statements
+
+Add `SET autocommit_before_ddl = false;` as the first line of **Creation Statement**:
+
+```sql
+SET autocommit_before_ddl = false;
+CREATE USER "{{username}}" WITH ENCRYPTED PASSWORD '{{password}}' VALID UNTIL '{{expiration}}';
+GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO "{{username}}";
+```
+
+Without that line, CockroachDB can commit `CREATE USER` before it runs `GRANT`, so if `GRANT` fails, the new user stays in your cluster with no lease you can revoke.
+
+**Renew Statement** and **Revocation Statement** work on CockroachDB without changes.
+
## Audit or revoke leases
Once you have created one or more leases, you'll be able to access them by selecting the respective dynamic secret item on the dashboard.
This will allow you to see the expiration time of the lease or delete the lease before it's set time to live.