Apache Polaris Connection¶
The polaris connection type points at one Polaris deployment (one base URL) and says how to
authenticate to it. PolarisHook and its
subclasses turn it into authenticated clients of the official apache-polaris SDK, and can hand
the same settings to pyiceberg, Spark and Trino.
Default Connection IDs¶
Polaris hooks and operators use polaris_default by default.
How Polaris authenticates¶
Every Polaris request carries Authorization: Bearer <token> and, in multi-realm deployments,
a realm header. Each realm is configured server-side with one of three authentication types,
and the connection’s Auth Type must match how its tokens are obtained:
Server realm type |
Who issues tokens |
Connection |
|---|---|---|
|
Polaris, from its token endpoint |
|
|
An OIDC identity provider (Keycloak, Okta, Entra ID, …); Polaris’s token endpoint returns HTTP 501 |
|
|
Either |
|
any |
A token obtained outside Airflow |
|
Configuring the Connection¶
- Polaris URL (host)
Base URL of Polaris, for example
https://polaris.example.com. The scheme defaults tohttps; a path prefix is kept (https://gateway.example.com/polaris). Port is optional.- Client ID (login)
internal: the Polaris principal’s client ID.oidc: the client ID registered with the identity provider. Unused fortoken.- Client Secret or Token (password)
internal/oidc: the matching client secret.token: the bearer token itself. This is the only field that holds a secret.- Extra (optional)
A JSON dictionary. On Airflow 3.2 and later the connection form shows these as separate fields; on Airflow 3.1, enter them as JSON in Extra.
auth_type:internal(default),oidcortoken.realm: realm to send in the realm header on every Polaris request, and oninternaltoken requests (Polaris tokens are bound to a realm). Leave empty for the server’s default realm.realm_header: realm header name, defaultPolaris-Realm. Change it only if the server setspolaris.realm-context.header-name.scope:internal: the principal roles the token activates, as space-separatedPRINCIPAL_ROLE:<name>entries, defaultPRINCIPAL_ROLE:ALL. Polaris rejects token requests without a valid scope. Prefer naming roles explicitly overALL(see Least privilege).oidc: sent to the identity provider unchanged, for exampleapi://polaris/.defaultfor Entra ID. With an identity provider, the Polaris roles come from claims in the token, not from this scope.
oauth2_server_uri: token endpoint. Required foroidc(the identity provider’s endpoint). Optional forinternal, where it defaults to<host>/api/catalog/v1/oauth/tokens; override it behind a proxy or if Polaris moves the endpoint.audience,resource(oidconly): extra token-request parameters some identity providers require.client_auth_method:client_secret_basic(default, HTTP Basic header) orclient_secret_post(in the request body). Polaris accepts both; identity providers may accept only one.default_catalog: catalog used when an operator or hook call does not name one. Also used by Test Connection.verify:true(default),false, or the path to a CA bundle.catalog_path,management_path: API paths under the host, default/api/catalogand/api/management/v1. Change them only for non-standard gateways.timeout: HTTP timeout in seconds for token and API requests, default30.
Token handling¶
For internal and oidc the hook runs the OAuth2 client-credentials grant, keeps the token
in memory for the lifetime of the hook (one task), refreshes it 60 seconds (at most half its
lifetime) before it expires, and retries a call once with a fresh token if Polaris answers HTTP
401. The lifetime comes from expires_in, else the JWT exp claim, else 5 minutes. Tokens
are masked in task logs, and the hooks and operators never write them to the database or XCom.
token connections are used as-is and cannot be refreshed.
Test Connection¶
A token alone proves little: Polaris only checks the requested principal roles when the token is used. Test Connection therefore gets a token and then makes one API call:
with
default_catalog, it reads that catalog’s configuration;otherwise it lists catalogs. An HTTP 403 still counts as success: authentication worked, and the principal simply lacks the privilege to list catalogs.
Airflow 3 disables the Test button by default; enable it with [core] test_connection =
Enabled (AIRFLOW__CORE__TEST_CONNECTION=Enabled).
Troubleshooting¶
Error |
What to check |
|---|---|
Token endpoint |
|
Token endpoint |
Client ID / secret; a credentials reset invalidates the old secret immediately (a rotation keeps it valid until the next rotation) |
Token endpoint |
Client ID and secret are both set; for an identity
provider, |
Token endpoint |
The realm uses external authentication: use |
HTTP 404 |
|
HTTP 401 with a fresh token |
The principal exists in this realm and holds every
role named in |
HTTP 403 “must rotate credentials first” |
The principal was created with
|
“No catalog given, and connection … has no |
Pass |
default_catalog” |
Least privilege¶
Create one connection per role set rather than one all-powerful connection: for example a
connection with scope PRINCIPAL_ROLE:catalog_admin for provisioning Dags and one with a
read-only role for maintenance Dags. PRINCIPAL_ROLE:ALL activates every role the principal
holds.
Using the connection with engines¶
get_iceberg_catalog()returns a pyicebergRestCatalog(icebergextra) with the same auth, realm and TLS settings.get_iceberg_rest_properties()returns Iceberg REST catalog properties for Spark (engine="spark") or Trino (engine="trino"). They carry a short-lived token, never the client secret. Withinternalauth the Spark properties include the connection’s scope, so Spark’s Iceberg client keeps the token fresh through Polaris token exchange. Otherwise the properties turn the engine’s token refresh off, so the job must finish before the token expires: Polaris cannot exchange an identity provider’s token (oidc) or a static one (token), and Trino accepts a scope only together with a credential, so its properties carry the token alone.With
oidc, setscopewhen the connection also setsaudience,resource,client_secret_postor custom TLS verification: pyiceberg then sends the client secret in the request body and, without a scope, asks forcatalog, which most identity providers reject.
Warning
get_iceberg_rest_properties() contains a bearer token, and
PolarisCatalogHook.get_iceberg_catalog_properties() contains the client secret (or the
token for auth_type=token). Pass them straight to the engine or pyiceberg; do not log
them or return them from a task, since return values go to XCom.
Extras that change where requests go¶
Three extras are under the control of whoever can edit the connection, as for any Airflow
connection: verify (false disables TLS verification, a path selects a CA bundle on the
worker), oauth2_server_uri (where the token request goes) and the base URL with
catalog_path / management_path. The token endpoint only ever receives this connection’s
own credentials, and a warning is logged when verify is false. Restrict who can edit
Polaris connections as you would for any connection that holds credentials.
Examples¶
Internal authentication, JSON form (recommended, since the host is a full URL):
export AIRFLOW_CONN_POLARIS_DEFAULT='{
"conn_type": "polaris",
"host": "https://polaris.example.com",
"login": "etl-svc",
"password": "<client secret>",
"extra": {"realm": "PROD", "scope": "PRINCIPAL_ROLE:etl_writer", "default_catalog": "analytics"}
}'
External identity provider:
export AIRFLOW_CONN_POLARIS_DEFAULT='{
"conn_type": "polaris",
"host": "https://polaris.example.com",
"login": "<IdP client id>",
"password": "<IdP client secret>",
"extra": {
"auth_type": "oidc",
"oauth2_server_uri": "https://keycloak.example.com/realms/polaris/protocol/openid-connect/token",
"realm": "PROD"
}
}'
A token obtained outside Airflow:
export AIRFLOW_CONN_POLARIS_DEFAULT='{
"conn_type": "polaris",
"host": "https://polaris.example.com",
"password": "<bearer token>",
"extra": {"auth_type": "token", "realm": "PROD"}
}'
URI form:
export AIRFLOW_CONN_POLARIS_DEFAULT='polaris://etl-svc:<client secret>@polaris.example.com/?realm=PROD&scope=PRINCIPAL_ROLE%3Aetl_writer'
In URI form the host carries no scheme, so the hook uses https; use the JSON form for
http://. A path after the host (polaris://...@gateway.example.com/polaris) is the path
prefix. URL-encode reserved characters in the client secret (/, +, @, :, …), and
give extras such as verify=false as query parameters.