Skip to content

Add Google Artifact Registry credential retrieval - #615

Draft
zaniebot wants to merge 18 commits into
mainfrom
zb/google-artifact-registry-native-auth
Draft

zaniebot wants to merge 18 commits into
mainfrom
zb/google-artifact-registry-native-auth

Conversation

@zaniebot

Copy link
Copy Markdown
Collaborator

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.

@astral-automations-bot astral-automations-bot Bot added enhancement New feature or request area:registry Related to package indexes and registries labels Aug 12, 2026
@astral-automations-bot
astral-automations-bot Bot force-pushed the zb/google-artifact-registry-native-auth branch 4 times, most recently from da9f1bf to 0d7dc0f Compare September 2, 2026 18:03
@zaniebot zaniebot added priority:3 Normal: useful features, documentation, usability, or routine efficiency improvements. size:4 Complex: architectural or security-sensitive work requiring broad or cross-repository context. risk:3 Credible risk of meaningful incorrect behavior or regression; bounded or recoverable. labels Sep 9, 2026
@zaniebot zaniebot added the build:skip-release Disable building release binaries for a pull request label Oct 7, 2026
@astral-automations-bot
astral-automations-bot Bot force-pushed the zb/google-artifact-registry-native-auth branch from 0d7dc0f to 6a5633a Compare October 7, 2026 23:03
Comment thread crates/uv-auth/src/providers.rs Outdated
Comment on lines +144 to +148
} else if let Some(path) = context
.env_var(EnvVars::XDG_CONFIG_HOME)
.filter(|path| !path.is_empty())
{
PathBuf::from(path).join("gcloud")

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[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.

Comment thread crates/uv-auth/src/providers.rs Outdated
Comment on lines +333 to +335
let token_expiry = credential
.token_expiry?
.parse::<jiff::Timestamp>()

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[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.

@codspeed

codspeed Bot commented Oct 8, 2026 •

Copy link
Copy Markdown

Merging this PR will not alter performance

⚠️ 8 benchmarks spent significant time in system calls

System calls cannot be consistently instrumented, so they are not included in the measure, which understates the real cost. Please switch to the Walltime instrument to accurately measure system calls.

Measurement and system calls

✅ 69 untouched benchmarks
⏩ 35 skipped benchmarks1


Comparing zb/google-artifact-registry-native-auth (b27781b) with main (1456bba)

Open in CodSpeed

Footnotes

  1. 35 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

@zaniebot
zaniebot deployed to automations October 9, 2026 00:23 — with GitHub Actions Active
@zaniebot
zaniebot deployed to automations October 9, 2026 00:28 — with GitHub Actions Active
Comment thread crates/uv-auth/src/providers.rs Outdated
Comment on lines +267 to +273
result
.inspect_err(|err| {
debug!(
"Failed to retrieve Google Artifact Registry Application Default Credentials: {err}"
);
})
.ok()?;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[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.

Comment thread crates/uv-auth/src/middleware.rs Outdated
Comment on lines +908 to +912
&& self
.artifact_registry_provider
.credentials_for(url)
.await
.is_some()

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[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.

@zaniebot
zaniebot deployed to automations October 9, 2026 18:27 — with GitHub Actions Active
@zaniebot
zaniebot deployed to automations October 9, 2026 18:31 — with GitHub Actions Active
Comment thread crates/uv-publish-commands/src/lib.rs Outdated
Comment on lines +384 to +386
ArtifactRegistryProvider::default()
.cache_credentials_for(&publish_url, credentials_cache)
.await?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[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.

Comment thread crates/uv-auth/src/credentials.rs Outdated
Comment on lines +670 to +674
let initial_credentials = initial_credentials.lock().await.take();
let credentials = match initial_credentials {
Some(credentials) => Some(credentials),
None => provider.credentials_for(request.url()).await?,
};

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[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.

@zaniebot
zaniebot deployed to automations October 9, 2026 19:02 — with GitHub Actions Active
@zaniebot
zaniebot deployed to automations October 9, 2026 19:08 — with GitHub Actions Active
Comment thread crates/uv-publish-commands/src/lib.rs Outdated
trusted_publishing,
keyring_provider,
&oidc_client,
&client_builder.auth_middleware(),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[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.

Comment thread crates/uv-auth/src/providers.rs Outdated
Comment on lines +38 to +41
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";

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[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.

@zaniebot
zaniebot deployed to automations October 9, 2026 19:36 — with GitHub Actions Active
Comment on lines +1442 to +1444
let middleware = AuthMiddleware::new()
.with_cache(CredentialsCache::new())
.with_artifact_registry_provider(ArtifactRegistryProvider::with_signer(

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[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.

Comment thread docs/concepts/authentication/http.md Outdated
Comment on lines +11 to +12
- Built-in authentication for supported services, such as
[Google Artifact Registry](../../guides/integration/google.md)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[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.

@zaniebot
zaniebot deployed to automations October 9, 2026 20:41 — with GitHub Actions Active
@zaniebot
zaniebot deployed to automations October 9, 2026 20:46 — with GitHub Actions Active
(publish_url, check_url)
};

let client_builder = client_builder.clone().index_locations(&index_locations)?;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[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.

@astral-automations-bot
astral-automations-bot Bot force-pushed the zb/google-artifact-registry-native-auth branch from 78b661a to b27781b Compare October 16, 2026 14:09
Comment on lines +372 to +374
if matches!(auth_policy, AuthPolicy::Never) {
return next.run(request, extensions).await;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[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.

Comment on lines +505 to +509
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#"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[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.

This branch was successfully deployed

1 active deployment
automations — b27781b8 Deployed Oct 16, 2026 by astral-automations-bot[bot] via review-code-quality / report #10582
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:registry Related to package indexes and registries build:skip-release Disable building release binaries for a pull request enhancement New feature or request priority:3 Normal: useful features, documentation, usability, or routine efficiency improvements. risk:3 Credible risk of meaningful incorrect behavior or regression; bounded or recoverable. size:4 Complex: architectural or security-sensitive work requiring broad or cross-repository context.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants