set temporary token for cargo auth that the proxy will then replace#15298
Open
brettfo wants to merge 1 commit into
Open
set temporary token for cargo auth that the proxy will then replace#15298brettfo wants to merge 1 commit into
brettfo wants to merge 1 commit into
Conversation
edb2a0d to
a60503c
Compare
Contributor
There was a problem hiding this comment.
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_namesand use it to detect registries declared in.cargo/config.toml. - When
cargo_set_registry_token_authis enabled, write$CARGO_HOME/credentials.tomlwith 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
ad48f2b to
2a206e2
Compare
2a206e2 to
aa06a56
Compare
4680b1e to
614ee02
Compare
614ee02 to
b4a1b06
Compare
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>
b4a1b06 to
1547120
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
Previous PRs #14340 and #14359 have made progress on this but custom private registries still can't authenticate appropriately.
This PR addresses that by:
.cargo/config.tomlfile for custom registriesgarbage_tokenis set for those registriesCARGO_REGISTRY_GLOBAL_CREDENTIAL_PROVIDERS=cargo:tokento force Cargo tooling to use these environment variablesAuthorizationheader with the real tokenThis new behavior has been placed behind the
$DEPENDABOTenvironment variable (only set in an official run) and the feature flagcargo_set_registry_token_authwhich 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: