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

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.

Related

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

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.

Maven fails to publish artifact to AWS S3

I am trying to upload a jar to S3 via gitlab CI pipeline.
On deploy stage a run a job with a script.
- mvn -s ../aws-settings.xml deploy
my aws-settings.xml file looks like this (AWS access keys are set in gitlab CI as environment variables)
<settings>
<servers>
<server>
<id>artifact-s3-repo</id>
<username>${env.AWS_ACCESS_KEY_ID}</username>
<password>${env.AWS_SECRET_ACCESS_KEY}</password>
<configuration>
<region>${env.AWS_DEFAULT_REGION}</region>
</configuration>
</server>
</servers>
</settings>
and in my pom.xml I set distribution managment as
<distributionManagement>
<repository>
<id>artifact-s3-repo</id>
<url>s3://<myartifactbucketname>/</url>
</repository>
</distributionManagement>
my pipeline fails on deploy stage with the following output
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) on project <my-project-name>: Failed to deploy artifacts/metadata: Cannot access s3://<myartifactbucketname>/ with type default using the available connector factories: BasicRepositoryConnectorFactory: Cannot access s3://<myartifactbucketname>/ using the registered transporter factories: WagonTransporterFactory: java.util.NoSuchElementException
I need some hints to configure the connection to aws properly (without adding additional plugins if possible). Thank you in advance.
I didn't manage to publish artifact to S3 via maven deploy , but I implemented AWS CLI commands in my pipeline script

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>

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