Repository navigation
Bind the central server id to Central's publishing origins and count altDeploymentRepository as a declared origin - #14104
slachiewicz wants to merge 3 commits into
Conversation
gnodet-bot
left a comment
There was a problem hiding this comment.
Review: Bind central server id to Central's publishing origins
Verdict: LGTM — well-designed credential scoping change with good test coverage.
What This Does
This PR makes two improvements to Maven's credential scoping:
- Binds the
centralserver id to Central Portal's publishing origins (central.sonatype.com,ossrh-staging-api.central.sonatype.com), so users who configure acentralserver for publishing don't need explicit<repositoryOrigins>. - Counts
altDeploymentRepository(and variants) as a declared credential origin, so credentials in strict/origin scope work for deployment repositories specified on the command line.
Analysis
Security guard is correct: addCentralPublishingOrigins only adds publishing origins when central's origin set is exactly {https://repo.maven.apache.org} — once a mirror, custom repository, or explicit <repositoryOrigins> adds another origin, the guard blocks. This prevents credential leakage if the user has a customized central configuration.
Ordering is correct: addCentralPublishingOrigins is called after all other origin registration (server loop + deployment repo properties), ensuring the guard sees all declarations.
Deployment repo parsing is robust: addDeploymentRepositoryOrigin handles both id::url and the legacy id::layout::url format via indexOf("::") / lastIndexOf("::"). Edge cases (null, missing ::, empty id) are properly guarded; malformed URLs fall through to the existing try/catch in addOrigin.
Test coverage is thorough: 4 unit tests + 3 integration tests covering happy path, guard activation, id isolation, and deployment repo parsing edge cases (null, no-id, empty-id, legacy format).
Minor Observations (Non-blocking)
-
Empty URL edge case:
"id::"(empty string after::) would reachaddOriginwith an empty URL. This is safely caught by the existingURISyntaxException | IllegalArgumentExceptionhandler inaddOrigin, but could be guarded early with an!url.isEmpty()check inaddDeploymentRepositoryOriginfor clarity. -
Integration test coverage: Only
altDeploymentRepositoryis tested inDefaultRepositorySystemSessionFactoryTest, notaltReleaseDeploymentRepositoryoraltSnapshotDeploymentRepository. Since all three go through the same loop calling the same method, this is adequate — but a parameterized test covering all three would make the array contract explicit.
This review was generated by an AI agent, Hermès on behalf of @gnodet.
|
One interaction worth considering: the server aliases feature from #2333 and the credential scoping fix here may not compose correctly. Scenario: a user configures <server>
<id>my-publishing-server</id>
<username>...</username>
<password>...</password>
<aliases>
<alias>central</alias>
</aliases>
</server>The Set<String> origins = declaredOrigins.get(CENTRAL_ID);
if (origins != null && origins.equals(Set.of(CENTRAL_ORIGIN))) {
origins.addAll(CENTRAL_PUBLISHING_ORIGINS);
}Since no repository or mirror carries the id Suggested fix: relax the condition to also cover the alias case ( In public static void addCentralPublishingOrigins(
Map<String, Set<String>> declaredOrigins, boolean hasDefaultCentralRepo) {
if (!hasDefaultCentralRepo) {
return;
}
Set<String> origins = declaredOrigins.get(CENTRAL_ID);
// Cover both cases:
// - explicit <server id="central"> with default repo → origins == {repo.maven.apache.org}
// - <aliases><alias>central</alias> without a declared repo → origins == null
if (origins == null || origins.equals(Set.of(CENTRAL_ORIGIN))) {
declaredOrigins.computeIfAbsent(CENTRAL_ID, k -> new HashSet<>())
.addAll(CENTRAL_PUBLISHING_ORIGINS);
}
}This keeps the existing guard (a mirror or This comment was generated by an AI agent, Hermès on behalf of @gnodet. |
The default repository gives the id central the origin repo.maven.apache.org, which kept a settings server with that id from authenticating deployments to central.sonatype.com (HTTP 401 on snapshot publishing). The publishing origins are added only while the built-in location is the sole origin of the id. Do not fix this by dropping the default repository's origin instead: a parent POM can declare a repository central at another host, and that binding is what withholds the credentials there.
A deployment repository given on the command line as id::url was not known to the credential scoping: its server was used with a warning in the origin scope and refused in the strict scope, although the warning itself says a repository declared on the command line counts. Only the user properties of the request are read, so a POM property of the same name declares nothing.
The binding of the id central to Central's publishing origins keeps deployments configured before credential scoping working; the warning names the explicit replacement so the binding can be removed later.
35a4862 to
fc66a78
Compare
A settings server with the id
centralcould not authenticate snapshot deployments to Maven Central: the default repository binds that id tohttps://repo.maven.apache.org, so its credentials were withheld fromhttps://central.sonatype.comand the deploy ended withHTTP Status: 401. The id is the defaultpublishingServerIdofcentral-publishing-maven-plugin.The id
centralis now also bound to the origins Central is published to,https://central.sonatype.comandhttps://ossrh-staging-api.central.sonatype.com, as long as the built-in location is its only origin. A mirror, a repository or a server<repositoryOrigins>that gives the id another origin takes over and nothing is added. The default repository's origin stays bound on purpose: a parent POM can declare a repositorycentralat another host, and that binding is what withholds the credentials there.When credentials are used through this binding, Maven warns once per session that the binding will be removed in a future release and names the replacements: the two origins in the server's
<repositoryOrigins>, or a server id of its own such as thepublishingServerIdofcentral-publishing-maven-plugin. Server aliases need nothing extra: the default repositorycentralis always among the request's repositories, so an aliascentralgets the same binding.A deployment repository given on the command line with
altDeploymentRepository,altReleaseDeploymentRepositoryoraltSnapshotDeploymentRepositorynow declares the origin of its id, as the existing warning already says a command-line repository does. Such a server is used without a warning, works in thestrictscope, and its credentials are no longer offered to a repository that reuses the id at another host. Only user properties are read; a POM property of the same name declares nothing.Verified:
mvn deploy:deploy -DaltDeploymentRepository=central::https://central.sonatype.com/repository/maven-snapshots/with a settings servercentralon a 4.0.x build, against a local stand-in forcentral.sonatype.com→ 401 without credentials before, deployed with credentials after. On master only the unit tests were run. The warning was run end to end on a 3.10.x build only; here it is covered by unit tests.Verified: the same command with
-DaltDeploymentRepository=sonatype-central::<url>and a settings serversonatype-centralon a 4.0.x build → one warning and refused understrictbefore; no warning and deployed understrictafter.I have not run the core ITs.