dbt-databricks icon indicating copy to clipboard operation
dbt-databricks copied to clipboard

Auth token warning using oauth M2M

Open septponf opened this issue 1 year ago • 7 comments

When running dbt in an Azure Devops Agent (for continues integration reasons) I get this warning:

09:13:52  Concurrency: 6 threads (target='test')
09:13:52  
09:13:53  databricks-sql-connector adapter: Token exchange failed, using external token: %s
WARNING:databricks.sql.auth.token_federation:Token exchange failed, using external token: 'access_token'

It still works, the project runs, but I would like to understand what might be happening here. I am not able to reproduce this on my local machine using the same M2M profile. Maybe you can point me in the right direction?

Profile using an azure service principal:

    test:
      host: the_host
      http_path: the_path
      catalog: the_catalog
      schema: test
      threads: 6
      type: databricks
      auth_type: oauth
      azure_client_id: "{{ env_var('DATABRICKS_CLIENT_ID') }}"
      azure_client_secret: "{{ env_var('DATABRICKS_CLIENT_SECRET') }}"

Python 3.11.13 Running with dbt=1.10.8 Registered adapter: databricks=1.10.9

The Devops Azure Agent runs an ubuntu-24.04 Image Version: 20250929.60.1

septponf avatar Oct 30 '25 10:10 septponf

Can you please cross post this with https://github.com/databricks/databricks-sql-python?

benc-db avatar Oct 30 '25 16:10 benc-db

Can you please cross post this with https://github.com/databricks/databricks-sql-python?

There was a reply from databricks-sql-python team. Does it mean that dbt-databricks should fail silently as well, without flooding the log? Or should I change something in my setup?

septponf avatar Nov 11 '25 14:11 septponf

Hello, im also looking to see what the solution for this is, i am seeing the same error

Token exchange failed, using external token: 'access_token'

it still works but keen to understand the warning.

eugenecg avatar Dec 03 '25 06:12 eugenecg

This issue has been marked as Stale because it has been open for 180 days with no activity. If you would like the issue to remain open, please remove the stale label or comment on the issue.

github-actions[bot] avatar Jun 02 '26 02:06 github-actions[bot]

Still relevant

septponf avatar Jun 02 '26 07:06 septponf

@jprakash-db^ 👀

sd-db avatar Jun 02 '26 08:06 sd-db

Since it seems like this will never get fixed, and our CI logs are just 50% this warning over and over again, I took the time to implement a workaround on Azure DevOps, it should also work fine on Github Actions.

You can just drop this into your pipeline and it will silence the warnings.

            # We authenticate dbt with an Azure AD access token (see the AzureCLI step below).
            # databricks-sql-python (bundled with dbt-databricks) wraps every access token in a
            # token-federation provider; because the Azure AD issuer differs from the Databricks
            # host it attempts a token exchange on each connection, fails (no federation policy is
            # configured for this issuer), and falls back to the external token - which works fine.
            # The fallback is harmless but logs a WARNING on every connection, spamming the build.
            # The connector exposes no flag to disable this, so we drop the federation logger to
            # ERROR via a sitecustomize.py that every later `dbt` process auto-imports at startup.
            - script: |
                set -ex
                SITEDIR="$(Agent.TempDirectory)/pysite"
                mkdir -p "$SITEDIR"
                cat > "$SITEDIR/sitecustomize.py" << 'EOF'
                import logging
                logging.getLogger("databricks.sql.auth.token_federation").setLevel(logging.ERROR)
                EOF
                echo "##vso[task.setvariable variable=PYTHONPATH]$SITEDIR"
              displayName: Silence databricks token-federation warning

Korijn avatar Jun 29 '26 10:06 Korijn

@sd-db Any news?

lorogno avatar Aug 06 '26 22:08 lorogno

@lorogno we are looking to prioritise auth work in dbt-databricks in the coming few weeks. Will look to pick it up then

sd-db avatar Aug 13 '26 13:08 sd-db