Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven settings.xml with an Artifactory <server/> using SSH keys for authentication

Using the Artifacory generated maven settings I can run mvn deploy, the build completes, and artifacts are deployed successfully.

With the ability to upload a public key to Artifactory (see: https://jfrog.com/article/ssh/), I was hoping to swap out the username/password in the generated ~/.m2/settings.xml with a privateKey/passphrase pair (see: https://maven.apache.org/settings.html#Servers).

Unfortunately, switching from username/password to privateKey/passphrase I get the following "Not authorized" error:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.8.2:deploy (default-deploy) on project my-project: Failed to retrieve remote metadata com.test:my-project:1.0-SNAPSHOT/maven-metadata.xml: Could not transfer metadata com.test:my-project:1.0-SNAPSHOT/maven-metadata.xml from/to my-artifactory (https://na.artifactory.xxxx.com:443/artifactory/my-artifactory-local): Not authorized -> [Help 1]

Does Artifactory support privateKey/passphrase authentication from Maven? Or, is it possible to use something other than username/password (API Key maybe?) to allow Maven to authenticate?

like image 897
Erik Goepfert Avatar asked Oct 25 '19 14:10

Erik Goepfert


People also ask

How do I get settings xml from Artifactory?

xml file. Once you have created your Maven repository, go to Application | Artifactory | Artifacts, select your Maven repository and click Set Me Up. In the Set Me Up dialog, click Generate Maven Settings. You can now specify the repositories you want to configure for Maven.

How add SSH key to Artifactory?

In Artifactory UI, click on the user name and on Edit Profile (in the top right corner) and add your public key in the SSH Public Key (RSA) field.

Where is settings xml for Maven?

The Maven settings file, settings. xml , is usually kept in the . m2 directory inside your home directory.


1 Answers

I don't know about getting public key authentication to work with Artifactory and Maven, but at least with Artifactory 6.15.1 you can use the Artifactory API Key for your account instead of the password. In the Artifactory web UI, click on your login name to open your profile, enter your current password to unlock your profile, then copy the API Key and paste it in to the <servers> section of your Maven settings.xml, replacing ARTIFACTORY_USERNAME and ARTIFACTORY_API_KEY in the sample below:

   <servers>
       <server>
           <id>central</id>
           <username>ARTIFACTORY_USERNAME</username>
           <password>ARTIFACTORY_API_KEY</password>
       </server>
       <server>
           <id>snapshots</id>
           <username>ARTIFACTORY_USERNAME</username>
           <password>ARTIFACTORY_API_KEY</password>
       </server>
   </servers>
like image 110
Richard Neish Avatar answered Oct 06 '22 22:10

Richard Neish