Skip to content

Add uv auth commands (login, logout, and token)#15539

Merged
zanieb merged 32 commits intofeature/authfrom
zb/uv-auth-ii
Aug 28, 2025
Merged

Add uv auth commands (login, logout, and token)#15539
zanieb merged 32 commits intofeature/authfrom
zb/uv-auth-ii

Conversation

@zanieb
Copy link
Member

@zanieb zanieb commented Aug 26, 2025

Picks up the work from

There are some high-level changes from those pull requests

  1. We do not stash seen credentials in the keyring automatically, that can be future work
  2. We use auth login and auth logout (for future consistency)
  3. We add a token command for showing the credential that will be used

As well as many smaller changes to API, messaging, testing, etc.

@zanieb zanieb temporarily deployed to uv-test-registries August 26, 2025 17:22 — with GitHub Actions Inactive
@zanieb zanieb temporarily deployed to uv-test-registries August 27, 2025 14:11 — with GitHub Actions Inactive
@zanieb zanieb temporarily deployed to uv-test-registries August 27, 2025 15:51 — with GitHub Actions Inactive
@zanieb zanieb changed the title Add uv auth commands (login, logout, and show) Add uv auth commands (login, logout, and token) Aug 27, 2025
KeyringProviderType::Native
);
}
};
Copy link
Member

Choose a reason for hiding this comment

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

Do we need to enable users to specify a keyring provider type on a per-URL basis? Like, would it ever be the case that a user wants to use (e.g.) the AWS keyring plugin via subprocess, but then store credentials for some URLs via the native plugin? (This is, in a vague way, coming from me being confused that --keyring-provider is respected here at all, since it only ever works for native.)

Copy link
Member Author

Choose a reason for hiding this comment

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

(This is, in a vague way, coming from me being confused that --keyring-provider is respected here at all, since it only ever works for native.)

I think we actually can support the subprocess keyring here — I just didn't want to add support for that yet.

Do we need to enable users to specify a keyring provider type on a per-URL basis? Like, would it ever be the case that a user wants to use (e.g.) the AWS keyring plugin via subprocess, but then store credentials for some URLs via the native plugin?

This is probably a realistic use-case, yeah. I think we'd need to add a concept like keyring-provider-service which maps a service URL to a keyring provider.

// FIXME: It would be preferable to accept the value of --password or --token
// from stdin, perhaps checking here for `-` as an indicator to read stdin. We
// could then warn if the password is provided as a plaintext argument.
let password = if let Some(password) = password {
Copy link
Member

Choose a reason for hiding this comment

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

I am also wondering if we should not accept credentials over plaintext on the CLI, hmm.

Copy link
Member Author

Choose a reason for hiding this comment

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

As in, not accept it via a CLI flag and require stdin?

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't think it's quite right to outright ban this, e.g., Git allows credentials interactively and we already allow passwords in plaintext in URLs.

}
};

let credentials = Credentials::basic(Some(username), Some(password));
Copy link
Member

Choose a reason for hiding this comment

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

Again a vague thing where I'm wondering if we should be using Credentials::Bearer for tokens, rather than basic.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah that's complicated. Our current semantics for tokens is that it's a shortcut for __token__:<token> because that's a common pattern for allowing tokens over HTTP basic authentication. This matches, e.g., the publish API we have. I think we want to allow Bearer authentication too, but I think it'd be another dimension of options?

.as_ref()
.map(|username| format!("{username}@{url}"))
.unwrap_or_else(|| url.to_string());
let username = username.unwrap_or_else(|| String::from("__token__"));
Copy link
Member

Choose a reason for hiding this comment

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

If you wanted to get fancy, you could make this Cow... Like username.map(Cow::Owned).unwrap_or(Cow::Borrowed("__token__")).

(You def don't need to do this, just thought you mind find it interesting.)

Copy link
Member Author

Choose a reason for hiding this comment

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

👍 I thought about using Cow but figured it wasn't worth the time right now.

@zanieb zanieb changed the base branch from main to feature/auth August 28, 2025 13:19
@zanieb zanieb temporarily deployed to uv-test-registries August 28, 2025 13:28 — with GitHub Actions Inactive
@zanieb zanieb marked this pull request as ready for review August 28, 2025 13:31
@zanieb zanieb merged commit 41893a6 into feature/auth Aug 28, 2025
116 checks passed
@zanieb zanieb deleted the zb/uv-auth-ii branch August 28, 2025 13:34
zanieb added a commit that referenced this pull request Aug 29, 2025
Picks up the work from

- #14559
- #14896

There are some high-level changes from those pull requests

1. We do not stash seen credentials in the keyring automatically
2. We use `auth login` and `auth logout` (for future consistency)
3. We add a `token` command for showing the credential that will be used

As well as many smaller changes to API, messaging, testing, etc.

---------

Co-authored-by: John Mumm <jtfmumm@gmail.com>
zanieb added a commit that referenced this pull request Aug 30, 2025
Picks up the work from

- #14559
- #14896

There are some high-level changes from those pull requests

1. We do not stash seen credentials in the keyring automatically
2. We use `auth login` and `auth logout` (for future consistency)
3. We add a `token` command for showing the credential that will be used

As well as many smaller changes to API, messaging, testing, etc.

---------

Co-authored-by: John Mumm <jtfmumm@gmail.com>
zanieb added a commit that referenced this pull request Aug 31, 2025
Picks up the work from

- #14559
- #14896

There are some high-level changes from those pull requests

1. We do not stash seen credentials in the keyring automatically
2. We use `auth login` and `auth logout` (for future consistency)
3. We add a `token` command for showing the credential that will be used

As well as many smaller changes to API, messaging, testing, etc.

---------

Co-authored-by: John Mumm <jtfmumm@gmail.com>
zanieb added a commit that referenced this pull request Sep 2, 2025
Picks up the work from

- #14559
- #14896

There are some high-level changes from those pull requests

1. We do not stash seen credentials in the keyring automatically
2. We use `auth login` and `auth logout` (for future consistency)
3. We add a `token` command for showing the credential that will be used

As well as many smaller changes to API, messaging, testing, etc.

---------

Co-authored-by: John Mumm <jtfmumm@gmail.com>
@zanieb zanieb mentioned this pull request Sep 3, 2025
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.

3 participants