Pipelines

Set up a service account for pipelines

Create a service account for a pipeline, give it data access, and register it in Airflow as the lakehouse connection.

A pipeline that touches the lakehouse works as a service account, not as you. You create the service account in the portal’s Identity app, give it data access in the Data Catalog, and register it in Airflow as the databaas_lakehouse connection. databaas-utils reads that connection, so no DAG ever holds a credential.

This page is the whole flow, once, for one pipeline. Every step happens in a browser.

Before you start

Prerequisite

  • The Administer platform app permission. It shows Identity in the portal sidebar’s Administration group, and opens Admin → Connections in Airflow. See the permissions reference.
  • An account in Identity that may create service users and their keys.
  • The right to grant on the warehouse or namespace the pipeline will use: Manage grants or ownership on it, or Data admin. See data permissions.

<your-databaas-domain> below is the domain you open the portal on. Identity and the catalog sit on its auth. and catalog. subdomains; step 3 needs both addresses.

1. Create the service account in Identity

  1. In the portal sidebar, open Identity under Administration.
  2. Users → Service Users → New. Name it after the pipeline it will run, for example airflow-open-meteo. Access Token Type JWT. Save.
  3. Open the new user → Keys → New → type JSON → pick an expiry → Add.
  4. The browser downloads a file once. There is no way to retrieve it again. If you lose it, delete the key and make a new one. You paste its contents into Airflow in step 3.

It looks like this:

{
  "type": "serviceaccount",
  "keyId": "391305913807408172",
  "key": "-----BEGIN RSA PRIVATE KEY-----\n…\n-----END RSA PRIVATE KEY-----\n",
  "userId": "391305903103544364"
}

Do not use a Personal Access Token. Identity offers one on the same screen, and it looks like the simpler option. It only works against Identity’s own APIs: the catalog cannot validate it and rejects it with AuthenticationFailed. Use the JSON key. databaas-utils signs a short-lived assertion with its private key and exchanges that for an access token each time a task needs one.

Copy the project ID

While you are in Identity, open Projects → Databaas and copy the project’s ID. Step 3 puts it in the connection’s scope: every token the pipeline gets must carry this project as its audience, or the catalog and Trino reject it.

2. Give it data access in the Data Catalog

The service account can authenticate, but it cannot see a single table until you grant it something.

  1. In the portal, open Data Catalog and select the namespace the pipeline owns, or the databaas-lakehouse warehouse.
  2. Open the Permissions tab and add a grant. Search for the name you gave the account in step 1; it is listed as a Service account.
  3. Grant what the pipeline needs: Select to read, Modify to write, and Create if it creates tables.
  4. Save.

Grant on the pipeline’s own namespace rather than the whole warehouse. A pipeline that can only write its own namespace cannot overwrite another team’s tables.

If the pipeline creates its own namespaces, which scoped() makes it do on every branch deploy, it needs Create one level up, on the warehouse, not only inside a namespace that does not exist yet.

See data permissions for every grant level.

3. Add the Airflow connection

This is what the DAG actually reads.

  1. In Pipelines, open Admin → Connections and add a new connection.
  2. Set Connection Type to Databaas Lakehouse first. The form then shows the lakehouse fields below.
  3. Fill in the fields in the table. Leave every other field empty; Description is optional free text.
  4. Save.
FieldValueNotes
Connection IDdatabaas_lakehouseThe id databaas-utils uses unless a DAG passes another conn_id=.
Connection TypeDatabaas LakehouseGives the labelled form below instead of a JSON blob.
Lakekeeper URLhttps://catalog.<your-databaas-domain>The full address, including https://. Not the /catalog path: a URL ending in /catalog is rejected.
Warehousedatabaas-lakehouse, or emptyEmpty means databaas-lakehouse. Set it if you granted on another warehouse in step 2.
Service account JSON keythe whole downloaded fileOpen the file from step 1 in a text editor, select everything from the first { to the last }, and paste it unchanged.
Token URLhttps://auth.<your-databaas-domain>/oauth/v2/tokenIdentity’s token endpoint. It must be the full URL, including https:// and /oauth/v2/token.
OAuth scopeopenid urn:zitadel:iam:org:project:id:<project ID>:audReplace <project ID> with the ID from step 1. This puts the project in the token’s audience.

Keep the trailing :aud

A scope without the trailing :aud gives a token the catalog accepts but Trino does not. Catalog reads and writes then work, while anything that queries through Trino, such as a dbt run, fails with 401 Invalid Audience.

Check the Token URL character by character

Airflow does not check the fields when you save. A typo in Token URL, such as a missing / before oauth, only shows up when the first task asks for a token, as a low-level connection error. Verify the connection (below) before you run a real DAG.

Paste the key from the file, never retype it. A mangled newline inside the private key fails as an unrelated-looking signature error.

4. Use it in a DAG

Nothing to install and nothing to configure. Ask for what you need and the connection is resolved behind it.

from airflow.sdk import task


@task
def write_forecast(rows: list[dict]):
    import pyarrow as pa
    from databaas_utils.airflow import get_catalog, scoped

    catalog = get_catalog()
    table = catalog.load_table(f"{scoped('open_meteo')}.forecast")
    table.append(pa.Table.from_pylist(rows, schema=table.schema().as_arrow()))

Every helper — the catalog, file stores, Zarr groups, the index and scoped() — is listed in what databaas-utils gives you. If you registered the connection under another id, pass it as conn_id=. An unresolvable connection raises ConnectionNotConfigured rather than quietly writing somewhere else.

Verifying

Airflow’s Test button for connections is turned off, so check the connection with a DAG. Add this one to your pipeline repository and trigger it once from the Airflow UI:

dags/check_lakehouse_connection.py
from airflow.sdk import dag, task


@dag(schedule=None, catchup=False)
def check_lakehouse_connection():
    @task
    def check():
        from databaas_utils.airflow import LakehouseHook

        ok, message = LakehouseHook().test_connection()
        print(message)
        if not ok:
            raise RuntimeError(message)

    check()


check_lakehouse_connection()

The check fetches a token and reads the warehouse, and reports the first link in the chain that broke: the connection fields, the token endpoint, or the warehouse. Success reads Connected to … — warehouse 'databaas-lakehouse' resolved to ….

The check talks to the catalog only, so it does not catch a missing :aud in OAuth scope. If your pipeline queries through Trino, confirm the scope against the table in step 3.

Troubleshooting

SymptomCause
AuthenticationFailed from the catalogA Personal Access Token was used instead of the JSON key. See step 1.
A connection or URL error while fetching a tokenToken URL has a typo or is not the full https://…/oauth/v2/token URL. See step 3.
service_account_key was supplied without token_urlToken URL is empty.
NoSuchWarehouseThe account has no grant on the warehouse, or Warehouse has a typo. See step 2.
403 / not authorized on a namespace or tableThe account has no grant. See step 2.
403 only when creating a namespaceThe grant is on the namespace, not the warehouse. See step 2.
401 Invalid Audience from TrinoOAuth scope lacks the trailing :aud. See step 3.
ConnectionNotConfiguredNo connection under that id. Check the id the DAG asks for as well as the one you created.
ConfigurationError: … has no hostLakekeeper URL is empty.
Signature or token errors after editing the keyThe private key’s newlines were mangled. Paste the file’s contents again.

Notes

  • One account per pipeline, not one per person. A pipeline authenticating as a person breaks when that person leaves, and its access is whatever that person happened to have rather than what the pipeline needs.
  • Keys expire. You set the expiry yourself in step 1, so put it in a calendar. To rotate: create a new key, paste it into the connection’s Service account JSON key field, then delete the old key in Identity. Step 2 does not repeat, because the account itself does not change.