fix: preserve Route 53 private hosted-zone VPC associations (#2342)

* fix: preserve Route 53 private hosted-zone VPC associations

Fixes #2294

* fix(route53): correct SDK accessor, validate VPC, dedupe test order

Addresses @pgermosen's three review points:

1. sdk-test-java failed to compile: the real SDK accessor for the VPCs list is
   vpCs(), not vpcs(). Confirmed with javap against the pinned
   route53-2.44.14.jar.

2. parseVpcAssociation accepted a <VPC> element carrying only one of VPCId /
   VPCRegion and still marked the zone private with a half-populated
   association. AWS requires both together whenever VPC is present, so an
   incomplete element is now rejected with InvalidInput/400.

3. Route53IntegrationTest had two methods at @Order(3), leaving their relative
   order undefined. Renumbered the trailing cases so every order is unique.

---------

Co-authored-by: Matt Van Horn <455140+mvanhorn@users.noreply.github.com>
This commit is contained in:
Matt Van HornandMatt Van Horn authored and GitHub committed 2026-08-20 23:28:14 -04:00
1 parent c4597f2e53
commit 967ea843a0
6 files changed
+232 -28

No files matched your search

@@ -12,6 +12,7 @@ import io.github.hectorvent.floci.services.route53.model.HealthCheckConfig;
import io.github.hectorvent.floci.services.route53.model.HostedZone;
import io.github.hectorvent.floci.services.route53.model.ResourceRecord;
import io.github.hectorvent.floci.services.route53.model.ResourceRecordSet;
import io.github.hectorvent.floci.services.route53.model.VpcAssociation;
import jakarta.inject.Inject;
import jakarta.ws.rs.DELETE;
import jakarta.ws.rs.DefaultValue;
@@ -60,25 +61,26 @@ public class Route53Controller {
String name = XmlParser.extractFirst(body, "Name", null);
String callerRef = XmlParser.extractFirst(body, "CallerReference", null);
String comment = XmlParser.extractFirst(body, "Comment", null);
boolean privateZone = "true".equalsIgnoreCase(
XmlParser.extractFirst(body, "PrivateZone", "false"));
VpcAssociation vpcAssociation = parseVpcAssociation(body);
if (name == null || callerRef == null) {
throw new AwsException("InvalidInput", "Name and CallerReference are required.", 400);
}
CreateZoneResult result = service.createHostedZone(name, callerRef, comment, privateZone);
String xml = new XmlBuilder()
CreateZoneResult result = service.createHostedZone(name, callerRef, comment, vpcAssociation);
XmlBuilder xml = new XmlBuilder()
.start("CreateHostedZoneResponse", NS)
.raw(xmlHostedZone(result.zone()))
.raw(xmlChangeInfo(result.change()))
.raw(xmlDelegationSet())
.end("CreateHostedZoneResponse")
.build();
.raw(xmlDelegationSet());
if (!result.zone().getVpcAssociations().isEmpty()) {
xml.raw(xmlVpcAssociation(result.zone().getVpcAssociations().getFirst()));
}
xml.end("CreateHostedZoneResponse");
return Response.created(URI.create("/2013-04-01/hostedzone/" + result.zone().getId()))
.type(XML)
.entity(xml)
.entity(xml.build())
.build();
} catch (AwsException e) {
return xmlErrorResponse(e);
@@ -94,6 +96,7 @@ public class Route53Controller {
.start("GetHostedZoneResponse", NS)
.raw(xmlHostedZone(zone))
.raw(xmlDelegationSet())
.raw(xmlVpcAssociations(zone.getVpcAssociations()))
.end("GetHostedZoneResponse")
.build();
return Response.ok(xml, XML).build();
@@ -541,6 +544,26 @@ public class Route53Controller {
return xml.build();
}
private String xmlVpcAssociation(VpcAssociation association) {
return new XmlBuilder()
.start("VPC")
.elem("VPCRegion", association.getVpcRegion())
.elem("VPCId", association.getVpcId())
.end("VPC")
.build();
}
private String xmlVpcAssociations(List<VpcAssociation> associations) {
if (associations == null || associations.isEmpty()) {
return "";
}
XmlBuilder xml = new XmlBuilder().start("VPCs");
for (VpcAssociation association : associations) {
xml.raw(xmlVpcAssociation(association));
}
return xml.end("VPCs").build();
}
private String xmlResourceRecordSet(ResourceRecordSet rrs) {
XmlBuilder xml = new XmlBuilder()
.start("ResourceRecordSet")
@@ -611,6 +634,23 @@ public class Route53Controller {
// ── Request parsers ───────────────────────────────────────────────────────
private VpcAssociation parseVpcAssociation(String body) {
List<Map<String, String>> vpcs = XmlParser.extractGroups(body, "VPC");
if (vpcs.isEmpty()) {
return null;
}
Map<String, String> vpc = vpcs.get(0);
String vpcId = vpc.get("VPCId");
String vpcRegion = vpc.get("VPCRegion");
// AWS requires VPCId and VPCRegion together whenever VPC is present; a
// half-populated element must not mark the zone private.
if (vpcId == null || vpcId.isEmpty() || vpcRegion == null || vpcRegion.isEmpty()) {
throw new AwsException(
"InvalidInput", "VPCId and VPCRegion are both required when VPC is specified.", 400);
}
return new VpcAssociation(vpcId, vpcRegion);
}
/**
* Parses the ChangeBatch XML using StAX to correctly handle multiple Change elements,
* each containing a ResourceRecordSet with its own set of ResourceRecord/Value children.
@@ -11,6 +11,7 @@ import io.github.hectorvent.floci.services.route53.model.HealthCheckConfig;
import io.github.hectorvent.floci.services.route53.model.HostedZone;
import io.github.hectorvent.floci.services.route53.model.ResourceRecord;
import io.github.hectorvent.floci.services.route53.model.ResourceRecordSet;
import io.github.hectorvent.floci.services.route53.model.VpcAssociation;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
@@ -63,7 +64,7 @@ public class Route53Service {
// ── Hosted Zones ──────────────────────────────────────────────────────────
public synchronized CreateZoneResult createHostedZone(String name, String callerReference,
String comment, boolean privateZone) {
String comment, VpcAssociation vpcAssociation) {
String normalizedName = normalizeName(name);
for (HostedZone existing : zoneStore.scan(k -> true)) {
@@ -74,7 +75,7 @@ public class Route53Service {
}
String id = generateZoneId();
HostedZone zone = new HostedZone(id, normalizedName, callerReference, comment, privateZone);
HostedZone zone = new HostedZone(id, normalizedName, callerReference, comment, vpcAssociation);
zoneStore.put(id, zone);
recordStore.put(id, buildDefaultRecords(normalizedName));
ChangeInfo change = newChange(null);
@@ -2,6 +2,9 @@ package io.github.hectorvent.floci.services.route53.model;
import io.quarkus.runtime.annotations.RegisterForReflection;
import java.util.ArrayList;
import java.util.List;
@RegisterForReflection
public class HostedZone {
@@ -11,6 +14,7 @@ public class HostedZone {
private String comment;
private boolean privateZone;
private int resourceRecordSetCount;
private List<VpcAssociation> vpcAssociations = new ArrayList<>();
public HostedZone() {}
@@ -24,6 +28,14 @@ public class HostedZone {
this.resourceRecordSetCount = 2;
}
public HostedZone(String id, String name, String callerReference,
String comment, VpcAssociation vpcAssociation) {
this(id, name, callerReference, comment, vpcAssociation != null);
if (vpcAssociation != null) {
this.vpcAssociations.add(vpcAssociation);
}
}
public String getId() { return id; }
public void setId(String id) { this.id = id; }
@@ -43,4 +55,9 @@ public class HostedZone {
public void setResourceRecordSetCount(int resourceRecordSetCount) {
this.resourceRecordSetCount = resourceRecordSetCount;
}
public List<VpcAssociation> getVpcAssociations() { return vpcAssociations; }
public void setVpcAssociations(List<VpcAssociation> vpcAssociations) {
this.vpcAssociations = vpcAssociations != null ? vpcAssociations : new ArrayList<>();
}
}
@@ -0,0 +1,23 @@
package io.github.hectorvent.floci.services.route53.model;
import io.quarkus.runtime.annotations.RegisterForReflection;
@RegisterForReflection
public class VpcAssociation {
private String vpcId;
private String vpcRegion;
public VpcAssociation() {}
public VpcAssociation(String vpcId, String vpcRegion) {
this.vpcId = vpcId;
this.vpcRegion = vpcRegion;
}
public String getVpcId() { return vpcId; }
public void setVpcId(String vpcId) { this.vpcId = vpcId; }
public String getVpcRegion() { return vpcRegion; }
public void setVpcRegion(String vpcRegion) { this.vpcRegion = vpcRegion; }
}