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

How to set username for keyring cli based pip authorization (Azure artifacts) #2563

Closed
jenshnielsen opened this issue Mar 20, 2024 · 6 comments
Assignees
Labels
enhancement New feature or improvement to existing functionality

Comments

@jenshnielsen
Copy link

For keyring authorization to work with Azure artifacts and the keyring CLI I have to supply a default username that must be
VssSessionToken

Trying to set this for UV in the same way as I would do for pip e.g.

uv pip install --keyring-provider subprocess --index-url https://[email protected]/nameoforg/_packaging/nameoffeed/pypi/simple/ nameofpackage --verbose

results in no keyring operation probably because UV identifies the username as a password/token

DEBUG No cache entry for: https://pkgs.dev.azure.com/nameoforg/_packaging/nameoffeed/pypi/simple/nameofpackage/
DEBUG Request already has an authorization header: https://pkgs.dev.azure.com/nameoforg/_packaging/nameoffeed/pypi/simple/nameofpackage/
error: HTTP status client error (401 Unauthorized) for url (https://pkgs.dev.azure.com/nameoforg/_packaging/nameoffeed/pypi/simple/nameofpackage/)

It seems that pip supports that the form where only one part is given could be both username and a usernameless token but UV does not.

Using the default password on the other hand results in no response from keyring (can be confirmed by calling keyring directly)

uv pip install --keyring-provider subprocess --index-url https://pkgs.dev.azure.com/nameoforg/_packaging/nameoffeed/pypi/simple/ nameofpackage --verbose
DEBUG No cache entry for: https://pkgs.dev.azure.com/nameoforg/_packaging/nameoffeed/pypi/simple/nameofpackage/
DEBUG Running `keyring get` for `[https://pkgs.dev.azure.com/nameoforg/_packaging/nameoffeed/pypi/simple/nameofpackage/`](https://pkgs.dev.azure.com/nameoforg/_packaging/nameoffeed/pypi/simple/nameofpackage/%60) with username `oauth2accesstoken`
DEBUG No keyring credentials found for https://pkgs.dev.azure.com/nameoforg/_packaging/nameoffeed/pypi/simple/nameofpackage/
DEBUG No credentials found for: https://pkgs.dev.azure.com/nameoforg/_packaging/nameoffeed/pypi/simple/nameofpackage/
error: HTTP status client error (401 Unauthorized) for url (https://pkgs.dev.azure.com/nameoforg/_packaging/nameoffeed/pypi/simple/nameofpackage/)

If I manually rebuild uv with the default username changed from oauth2accesstoken to VssSessionToken everything works correctly.

Is there a different way I am supposed to embed the username?

System:
Windows 11
Python 3.12 conda env
uv 1.22

@zanieb
Copy link
Member

zanieb commented Mar 20, 2024

I think we just don't support this yet although we probably can!

Can you share the keyring invocation we are performing and the other you would prefer?

@zanieb zanieb added the enhancement New feature or improvement to existing functionality label Mar 20, 2024
@zanieb zanieb self-assigned this Mar 20, 2024
@zanieb
Copy link
Member

zanieb commented Mar 20, 2024

Okay thanks I can take a look into this unless @BakerNet is interested

@jenshnielsen
Copy link
Author

jenshnielsen commented Mar 20, 2024

Thanks @zanieb
In the first example with the username given as part of the url (but no password in the url)
no keyring invocation is triggered since UV seems to assume that the username provided in the url is a token.

In the second example you call keyring something like this (which would return None)

keyring get https://pkgs.dev.azure.com/nameoforg/_packaging/nameoffeed/pypi/simple/ oauth2accesstoken

but I would need.

keyring get https://pkgs.dev.azure.com/nameoforg/_packaging/nameoffeed/pypi/simple/ VssSessionToken 

which correctly returns a token when I call it from the commandline

@BakerNet
Copy link
Contributor

BakerNet commented Mar 20, 2024

Okay thanks I can take a look into this unless @BakerNet is interested

I know why this is happening and can work on it. It's because of the early return in the middleware when the header is already added from the URL. If there is a username in the URL, but no password, it should be checking keyring and replacing the header if found.

pip only relies on URL encoded auth if it includes a password, but uv is currently relying on it even if it only contains username.

@BakerNet
Copy link
Contributor

The PR for this has been ready for a few days (#2570 )

I don't mean to rush, just an FYI in case it wasn't clear it's ready for review.

zanieb added a commit that referenced this issue Apr 16, 2024
Closes 

- #2822 
- #2563 (via #2984)

Partially address:

- #2465
- #2464

Supersedes:

- #2947
- #2570 (via #2984)

Some significant refactors to the whole `uv-auth` crate:

- Improving the API
- Adding test coverage
- Fixing handling of URL-encoded passwords
- Fixing keyring authentication
- Updated middleware (see #2984 for more)
@zanieb
Copy link
Member

zanieb commented Apr 16, 2024

Should be resolved by #2976 and available in the next release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or improvement to existing functionality
Projects
None yet
Development

No branches or pull requests

3 participants