Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Esoteric Bug with regards to authentication via requests headers= argument being overwritten by .netrc #337

Closed
ewengillies opened this issue May 8, 2023 · 6 comments · Fixed by #338
Assignees
Labels
bug Something isn't working

Comments

@ewengillies
Copy link

Describe the bug

It's an odd one that set me back around a day: I hope to save people a similar amount of frustration.

When running a python model on an all purpose cluster, I would get this error:

10:54:28    Error getting status of cluster.
10:54:28     b'{"error_code": "403", "message": "Invalid access token."}'

despite putting a brand new token into the profiles.yml for the target corresponding all purpose cluster.

Turns out that the my .netrc file was to blame. It had an expired token for the same host:. Also turns out that the requests library overrides authentication methods passed through header= argument with the contents of the .netrc file, as stated here: https://requests.readthedocs.io/en/latest/user/authentication/#netrc-authentication

To be 100% clear, my .netrc file looked like this (replacing sensitive info below):

.netrc:

machine <my-workspace>.cloud.databricks.com
login token
password <expired_token>

My .profiles contained a target like:

all_purpose:
  type: databricks
  host: <my-workspace>.cloud.databricks.com
  http_path: <sql_path_for_all_purpose_cluster>
  catalog: <catalog>
  schema: <schema>
  token: <valid_token>
  threads: 1

Then the weird part:

Steps To Reproduce

Fairly easy to trigger:

Expected behavior

I'd expect the token provided in my profiles.yml to take precedence.

Screenshots and log output

Not needed IMO, already know the cause.

System information

Relevant versions are:

  • dbt-databricks==1.5.0
  • requests==2.28.1

Additional context

I would say the solution is to ensure the dbt-databricks code uses the auth argument instead. It seems a "bearer token" auth method doesn't come included in requests (which seems odd but okay). To this end there is a good SO solution to this: https://stackoverflow.com/a/58055668

I would also highlight that while this feels like it might only be a me problem, Databricks has lots of docs around using .netrc file, as linked before: Databricks API documentation. Doesn't seem too far-fetched someone else will fall into this trap, and its a hard one to get out of.

@ewengillies ewengillies added the bug Something isn't working label May 8, 2023
@andrefurlan-db
Copy link
Collaborator

Thanks for the bug report, we clearly missed this edge case. We'll address it soon. For the time being we'll not honour the .netrc file in dbt-databricks. Especially now with OAuth support, saving tokens locally should not be as important.

@ewengillies
Copy link
Author

Thanks for your response. I think it makes sense to ignore the .netrc file, its strange how right now its implicitly included thanks to requests.

Will look into OAuth support as well, thanks!

@susodapop
Copy link
Contributor

I've written the fix and opened #338

@benc-db
Copy link
Collaborator

benc-db commented Sep 13, 2023

Closing as fixed. If the issue still exists, please reopen.

@benc-db benc-db closed this as completed Sep 13, 2023
@lennartkats-db
Copy link
Contributor

@benc-db This issue still appears to happen as the fix wasn't merged yet, could we reopen? This issue breaks materialized views when a .netrc file is present. See #338 (comment).

@lennartkats-db
Copy link
Contributor

Btw here's a link to the bug in requests that seems to cause this issue: psf/requests#3929

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants