TL;DR; I’m getting sporadic 401/403 responses from Artifactory when Gradle tries to GET / HEAD my repositories for its dependencies. These requests are coming in as “non_authenticated_user” in my Artifactory logs which makes no sense because I’m seeing other requests from the same build coming in as the proper user which get properly resolved. I have no idea what’s going on, why does it look like Gradle is sending some requests to Artifactory with proper credentials and some with invalid credentials?
The longer version
We’re in the process of moving our CI from local Jenkins to GitLab. We have a few Gradle builds (regular Java/Scala projects, nothing special really) that need to get Artifacts from both the “global” repos (jcenter and mavenCentral) as well as from our internal Artifactory repository.
Some of these projects are working fine but we’re having problems with some of the others. The issue is that the build fails with a 403 from Artifactory when trying to fetch some of the artifacts from the internal repos.
As I said, we’re seeing this problem with at least two of our projects. The first one we took a look at we ended up fiddling around a bit with the order of the repository definitions in the Gradle file, upgraded Gradle to 4.10.3 and then everything started to work fine and has been stable ever since.
I should note that we haven’t been experiencing this problem on local development machines, except for one developer who says he’s seen this but usually building the project again fixes the problem. We saw this happen every now and then on our old Jenkins CI but the same there, retrying the build usually worked. In GitLab, we see this problem more frequently and for one of our projects, its been pretty consistent.
Long story short, this is simply due to the fact that the 403 responses are sporadic and unpredictable. Building a few times usually builds up the Gradle cache on dev machines and on Jenkins as Gradle re-uses the same directory for GRADLE_HOME. On GitLab, things are a bit more isolated so every new job gets a fresh GRADLE_HOME. We’ll try to fix that of course, but that would only be slapping a band-aid on the problem. This realization made it possible for us to reproduce the problem on our local machines, simply delete the Gradle cache before the build and you will (often… but not always) run into a 403 from Artifactory.
For the second project. We’re using Gradle 5.6.2 there so we can’t upgrade that any further. This project keeps giving us 403 errors in GitLab CI. The problem is worse if we configure GitLab to check out a rather large submodule containing test data. This makes no sense since Gradle hasn’t even started when the submodule checkout is performed. But if we checkout the submodule we almost always get the 403 from Artifactory, if we don’t check out the submodule, the build goes through.
So, here is the definition of our repositories in our Gradle build file for this second project:
repositories {
jcenter()
mavenCentral()
maven {
url "${artifactory_contextUrl}/libs-release"
credentials {
username "$artifactory_user"
password "$artifactory_password"
}
}
maven {
url "${artifactory_contextUrl}/libs-staging"
credentials {
username "$artifactory_user"
password "$artifactory_password"
}
}
maven {
url "${artifactory_contextUrl}/libs-snapshot"
credentials {
username "$artifactory_user"
password "$artifactory_password"
}
}
}
We are using the -Dorg.gradle.daemon=false
flag so that should not be messing with anything and I’ve verified that the values for artifactory_user and artifactory_password are correct.
These three repositories are all virtual repositories that point to one or two concrete (local) repositories in our Artifactory. I’ve verified that the user we’re using has read access to the virtual repos as well as the local repos.
As I said, the Gradle build ends in a bunch of 403 errors (it differs which artifacts give us a 403 response) but here is the relevant log from Artifactory from a single build run that quickly resulted in a 403 error:
20190926112214|1|REQUEST|10.3.104.55|non_authenticated_user|GET|/libs-release/com/mycompany/ourproduct/ourproduct-model/1.2-SNAPSHOT/maven-metadata.xml|HTTP/1.0|401|0
20190926112214|11|REQUEST|10.3.104.55|build|GET|/libs-release/com/mycompany/ourproduct/ourproduct-model/1.2-SNAPSHOT/maven-metadata.xml|HTTP/1.0|404|0
20190926112214|2|REQUEST|10.3.104.55|non_authenticated_user|GET|/libs-release/com/mycompany/ourproduct/ourproduct-model/1.2-SNAPSHOT/ourproduct-model-1.2-SNAPSHOT.pom|HTTP/1.0|403|0
20190926112214|1|REQUEST|10.3.104.55|non_authenticated_user|GET|/libs-release/com/mycompany/ourproduct/ourproduct-base-exception/1.2-SNAPSHOT/maven-metadata.xml|HTTP/1.0|401|0
20190926112214|2|REQUEST|10.3.104.55|build|GET|/libs-release/com/mycompany/ourproduct/ourproduct-base-exception/1.2-SNAPSHOT/maven-metadata.xml|HTTP/1.0|404|0
20190926112214|0|REQUEST|10.3.104.55|non_authenticated_user|GET|/libs-release/com/mycompany/ourproduct/ourproduct-base-exception/1.2-SNAPSHOT/ourproduct-base-exception-1.2-SNAPSHOT.pom|HTTP/1.0|403|0
20190926112214|0|REQUEST|10.3.104.55|non_authenticated_user|GET|/libs-staging/com/mycompany/ourproduct/ourproduct-model/1.2-SNAPSHOT/maven-metadata.xml|HTTP/1.0|401|0
20190926112214|1|REQUEST|10.3.104.55|non_authenticated_user|GET|/libs-staging/com/mycompany/ourproduct/ourproduct-model/1.2-SNAPSHOT/maven-metadata.xml|HTTP/1.0|403|0
20190926112214|1|REQUEST|10.3.104.55|non_authenticated_user|GET|/libs-staging/com/mycompany/ourproduct/ourproduct-base-exception/1.2-SNAPSHOT/maven-metadata.xml|HTTP/1.0|401|0
20190926112214|1|REQUEST|10.3.104.55|non_authenticated_user|GET|/libs-staging/com/mycompany/ourproduct/ourproduct-base-exception/1.2-SNAPSHOT/maven-metadata.xml|HTTP/1.0|403|0
20190926112214|0|REQUEST|10.3.104.55|non_authenticated_user|GET|/libs-snapshot/com/mycompany/ourproduct/ourproduct-model/1.2-SNAPSHOT/maven-metadata.xml|HTTP/1.0|401|0
20190926112214|1|REQUEST|10.3.104.55|non_authenticated_user|GET|/libs-snapshot/com/mycompany/ourproduct/ourproduct-model/1.2-SNAPSHOT/maven-metadata.xml|HTTP/1.0|403|0
20190926112214|1|REQUEST|10.3.104.55|non_authenticated_user|GET|/libs-snapshot/com/mycompany/ourproduct/ourproduct-base-exception/1.2-SNAPSHOT/maven-metadata.xml|HTTP/1.0|401|0
20190926112214|1|REQUEST|10.3.104.55|non_authenticated_user|GET|/libs-snapshot/com/mycompany/ourproduct/ourproduct-base-exception/1.2-SNAPSHOT/maven-metadata.xml|HTTP/1.0|403|0
20190926112214|1|REQUEST|10.3.104.55|build|GET|/libs-release/com/mycompany/ourproduct/ourproduct-base-config/1.2-SNAPSHOT/maven-metadata.xml|HTTP/1.0|404|0
20190926112214|0|REQUEST|10.3.104.55|non_authenticated_user|GET|/libs-release/com/mycompany/ourproduct/ourproduct-base-config/1.2-SNAPSHOT/ourproduct-base-config-1.2-SNAPSHOT.pom|HTTP/1.0|403|0
20190926112214|0|REQUEST|10.3.104.55|build|GET|/libs-staging/com/mycompany/ourproduct/ourproduct-base-config/1.2-SNAPSHOT/maven-metadata.xml|HTTP/1.0|404|0
20190926112214|1|REQUEST|10.3.104.55|non_authenticated_user|GET|/libs-staging/com/mycompany/ourproduct/ourproduct-base-config/1.2-SNAPSHOT/ourproduct-base-config-1.2-SNAPSHOT.pom|HTTP/1.0|403|0
20190926112214|5|REQUEST|10.3.104.55|build|GET|/libs-snapshot/com/mycompany/ourproduct/ourproduct-base-config/1.2-SNAPSHOT/maven-metadata.xml|HTTP/1.0|200|782
20190926112214|1|REQUEST|10.3.104.55|non_authenticated_user|GET|/libs-snapshot/com/mycompany/ourproduct/ourproduct-base-config/1.2-SNAPSHOT/ourproduct-base-config-1.2-20190926.102550-80.pom|HTTP/1.0|403|0
20190926112214|1|REQUEST|10.3.104.55|build|GET|/libs-release/com/mycompany/ourproduct/ourproduct-drivers/1.2-SNAPSHOT/maven-metadata.xml|HTTP/1.0|404|0
20190926112214|0|REQUEST|10.3.104.55|non_authenticated_user|GET|/libs-release/com/mycompany/ourproduct/ourproduct-drivers/1.2-SNAPSHOT/ourproduct-drivers-1.2-SNAPSHOT.pom|HTTP/1.0|403|0
20190926112214|0|REQUEST|10.3.104.55|build|GET|/libs-staging/com/mycompany/ourproduct/ourproduct-drivers/1.2-SNAPSHOT/maven-metadata.xml|HTTP/1.0|404|0
20190926112214|0|REQUEST|10.3.104.55|non_authenticated_user|GET|/libs-staging/com/mycompany/ourproduct/ourproduct-drivers/1.2-SNAPSHOT/ourproduct-drivers-1.2-SNAPSHOT.pom|HTTP/1.0|403|0
20190926112214|4|REQUEST|10.3.104.55|build|GET|/libs-snapshot/com/mycompany/ourproduct/ourproduct-drivers/1.2-SNAPSHOT/maven-metadata.xml|HTTP/1.0|200|778
20190926112214|1|REQUEST|10.3.104.55|non_authenticated_user|GET|/libs-snapshot/com/mycompany/ourproduct/ourproduct-drivers/1.2-SNAPSHOT/ourproduct-drivers-1.2-20190926.102550-80.pom|HTTP/1.0|403|0
As you can see, some requests are done by the “build” user but others are reported as “non_authenticated_user”.
This makes no sense to me as I’m providing the proper credentials (otherwise I’d have no “build” user requests) and there is only a single Gradle process running.
Has anybody seen anything like this? Any ideas what might be going on here?