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

OAuth breaks if a bad .netrc file is present #121

Closed
susodapop opened this issue May 11, 2023 · 0 comments · Fixed by #122
Closed

OAuth breaks if a bad .netrc file is present #121

susodapop opened this issue May 11, 2023 · 0 comments · Fixed by #122

Comments

@susodapop
Copy link
Contributor

While fixing databricks/dbt-databricks#337 I found that the same bug plagueing dbt-databricks affects pysql as well.

To reproduce this issue:

  1. Add an intentionally bad ~/.netrc to your workstation, like this:
machine <my-workspace>.cloud.databricks.com
login token
password <expired_token>
  1. Try to run the interactive_oauth.py example using the same host name specified in the .netrc file.
  2. You'll receive this exception:
    access_token = oauth_response["access_token"]
KeyError: 'access_token'

The fix

Straightforward: force requests to not use the .netrc file when making requests to Databricks OAuth endpoints. These requests are unauthenticated (no auth header is required). The bug here is that if you include an auth header in the request to https://****.staging.cloud.databricks.com/oidc/v1/token the Databricks runtime will return an error response. oauth.py looks for access_token in this response and doesn't find one, so it raises an Exception.

If .netrc is present, requests always uses it. Even for these requests that are supposed to be unauthenticated. So we need to force it to not do this.

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 a pull request may close this issue.

1 participant