Problem
When attempting to build a Cargo project or download a Cargo package from a Cargo repository that permits anonymous access and has the "Restrict repository content to authenticated users" option unchecked, the build can fail with an authentication related error.
Symptoms
The Cargo client will throw the following exception:
Caused by:
authenticated registries require a credential-provider to be configured
see https://doc.rust-lang.org/cargo/reference/registry-authentication.html for details
Possible causes
The Cargo client caches the config.json returned from a registry/repository under the $CARGO_HOME/registry/index/ directory, which defaults to:
- Windows: %USERPROFILE%\.cargo\registry\index
- Unix: $HOME/.cargo/registry/index
e.g. $HOME/.cargo/registry/index/localhost-4041918167e01b73/config.json
If the repository previously had the "Restrict repository content to authenticated users" option selected and later it is unselected, the Cargo client can still continue to cache the previous values containing the Cargo config key:value, "auth-required":true
Solution
Remove the $CARGO_HOME/registry/index/<registry>/config.json file or edit it and remove the "auth-required":true key:value e.g. Edit the config.json from:
{"dl":"http://localhost:8081/repository/cargo-repo/crates","api":"http://localhost:8081/repository/cargo-repo/", "auth-required":true}
To:
{"dl":"http://localhost:8081/repository/cargo-repo/crates","api":"http://localhost:8081/repository/cargo-repo/"}