azure-storage-wagon: Server failed to authenticate... Make sure ... Authorization header is formed correctly including the signature - azure-blob-storage

When trying to follow the instructions at this link, I am getting an authentication failure from azure-storage-wagon lib.
Here is how I configured my pom.xml :
<distributionManagement>
<snapshotRepository>
<id>my-repo-bucket-snapshot</id>
<url>http://stacctname99.blob.core.windows.net/snapshot</url>
</snapshotRepository>
<repository>
<id>my-repo-bucket-release</id>
<url>http://stacctname99.blob.core.windows.net/release</url>
</repository>
</distributionManagement>
And, in my .m2/settings.xml, I configured it like so:
<servers>
<server>
<id>my-repo-bucket-snapshot</id>
<username>stacctname99</username>
<password>XXrO5jvcWjtTcW/........MPrLIJsvb7A0Na3VK/Tg==</password>
</server>
<server>
<id>my-repo-bucket-release</id>
<username>stacctname99</username>
<password>XXrO5jvcWjtTcW/.......MPrLIJsvb7A0Na3VK/Tg==</password>
</server>
</servers>
And here is the error that I get on mvn deploy . It makes me wonder if I shouldn't use a https/http url?
[ERROR] Failed to execute goal
org.apache.maven.plugins:maven-deploy-plugin:2.8.2:deploy
(default-deploy) on project storage-wagon-poc: Failed to deploy
artifacts: Could not transfer artifact
com.st.azure:storage-wagon-poc:jar:1.0-20220518.171854-1 from/to
my-repo-bucket-snapshot
(http://stacctname99.blob.core.windows.net/snapshot):
authorization failed for
http://stacctname99.blob.core.windows.net/snapshot/com/st/azure/storage-wagon-poc/1.0-SNAPSHOT/storage-wagon-poc-1.0-20220518.171854-1.jar,
status: 403 Server failed to authenticate the request. Make sure the
value of Authorization header is formed correctly including the
signature.
NOTE1: My storage account does not require https. My storage account is public access to both blobs and container. In debug mode, this azure-storage-wagon extension does not show me the header it sends in the request. How would you troubleshoot? Do you see a typo in my setup? The GitHub repo does not allow creating a new issue.
NOTE2: The lib seems to be looking for 6 env variables: https://github.com/Azure/azure-sdk-for-java/blob/83f62af66b349c4dc663489570ad78f97dfee2b1/sdk/identity/azure-identity/src/main/java/com/azure/identity/EnvironmentCredential.java BUT I am unsure where to find some of those values since the storageapp in azure portal does not just show them to you.

Related

Configure Nexus connection for maven deployment

Im trying to gain some experience in working with Nexus and TeamCity.
To do so i set both servers up on my local machine and configured a pet project thats located on github.com in a private repo.
But i can't get my TC-Build to run because the Maven deploy step fails with following message.
[14:58:55][Step 2/2] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) on project Worm: Failed to deploy artifacts: Could not transfer artifact org.test.worm:Worm:jar:1.0.0 from/to local_nexus (http://localhost:8081/repository/org.test): Transfer failed for http://localhost:8081/repository/org.test/org/test/worm/Worm/1.0.0/Worm-1.0.0.jar 401 Unauthorized
Seems like it fails due to wrongly configured authorization but i can't find the mistake.
In my projects pom.xml it is configured like this
<distributionManagement>
<repository>
<id>local_nexus</id>
<name>Deployment</name>
<url>http://localhost:8081/repository/org.test</url>
</repository>
</distributionManagement>
and in my mavens settings.xml like this
<server>
<id>local_nexus</id>
<username>admin</username>
<password>admin</password>
</server>
Im using the default admin user (user/pw is correct, logging into nexus with the same user) that is created when installing nexus. Same user that created the repository.
TC running under localhost:8080 and Nexus under localhost:8081
Please tell me what i configured wrongly or what i forgot.
Using mvn help:effective-settings i could confirm that the settings.xml was configured correctly. But it made me realize that my TeamCity Server was using a different (its own) maven instance than my local machine. So the solution was to either set the maven-home for TeamCity or to configure the settings.xml of the other maven instance.
Stupid mistake i should have noticed way sooner.

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?
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>

s3-storage-wagon maven plugin and upload to S3 bucket

I need to upload my build artifact to S3 bucket. For this purpose, I'm trying to use s3-storage-wagon maven plugin
This is my configuration in pom.xml:
<distributionManagement>
<repository>
<id>s3.artifacts.release</id>
<url>s3://${artifactrepo.url}/release</url>
</repository>
<snapshotRepository>
<id>s3.artifacts.snapshot</id>
<url>s3://${artifactrepo.url}/snapshot</url>
</snapshotRepository>
</distributionManagement>
<extensions>
<extension>
<groupId>com.gkatzioura.maven.cloud</groupId>
<artifactId>s3-storage-wagon</artifactId>
<version>1.0</version>
</extension>
</extensions>
settings.xml
<server>
<id>s3.artifacts.release</id>
<username>Access key ID</username>
<password>Secret</password>
</server>
<server>
<id>s3.artifacts.snapshot</id>
<username>Access key ID</username>
<password>Secret</password>
</server>
During Maven deploy this plugin fails with the following error:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.8.2:deploy (default-deploy) on project pipeline: Failed to retrieve remote metadata com.xxx:xxx:0.0.4-SNAPSHOT/maven-metadata.xml: Could not transfer metadata com.xxx:xxx:0.0.4-SNAPSHOT/maven-metadata.xml from/to s3.artifacts.snapshot (s3://my-backet/snapshot): Could not authenticate: Access Denied (Service: Amazon S3; Status Code: 403; Error Code: AccessDenied; Request ID: 8KJHKHFKHFGA48; S3 Extended Request ID: 2j/bW/INn+qCzVqwer+Fawv75qwerkUPmO7flQa8z34523445werrtwertGTs919tJpYoM=) -> [Help 1]
We are using GUI S3 client for Windows and are able to access the target S3 bucket without any issue. What may be wrong with our s3-storage-wagon maven plugin configuration?
Looks like your AWS credentials for S3 do not have upload (PutObject most likely) permission. The portion of the message telling you this is:
Could not authenticate: Access Denied (Service: Amazon S3;...
Or perhaps you need to setup your ~/.aws/credentials file so that the default profile is able to access the S3 bucket you are using.
If you need to use alternate profiles (the non-default profile in your ~/.aws/credentials file) you will likely need to specify the profile using one of the many ways AWS SDKs support this. I would start by trying AWS_PROFILE=my-profile such as the following (assuming bash):
AWS_PROFILE=my-profile mvn deploy
See https://github.com/gkatzioura/CloudStorageMaven/tree/master/S3StorageWagon#authentication for further info on how to provide credentials to this plugin.

nexus-staging-maven-plugin returns 401 without information

I am working on getting Anonimatron available as libary in the central Maven Repository. In order to do that I followed the documentation in the sonatype documentation. The nexus staging plugin gives me a 401 error when running mvn deploy and I can't figure out why because it does not tell me what is going on.
I have a working account at oss.sonatype.org, and I have created a user access token there. The access token is stored in the servers section of my maven ~/.m2/settings.xml like so (token removed for reasons):
<servers>
<server>
<id>ossrh</id>
<username>USER_TOKEN</username>
<password>USER_PASSPHRASE</password>
</server>
</servers>
Then, in my maven https://github.com/realrolfje/anonimatron/blob/feature/anonimatron-as-library/pom.xml file I added the nexus staging plugin:
<distributionManagement>
<snapshotRepository>
<id>sonatype-snapshots</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
</snapshotRepository>
<repository>
<id>sonatype-release</id>
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2</url>
</repository>
</distributionManagement>
[...]
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<version>1.6.7</version>
<extensions>true</extensions>
<configuration>
<serverId>ossrh</serverId>
<nexusUrl>https://oss.sonatype.org/</nexusUrl>
<autoReleaseAfterClose>true</autoReleaseAfterClose>
</configuration>
</plugin>
When I run mvn deploy, I get the error:
[ERROR] Failed to execute goal org.sonatype.plugins:nexus-staging-maven-plugin:1.6.7:deploy (injected-nexus-deploy) on project anonimatron: Failed to deploy artifacts: Could not transfer artifact com.rolfje.anonimatron:anonimatron:jar:javadoc:1.9.3-20180512.204932-1 from/to sonatype-snapshots (https://oss.sonatype.org/content/repositories/snapshots): Failed to transfer file: https://oss.sonatype.org/content/repositories/snapshots/com/rolfje/anonimatron/anonimatron/1.9.3-SNAPSHOT/anonimatron-1.9.3-20180512.204932-1-javadoc.jar. Return code is: 401, ReasonPhrase: Unauthorized. -> [Help 1]
To check wether my token is indeed valid, I tried uploading with curl:
curl -u USER_TOKEN:USER_PASSPHRASE \
https://oss.sonatype.org/content/repositories/snapshots/com/rolfje/anonimatron/anonimatron/1.9.3-SNAPSHOT/anonimatron-1.9.3-20180512.093802-1-javadoc.jar \
--request PUT --data target/anonimatron-1.9.3-SNAPSHOT.jar
This succeeds and I can see the uploaded jar appear in the Nexus Repository Manager.
I have executed the same steps as in this question but since I have not uploaded anything yet, version numbers can not collide, although I did do a manual javadoc upload at the end. Since that is a snapshot, and it worked, I think my problem is with the nexus-staging-maven-plugin.
What I am searching for is a way to debug the nexus-staging-maven-plugin so that I know why it is failing. It does not tell me which credentials it is using, wether it loaded those from the settings.xml file, and what exact steps it is taking, even if I run mvn with -e and -X flags.
Executing a deploy with the standard maven-deploy plugin, as #khmarbaise mentioned, did seem to work. I reported this problem to sonatype as part of issues
OSSRH-39766 and OSSRH-39777.
Joel regenerated my permissions and now the nexus release plugin seems to be working. Note that this could also be caused by the maven-deploy which might have "primed" something.
All in all, the nexus release plugin could do with some improvements on the logging, particularly:
What profile is used to execute the steps
What step (exactly) is being executed
If there is a 401, tell which userid was used to execute that step and from which environment that was fetched (command line, settings.xml, etc).
I see some people struggling with the nexus plugin, while the plugin should actually make life easier.
Thanks to SonaType for the fast and helpful responses!
Add the following in your ~/.m2/settings.xml file:
<servers>
<server>
<id>ossrh</id>
<username>{YOUR_JIRA_USERNAME}</username>
<password>{YOUR_JIRA_PASSWORD}</password>
</server>
</servers>
Also, update your pom.xml:
<distributionManagement>
<snapshotRepository>
<id>ossrh</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
</snapshotRepository>
<repository>
<id>ossrh</id>
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
</repository>
</distributionManagement>
Make sure repository id and server id matches.
In this example, the id is "ossrh".
Also, note that the username and password should be same as your jira login. That's it mvn clean deploy will now upload your jar to sonatype repoditory. Happy Deploying!!

Deploy from Maven to Nexus got error: ReasonPhrase:Forbidden

http://numberformat.wordpress.com/2011/05/18/nexus-repository/
I am following the above link to setup Maven and Nexus, everything new. I couldn't left a new comment there so I post here.
After so long, I am in another company, when I tried to setup a simple sample in my local PC, I got this error in "mvn deploy" to the simple Maven my-app sample. I installed the simple Nexus Open Source w/o Tomcat.
[WARNING] Could not transfer metadata com.mycompany.app:my-app:1.0-SNAPSHOT/maven-metadata.xml from/to snapshots (localhost:8081/nexus/content/repositories/snapshots): Access denied to: localhosts:8081/nexus/content/repositories/snapshots/com/mycompany/app/my-app/1.0-SNAPSHOT/maven-metadata.xml , ReasonPhrase:Forbidden.
In your settings.xml located in MAVEN_HOME/conf you have to add in servers section
<server>
<id>nexus-releases</id>
<username>deploy</username>
<password>123456</password>
</server>
And in your pom must looks like
<distributionManagement>
<repository>
<id>nexus-releases</id>
<url>http://localhost:8081/nexus/content/repositories/releases</url>
</repository>
</distributionManagement>
Ids have to be the same.
Richard Seddon resolved my issue in nexus-users group.
Add this to nonProxyHosts:
localhost
You need to be authorized to run deployment. This is done by having the server section in your settings.xml. Check out the Nexus eval guide, specifically the publishing section and the sample projects in there for more detail.

Resources