Repository navigation
Jwt access token auth - #747
BentsiLeviav wants to merge 8 commits into
Conversation
Pass a ClickHouse Cloud JWT to clickhouse-connect either as a static access_token or through a profile-named Python callable that the driver calls on connect and again when the server rejects the current token. HTTP driver only; combining with user/password, or using the native driver, is rejected with a clear error. Requires clickhouse-connect>=1.2.0.
Against OSS ClickHouse: the token is sent as a Bearer header and the provider is called again after a rejection. Against ClickHouse Cloud, gated on DBT_CH_TEST_ACCESS_TOKEN: dbt runs end to end with both options, including a refresh after an expired token.
|
Docs drift check: resolved, docs now match this PR's changes. |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 96228a5. Configure here.
| raise DbtConfigError( | ||
| 'Dictionary sources cannot authenticate with a JWT; set user/password for the ' | ||
| 'dictionary via the connection_overrides config.' | ||
| ) |
There was a problem hiding this comment.
Dictionary JWT guard allows empty user
Medium Severity
The new dictionary JWT check only tests whether user is present in connection_overrides, not whether a usable user (and password) is actually provided. A falsy user still passes, then the existing loop drops empty override values, so a JWT profile can create a ClickHouse dictionary with no credentials — the failure mode this guard was meant to block.
Additional Locations (1)
Reviewed by Cursor Bugbot for commit 96228a5. Configure here.
There was a problem hiding this comment.
hey @BentsiLeviav, I think the changes are good and the tests also look suitable! I have some smaller remarks below.
I think we should add the access token for ci runs, since some of the tests won't run otherwise. probably a fresh one for every new run. maybe we can leave this for a follow-up issue.
I would also think that additional documentation on this (maybe a small "jwt authentication" section) could be helpful, with suggestions where to best place the access_token_provider function, the dictionary constraints, and maybe links to additional resources for access token (provider) creation
| except (ImportError, AttributeError) as ex: | ||
| raise DbtConfigError(f'Could not import access_token_provider {path!r}: {ex}') from ex | ||
| if not callable(provider): | ||
| raise DbtConfigError(f'access_token_provider {path!r} is not callable') |
There was a problem hiding this comment.
you might also want to check whether the function is allowed to be called with zero arguments (as stated by the contract). but it's not that critical, as a wrong signature will probably raise when clickhouse-connect tries to first call it.
| from tests.integration.adapter.clickhouse import token_provider_stub | ||
|
|
||
| _CLOUD = os.environ.get('DBT_CH_TEST_CLOUD', '').lower() in ('1', 'true', 'yes') | ||
| _TOKEN = os.environ.get('DBT_CH_TEST_ACCESS_TOKEN') |
There was a problem hiding this comment.
we don't set DBT_CH_TEST_ACCESS_TOKEN anywhere, so CI wouldn't run the tests that require the token. should we add them through test_cloud.yml?
canbekley
left a comment
There was a problem hiding this comment.
@BentsiLeviav I pushed some of the changes that I noted as suggestions earlier and also added user docs. can you have a final look?
I left out the CI wiring of DBT_CH_TEST_ACCESS_TOKEN, we can follow up on this when needed.
AI review gate — Human approval in place of AI reviewApproved on the head commit by canbekley (write access, not the author), standing in for the AI review:
What to do:
Evaluated at |
| "dbt-adapters>=1.22.10,<1.25.0", # This version should be dbt-adapters<2.0, but keeping it fixed for now to avoid unexpected issues. We need to frequently update it. | ||
| # installed via dbt-adapters but used directly | ||
| "dbt-common>=1.36,<2.0", | ||
| "agate>=1.0,<2.0", |
There was a problem hiding this comment.
these are unrelated changes, not introduced with this PR but with #776. we've set them because there are direct imports from those packages
| "dbt-adapters>=1.22.0,<1.25.0", # This version should be dbt-adapters<2.0, but keeping it fixed for now to avoid unexpected issues. We need to frequently update it. | ||
| "dbt-adapters>=1.22.10,<1.25.0", # This version should be dbt-adapters<2.0, but keeping it fixed for now to avoid unexpected issues. We need to frequently update it. | ||
| # installed via dbt-adapters but used directly | ||
| "dbt-common>=1.36,<2.0", |
There was a problem hiding this comment.
Is this for the new used exception type?


Summary
Exact testing strategy TBD.
Close #745
Checklist
Delete items not relevant to your PR:
docswas updated with further explanations or tutorialsNote
Medium Risk
Changes connection authentication and profile validation on a security-sensitive path; misconfiguration is blocked early, but upgrades depend on clickhouse-connect 1.2.0+ and JWT is limited to the HTTP driver.
Overview
Adds JWT authentication for ClickHouse Cloud on the HTTP driver, so profiles can use
access_tokenoraccess_token_providerinstead ofuser/password. Static tokens are passed through toclickhouse-connect; a provider is a importable Python callable (module:functionormodule.function) that supplies a JWT on connect and again when the server rejects the token.ClickHouseCredentialsnow owns driver/port defaults (moved out ofget_db_client), validates JWT options (no mixing with password auth, http-only, token vs provider exclusivity), and resolves providers viaresolve_token_provider().ChHttpClientomitsusernamewhen using JWT, forwardsaccess_token/token_provider, and still releases dedicated connection pools on non-retryable auth failures.Dictionary models with a
clickhousesource must supplyconnection_overridesuser/password when the main profile uses JWT. Minimumclickhouse-connectis raised to 1.2.0. User docs and v2 parity notes describe setup; integration and unit tests cover wiring and Cloud runs.Reviewed by Cursor Bugbot for commit bbd7401. Bugbot is set up for automated code reviews on this repo. Configure here.