如何使用S3作为maven repository?

w8ntj3qf  于 2024-01-06  发布在  Maven
关注(0)|答案(3)|浏览(308)

我无法将maven工件部署到S3。
即使我对存储桶具有写访问权限,也会收到“拒绝”异常。
当我运行mvn deploy -DskipTests时,我得到以下错误:

  1. Caused by: com.amazonaws.services.s3.model.AmazonS3Exception: Access Denied (Service: Amazon S3; Status Code: 403; Error Code: AccessDenied; Request ID: 5CFBE8472B760710; S3 Extended Request ID: cxvn4bs9sg2hNEZRbno2dxocwSj8i6jCSNSQtsZL2H7h2y/cY2koFhExrGv3mACLK+kfcxHfKkg=), S3 Extended Request ID: cxvn4bs9sg2hNEZRbno2dxocwSj8i6jCSNSQtsZL2H7h2y/cY2koFhExrGv3mACLK+kfcxHfKkg=
  2. at com.amazonaws.http.AmazonHttpClient$RequestExecutor.handleErrorResponse(AmazonHttpClient.java:1630)

字符串
S3请求由wagon插件触发:

  1. >> PUT /release/ HTTP/1.1
  2. >> Host: inuka-mvn-repo.s3.eu-west-1.amazonaws.com
  3. >> x-amz-content-sha256: UNSIGNED-PAYLOAD
  4. >> Authorization: AWS4-HMAC-SHA256 Credential=AKIAUMQWI47EFQZPBQW3/20191018/eu-west-1/s3/aws4_request, SignedHeaders=amz-sdk-invocation-id;amz-sdk-retry;content-length;content-type;host;user-agent;x-amz-acl;x-amz-content-sha256;x-amz-date, Signature=b20a1e2fb100eae4b70d7c0922fde9164bc7326d02074627e54d860359d8b298
  5. >> X-Amz-Date: 20191018T145734Z
  6. >> x-amz-acl: public-read
  7. >> User-Agent: aws-sdk-java/1.11.276 Mac_OS_X/10.13.6 Java_HotSpot(TM)_64-Bit_Server_VM/25.60-b23 java/1.8.0_60
  8. >> amz-sdk-invocation-id: 47ea0bcd-c021-6d48-2547-f9a276c055cd
  9. >> amz-sdk-retry: 0/0/500
  10. >> Content-Type: application/octet-stream
  11. >> Content-Length: 0
  12. >> Connection: Keep-Alive
  13. >> "PUT /release/ HTTP/1.1"
  14. >> "Host: inuka-mvn-repo.s3.eu-west-1.amazonaws.com"
  15. >> "x-amz-content-sha256: UNSIGNED-PAYLOAD"
  16. >> "Authorization: AWS4-HMAC-SHA256 Credential=AKIAUMQWI47EFQZPBQW3/20191018/eu-west-1/s3/aws4_request, SignedHeaders=amz-sdk-invocation-id;amz-sdk-retry;content-length;content-type;host;user-agent;x-amz-acl;x-amz-content-sha256;x-amz-date, Signature=b20a1e2fb100eae4b70d7c0922fde9164bc7326d02074627e54d860359d8b298"
  17. >> "X-Amz-Date: 20191018T145734Z"
  18. >> "x-amz-acl: public-read"
  19. >> "User-Agent: aws-sdk-java/1.11.276 Mac_OS_X/10.13.6 Java_HotSpot(TM)_64-Bit_Server_VM/25.60-b23 java/1.8.0_60"
  20. >> "amz-sdk-invocation-id: 47ea0bcd-c021-6d48-2547-f9a276c055cd"
  21. >> "amz-sdk-retry: 0/0/500"
  22. >> "Content-Type: application/octet-stream"
  23. >> "Content-Length: 0"
  24. >> "Connection: Keep-Alive"
  25. >> ""


S3响应

  1. << "HTTP/1.1 403 Forbidden"
  2. << "x-amz-request-id: 83C798E7B7B523ED"
  3. << "x-amz-id-2: 6QylxeiERpjXVuThC0VXYqCGSL9+pWqw5Kdi/1PpI+ly1eBMxYY+byB59T7yGLf2D5vPOLTLAPA="
  4. << "Content-Type: application/xml"
  5. << "Transfer-Encoding: chunked"
  6. << "Date: Fri, 18 Oct 2019 14:57:33 GMT"
  7. << "Server: AmazonS3"
  8. << ""
  9. << HTTP/1.1 403 Forbidden
  10. << x-amz-request-id: 83C798E7B7B523ED
  11. << x-amz-id-2: 6QylxeiERpjXVuThC0VXYqCGSL9+pWqw5Kdi/1PpI+ly1eBMxYY+byB59T7yGLf2D5vPOLTLAPA=
  12. << Content-Type: application/xml
  13. << Transfer-Encoding: chunked
  14. << Date: Fri, 18 Oct 2019 14:57:33 GMT
  15. << Server: AmazonS3
  16. e kept alive for 60000 MILLISECONDS
  17. << "f3"
  18. << "<?xml version="1.0" encoding="UTF-8"?>[\n]"
  19. << "<Error><Code>AccessDenied</Code><Message>Access Denied</Message><RequestId>83C798E7B7B523ED</RequestId><HostId>6QylxeiERpjXVuThC0VXYqCGSL9+pWqw5Kdi/1PpI+ly1eBMxYY+byB59T7yGLf2D5vPOLTLAPA=</HostId></Error>"
  20. << "0"
  21. << ""


我使用com.github.platform-team:aws-maven上传到S3

  1. <build>
  2. ...
  3. <extensions>
  4. <extension>
  5. <groupId>com.github.platform-team</groupId>
  6. <artifactId>aws-maven</artifactId>
  7. <version>6.0.0</version>
  8. </extension>
  9. </extensions>
  10. </build>


这是我的maven repo配置

  1. <distributionManagement>
  2. <repository>
  3. <id>repo.inuka</id>
  4. <url>s3://*****-mvn-repo/release</url>
  5. </repository>
  6. </distributionManagement>


我可以从命令行对s3进行写访问:

  1. halils-mbp:inuka-be halil$ aws s3 cp pom.xml s3://inuka-mvn-repo
  2. upload: ./pom.xml to s3://inuka-mvn-repo/pom.xml


谁能帮帮我,为什么maven wagon插件com.github.platform-team:aws-maven不能上传到S3?

vxf3dgd4

vxf3dgd41#

我猜你错过了配置你的S3策略或m2设置的服务器ID不匹配与您的pom distributionManagements,也有snapshotRepositoryrepository
举例说明:

  1. <distributionManagement>
  2. <snapshotRepository>
  3. <id>YOUR_BUCKET_NAME-snapshot</id>
  4. <url>s3://YOUR_BUCKET_NAME/snapshot</url>
  5. </snapshotRepository>
  6. <repository>
  7. <id>YOUR_BUCKET_NAME-release</id>
  8. <url>s3://YOUR_BUCKET_NAME/release</url>
  9. </repository>
  10. </distributionManagement>

字符串
我发现这个maven扩展很有用,它是建立在apache wagon之上的,链接:https://github.com/ehsaniara/maven-repository-aws-s3
您可以从https://github.com/ehsaniara/maven-repository-aws-s3#configure-by-aws-console开始
Setp1:您可以使用以下权限创建s3策略:

  1. {
  2. "Version": "2012-10-17",
  3. "Statement": [
  4. {
  5. "Effect": "Allow",
  6. "Action": [
  7. "s3:PutObject",
  8. "s3:GetObject",
  9. "s3:CreateBucket",
  10. "s3:ListBucket",
  11. "s3:DeleteObject"
  12. ],
  13. "Resource": "arn:aws:s3:::YOUR_BUCKET_NAME/*"
  14. }
  15. ]
  16. }


然后创建一个IAM用户并附加该策略。
.m2/setting上添加snapshotrelease服务器ID

  1. <settings>
  2. <servers>
  3. ...
  4. ...
  5. <server>
  6. <id>YOUR_BUCKET_NAME-snapshot</id>
  7. <username>AWS_ACCESS_KEY_ID</username>
  8. <password>AWS_SECRET_ACCESS_KEY</password>
  9. <configuration>
  10. <region>AWS_REGION</region>
  11. <publicRepository>false</publicRepository>
  12. </configuration>
  13. </server>
  14. <server>
  15. <id>YOUR_BUCKET_NAME-release</id>
  16. <username>AWS_ACCESS_KEY_ID</username>
  17. <password>AWS_SECRET_ACCESS_KEY</password>
  18. <configuration>
  19. <region>AWS_REGION</region>
  20. <publicRepository>false</publicRepository>
  21. </configuration>
  22. </server>
  23. ....
  24. ....
  25. </servers>
  26. </settings>


然后将以下扩展名添加到您的pom中

  1. <extensions>
  2. <extension>
  3. <groupId>com.github.ehsaniara</groupId>
  4. <artifactId>maven-repository-aws-s3</artifactId>
  5. <version>1.2.10</version>
  6. </extension>
  7. </extensions>

展开查看全部
zzzyeukh

zzzyeukh2#

我做了一个支持AWS SSO(OIDC auth)的SDK,它使用了第二个版本。也许它对那些像我一样在搜索此类功能时发现这个问题的人有用。
https://github.com/embriq-nordic/aws-oidc-s3-maven-wagon

  1. <extension>
  2. <groupId>io.github.embriq-nordic</groupId>
  3. <artifactId>aws-oidc-s3-maven-wagon</artifactId>
  4. <version>1.1.0</version>
  5. </extension>

字符串
由于它使用SDK的第二个版本,因此它使用该版本所使用的凭据提供程序链。
当然,您仍然需要创建一个策略/角色,如Jay Ehsaniara的回答中所述。

ldxq2e6h

ldxq2e6h3#

大多数Maven S3 wagons,包括问题中提到的那个,似乎都不支持开箱即用的私有权限写入bucket。结果是,即使你的IAM策略很好,你的身份验证细节也很好,当涉及到PUT调用时,你也会得到403。
我发现的唯一一个可以开箱即用的私有bucket是Allogy wagon

  1. <build>
  2. ...
  3. <extensions>
  4. <extension>
  5. <groupId>com.allogy.maven.wagon</groupId>
  6. <artifactId>maven-s3-wagon</artifactId>
  7. <version>1.2.0</version>
  8. </extension>
  9. </extensions>
  10. ...
  11. </build>

字符串

相关问题