Skip to content

set temporary token for cargo auth that the proxy will then replace#15298

Open
brettfo wants to merge 1 commit into
mainfrom
dev/brettfo/cargo-auth
Open

set temporary token for cargo auth that the proxy will then replace#15298
brettfo wants to merge 1 commit into
mainfrom
dev/brettfo/cargo-auth

Conversation

@brettfo

@brettfo brettfo commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

Fixes #14172

Goes along with dependabot/cli#631

When custom Cargo feeds are used the proxy auto-updates the request headers appropriately, but the Cargo tooling isn't aware of this and complains with the error:

... authenticated registries require a credential-provider to be configured.

Previous PRs #14340 and #14359 have made progress on this but custom private registries still can't authenticate appropriately.

This PR addresses that by:

  1. Scanning the .cargo/config.toml file for custom registries
  2. Matches those against known credential objects
  3. Builds an environment variable hash where a custom token of garbage_token is set for those registries
  4. Sets CARGO_REGISTRY_GLOBAL_CREDENTIAL_PROVIDERS=cargo:token to force Cargo tooling to use these environment variables
  5. Calls the cargo tooling with these environment variables
  6. The proxy will then replace the Authorization header with the real token

This new behavior has been placed behind the $DEPENDABOT environment variable (only set in an official run) and the feature flag cargo_set_registry_token_auth which has yet to be created on the internal side.

Manually verified locally with the dependabot CLI and setting the experiment flag in the job file.

Future work:

  • add the new experiment flag internally

@github-actions github-actions Bot added the L: rust:cargo Rust crates via cargo label Jun 12, 2026
@brettfo brettfo force-pushed the dev/brettfo/cargo-auth branch from edb2a0d to a60503c Compare June 12, 2026 18:52
@brettfo brettfo marked this pull request as ready for review June 12, 2026 19:04
@brettfo brettfo requested a review from a team as a code owner June 12, 2026 19:04
Copilot AI review requested due to automatic review settings June 12, 2026 19:04

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the Cargo ecosystem to avoid Cargo auth errors with custom registries when Dependabot’s proxy injects credentials at request time, by configuring Cargo to accept token-based auth and by writing placeholder registry tokens into Cargo’s credentials file (behind an experiment flag).

Changes:

  • Add Dependabot::Cargo::FileFetcher.custom_registry_names and use it to detect registries declared in .cargo/config.toml.
  • When cargo_set_registry_token_auth is enabled, write $CARGO_HOME/credentials.toml with placeholder tokens for each detected custom registry.
  • Update the Cargo updater Docker image to force token auth via Cargo config.
Show a summary per file
File Description
cargo/lib/dependabot/cargo/file_fetcher.rb Adds registry-name extraction and (experiment-gated) credentials file generation for placeholder tokens.
cargo/spec/dependabot/cargo/file_fetcher_spec.rb Adds unit/spec coverage for registry extraction and credentials writing behavior under the experiment flag.
cargo/Dockerfile Attempts to force Cargo token auth in the updater image.

Copilot's findings

  • Files reviewed: 3/3 changed files
  • Comments generated: 3

Comment thread cargo/lib/dependabot/cargo/file_fetcher.rb Outdated
Comment thread cargo/lib/dependabot/cargo/file_fetcher.rb Outdated
Comment thread cargo/Dockerfile Outdated
@brettfo brettfo force-pushed the dev/brettfo/cargo-auth branch 7 times, most recently from ad48f2b to 2a206e2 Compare June 16, 2026 17:02
Comment thread cargo/lib/dependabot/cargo/file_fetcher.rb Fixed
@brettfo brettfo force-pushed the dev/brettfo/cargo-auth branch from 2a206e2 to aa06a56 Compare June 16, 2026 17:46
@brettfo brettfo marked this pull request as draft June 18, 2026 18:21
@brettfo brettfo force-pushed the dev/brettfo/cargo-auth branch 6 times, most recently from 4680b1e to 614ee02 Compare June 18, 2026 19:21
@brettfo brettfo marked this pull request as ready for review June 18, 2026 19:38
@brettfo brettfo requested a review from Copilot June 18, 2026 19:39

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot's findings

  • Files reviewed: 4/4 changed files
  • Comments generated: 4

Comment thread cargo/lib/dependabot/cargo/helpers.rb
Comment thread cargo/lib/dependabot/cargo/helpers.rb Outdated
Comment thread cargo/lib/dependabot/cargo/helpers.rb
Comment thread cargo/lib/dependabot/cargo/file_updater/lockfile_updater.rb
@brettfo brettfo force-pushed the dev/brettfo/cargo-auth branch from 614ee02 to b4a1b06 Compare June 18, 2026 19:51
Add Helpers.cargo_command_env which builds the complete environment
variable hash for running cargo commands:

1. Sets CARGO_REGISTRIES_{NAME}_TOKEN=garbage_token for each custom
   registry whose index URL matches a known credential
2. Merges real CARGO_REGISTRY* vars from the process environment
3. Sets CARGO_REGISTRY_GLOBAL_CREDENTIAL_PROVIDERS=cargo:token

The proxy replaces the garbage tokens with real credentials at runtime.
Both lockfile_updater and version_resolver now use this shared helper.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@brettfo brettfo force-pushed the dev/brettfo/cargo-auth branch from b4a1b06 to 1547120 Compare June 18, 2026 20:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

L: rust:cargo Rust crates via cargo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CodeArtifact authentication works, but token is not available to cargo credential-provider

3 participants