mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(dns): answer an own-suffix name with the emulator's address when its stored record has no resolvable target (#9360)
Since #8926 a stored public zone under an emulator suffix answers A and AAAA, and a public alias to a target Floci does not serve, such as a Cognito custom domain aliased to CloudFront, got REFUSED, so a container asked public DNS and got its own loopback address. An A or AAAA standard query for a name under an emulator suffix that the stored zone refuses is now answered as the emulator's own name, after the VPC forwarding-rule check. A query with more than one question, a class other than IN, or a non-standard opcode or flag stays REFUSED. Closes #9359.
This commit is contained in:
1 parent
5b2fa9a30d
commit
398d34239e
4 files changed
+90
-17
No files matched your search
@@ -408,6 +408,36 @@ class EmbeddedDnsServerTest {
|
||||
dns.planQuery("example.com", CLIENT, MY_IP, 1).ruleTargets());
|
||||
}
|
||||
|
||||
@Test
|
||||
void planQuery_answersAnOwnNameWhoseStoredAddressIsRefusedLikeAnyOtherOwnName() {
|
||||
DnsRecordSource refusing = new DnsRecordSource() {
|
||||
@Override
|
||||
public Optional<DnsAnswer> resolveAuthoritative(String name, int type) {
|
||||
return Optional.of(DnsAnswer.refused());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<DnsAnswer> resolveIpv4(String name) {
|
||||
return Optional.empty();
|
||||
}
|
||||
};
|
||||
EmbeddedDnsServer dns = withRules(List.of(refusing),
|
||||
rules("vpc-a", forward("rule.localhost.floci.io", "10.1.0.53")), clientVpc("vpc-a"));
|
||||
|
||||
assertEquals(List.of(MY_IP),
|
||||
dns.planQuery("api.auth.localhost.floci.io", CLIENT, MY_IP, 1).answer().orElseThrow().addresses());
|
||||
assertEquals(DnsAnswer.noData(),
|
||||
dns.planQuery("api.auth.localhost.floci.io", CLIENT, MY_IP, 28).answer().orElseThrow());
|
||||
assertEquals(DnsAnswer.refused(),
|
||||
dns.planQuery("api.auth.localhost.floci.io", CLIENT, MY_IP, 16).answer().orElseThrow());
|
||||
assertEquals(DnsAnswer.refused(),
|
||||
dns.planQuery("api.auth.example.test", CLIENT, MY_IP, 1).answer().orElseThrow());
|
||||
assertEquals(DnsAnswer.refused(),
|
||||
dns.planQuery("ip-172-16-128-9.ec2.internal", CLIENT, MY_IP, 1).answer().orElseThrow());
|
||||
assertEquals(List.of(new DnsForwardingRule.Target("10.1.0.53", 53)),
|
||||
dns.planQuery("api.rule.localhost.floci.io", CLIENT, MY_IP, 1).ruleTargets());
|
||||
}
|
||||
|
||||
@Test
|
||||
void planQuery_keepsResolvingWhenARuleSourceThrows() {
|
||||
DnsForwardingRuleSource failing = (accountId, region, vpcId) -> {
|
||||
|
||||
@@ -2,6 +2,7 @@ package io.floci.aws.core.common.dns;
|
||||
|
||||
import io.floci.aws.services.route53.Route53DnsRecordSource;
|
||||
import io.floci.aws.services.route53.Route53Service;
|
||||
import io.floci.aws.services.route53.model.AliasTarget;
|
||||
import io.floci.aws.services.route53.model.ResourceRecord;
|
||||
import io.floci.aws.services.route53.model.ResourceRecordSet;
|
||||
import io.floci.aws.services.route53.model.VpcAssociation;
|
||||
@@ -296,22 +297,40 @@ class Route53DnsPacketIntegrationTest {
|
||||
}
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@CsvSource({"A,1,1", "AAAA,28,0"})
|
||||
void anOwnNameAliasToATargetFlociDoesNotServeAnswersAsTheEmulator(String recordType, int type, int answers)
|
||||
throws Exception {
|
||||
String zone = uniqueName() + ".localhost.floci.io";
|
||||
String id = createZone(zone);
|
||||
String name = "api.auth." + zone;
|
||||
AliasTarget cloudFront = new AliasTarget();
|
||||
cloudFront.setHostedZoneId("Z2FDTNDATAQYW2");
|
||||
cloudFront.setDnsName("d111111abcdef8.cloudfront.net.");
|
||||
ResourceRecordSet alias = new ResourceRecordSet();
|
||||
alias.setName(name);
|
||||
alias.setType(recordType);
|
||||
alias.setAliasTarget(cloudFront);
|
||||
change(id, "CREATE", alias);
|
||||
|
||||
byte[] response = query(DnsTestQuery.query(name, type, 0x1234));
|
||||
assertPrivateHeader(response, 0, answers);
|
||||
if (type == 1) {
|
||||
assertArrayEquals(new DnsRecord.Address(1, "127.0.0.1").data(),
|
||||
Arrays.copyOfRange(response, response.length - 4, response.length));
|
||||
}
|
||||
for (int field : List.of(2, 4, -1, -2)) {
|
||||
assertHeader(query(malformed(DnsTestQuery.query(name, type, 0x1234), field)), 5, false, 0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void privateZonePrecedenceAndPublicQueryShapeRemainExplicit() throws Exception {
|
||||
String name = uniqueName() + ".example";
|
||||
String id = createZone(name);
|
||||
change(id, "CREATE", record("marker." + name, "TXT", 60, "\"public\""));
|
||||
for (int field : List.of(2, 4, -1, -2)) {
|
||||
byte[] request = DnsTestQuery.query("marker." + name, 16, 0x1234);
|
||||
ByteBuffer packet = ByteBuffer.wrap(request);
|
||||
if (field == -2) {
|
||||
packet.putShort(2, (short) 0x0140);
|
||||
} else if (field == -1) {
|
||||
packet.putShort(request.length - 2, (short) 3);
|
||||
} else {
|
||||
packet.putShort(field, (short) (field == 2 ? 0x0900 : 2));
|
||||
}
|
||||
assertHeader(query(request), 5, false, 0, 0);
|
||||
assertHeader(query(malformed(DnsTestQuery.query("marker." + name, 16, 0x1234), field)), 5, false, 0, 0);
|
||||
}
|
||||
String privateId = route53.createHostedZone(name, UUID.randomUUID().toString(), null,
|
||||
new VpcAssociation("vpc-dns-packet", "us-east-1")).zone().getId();
|
||||
@@ -390,6 +409,19 @@ class Route53DnsPacketIntegrationTest {
|
||||
return "dns-" + UUID.randomUUID().toString().substring(0, 8);
|
||||
}
|
||||
|
||||
/** A shape a public zone refuses: opcode 1, two questions, class CH, or the reserved Z bit. */
|
||||
private static byte[] malformed(byte[] request, int field) {
|
||||
ByteBuffer packet = ByteBuffer.wrap(request);
|
||||
if (field == -2) {
|
||||
packet.putShort(2, (short) 0x0140);
|
||||
} else if (field == -1) {
|
||||
packet.putShort(request.length - 2, (short) 3);
|
||||
} else {
|
||||
packet.putShort(field, (short) (field == 2 ? 0x0900 : 2));
|
||||
}
|
||||
return request;
|
||||
}
|
||||
|
||||
|
||||
private static void assertPrivateHeader(byte[] response, int rcode, int answers) {
|
||||
ByteBuffer packet = ByteBuffer.wrap(response);
|
||||
|
||||
Reference in new issue
Block a user