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

google.auth.default raises 404 when run from Travis with Python 3.7. #287

Closed
tswast opened this issue Aug 31, 2018 · 7 comments
Closed

google.auth.default raises 404 when run from Travis with Python 3.7. #287

tswast opened this issue Aug 31, 2018 · 7 comments
Assignees
Labels
status:awaiting information type: question Request for information or clarification. Not an issue.

Comments

@tswast
Copy link
Contributor

tswast commented Aug 31, 2018

Failed to retrieve http://metadata.google.internal/computeMetadata/v1/instance/service-accounts/default/?recursive=true from the Google Compute Enginemetadata service. Status: 404 Response

See: https://travis-ci.org/max-sixty/pandas-gbq/jobs/422752133 for googleapis/python-bigquery-pandas#206

I think this is related to the fact that Travis CI runs on GCE but it locks down access to APIs. Somehow google.auth.default() is not catching the 404.

/cc @max-sixty

@JustinBeckwith JustinBeckwith added triage me I really want to be triaged. 🚨 This issue needs some love. labels Sep 1, 2018
@tseaver tseaver added bug priority: p2 Moderately-important priority. Fix may not be included in next release. and removed 🚨 This issue needs some love. triage me I really want to be triaged. labels Oct 1, 2018
@tseaver
Copy link
Contributor

tseaver commented Oct 1, 2018

google.auth._default._get_gce_credentials and google.auth.compute_engine._metadata.ping each catch exceptions.TransportError from the request object, which is by default an instance of google.auth.transport._http_client.Request. Is pandas-gbq overriding that default?

@tseaver tseaver added question type: question Request for information or clarification. Not an issue. status:awaiting information and removed bug priority: p2 Moderately-important priority. Fix may not be included in next release. labels Oct 1, 2018
@tswast
Copy link
Contributor Author

tswast commented Oct 2, 2018

No, pandas-gbq isn't overriding anything in google-auth. I'm not sure why this error seems to only show up in Python 3.7.

@tswast
Copy link
Contributor Author

tswast commented Oct 4, 2018

Looks like this error started popping up on other versions of Python, too. https://travis-ci.org/pydata/pandas-gbq/jobs/437226967

I think the issue is that google.auth.default() can throw a google.auth.exceptions.RefreshError on Travis and that pandas-gbq is only looking for DefaultCredentialsError. Shouldn't python-google-auth catch RefreshError and re-throw as DefaultCredentialsError in this case? (Or maybe skip checking metadata server in this case and move on to the next step?)

@theacodes
Copy link
Contributor

What's the case where it throws a RefreshError?

@tswast
Copy link
Contributor Author

tswast commented Oct 8, 2018

Now that I look more closely at the stack trace, it's not google.auth.default() that's raising the RefreshError, it's when we call QueryJob._begin() in the google-cloud-bigquery client library.

I'm guessing that means somehow google.auth.default() is returning GCE credentials on Travis, but then it fails when we try to use / refresh those credentials. Travis does run on GCE, so I guess I'm not too surprised by this, but it does seem to be a somewhat new error. Maybe Travis changed their configuration and now calls to the metadata server aren't blocked anymore?

@Fryuni
Copy link

Fryuni commented Feb 16, 2019

Where did you define the default credentials?
If there are no default credentials on the environment, the library checks gcloud application default, if it is not there it checks app engine metadata endpoint and then the GCE metadata endpoint.

There is the line export SERVICE_ACCOUNT_KEY=[secure] which I think is the content of the service account key you are trying to use... right?!
If it is, add the following before you start your code (normally I would put it at the end of before_install):

echo "$SERVICE_ACCOUNT_KEY" > /tmp/credentials.json
export GOOGLE_APPLICATION_CREDENTIALS="/tmp/credentias.json"

Obviously, you can choose any path you want to store it.

The default credentials that takes precedence over all other is the environment variable GOOGLE_APPLICATION_CREDENTIALS, and it needs to point to a service account key file. If you just put the content of the key on the variable it won't work.

@tswast
Copy link
Contributor Author

tswast commented Feb 16, 2019

I should clarify, this error happens on PRs from forks (not branches), meaning the GOOGLE_APPLICATION_CREDENTIALS environment variable is not available.

I've changed several things with pandas-gbq system tests on CI since filing this bug, including migrating to CircleCI. We can close this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status:awaiting information type: question Request for information or clarification. Not an issue.
Projects
None yet
Development

No branches or pull requests

5 participants