Skip to contentManaged Kafka is live: Apache Kafka on AWS for half the cost of MSK

PostgreSQL

Connect Databricks Lakebase with OAuth

Connect Artie to a Databricks Lakebase Postgres destination with OAuth. Artie signs in as a Databricks service principal, so no database password is stored.

Use this guide for a Databricks Lakebase Postgres destination when you don’t want to allow native Postgres password logins. Artie signs in as a Databricks service principal and uses a short-lived Postgres credential, so no database password is stored. For other PostgreSQL databases, or Lakebase with a password role, follow the PostgreSQL destination setup.

Databricks Lakebase OAuth works for PostgreSQL destinations only, not sources.

Prerequisites

  • A Lakebase project. Instances upgraded from Lakebase Provisioned are also supported.
  • Workspace admin access, to add a service principal and generate an OAuth secret for it.
  • A Databricks OAuth sign-in to the Lakebase database with CREATE and CREATE ROLE, such as the project owner.

1. Create a service principal

Artie signs in to Databricks as this service principal.

  1. Add the service principal

    In your Databricks workspace, go to Settings > Identity and access. Next to Service principals, select Manage, then add a service principal for Artie.

  2. Enable workspace access

    On the service principal’s Configurations tab, enable Workspace access.

    Lakebase only issues database credentials to service principals that have workspace access.

  3. Generate an OAuth secret

    On the Secrets tab, select Generate secret, then copy the client ID and the secret.

    Databricks shows the secret once. The client ID is the service principal’s application ID.

Artie requests the all-apis scope, so the secret must allow it. Before the secret expires, generate a new one and update the destination’s Client secret in Artie.

2. Create the service principal’s Postgres role

In the Lakebase App, open your project’s SQL Editor, then select the branch and the databricks_postgres database. Run this SQL while signed in with Databricks OAuth:

SQL
CREATE EXTENSION IF NOT EXISTS databricks_auth;

-- The role name is the service principal's client ID (case-sensitive).
SELECT databricks_create_role('CLIENT_ID', 'SERVICE_PRINCIPAL');

-- New OAuth roles can only log in. Allow connecting and creating the schemas Artie needs.
GRANT CONNECT, CREATE ON DATABASE databricks_postgres TO "CLIENT_ID";

-- If the target schema already exists, allow creating tables in it.
GRANT USAGE, CREATE ON SCHEMA SCHEMA_NAME TO "CLIENT_ID";

Replace CLIENT_ID with the service principal’s client ID, for example 6f1c2a7e-3b4d-4e8f-9a0b-1c2d3e4f5a6b. Replace SCHEMA_NAME with an existing schema Artie writes to, for example analytics. If you use another database, replace databricks_postgres.

Sessions that signed in with a Postgres password can’t create OAuth roles.

Artie owns the schemas and tables it creates, so it can run DDL such as ALTER TABLE on them. Lakebase doesn’t support transferring ownership with a plain ALTER ... OWNER TO, so grant access to an existing schema instead.

3. Find the connection details

In the Lakebase App, open your project’s Branches page, select the branch, and open its Computes tab. Collect these three values for the Artie connection form:

Field in ArtieWhere to find it
HostOn the compute, select Connect and copy the direct host, not the -pooler host.
EndpointIn the compute’s Get ID menu, copy the Resource name.
Workspace hostYour workspace’s hostname without https://, for example dbc-1234abcd-5678.cloud.databricks.com.

Use the direct host because Lakebase connection pooling doesn’t support OAuth roles.

The endpoint has the format projects/<project>/branches/<branch>/endpoints/<endpoint>, for example projects/my-project/branches/production/endpoints/primary. To list endpoints from the Databricks CLI instead, run this command:

Bash
databricks postgres list-endpoints projects/PROJECT_ID/branches/BRANCH_ID

Replace PROJECT_ID and BRANCH_ID with your Lakebase project and branch IDs.

4. Add the destination in Artie

Complete these steps in the pipeline setup flow in the Artie dashboard.

  1. Choose PostgreSQL

    On Choose your destination, select PostgreSQL, then select Continue.

  2. Choose a network method

    On How would you like to connect your destination?, select Allowlist Artie IPs, SSH tunnel or PrivateLink.

    PrivateLink needs an Enterprise plan. Connection options describes each method.

  3. Skip the password role SQL

    On Prepare your PostgreSQL account, select Continue.

    This step shows SQL for a password role until the destination has a client ID. You already created the OAuth role in step 2, Create the service principal’s Postgres role.

  4. Select the authentication method

    On Connect PostgreSQL, set Authentication method to Databricks Lakebase OAuth.

    The User and Password fields are replaced by Workspace host, Endpoint, Client ID and Client secret.

  5. Enter the connection details

    Enter the Host, Port 5432, Workspace host, Endpoint, Client ID and Client secret.

    Workspace host must be a bare hostname, with no https://, path or port.

  6. Choose the database and schema

    Select the database and schema Artie writes to. Use databricks_postgres as the database unless you created another one.

To edit the destination of an existing pipeline, use the same fields on the pipeline page.

Verify the connection

On Connect PostgreSQL, select Verify destination. The step shows Destination verified, and the button changes to Continue.

Verify destination needs at least one table. If you haven’t chosen tables, the button reads Test connection and checks the connection only. To continue without the check, select Verify later.

Advanced

These sections cover how Artie handles the OAuth credential, tables owned by another role, and network access.

OAuth credential refresh

Artie exchanges the client ID and secret for a workspace OAuth token. It then calls the Lakebase credentials API for a Postgres credential that’s valid for 60 minutes.

Artie caches the credential and requests a new one 5 minutes before it expires. Each new connection signs in with the cached credential.

Lakebase only checks the credential at sign-in, so open connections stay open after it expires.

Artie always connects to Lakebase over TLS.

Write to tables that another role owns

To let Artie write rows to existing tables owned by another role, grant it SELECT, INSERT, UPDATE, DELETE on them. Schema changes such as ALTER TABLE need ownership.

To move ownership to the service principal, use Lakebase’s temporary shared role procedure.

Network access

Choosing OAuth over password sign-in doesn’t change who can reach the database. Your workspace’s IP access lists, ingress policies or Private Link control network access separately.

Allow Artie’s IP addresses, or connect through PrivateLink.

With an SSH tunnel, Artie still requests OAuth tokens from the workspace host directly, not through the tunnel.

Was this page helpful?