To allow the Conda CLI to access Artifact Registry repositories, you must provide an authentication token with requests to Artifact Registry. This page describes how to configure authentication with an Artifact Registry Conda package repository.
Before you begin
- If you don't have a Conda repository yet, then create a Conda package repository.
- Verify that Conda is installed. If Conda isn't installed, run and install Miniforge.
- Verify that the user account or service account you are using has the required permissions to access the repository.
-
Install the Google Cloud CLI. After installation, initialize the Google Cloud CLI by running the following command:
gcloud initIf you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
- (Optional) Configure defaults for gcloud CLI commands.
Authenticate a channel with oauth tokens
A Conda channel is the address to a location where one or more Conda packages are stored. Before you can install packages in your Conda environment, you must add the channel for that package to your Conda configuration file.
To allow the Conda CLI to call Artifact Registry directly, you must authenticate your Conda channel in Google Cloud by doing the following:
In the gcloud CLI, run the following command to store the identity of an
oauthtoken in a TOKEN variable:export TOKEN="oauth2accesstoken:$(gcloud auth print-access-token)"Add your Conda repository as a channel in your Conda configuration file:
Conda
conda config --add channels \ https://$TOKEN@LOCATION-conda.pkg.dev/PROJECT/REPOSITORYMiniforge
conda config --add channels \ https://$TOKEN@LOCATION-conda.pkg.dev/PROJECT/REPOSITORYMamba
mamba config --add channels \ https://$TOKEN@LOCATION-conda.pkg.dev/PROJECT/REPOSITORYMicromamba
micromamba config --add channels \ https://$TOKEN@LOCATION-conda.pkg.dev/PROJECT/REPOSITORYWhere:
- TOKEN stores the value of the
oauthtoken generated by runningoauth2accesstoken:$(gcloud auth print-access-token). - LOCATION is the regional or multi-regional location for the repository.
- PROJECT is the ID of the project containing the repository.
- REPOSITORY is the ID of the repository.
- TOKEN stores the value of the
Refresh an expired oauth token
An oauth token expires after one hour. To re-authenticate your channel
with a new token, do the following:
Remove your channel from your configuration file:
Conda
conda config --remove channels CHANNEL_NAMEMiniforge
conda config --remove channels CHANNEL_NAMEMamba
mamba config --remove channels CHANNEL_NAMEMicromamba
micromamba config --remove channels CHANNEL_NAMEFollow the previous step that described creating a new
oauthtoken.Add your Conda repository back to your Conda configuration file, using your new token value.