fix: support native macOS keyring credential lookup#18776
Open
pietrodn wants to merge 1 commit intoastral-sh:mainfrom
Open
fix: support native macOS keyring credential lookup#18776pietrodn wants to merge 1 commit intoastral-sh:mainfrom
pietrodn wants to merge 1 commit intoastral-sh:mainfrom
Conversation
07c2e8b to
aa0b141
Compare
When `UV_PREVIEW_FEATURES=native-auth` is set, `uv auth login` stores credentials in the macOS Keychain keyed by service name + username. But during `uv sync`, no username is available in the request URL, because it is stored inside the keychain entry itself. So, the lookup fails if the username is not embedded in the index URL. Fix by adding `find_credential_by_service` to uv-keyring, which searches by service name alone (without an account/username), returning the first matching credential. The `fetch_native` method now falls back to this search when no username is provided.
aa0b141 to
9e384a5
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Relates to #12591 and #8810 (this comment).
Summary
When
UV_PREVIEW_FEATURES=native-authis set,uv auth loginstores credentials in the macOS Keychain keyed by service name + username. But duringuv sync, no username is available in the request URL — it's stored inside the keychain entry itself.fetch_nativereturnedNoneimmediately whenusernamewasNone, silently skipping the keychain lookup. Plaintext credential lookup works fine, so the problem is specific tonative-authon macOS.The fix adds
find_credential_by_servicetouv-keyring, using the macOSSecItemCopyMatchingAPI to search by service name alone (no account/username required), returning the first matching credential.fetch_nativenow falls back to this search when no username is provided.Test Plan
New unit test
test_find_credential_by_service_without_accountinuv-keyring:cargo test -p uv-keyring --features native-auth --lib -- test_find_credential_by_serviceAll existing keyring tests pass:
Here below I provide a manual test setup to validate the fix. It can be employed to verify the issue and the resolution even if an alternative approach is preferred.
Manual end-to-end reproduction with a local pypiserver
1. Set up a private Python index with basic auth
2. Create a test project
3. Reproduce the bug (before fix)
UV_PREVIEW_FEATURES=native-auth \ uv auth login http://localhost:8099 --username testuser --password testpass # FAILS with "Missing credentials" UV_PREVIEW_FEATURES=native-auth uv sync --no-cache4. Verify the fix (after fix)
5. Verify plaintext credentials still work
6. Cleanup
I used Claude Code to diagnose the bug and propose the fix. I reviewed all produced code manually and re-wrote the PR description in my own words, in compliance with the AI policy. Also, I tested the fix on a real-world private Python index. Let me know if something needs to be changed or if I am missing some critical context.