#12053·cube

Trino/Presto driver: per-connection credential callback (like Snowflake's prepareConnectOptions)

Author: VivekMalipatelCreated Sep 30, 2026Updated Sep 30, 2026

Is your feature request related to a problem? Please describe.

@cubejs-backend/trino-driver (through PrestoDriver) resolves user, basic_auth/custom_auth and headers once, in the constructor, and builds a single presto.Client from them. queryPromised then sends those constructor-time headers on every execute. So a Trino driver can't present a credential that changes after the driver was built.

This matters for multi-tenant deployments where each caller must query Trino as themselves:

  • contextToOrchestratorId is keyed per user, so each user gets their own driver.
  • Each caller's identity is short-lived: an OAuth/JWT bearer, and optionally per-query Trino extra credentials (X-Trino-Extra-Credential) for connectors that support user-credential-name/password-credential-name.
  • A credential resolved once at driver creation is presented again after it expires, because the driver outlives the token.

Today the only ways around this are to rebuild the driver, or to monkey-patch queryPromised.

Describe the solution you'd like

The equivalent of the Snowflake driver's prepareConnectOptions() for Trino/Presto: an async hook invoked before each query (or each client creation) that returns the auth (custom_auth / basic_auth) and extra headers to use for that request. For example, a driver option such as:

javascript
new TrinoDriver({
  credentials: async () => ({
    customAuth: `Bearer ${await currentToken()}`,
    headers: { 'X-Trino-Extra-Credential': '...' },
  }),
})

or an overridable prepareConnectOptions() method, matching SnowflakeDriver.

Describe alternatives you've considered

  • Resolving the credential in driverFactory. That fixes it at driver creation, so it goes stale when the token expires.
  • Patching PrestoDriver.prototype.queryPromised from cube.js. It works, but it depends on internals.

Additional context

Related: #7600 (Starburst connector with OAuth2 passthrough). Checked against @cubejs-backend/trino-driver and @cubejs-backend/prestodb-driver 1.7.40.