From e286aef0151e82f6d4ef6408de17a26d6266d627 Mon Sep 17 00:00:00 2001 From: Priamo Germosen <6233424+pgermosen@users.noreply.github.com> Date: Sat, 14 Nov 2026 15:42:29 -0400 Subject: [PATCH] fix(codeartifact): resolve upstreams in AWS's order, through their external connections (#8356) Three ways a read through upstream repositories differed from the User Guide: - Upstreams were searched breadth-first. "If an upstream repository has its own upstream repositories, the same logic is used to find a package version before moving to the next upstream repository": the guide's own example, my_repo with upstreams A and B, A with C and D and D with E, is searched my_repo, A, C, D, E, B. The walk is depth-first in each repository's listed order now. - A version an upstream had itself retained named that upstream as its origin, and one the upstream got from public:npmjs came back INTERNAL. A version's DomainEntryPoint is where it "originally entered" the domain, so a retained version now carries its upstream's own entry point: the external connection, EXTERNAL, or the repository it was published to, however many upstreams it came through. It is read again when the version's claim is confirmed, so a copy made while the upstream's own fetch is still finishing gets that fetch's connection. - An upstream's external connection was never consulted, so a version no upstream had fetched yet was a 404. AWS fetches it through the upstream's connection and retains it there and in the repository the request was made to. A miss at every upstream now tries the external connections of the upstreams in the same order, for npm, Maven, PyPI and NuGet, and a packument, Simple index or maven-metadata.xml read through such an upstream offers what its connection has. That fetch skips a version Archived or Disposed at the upstream, or here in the Simple index, reads this repository's fences before it starts, so a deletion during it is not undone, and passes on an npm client's ask for the full packument. The four formats share it in UpstreamExternalConnectionFetch. --- docs/services/codeartifact.md | 31 +++-- ...tifactMavenExternalConnectionImporter.java | 12 ++ ...tifactMavenUpstreamRepositoryImporter.java | 58 +++++++-- .../CodeArtifactNpmDataPlane.java | 6 +- ...ArtifactNpmExternalConnectionImporter.java | 12 ++ ...ArtifactNpmUpstreamRepositoryImporter.java | 54 +++++++-- ...tifactNuGetExternalConnectionImporter.java | 13 ++ ...tifactNuGetUpstreamRepositoryImporter.java | 45 +++++-- ...rtifactPypiExternalConnectionImporter.java | 28 ++++- ...rtifactPypiUpstreamRepositoryImporter.java | 90 ++++++++++---- .../codeartifact/CodeArtifactService.java | 80 +++++++++---- .../UpstreamExternalConnectionFetch.java | 87 ++++++++++++++ .../UpstreamRepositoryResolver.java | 62 +++++----- ...ctMavenExternalConnectionImporterTest.java | 10 ++ ...ctMavenUpstreamRepositoryImporterTest.java | 99 +++++++++++++++- ...factNpmExternalConnectionImporterTest.java | 10 ++ ...factNpmUpstreamRepositoryImporterTest.java | 99 +++++++++++++++- ...ctNuGetExternalConnectionImporterTest.java | 11 ++ ...ctNuGetUpstreamRepositoryImporterTest.java | 65 +++++++++- ...actPypiExternalConnectionImporterTest.java | 20 ++++ ...actPypiUpstreamRepositoryImporterTest.java | 104 +++++++++++++++- .../codeartifact/CodeArtifactServiceTest.java | 111 ++++++++++++++++++ .../UpstreamRepositoryResolverTest.java | 26 ++-- 23 files changed, 984 insertions(+), 149 deletions(-) create mode 100644 src/main/java/io/floci/aws/services/codeartifact/UpstreamExternalConnectionFetch.java diff --git a/docs/services/codeartifact.md b/docs/services/codeartifact.md index 87421d4adb..683bf5571f 100644 --- a/docs/services/codeartifact.md +++ b/docs/services/codeartifact.md @@ -419,19 +419,24 @@ state. A repository-to-repository upstream chain resolves the same way, for all four formats, reusing the exact claim/fence/origin-tracking machinery above: a GET/HEAD/tarball-download/packument - miss searches the repository's own `upstreams`, transitively (an upstream's own upstreams are - searched too, breadth-first, matching AWS's documented priority order) and not just its direct - list, for the first repository with a usable copy. Two real differences from the - external-connection case: an Archived or Disposed version *at the resolved upstream repository - itself* is skipped, the walk continuing to the next candidate, since a same-domain upstream has - a real CodeArtifact-shaped status to check that a public registry never does; and each candidate - is checked only for what it already has retained, not what it could itself still pull from its - own configured external connection (AWS documents a downstream request chaining through an - upstream's own external connection too, so a version a candidate upstream hasn't fetched yet - from its own `public:*` connection stays a miss here, even though AWS would resolve it). Since a - same-domain upstream read never leaves this process, pypi's own version here needs none of the - real external connection's PEP 691 sha256 re-verification or background-thread split: every - asset of the resolved version is imported synchronously, in one pass. + miss searches the repository's own `upstreams`, transitively, for the first repository with a + usable copy. The order is AWS's documented priority order: depth-first, in each repository's + listed order, an upstream's own upstreams searched before the next one, so `my_repo` with + upstreams `A` and `B`, `A` with `C` and `D` and `D` with `E` is searched `A, C, D, E, B`. An + Archived or Disposed version *at the resolved upstream repository itself* is skipped, the walk + continuing to the next candidate, since a same-domain upstream has a real CodeArtifact-shaped + status to check that a public registry never does. A version no upstream holds is fetched + through an upstream's own external connection, the first in that same order that has one, and + retained both there and in the repository the request was made to, as AWS documents for a + downstream request chaining through an upstream's `public:*` connection; a packument, Simple + index or `maven-metadata.xml` read through such an upstream offers what its connection has too. + A retained version's `origin.domainEntryPoint` names where it entered the domain: the external + connection it was fetched through, `EXTERNAL`, or the repository it was published to, however + many upstreams it was retained through. Since the copy from a same-domain upstream never leaves + this process (a fetch through an upstream's connection is that connection's own import), pypi's + own copy here needs none of the real external connection's PEP 691 sha256 re-verification or + background-thread split: every asset of the resolved version is copied synchronously, in one + pass. - **Maven external-connection retention is the one place this emulator makes a real outbound call to the public internet**, rather than only ever talking to a container it started itself. An offline environment, or a real outage of the public repository being connected to, means a diff --git a/src/main/java/io/floci/aws/services/codeartifact/CodeArtifactMavenExternalConnectionImporter.java b/src/main/java/io/floci/aws/services/codeartifact/CodeArtifactMavenExternalConnectionImporter.java index ec5330d7e4..25d4764ed6 100644 --- a/src/main/java/io/floci/aws/services/codeartifact/CodeArtifactMavenExternalConnectionImporter.java +++ b/src/main/java/io/floci/aws/services/codeartifact/CodeArtifactMavenExternalConnectionImporter.java @@ -372,6 +372,18 @@ public class CodeArtifactMavenExternalConnectionImporter { false); } + /** + * Whether {@code repository} has a Maven external connection to fetch through. A repository + * deleted since its name was read, as an upstream in a search order can be, has none. + */ + boolean hasExternalConnection(String region, String domain, String owner, String repository) { + try { + return mavenExternalConnectionName(region, domain, owner, repository) != null; + } catch (AwsException e) { + return false; + } + } + private String mavenExternalConnectionName(String region, String domain, String owner, String repository) { return service.describeRepository(region, domain, owner, repository).getExternalConnections().stream() .filter(ec -> "maven".equals(ec.getPackageFormat())) diff --git a/src/main/java/io/floci/aws/services/codeartifact/CodeArtifactMavenUpstreamRepositoryImporter.java b/src/main/java/io/floci/aws/services/codeartifact/CodeArtifactMavenUpstreamRepositoryImporter.java index 3120027c99..29d44d3012 100644 --- a/src/main/java/io/floci/aws/services/codeartifact/CodeArtifactMavenUpstreamRepositoryImporter.java +++ b/src/main/java/io/floci/aws/services/codeartifact/CodeArtifactMavenUpstreamRepositoryImporter.java @@ -26,11 +26,15 @@ import java.util.function.Predicate; *