Match Apache Maven's anonymous-first authentication for POM and JAR downloads#8169
Draft
Jammy-Louie wants to merge 2 commits into
Draft
Match Apache Maven's anonymous-first authentication for POM and JAR downloads#8169Jammy-Louie wants to merge 2 commits into
Jammy-Louie wants to merge 2 commits into
Conversation
Mirror Apache Maven Resolver's DeferredCredentialsProvider: issue POM, metadata, reachability, jar-existence, and artifact requests without credentials, and send Basic auth only once the server challenges an anonymous request with a 4xx. Both downloaders previously applied credentials preemptively, leaking them to repositories that serve anonymously. Split out applyTimeoutToRequest so anonymous requests keep their timeouts without sending configured headers or credentials.
…robes Add a session-scoped MavenAuthenticationCache on the ExecutionContext that records repository endpoints (host:port) which challenged an anonymous request. Once a host is known to require credentials, both MavenPomDownloader and MavenArtifactDownloader authenticate preemptively rather than paying another anonymous 401 round-trip, mirroring Apache Maven Resolver's per-session BasicAuthCache. MavenArtifactDownloader now accepts an ExecutionContext (additive constructors; existing ones default to a per-instance context) so the JAR phase shares the cache populated during POM resolution. JavaRewriteRpc passes its context through.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
MavenPomDownloader(reachability probes, jar-existence HEAD, and body/metadata GETs) andMavenArtifactDownloadernow request without credentials first and retry with credentials on a credential-rejecting 4xx. This also stops sending credentials to repositories that serve anonymously.host:portset on theExecutionContextrecords which endpoints required authentication, mirroring Maven Resolver'sBasicAuthCache(and the existinggetUnreachableEndpointspattern). Once a host is known to require auth, both downloaders authenticate preemptively.MavenArtifactDownloadergains additiveExecutionContextconstructors, andJavaRewriteRpcpasses its context through so the jar phase shares the cache warmed during POM resolution.The first request to a private host costs one extra anonymous 401 probe before authenticating; the cache limits this to once per host per session, the same one-time cost Maven pays.
Test plan
MavenPomDownloaderTest#doesNotSendCredentialsWhenRepositoryServesAnonymouslyMavenPomDownloaderTest#authenticatesPreemptivelyAfterCredentialsRequiredMavenArtifactDownloaderTest#retriesWithCredentialsWhenAnonymousReturns401,#retriesWithHttpHeaderAuthWhenAnonymousReturns401MavenArtifactDownloaderTest#doesNotFallBackToAnonymousOnTransientClientErrorMavenArtifactDownloaderTest#authenticatesPreemptivelyAfterFirstChallengeForSameHostrewrite-mavenmodule test suite