Skip to content

Jwt access token auth - #747

Open
BentsiLeviav wants to merge 8 commits into
mainfrom
jwt-access-token-auth
Open

BentsiLeviav wants to merge 8 commits into
mainfrom
jwt-access-token-auth

Conversation

@BentsiLeviav

@BentsiLeviav BentsiLeviav commented Sep 23, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Exact testing strategy TBD.
Close #745

Checklist

Delete items not relevant to your PR:

  • Unit and integration tests covering the common scenarios were added
  • A changelog entry was added following Updating the Changelog (user-facing, concise, PR link)
  • For significant changes, documentation in docs was updated with further explanations or tutorials

Note

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_token or access_token_provider instead of user/password. Static tokens are passed through to clickhouse-connect; a provider is a importable Python callable (module:function or module.function) that supplies a JWT on connect and again when the server rejects the token.

ClickHouseCredentials now owns driver/port defaults (moved out of get_db_client), validates JWT options (no mixing with password auth, http-only, token vs provider exclusivity), and resolves providers via resolve_token_provider(). ChHttpClient omits username when using JWT, forwards access_token/token_provider, and still releases dedicated connection pools on non-retryable auth failures.

Dictionary models with a clickhouse source must supply connection_overrides user/password when the main profile uses JWT. Minimum clickhouse-connect is 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.

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.
@workflow-authentication-public workflow-authentication-public Bot added the needs-docs PR has user-visible changes without matching docs updates label Sep 23, 2026
@workflow-authentication-public

workflow-authentication-public Bot commented Sep 23, 2026 •

Copy link
Copy Markdown

Docs drift check: resolved, docs now match this PR's changes.

@BentsiLeviav
BentsiLeviav marked this pull request as ready for review September 30, 2026 09:09
@canbekley canbekley self-assigned this Nov 23, 2026
@workflow-authentication-public workflow-authentication-public Bot removed the needs-docs PR has user-visible changes without matching docs updates label Nov 23, 2026

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

Fix All in Cursor

❌ 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.'
)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 96228a5. Configure here.

@canbekley canbekley left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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')

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread dbt/adapters/clickhouse/dbclient.py Resolved
Comment thread docs/features-and-configurations.mdx Resolved
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')

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
canbekley previously approved these changes Nov 26, 2026

@canbekley canbekley left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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.

@github-actions

github-actions Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

AI review gate — Human approval in place of AI review

Approved on the head commit by canbekley (write access, not the author), standing in for the AI review:

  • Cursor Bugbot is still reviewing this commit.

What to do:

  • Nothing to do yet if the review is running. The gate turns green when it finishes clean.
  • No review showing up? Post bugbot run as a new top-level PR comment. If that does nothing, Bugbot is probably not enabled for this repository: ask a repository administrator.

Evaluated at bbd74018. This required workflow does not re-run on its own once the AI review later concludes — check the Cursor Bugbot check on this commit directly for its current state.

Comment thread pyproject.toml
"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",

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@canbekley, what is this used for?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these are unrelated changes, not introduced with this PR but with #776. we've set them because there are direct imports from those packages

Comment thread pyproject.toml
"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",

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this for the new used exception type?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see above

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support JWT authentication (ClickHouse Cloud)

2 participants