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

Support for skipping ADC/using only gcloud auth? #22

Open
tfh-cri opened this issue Nov 6, 2021 · 3 comments
Open

Support for skipping ADC/using only gcloud auth? #22

tfh-cri opened this issue Nov 6, 2021 · 3 comments
Assignees

Comments

@tfh-cri
Copy link

tfh-cri commented Nov 6, 2021

As a developer, when using the plugin in conjunction with twine for uploading packages to a registry, I don't typically want to have the GOOGLE_APPLICATION_CREDENTIALS set to a local key, since I'm using gcloud auth login for most other things. And, developing on a local workstation, I don't have a reachable metadata service either.

In that usage, a typical session looks something like:

-> % twine upload --non-interactive --repository-url  https://europe-west2-python.pkg.dev/MYPROJECT/py-test-repo/ dist/somepackage-2.0.0* --verbose -c 'hello'
Uploading distributions to https://europe-west2-python.pkg.dev/MYPROJECT/py-test-repo/
  dist/somepackage-2.0.0-py3-none-any.whl (261.8 KB)
WARNING:root:Failed to retrieve Application Default Credentials: Could not automatically determine credentials. Please set GOOGLE_APPLICATION_CREDENTIALS or explicitly create credentials and re-run the application. For more information, please see https://cloud.google.com/docs/authentication/getting-started
WARNING:root:Trying to retrieve credentials from gcloud...
username set from keyring
INFO:twine.auth:username set from keyring
WARNING:google.auth.compute_engine._metadata:Compute Engine Metadata server unavailable on attempt 1 of 3. Reason: timed out
WARNING:google.auth.compute_engine._metadata:Compute Engine Metadata server unavailable on attempt 2 of 3. Reason: [Errno 113] No route to host
WARNING:google.auth.compute_engine._metadata:Compute Engine Metadata server unavailable on attempt 3 of 3. Reason: timed out
WARNING:google.auth._default:Authentication failed using Compute Engine authentication due to unavailable metadata server.
WARNING:root:Failed to retrieve Application Default Credentials: Could not automatically determine credentials. Please set GOOGLE_APPLICATION_CREDENTIALS or explicitly create credentials and re-run the application. For more information, please see https://cloud.google.com/docs/authentication/getting-started
WARNING:root:Trying to retrieve credentials from gcloud...
password set from keyring
INFO:twine.auth:password set from keyring
username: oauth2accesstoken
INFO:twine.repository:username: oauth2accesstoken
password: <hidden>
INFO:twine.repository:password: <hidden>
Uploading somepackage-2.0.0-py3-none-any.whl

Where the ADC error spam and delays checking for a metadata service somewhat hinder the usability of this approach.

If I explicitly set GOOGLE_APPLICATION_CREDENTIALS to something invalid, it appears to skip the metadata check, but still not ideal:

> % GOOGLE_APPLICATION_CREDENTIALS=/dev/null twine upload --non-interactive --repository-url  https://europe-west2-python.pkg.dev/MYPROJECT/py-test-repo/ dist/somepackage-2.0.0* --verbose -c 'hello' 
Uploading distributions to https://europe-west2-python.pkg.dev/MYPROJECT/py-test-repo/
  dist/somepackage-2.0.0-py3-none-any.whl (261.8 KB)
  dist/somepackage-2.0.0.linux-x86_64.tar.gz (148.6 KB)
  dist/somepackage-2.0.0.tar.gz (256.0 KB)
WARNING:root:Failed to retrieve Application Default Credentials: ('File /dev/null is not a valid json file.', JSONDecodeError('Expecting value: line 1 column 1 (char 0)'))
WARNING:root:Trying to retrieve credentials from gcloud...
username set from keyring
INFO:twine.auth:username set from keyring
WARNING:root:Failed to retrieve Application Default Credentials: ('File /dev/null is not a valid json file.', JSONDecodeError('Expecting value: line 1 column 1 (char 0)'))
WARNING:root:Trying to retrieve credentials from gcloud...
password set from keyring
INFO:twine.auth:password set from keyring
username: oauth2accesstoken
INFO:twine.repository:username: oauth2accesstoken
password: <hidden>
INFO:twine.repository:password: <hidden>
Uploading somepackage-2.0.0-py3-none-any.whl

I'm not sure what the best solution that doesn't compromise usability or debugging for the probably-more-common automation/CI uses, but one idea would be checking for an explicit GOOGLE_APPLICATION_CREDENTIALS value and skipping the ADC attempt if it matches (or running it but suppressing output?) I was thinking maybe /dev/null as a flag value, since it shouldn't cause any harm to any other processes if they also happen to read it and attempt ADC.

A separate env var (KEYRING_ARTIFACTREG_AUTH_GCLOUD_FIRST or something?) could also maybe work.

One final option might be checking if the supplied username is some specific value, but that relies on all the keyring-consuming apps to correctly allow for the keyring interface modifying the provided username to get_credential(), which apparently at least Twine doesn't do properly.

See fork/commit referenced below (https://github.com/camresp/artifact-registry-python-tools/tree/poc-skip-adc) for a hacky version of the various options, the 2 env-var variants work, but the username doesn't, at least with twine.

Happy to make a better PR if there's interest in one or more of the approaches.

tfh-cri added a commit to camresp/artifact-registry-python-tools that referenced this issue Nov 6, 2021
@megan-kuo megan-kuo self-assigned this Nov 23, 2021
@megan-kuo
Copy link
Contributor

Hi @tfh-cri,

Thanks for filing this issue!

We're definitely open to ideas for this feature. I'll be working on a doc that will propose the changes needed and will update this bug with more information.

@saorio
Copy link

saorio commented Nov 4, 2022

I would like to use this in GCP, so my request is to handle credentials from the metadata server.

@leoskyrocker
Copy link

In our org, we install GAR packages locally for development. It is not a good use case to use a service account in this situation because we want to be able to tell which user accessed GAR. So, we are using the gcloud's auth login instead of the application default (adc).

However, currently it slows down the pip interactions if we don't specify the adc since it retries 3 times for every GAR interaction, so this is a legitimate issue for us. Our workaround is to use the gcloud login as the ADC (so we do gcloud auth login --update-adc), but this is more like a workaround we use because of the limitation from this lib.

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

No branches or pull requests

4 participants