[GRADLE-3091] HTTP dependency resolvers should support preemptive authentication Created: 18/May/14 Updated: 03/Aug/15 Resolved: 03/Aug/15 |
|
Status: | Resolved |
Project: | Gradle |
Affects Version/s: | None |
Fix Version/s: | 2.7-rc-1 |
Type: | Improvement | ||
Reporter: | Gradle Forums | Assignee: | Mark Vieira (Inactive) |
Resolution: | Fixed | Votes: | 3 |
Description |
Certain repos (GitHub being one of them) return 404 for unauthorized resources, instead of 401. If the user supplies credentials, we should just preemptively include them in the request. |
Comments |
Comment by Gradle Forums [ 18/May/14 ] |
I put the credentials into "gradle.properties" and in "build.gradle" I have this: maven { This works (at least in 1.11). |
Comment by Gradle Forums [ 18/May/14 ] |
I wonder if it depends on the way that the server does auth. Perhaps github does it differently than your server. On thing that's sort of unusual about github: if you don't auth with raw.githubusercontent.com, it returns a 404 Not Found rather than a 401 Unauthorized. In the debug logs I can see that gradle is trying to do an HTTP HEAD on the artifact url, where it gets a 404 (which implies that it didn't send auth info). Perhaps gradle doesn't auth until it does an HTTP GET, or it only auths if the server returns 404 Not Found? |
Comment by Gradle Forums [ 18/May/14 ] |
Looking more closely at the debug log, the line that says Target auth state: UNCHALLENGED is really suspicious. Why isn't it sending along auth info? 14:23:23.927 [DEBUG] [org.gradle.api.internal.externalresource.transport.http.HttpClientHelper] Performing HTTP HEAD: https://raw.githubusercontent.com/foobar/repo/master/releases/com/foobar/myartifact/0.0.1/mylib-0.0.1.pom 14:23:24.128 [DEBUG] [org.apache.http.impl.conn.PoolingClientConnectionManager] Connection leased: [id: 0][route: {s} ->https://raw.githubusercontent.com][total kept alive: 0; route allocated: 1 of 5; total allocated: 1 of 10] Just to be clear, even tho its showing 404 Not Found, the file really is there. I can curl it with my credentials and it pulls down fine: curl -u myusername https://raw.githubusercontent.com/foobar/repo/master/releases/com/foobar/myartifact/0.0.1/mylib-0.0.1.pom I think the problem is that gradle isn't sending auth info for HTTP HEAD, and github returns 404 Not Found when it doesn't get auth for private repos. |
Comment by Gradle Forums [ 18/May/14 ] |
More digging: [Why am I getting a 404 error on a repository that exists?]([1]https://developer.github.com/v3/troub...) |
Comment by Aaron Simmons [ 25/May/14 ] |
This may be related to |
Comment by Aaron Simmons [ 25/May/14 ] |
Hm, it seems like preemptive auth was removed on purpose : |
Comment by Aaron Simmons [ 25/May/14 ] |
From what I can gather, the best practice is to not send auth info if you don't have to. I can see a couple ways of handling this problem:
|
Comment by Rodrigo B. de Oliveira [ 03/Nov/14 ] |
An explicit preemptive flag as suggested by Aaron Simmons above seems to fit the bill nicely. |
Comment by Aaron Simmons [ 03/Nov/14 ] |
Can we please get some movement on this? I can't simply go in and unilaterally change this behavior-- gradle removed it for some reason and the devs need to discuss the options. |
Comment by Christian Bahl [ 04/Nov/14 ] |
i also prefer option 3, because i´m using jenkins with maven repository plugin. if jenkins is secured and auth is not send, it returns 403 (forbidden). so not to forget or add each status code the flag "preemptive" is the best solution and please add it to one of the next versions! |
Comment by Ryan Harter [ 28/Jan/15 ] |
I've submitted pull request 386 which implements option 3 above. |
Comment by Daz DeBoer [ 02/Mar/15 ] |
Seems like the workaround of embedding username/password in the repository URL is no longer an option, with Gradle 2.x: |
Comment by Ryan Harter [ 02/Mar/15 ] |
I've been using a custom build with my pending PR for several months now successfully. |
Comment by Aaron Simmons [ 02/Mar/15 ] |
Sadly I've resorted to using workaround plugins like https://github.com/layerhq/gradle-git-repo-plugin. I would build my own gradle with Ryan Harter's PR, but our team is too spread out (contractors, etc) to require everyone to build a custom gradle. |