ARTIFACTORY: Configure Cargo Remote Repository

AuthorFullName__c
Md Mohsin Ali
articleNumber
000006135
FirstPublishedDate
2024-07-02T08:39:42Z
lastModifiedDate
2025-05-23

ARTIFACTORY: Configure Cargo Remote Repository

Artifactory’s Cargo remote repository is used to proxy crates.io to resolve Rust packages. This article includes detailed steps to configure Artifactory’s Cargo remote repository with a cargo client that will enable the Cargo client to authenticate against Artifactory to resolve remote cargo packages.

Prerequisites
Step 1: In Artifactory
  • Create a Cargo remote repository by logging in as Administrator
    • Administration Panel => Repositories => Repositories.
  • On the top right corner of the Repositories UI, 
    • Click Add  Repositories => Remote Repository

User-added image

User-added image

  • After creating the Cargo remote repository, we need to configure it with our cargo client to start resolving cargo packages. To do that, Navigate to Application Panel => Artifactory => Artifacts => Search for [repoName] and Click Set Me Up.

User-added image
 

  • You will be prompted to enter your password.
    • Upon successful authentication, the configuration will be generated. 
    • Copy the generated configuration


Below is a sample configuration:

# Makes artifactory the default registry and saves passing --registry parameter
[registry]
default = "artifactory"

[registries.artifactory]
index = "sparse+https://<artURL>/artifactory/api/cargo/<repoName>/index/"

# Add these 2 sections for resolving dependencies from Artifactory
[source.artifactory-remote]
registry = "sparse+https://<artURL>/artifactory/api/cargo/<repoName>/index/"

[source.crates-io]
replace-with = "artifactory-remote"
Step 2: In cargo
  • Paste the copied configuration in the config.toml file, which generally is under ~/.cargo/config.toml (if not present, create one)
  • Perform cargo login as it will authenticate the cargo client against Artifactory
  • You will be asked to enter the Token that was generated in the Set Me Up section (Attached is the screenshot for reference). 

User-added image
Paste the token. Ex: Bearer <token>

$ cargo login
    Updating `artifactory` index
please paste the token found on https://crates.io/me below
Bearer <Token>
       Login token for `artifactory` saved


NOTE: For the latest versions of the cargo client, it is required to add the below line within the config.toml file to authenticate against Artifactory

[registry]
global-credential-providers = ["cargo:token"]
  • After successful login, we can start resolving cargo packages as below.
$ cargo add ratatui 
    Updating `artifactory-remote` index
      Adding ratatui v0.26.1 to dependencies.
             Features:
             + crossterm
             + underline-color
             - all-widgets
             - document-features
             - macros
             - serde
             - termion
             - termwiz
             - unstable
             - unstable-rendered-line-info
             - unstable-widget-ref
             - widget-calendar
    Updating `artifactory-remote` index
Debugging common cargo-remote issues:
  • 401 while resolving Cargo packages:
    • This generally indicates that you are not Authorized or the token provided during login is expired. In such case, perform cargo login against the cargo-remote repository with a newly generated token and it should fix the issue.
    • If the issue persists, enable the “Anonymous download & search” option under the cargo-remote repository configuration. 
      • NOTE: enabling Anonymous download & search will by-pass authentication

User-added image
 

  • Package versions are not matching upstream i.e outdated packages being served from Artifactory:
    • To fix this, perform ‘Zap Cache’ which will force Artifactory to update the existing metadata files from upstream.
    • If the package versions are still not updated, then clear the content of the cargo-remote-cache repository, this will remove all the previously cached packages/metadata, thus fixing the version issue.
  • 400/404/500 errors while resolving packages:
    • These errors/issues can happen due to multiple reasons but the popular ones are: the Artifactory server is unable to connect to the upstream, the Requested package/version is not available on the upstream & Artifactory cargo-remote repository is not configured correctly. Thus, verifying the connection, package/version & configuration can help in solving the issue.
Related links