Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jfrog CLI does not respect configured API key

I'm using Powershell DSC to set up a Windows Server 2012 R2 box. As part of the configuration process, I'm provisioning jfrog.exe and executing a configuration command as a service account:

jfrog rt config --url=$localArtifactoryInstance --user=$username --apikey=$apikey

This command creates .jfrog.jfrog-cli.conf in the service account's home directory (C:\Users\$serviceAccount.jfrog.jfrog-cli.conf) as expected, containing URL/username/apiKey.

Post-provisioning, this service account is charged with 'promoting' artifacts from one repository to another:

jfrog rt move '$devRepo/(Org)/(Org.Common.Configuration)/Org.Common.Configuration.1.0.0.nupkg' '$prodRepo/{1}/{2}/'

This command is rejected with a 401:

[Error] Artifactory response: 401 Unauthorized
{
  "errors": [
    {
      "status": 401,
      "message": "Bad authentication. Provided username or password are incorrect."
    }
  ]
}

However, when I add the same API key as is already configured in jfrog-cli.conf to the command:

jfrog rt move '$devRepo/(Org)/(Org.Common.Configuration)/Org.Common.Configuration.1.0.0.nupkg' '$prodRepo/{1}/{2}/' --ApiKey $apiKey

It is successful, and I can verify success via the Artifactory UI.

  • The service account executing the command is the same as the service account that executed jfrog rt config, and matches the username in jfrog-cli.conf.
  • The API key was generated in Artifactory for that service account
  • I have tried altering the username in jfrog-cli.conf to include and not include the domain
  • I have ensured that the environment variable 'HOME' exists and is pointed to the service account's home directory (https://github.com/JFrogDev/jfrog-cli-go/blob/master/utils/ioutils/ioutils.go seems to imply that this variable is necessary)
  • 'jfrog rt config show' shows the correct data

Thanks for any help or guidance you can supply!

like image 570
Matt Alioto Avatar asked Oct 31 '25 20:10

Matt Alioto


1 Answers

The '401 Unauthorized' response is a consequence of configuring both a username and an API key.

When running jfrog rt config, you may supply either a username/password pair or an API key. After configuring a username and api key, my commands failed since jfrog.exe was contacting the server with a username and no password.

The solution was to remove username from my Powershell DSC config entirely, and provide only url and apikey when running jfrog rt config.

like image 170
Matt Alioto Avatar answered Nov 04 '25 01:11

Matt Alioto



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!