Maven Nexus 问题 - 403 Forbidden 授权失败
Posted
技术标签:
【中文标题】Maven Nexus 问题 - 403 Forbidden 授权失败【英文标题】:Maven Nexus Issue - Authorization failed for 403 Forbidden 【发布时间】:2020-04-28 09:53:18 【问题描述】:我们已经讨论这个问题好几天了。
为从 Maven 和 Nexus 读取依赖项的 Java 应用创建了 Gitlab CI 管道
gitlab 管道被配置为作为具有管理员权限的 nexus 用户运行,这一点已经过多次验证。
但是,当执行 gitlab 管道时,我们得到以下错误:
[ERROR] Failed to execute goal on project hello-component: Could not resolve dependencies for project x.y.z:hello-component:jar:1.6-SNAPSHOT: Failed to collect dependencies at a.b:c:jar:4.5.1132100: Failed to read artifact descriptor for b:c:jar:4.5.1132100: Could not transfer artifact a.b:c:pom:4.5.1132100 from/to maven-snapshots (http://host:8081/repository/maven-snapshots): Authorization failed for http://host:8081/repository/maven-snapshots/a/b/c/4.5.1132100/nidp-4.5.1132100.pom 403 Forbidden -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal on project hello-component: Could not resolve dependencies for project x.y.z:hello-component:jar:1.6-SNAPSHOT: Failed to collect dependencies at a.b:c:jar:4.5.1132100
我还使用了以下指南:
https://blog.sonatype.com/how-to-use-gitlab-ci-with-nexus
我的 POM 有以下内容,环境变量在 ci/cd/settings/variables 中配置:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
</plugin>
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<version>1.5.1</version>
<executions>
<execution>
<id>default-deploy</id>
<phase>deploy</phase>
<goals>
<goal>deploy</goal>
</goals>
</execution>
</executions>
<configuration>
<serverId>maven-snapshots</serverId>
<nexusUrl>http://host:8081/repository/maven-snapshots</nexusUrl>
<skipStaging>true</skipStaging>
</configuration>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>maven-snapshots</id>
<url>http://host:8081/repository/maven-snapshots</url>
</repository>
<repository>
<id>maven-releases</id>
<url>http://host:8081/repository/maven-releases</url>
</repository>
<!--repository>
<id>nexus.local</id>
<url>$HOME/.m2/repository</url>
</repository-->
</repositories>
<distributionManagement>
<snapshotRepository>
<id>maven-snapshots</id>
<url>http://host:8081/repository/maven-snapshots</url>
</snapshotRepository>
<repository>
<id>maven-releases</id>
<url>http://host:8081/repository/maven-releases</url>
</repository>
</distributionManagement>
Gitlab CI 运行器具有以下功能:
image: maven:3.3.9-jdk-8
variables:
GIT_STRATEGY: clone
MAVEN_CLI_OPTS: "-s /opt/apache-maven-3.6.3/conf/settings.xml --batch-mode"
MAVEN_OPTS: "-Dmaven.repo.local=/home/gitlab-runner/.m2/repository"
cache:
paths:
- /home/gitlab-runner/.m2/repository/
- target/
stages:
- build
CodeBuild:
stage: build
script:
- /opt/apache-maven-3.6.3/bin/mvn $MAVEN_CLI_OPTS -X clean package
artifacts:
name: “x—y-component"
paths:
- ./target/x—y-component.jar
gitlab ci 服务器上的 Setting.xml 有以下 nexus 用户参考:
maven 快照 [管理员用户] [管理员密码]
任何帮助将不胜感激。
谢谢
【问题讨论】:
【参考方案1】:不确定是否仍然需要帮助,但您似乎没有为用于部署/解决依赖关系的用户角色授予必要的权限。请授予角色 nx-repository-view---* 权限。对其进行测试,然后您可以根据需要缩小范围。
【讨论】:
以上是关于Maven Nexus 问题 - 403 Forbidden 授权失败的主要内容,如果未能解决你的问题,请参考以下文章
使用 WebSockets 的 Spring Security - 禁止 403
无法找到 403 Forbidden 错误的原因:Nginx Daphne Django