Skip to content

Enable system keyring integration via --keyring-provider native #14559

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jtfmumm
Copy link
Contributor

@jtfmumm jtfmumm commented Jul 11, 2025

Proof of concept integration of system keyring for credentials, using the keyring-rs crate.

This PR adds a new keyring provider backend called KeyringProviderBackend::Native and configured via --keyring-provider native. When this backend is enabled, uv auth middleware will attempt to retrieve missing credentials from the system keyring. It will also store index credentials in the system keyring upon successful authentication, enabling users to provide their credentials for an index once and successfully authenticate on future invocations.

Credentials are stored in the system keyring for a "service"/username pair. For the service, this currently prefixes the index URL with uv-credentials-. This prefix could help prevent collisions but would also be useful for determining which keyring credentials have been set by uv. Note that this is currently using the index URL instead of the index name for the service.

Left to do:

  • Building on Linux requires libdbus, which is not currently installed in CI
  • Possibly put automatic storage of credentials behind a --preview flag, unless we think it's enough that you must explicitly configure a native keyring provider (we've discussed making it the default, but that's not the behavior here)
  • Determine how best to automate testing
  • Add documentation

/// Store credentials for the given [`Url`] to the keyring if the
/// keyring provider backend is `Native`.
#[instrument(skip_all, fields(url = % url.to_string(), username))]
pub fn store_if_native(&self, url: &DisplaySafeUrl, credentials: &Credentials) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could extend this to the Python keyring as well, but for this PR I've limited the scope to the new native backend.

@@ -374,6 +397,9 @@ impl AuthMiddleware {
.as_ref()
.is_ok_and(|response| response.error_for_status_ref().is_ok())
{
if let (Some(index_url), Some(keyring)) = (index_url, &self.keyring) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is currently only storing credentials on successful authentication if this is an index URL.

@jtfmumm jtfmumm force-pushed the jtfm/keyring-exploration branch from 371fe09 to 56755c7 Compare July 11, 2025 09:20
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 this pull request may close these issues.

1 participant