Repository navigation
Conversation
da9f1bf to
0d7dc0f
Compare
0d7dc0f to
6a5633a
Compare
| } else if let Some(path) = context | ||
| .env_var(EnvVars::XDG_CONFIG_HOME) | ||
| .filter(|path| !path.is_empty()) | ||
| { | ||
| PathBuf::from(path).join("gcloud") |
There was a problem hiding this comment.
[P2] Follow Google's ADC path rules instead of XDG
On Unix with a custom XDG_CONFIG_HOME and no CLOUDSDK_CONFIG, Google still stores ADC in ~/.config/gcloud/application_default_credentials.json. I verified that both the installed SDK and google-auth ignore XDG here. This branch skips that file, potentially selecting a different active gcloud identity or failing when gcloud is unavailable. Remove the XDG override from this path calculation and update the path test to follow Google's lookup rules.
| let token_expiry = credential | ||
| .token_expiry? | ||
| .parse::<jiff::Timestamp>() |
There was a problem hiding this comment.
[P2] Accept gcloud tokens with an unspecified expiry
The SDK supports credentials without an expiry, including CLOUDSDK_AUTH_ACCESS_TOKEN and auth/access_token_file. Using an isolated SDK configuration and a synthetic token, I verified that this exact config-helper command succeeds with token_expiry: null. The ? here discards those usable credentials, so authentication fails when ADC is unavailable. Validate expiry when present, use a bounded cache policy or avoid caching when absent, and update the missing-expiry test accordingly.
Merging this PR will not alter performance
|
| result | ||
| .inspect_err(|err| { | ||
| debug!( | ||
| "Failed to retrieve Google Artifact Registry Application Default Credentials: {err}" | ||
| ); | ||
| }) | ||
| .ok()?; |
There was a problem hiding this comment.
[P3] Preserve errors from explicitly configured ADC
When GOOGLE_APPLICATION_CREDENTIALS names an unreadable or malformed file, .ok()? discards the underlying error. The provider then caches None, and publishing reports only “Missing credentials,” obscuring the configuration problem. Return a structured error for explicitly configured ADC failures and preserve its source through the authentication layer; reserve None for absent optional credentials.
| && self | ||
| .artifact_registry_provider | ||
| .credentials_for(url) | ||
| .await | ||
| .is_some() |
There was a problem hiding this comment.
[P3] Reuse the credentials fetched for the current request
For supported gcloud tokens with missing or null token_expiry, the provider uses Duration::ZERO. This availability check therefore runs credential discovery and discards the token, then Authentication::authenticate immediately repeats discovery, launching gcloud twice for the same request. Publishing adds another availability probe. Carry the fetched credentials into the pending request while retaining the refreshable provider for subsequent requests, avoiding duplicate subprocesses without caching the token indefinitely.
| ArtifactRegistryProvider::default() | ||
| .cache_credentials_for(&publish_url, credentials_cache) | ||
| .await? |
There was a problem hiding this comment.
[P2] Preserve credential precedence during publish probing
With matching netrc or uv credential-store credentials and no explicit publish username/password, this probe inserts Google authentication before either store is consulted. AuthMiddleware::handle then uses its cache fast path, so the Google identity overrides higher-priority credentials. Malformed explicit ADC can also abort publishing before valid stored credentials are checked. Have the pre-prompt probe use the middleware’s normal credential-resolution order before populating the cache.
| let initial_credentials = initial_credentials.lock().await.take(); | ||
| let credentials = match initial_credentials { | ||
| Some(credentials) => Some(credentials), | ||
| None => provider.credentials_for(request.url()).await?, | ||
| }; |
There was a problem hiding this comment.
[P2] Retain expiry when saving the initial credentials
The saved credentials have no expiry and are consumed unconditionally here. When publishing without a check URL, credential discovery happens before PublishSession::upload reads metadata and hashes the distribution. If that work outlasts the token’s remaining lifetime, the first upload sends an expired token despite the provider’s expiry-aware cache. Carry known token expiry into the saved credentials and check it before reuse, while retaining one-shot reuse for tokens with unknown expiry.
| trusted_publishing, | ||
| keyring_provider, | ||
| &oidc_client, | ||
| &client_builder.auth_middleware(), |
There was a problem hiding this comment.
[P2] Load named-index configuration before probing credentials
For uv publish --index private-registry, this builder has not loaded the index's credentials or authentication policy. UV_INDEX_PRIVATE_REGISTRY_USERNAME/PASSWORD and index-URL credentials enter the shared cache later, through RegistryClientBuilder::cache_index_credentials during check_existing. Consequently, malformed explicit ADC aborts this probe even when complete index credentials are configured. Initialize the probe from the resolved index configuration and populate its shared credential cache before calling gather_credentials.
| const GOOGLE_APPLICATION_CREDENTIALS: &str = "GOOGLE_APPLICATION_CREDENTIALS"; | ||
|
|
||
| /// The environment variable containing the path to the Google Cloud SDK configuration directory. | ||
| const GOOGLE_CLOUD_SDK_CONFIG: &str = "CLOUDSDK_CONFIG"; |
There was a problem hiding this comment.
[P3] Register Google environment variables in EnvVars
These local constants bypass the repository's environment-variable registry. EnvVars::metadata() drives the environment reference, while TestContext::new_command_with uses EnvVars::all_names() to remove host configuration from test subprocesses. The new Google configuration therefore remains undocumented by the generator and escapes that isolation. Declare both variables in uv_static::EnvVars and reuse them here and in the tests.
| let middleware = AuthMiddleware::new() | ||
| .with_cache(CredentialsCache::new()) | ||
| .with_artifact_registry_provider(ArtifactRegistryProvider::with_signer( |
There was a problem hiding this comment.
[P3] Isolate the Google provider tests from host credential stores
These tests use a real Artifact Registry hostname, but AuthMiddleware::new() leaves netrc and text-store discovery enabled. A developer's matching netrc entry takes precedence over the injected signer, causing this test to receive ambient credentials instead of test-token. Other new provider tests have the same dependency on host configuration. Use the existing .with_netrc(None) and .with_text_store(None) overrides, enabling only the explicit fixture in tests of store precedence.
| - Built-in authentication for supported services, such as | ||
| [Google Artifact Registry](../../guides/integration/google.md) |
There was a problem hiding this comment.
[P3] Document that subprocess keyring disables Google discovery
Placing built-in authentication after keyring in the precedence list implies that discovery continues when keyring returns no credentials. However, fetch_artifact_registry_credentials requires self.keyring.is_none(), and the new keyring test explicitly enforces this exclusion. Users with UV_KEYRING_PROVIDER=subprocess therefore receive no native ADC or gcloud discovery, even without a matching keyring entry. Qualify this entry and the Google guide to explain that native discovery requires the subprocess keyring provider to be disabled.
| (publish_url, check_url) | ||
| }; | ||
|
|
||
| let client_builder = client_builder.clone().index_locations(&index_locations)?; |
There was a problem hiding this comment.
[P2] Honor the index authentication policy during uploads
Loading index policies here also applies them to the upload client, which uses OnlyAuthenticated. For a publish URL covered by authenticate = "never", the new probe correctly skips discovery, but AuthMiddleware::handle then takes its only_authenticated branch and reaches fetch_credentials anyway. A normal upload can therefore read ADC or invoke gcloud despite the policy, including failing on malformed explicit ADC. Enforce Never before credential lookup in that path too. The added policy test skips its non-normalized distribution before upload, so a focused middleware regression test is needed to exercise this combination.
78b661a to
b27781b
Compare
| if matches!(auth_policy, AuthPolicy::Never) { | ||
| return next.run(request, extensions).await; | ||
| } |
There was a problem hiding this comment.
[P2] Update the existing prompt test for the new Never behavior
test_credentials_prompt_auth_policy_never configures both AuthPolicy::Never and only_authenticated, then expects a local error and zero requests. This early return instead sends the request and returns the fixture's Ok(401) response, so its expect_err assertion will panic. Update that existing test to expect the unauthenticated response and request count while retaining its check that prompting never occurs.
| uv_snapshot!(context.filters(), context.publish() | ||
| .args(["--dry-run", "--publish-url", "https://us-central1-python.pkg.dev/project/repository/"]) | ||
| .arg(dummy_wheel()) | ||
| .env(EnvVars::NETRC, context.temp_dir.child("netrc").path()) | ||
| .env(EnvVars::GOOGLE_APPLICATION_CREDENTIALS, context.temp_dir.child("credentials.json").path()), @r#" |
There was a problem hiding this comment.
[P3] Make credential precedence tests reach authentication
With --dry-run and no check URL, this test only reads distribution metadata; neither netrc nor ADC is consulted. It therefore passes even if the netrc fixture is removed or Google discovery incorrectly precedes netrc. The two new named-index credential tests similarly return at the non-normalized filename check, whose behavior already has coverage. Use the existing injected-provider or mock-server patterns to exercise credential resolution and assert the selected credentials, with normalized distributions where publishing requests are needed.
Google Artifact Registry currently requires an explicit access token or the Python keyring plugin even when Application Default Credentials or active Google Cloud SDK credentials are already available. Add a native credential provider that follows existing authentication precedence for package indexes and publishing, caches short-lived tokens, and scopes automatic authentication to Python Artifact Registry hosts. Preserve the existing subprocess keyring path; active gcloud credential discovery remains Unix-only for now. Migrated from astral-sh#19611.