Skip to content

Commit bf189c5

Browse files
authored
Split the "Authentication" page into sections (#15575)
In preparation for more content for #15570
1 parent f461438 commit bf189c5

File tree

12 files changed

+221
-178
lines changed

12 files changed

+221
-178
lines changed

docs/concepts/authentication.md

Lines changed: 0 additions & 168 deletions
This file was deleted.
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# TLS certificates
2+
3+
By default, uv loads certificates from the bundled `webpki-roots` crate. The `webpki-roots` are a
4+
reliable set of trust roots from Mozilla, and including them in uv improves portability and
5+
performance (especially on macOS, where reading the system trust store incurs a significant delay).
6+
7+
## System certificates
8+
9+
In some cases, you may want to use the platform's native certificate store, especially if you're
10+
relying on a corporate trust root (e.g., for a mandatory proxy) that's included in your system's
11+
certificate store. To instruct uv to use the system's trust store, run uv with the `--native-tls`
12+
command-line flag, or set the `UV_NATIVE_TLS` environment variable to `true`.
13+
14+
## Custom certificates
15+
16+
If a direct path to the certificate is required (e.g., in CI), set the `SSL_CERT_FILE` environment
17+
variable to the path of the certificate bundle, to instruct uv to use that file instead of the
18+
system's trust store.
19+
20+
If client certificate authentication (mTLS) is desired, set the `SSL_CLIENT_CERT` environment
21+
variable to the path of the PEM formatted file containing the certificate followed by the private
22+
key.
23+
24+
## Insecure hosts
25+
26+
If you're using a setup in which you want to trust a self-signed certificate or otherwise disable
27+
certificate verification, you can instruct uv to allow insecure connections to dedicated hosts via
28+
the `allow-insecure-host` configuration option. For example, adding the following to
29+
`pyproject.toml` will allow insecure connections to `example.com`:
30+
31+
```toml
32+
[tool.uv]
33+
allow-insecure-host = ["example.com"]
34+
```
35+
36+
`allow-insecure-host` expects to receive a hostname (e.g., `localhost`) or hostname-port pair (e.g.,
37+
`localhost:8080`), and is only applicable to HTTPS connections, as HTTP connections are inherently
38+
insecure.
39+
40+
Use `allow-insecure-host` with caution and only in trusted environments, as it can expose you to
41+
security risks due to the lack of certificate verification.
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# Git credentials
2+
3+
uv allows packages to be installed from private Git repositories using SSH or HTTP authentication.
4+
5+
## SSH authentication
6+
7+
To authenticate using an SSH key, use the `ssh://` protocol:
8+
9+
- `git+ssh://git@<hostname>/...` (e.g., `git+ssh://[email protected]/astral-sh/uv`)
10+
- `git+ssh://git@<host>/...` (e.g., `git+ssh://[email protected]/astral-sh/uv`)
11+
12+
SSH authentication requires using the username `git`.
13+
14+
See the
15+
[GitHub SSH documentation](https://docs.github.com/en/authentication/connecting-to-github-with-ssh/about-ssh)
16+
for more details on how to configure SSH.
17+
18+
### HTTP authentication
19+
20+
To authenticate over HTTP Basic authentication using a password or token:
21+
22+
- `git+https://<user>:<token>@<hostname>/...` (e.g.,
23+
`git+https://git:[email protected]/astral-sh/uv`)
24+
- `git+https://<token>@<hostname>/...` (e.g., `git+https://[email protected]/astral-sh/uv`)
25+
- `git+https://<user>@<hostname>/...` (e.g., `git+https://[email protected]/astral-sh/uv`)
26+
27+
!!! note
28+
29+
When using a GitHub personal access token, the username is arbitrary. GitHub doesn't allow you to
30+
use your account name and password in URLs like this, although other hosts may.
31+
32+
If there are no credentials present in the URL and authentication is needed, the
33+
[Git credential helper](#git-credential-helpers) will be queried.
34+
35+
## Persistence of credentials
36+
37+
When using `uv add`, uv _will not_ persist Git credentials to the `pyproject.toml` or `uv.lock`.
38+
These files are often included in source control and distributions, so it is generally unsafe to
39+
include credentials in them.
40+
41+
If you have a Git credential helper configured, your credentials may be automatically persisted,
42+
resulting in successful subsequent fetches of the dependency. However, if you do not have a Git
43+
credential helper or the project is used on a machine without credentials seeded, uv will fail to
44+
fetch the dependency.
45+
46+
You _may_ force uv to persist Git credentials by passing the `--raw` option to `uv add`. However, we
47+
strongly recommend setting up a [credential helper](#git-credential-helpers) instead.
48+
49+
## Git credential helpers
50+
51+
Git credential helpers are used to store and retrieve Git credentials. See the
52+
[Git documentation](https://git-scm.com/doc/credential-helpers) to learn more.
53+
54+
If you're using GitHub, the simplest way to set up a credential helper is to
55+
[install the `gh` CLI](https://github.com/cli/cli#installation) and use:
56+
57+
```console
58+
$ gh auth login
59+
```
60+
61+
See the [`gh auth login`](https://cli.github.com/manual/gh_auth_login) documentation for more
62+
details.
63+
64+
!!! note
65+
66+
When using `gh auth login` interactively, the credential helper will be configured automatically.
67+
But when using `gh auth login --with-token`, as in the uv
68+
[GitHub Actions guide](../../guides/integration/github.md#private-repos), the
69+
[`gh auth setup-git`](https://cli.github.com/manual/gh_auth_setup-git) command will need to be
70+
run afterwards to configure the credential helper.
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# HTTP credentials
2+
3+
uv supports credentials over HTTP when querying package registries.
4+
5+
Authentication can come from the following sources, in order of precedence:
6+
7+
- The URL, e.g., `https://<user>:<password>@<hostname>/...`
8+
- A [`.netrc`](https://everything.curl.dev/usingcurl/netrc) configuration file
9+
- A [keyring](https://github.com/jaraco/keyring) provider (requires opt-in)
10+
11+
`.netrc` authentication is enabled by default, and will respect the `NETRC` environment variable if
12+
defined, falling back to `~/.netrc` if not.
13+
14+
To enable keyring-based authentication, pass the `--keyring-provider subprocess` command-line
15+
argument to uv, or set `UV_KEYRING_PROVIDER=subprocess`.
16+
17+
Authentication may be used for hosts specified in the following contexts:
18+
19+
- `[index]`
20+
- `index-url`
21+
- `extra-index-url`
22+
- `find-links`
23+
- `package @ https://...`
24+
25+
## Persistence of credentials
26+
27+
If authentication is found for a single index URL or net location (scheme, host, and port), it will
28+
be cached for the duration of the command and used for other queries to that index or net location.
29+
Authentication is not cached across invocations of uv.
30+
31+
When using `uv add`, uv _will not_ persist index credentials to the `pyproject.toml` or `uv.lock`.
32+
These files are often included in source control and distributions, so it is generally unsafe to
33+
include credentials in them. However, uv _will_ persist credentials for direct URLs, i.e.,
34+
`package @ https://username:password:example.com/foo.whl`, as there is not currently a way to
35+
otherwise provide those credentials.
36+
37+
If credentials were attached to an index URL during `uv add`, uv may fail to fetch dependencies from
38+
indexes which require authentication on subsequent operations. See the
39+
[index authentication documentation](../indexes.md#authentication) for details on persistent
40+
authentication for indexes.
41+
42+
## Learn more
43+
44+
See the [index authentication documentation](../indexes.md#authentication) for details on
45+
authenticating index URLs.
46+
47+
See the [`pip` compatibility guide](../../pip/compatibility.md#registry-authentication) for details
48+
on differences from `pip`.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Authentication
2+
3+
Authentication is required when working with private repositories or package indexes.
4+
5+
Learn more about authentication in uv:
6+
7+
- [HTTP authentication](./http.md)
8+
- [Git authentication](./git.md)
9+
- [TLS certificates](./certificates.md)
10+
- [Third-party services](./third-party.md)
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Third-party services
2+
3+
## Authentication with alternative package indexes
4+
5+
See the [alternative indexes integration guide](../../guides/integration/alternative-indexes.md) for
6+
details on authentication with popular alternative Python package indexes.
7+
8+
## Hugging Face support
9+
10+
uv supports automatic authentication for the Hugging Face Hub. Specifically, if the `HF_TOKEN`
11+
environment variable is set, uv will propagate it to requests to `huggingface.co`.
12+
13+
This is particularly useful for accessing private scripts in Hugging Face Datasets. For example, you
14+
can run the following command to execute the script `main.py` script from a private dataset:
15+
16+
```console
17+
$ HF_TOKEN=hf_... uv run https://huggingface.co/datasets/<user>/<name>/resolve/<branch>/main.py
18+
```
19+
20+
You can disable automatic Hugging Face authentication by setting the `UV_NO_HF_TOKEN=1` environment
21+
variable.

docs/concepts/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Read the concept documents to learn more about uv's features:
99
- [Package indexes](./indexes.md)
1010
- [Resolution](./resolution.md)
1111
- [The uv build backend](./build-backend.md)
12-
- [Authentication](./authentication.md)
12+
- [Authentication](./authentication/index.md)
1313
- [Caching](./cache.md)
1414
- [The pip interface](../pip/index.md)
1515

docs/concepts/indexes.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,8 @@ access to the authenticated URL at installation time.
184184
### Using credential providers
185185

186186
In addition to providing credentials directly, uv supports discovery of credentials from netrc and
187-
keyring. See the [HTTP authentication](./authentication.md#http-authentication) documentation for
188-
details on setting up specific credential providers.
187+
keyring. See the [HTTP authentication](./authentication/http.md) documentation for details on
188+
setting up specific credential providers.
189189

190190
By default, uv will attempt an unauthenticated request before querying providers. If the request
191191
fails, uv will search for credentials. If credentials are found, an authenticated request will be

docs/guides/integration/github.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -325,8 +325,8 @@ secret].
325325

326326
Then, you can use the [`gh`](https://cli.github.com/) CLI (which is installed in GitHub Actions
327327
runners by default) to configure a
328-
[credential helper for Git](../../concepts/authentication.md#git-credential-helpers) to use the PAT
329-
for queries to repositories hosted on `github.com`.
328+
[credential helper for Git](../../concepts/authentication/git.md#git-credential-helpers) to use the
329+
PAT for queries to repositories hosted on `github.com`.
330330

331331
For example, if you called your repository secret `MY_PAT`:
332332

0 commit comments

Comments
 (0)