From e9b53c9f58161ff774dae7b990a7479a7e86e645 Mon Sep 17 00:00:00 2001 From: Chirag Aggarwal Date: Thu, 3 Sep 2026 15:46:53 +0100 Subject: [PATCH 1/5] fix: isolate proxy DNS verification fixtures --- tests/e2e/Services/Proxy/ProxyBase.php | 24 ++++++------- tests/resources/coredns/Corefile | 49 +++++++++++++++++++------- 2 files changed, 49 insertions(+), 24 deletions(-) diff --git a/tests/e2e/Services/Proxy/ProxyBase.php b/tests/e2e/Services/Proxy/ProxyBase.php index 86a6e4d5f7..0e0522fb7c 100644 --- a/tests/e2e/Services/Proxy/ProxyBase.php +++ b/tests/e2e/Services/Proxy/ProxyBase.php @@ -12,8 +12,7 @@ trait ProxyBase protected function tearDown(): void { - // Cleanup for testRuleVerification test - // Required as it uses static domain name + // Cleanup fixture rules left by failed verification tests $rules = $this->listRules([ 'queries' => [ Query::endsWith('domain', 'webapp.com')->toString(), @@ -665,12 +664,13 @@ trait ProxyBase public function testRuleVerification(): void { + $fixture = \uniqid($this->getSide() . '-'); // 1. Site rule can verify $site = $this->setupSite(); $siteId = $site['siteId']; - $rule = $this->createSiteRule('stage-site.webapp.com', $siteId); + $rule = $this->createSiteRule("{$fixture}.stage-site.webapp.com", $siteId); $this->assertEquals(201, $rule['headers']['status-code']); $this->assertEquals('verifying', $rule['body']['status']); $this->assertEmpty($rule['body']['logs']); @@ -690,13 +690,13 @@ trait ProxyBase $function = $this->setupFunction(); $functionId = $function['functionId']; - $rule = $this->createFunctionRule('stage-function.webapp.com', $functionId); + $rule = $this->createFunctionRule("{$fixture}.stage-function.webapp.com", $functionId); $this->assertEquals(201, $rule['headers']['status-code']); $this->assertEquals('verifying', $rule['body']['status']); $this->assertEmpty($rule['body']['logs']); $this->cleanupRule($rule['body']['$id']); - $rule = $this->createAPIRule('stage-site.webapp.com'); + $rule = $this->createAPIRule("{$fixture}.stage-site.webapp.com"); $this->assertEquals(201, $rule['headers']['status-code']); $this->assertEquals('unverified', $rule['body']['status']); $this->assertStringContainsString('has incorrect CNAME value', $rule['body']['logs']); @@ -705,7 +705,7 @@ trait ProxyBase $this->cleanupFunction($functionId); // 3. Wrong A record fails to verify - $rule = $this->createAPIRule('wrong-a-webapp.com'); + $rule = $this->createAPIRule("{$fixture}.wrong-a-webapp.com"); $this->assertEquals(201, $rule['headers']['status-code']); $this->assertEquals('unverified', $rule['body']['status']); $this->assertStringContainsString('is missing CNAME record', $rule['body']['logs']); @@ -722,7 +722,7 @@ trait ProxyBase $this->cleanupRule($ruleId); // 4. Correct A record can verify - $rule = $this->createAPIRule('webapp.com'); + $rule = $this->createAPIRule("{$fixture}.correct-a.webapp.com"); $this->assertEquals(201, $rule['headers']['status-code']); $this->assertEquals('verifying', $rule['body']['status']); $this->assertEmpty($rule['body']['logs']); @@ -730,7 +730,7 @@ trait ProxyBase $this->cleanupRule($rule['body']['$id']); // 5. Correct CNAME record can verify (no CAA record) - $rule = $this->createAPIRule('stage.webapp.com'); + $rule = $this->createAPIRule("{$fixture}.stage.webapp.com"); $this->assertEquals(201, $rule['headers']['status-code']); $this->assertEquals('verifying', $rule['body']['status']); $this->assertEmpty($rule['body']['logs']); @@ -738,7 +738,7 @@ trait ProxyBase $this->cleanupRule($rule['body']['$id']); // 6. Missing CNAME record fails to verify - $rule = $this->createAPIRule('stage-missing-cname.webapp.com'); + $rule = $this->createAPIRule("{$fixture}.stage-missing-cname.webapp.com"); $this->assertEquals(201, $rule['headers']['status-code']); $this->assertEquals('unverified', $rule['body']['status']); $this->assertStringContainsString('is missing CNAME record', $rule['body']['logs']); @@ -755,7 +755,7 @@ trait ProxyBase $this->cleanupRule($ruleId); // 7. Wrong CNAME record fails to verify - $rule = $this->createAPIRule('stage-wrong-cname.webapp.com'); + $rule = $this->createAPIRule("{$fixture}.stage-wrong-cname.webapp.com"); $this->assertEquals(201, $rule['headers']['status-code']); $this->assertEquals('unverified', $rule['body']['status']); $this->assertStringContainsString('has incorrect CNAME value', $rule['body']['logs']); @@ -772,7 +772,7 @@ trait ProxyBase $this->cleanupRule($ruleId); // 8. Wrong CAA record fails to verify - $rule = $this->createAPIRule('stage-wrong-caa.webapp.com'); + $rule = $this->createAPIRule("{$fixture}.stage-wrong-caa.webapp.com"); $this->assertEquals(201, $rule['headers']['status-code']); $this->assertEquals('unverified', $rule['body']['status']); $this->assertStringContainsString('has incorrect CAA value', $rule['body']['logs']); @@ -789,7 +789,7 @@ trait ProxyBase $this->cleanupRule($ruleId); // 9. Correct CAA record can verify - $rule = $this->createAPIRule('stage-correct-caa.webapp.com'); + $rule = $this->createAPIRule("{$fixture}.stage-correct-caa.webapp.com"); $this->assertEquals(201, $rule['headers']['status-code']); $this->assertEquals('verifying', $rule['body']['status']); $this->assertEmpty($rule['body']['logs']); diff --git a/tests/resources/coredns/Corefile b/tests/resources/coredns/Corefile index df2739ad0e..3bec71804a 100644 --- a/tests/resources/coredns/Corefile +++ b/tests/resources/coredns/Corefile @@ -16,63 +16,88 @@ webapp.com { } template IN CNAME { - match "^stage-site\.webapp\.com\.$" + match "^([a-z0-9-]+\.)?stage-site\.webapp\.com\.$" answer "{{ .Name }} 60 IN CNAME sites.localhost." fallthrough } template IN CNAME { - match "^stage-function\.webapp\.com\.$" + match "^([a-z0-9-]+\.)?stage-function\.webapp\.com\.$" answer "{{ .Name }} 60 IN CNAME cname.localhost." fallthrough } template IN CNAME { - match "^stage\.webapp\.com\.$" + match "^([a-z0-9-]+\.)?stage\.webapp\.com\.$" answer "{{ .Name }} 60 IN CNAME cname.localhost." fallthrough } template IN CNAME { - match "^stage-wrong-cname\.webapp\.com\.$" + match "^([a-z0-9-]+\.)?stage-wrong-cname\.webapp\.com\.$" answer "{{ .Name }} 60 IN CNAME cname-wrong.tests.appwrite.io." fallthrough } template IN A { - match "^stage-wrong-caa\.webapp\.com\.$" + match "^([a-z0-9-]+\.)?correct-a\.webapp\.com\.$" + answer "{{ .Name }} 60 IN A 203.0.0.1" + fallthrough + } + + template IN A { + match "^([a-z0-9-]+\.)?stage-wrong-caa\.webapp\.com\.$" answer "{{ .Name }} 60 IN A 203.0.0.1" fallthrough } template IN CAA { - match "^stage-wrong-caa\.webapp\.com\.$" + match "^([a-z0-9-]+\.)?stage-wrong-caa\.webapp\.com\.$" answer "{{ .Name }} 60 IN CAA 0 issue \"unknown-issuer.org\"" fallthrough } - template IN A { - match "^stage-correct-caa\.webapp\.com\.$" + match "^([a-z0-9-]+\.)?stage-correct-caa\.webapp\.com\.$" answer "{{ .Name }} 60 IN A 203.0.0.1" fallthrough } template IN CAA { - match "^stage-correct-caa\.webapp\.com\.$" + match "^([a-z0-9-]+\.)?stage-correct-caa\.webapp\.com\.$" answer "{{ .Name }} 60 IN CAA 0 issue \"digicert.com\"" fallthrough } - forward . 1.1.1.1 + # Keep this test zone authoritative. Forwarding missing fixture records to a + # public resolver makes verification depend on external DNS availability. + template IN A { + match "^([a-z0-9-]+\.)*webapp\.com\.$" + rcode NOERROR + } + + template IN AAAA { + match "^([a-z0-9-]+\.)*webapp\.com\.$" + rcode NOERROR + } + + template IN CNAME { + match "^([a-z0-9-]+\.)*webapp\.com\.$" + rcode NOERROR + } + + template IN CAA { + match "^([a-z0-9-]+\.)*webapp\.com\.$" + rcode NOERROR + } } # Zones configuration wrong-a-webapp.com { bind 172.16.238.100 template IN A { - match "^wrong-a-webapp\.com\.$" + match "^([a-z0-9-]+\.)?wrong-a-webapp\.com\.$" answer "{{ .Name }} 60 IN A 203.0.0.5" fallthrough } -} \ No newline at end of file +} From c6a39580d5f4246f531ac7779a3ed21c37e64e85 Mon Sep 17 00:00:00 2001 From: Chirag Aggarwal Date: Thu, 3 Sep 2026 16:15:04 +0100 Subject: [PATCH 2/5] fix: include zone SOA in authoritative empty CoreDNS fixture answers The catch-all templates returned NOERROR with no answer and no authority section. utopia-php/dns rejects authoritative NODATA responses without an SOA record, so every CAA lookup for a webapp.com fixture threw and the site rule verification failed with 'DNS query failed.'. --- tests/resources/coredns/Corefile | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/resources/coredns/Corefile b/tests/resources/coredns/Corefile index 3bec71804a..c8f552d38a 100644 --- a/tests/resources/coredns/Corefile +++ b/tests/resources/coredns/Corefile @@ -71,23 +71,29 @@ webapp.com { # Keep this test zone authoritative. Forwarding missing fixture records to a # public resolver makes verification depend on external DNS availability. + # Authoritative empty answers must carry the zone SOA in the authority + # section (RFC 2308 NODATA), otherwise the DNS client rejects the response. template IN A { match "^([a-z0-9-]+\.)*webapp\.com\.$" + authority "webapp.com. 60 IN SOA ns.webapp.com. hostmaster.webapp.com. 1 3600 600 86400 60" rcode NOERROR } template IN AAAA { match "^([a-z0-9-]+\.)*webapp\.com\.$" + authority "webapp.com. 60 IN SOA ns.webapp.com. hostmaster.webapp.com. 1 3600 600 86400 60" rcode NOERROR } template IN CNAME { match "^([a-z0-9-]+\.)*webapp\.com\.$" + authority "webapp.com. 60 IN SOA ns.webapp.com. hostmaster.webapp.com. 1 3600 600 86400 60" rcode NOERROR } template IN CAA { match "^([a-z0-9-]+\.)*webapp\.com\.$" + authority "webapp.com. 60 IN SOA ns.webapp.com. hostmaster.webapp.com. 1 3600 600 86400 60" rcode NOERROR } } From 89138889ba3203c428789528dc3209189b0ab6fb Mon Sep 17 00:00:00 2001 From: Chirag Aggarwal Date: Fri, 4 Sep 2026 14:42:50 +0100 Subject: [PATCH 3/5] test: replace the CoreDNS fixture with an unbound recursive resolver The Proxy verification tests talk to a resolver the app believes is a public recursive one. CoreDNS is an authoritative server, so keeping the test zone self-contained meant regex templates plus catch-all NODATA rules bolted inside an authoritative zone. Unbound is a recursive resolver: fixtures are one local-data line per record, redirect zones cover the per-run unique prefixes, and forwarding is the server's own job. This mirrors deploy/dns-mock in appwrite-labs/cloud. Every zone that can answer negatively declares an SOA, because utopia-php/dns rejects an authoritative NXDOMAIN or NODATA without one and unbound only adds it when configured. --- docker-compose.override.yml | 16 ++-- tests/resources/coredns/Corefile | 109 ---------------------- tests/resources/dns/forward.conf | 12 +++ tests/resources/dns/unbound.conf | 35 +++++++ tests/resources/dns/zones.conf | 53 +++++++++++ tests/unit/Network/Validators/DNSTest.php | 4 +- 6 files changed, 110 insertions(+), 119 deletions(-) delete mode 100644 tests/resources/coredns/Corefile create mode 100644 tests/resources/dns/forward.conf create mode 100644 tests/resources/dns/unbound.conf create mode 100644 tests/resources/dns/zones.conf diff --git a/docker-compose.override.yml b/docker-compose.override.yml index 5245a1c333..0c627983f0 100644 --- a/docker-compose.override.yml +++ b/docker-compose.override.yml @@ -20,7 +20,7 @@ services: - ./src:/usr/src/code/src - ./dev:/usr/src/code/dev depends_on: - - coredns + - dns ports: - 9501:80 dns: @@ -301,23 +301,23 @@ services: volumes: - ./app:/usr/src/code/app - ./src:/usr/src/code/src - coredns: - image: coredns/coredns:1.12.4 - container_name: appwrite-coredns + dns: # Stand-in public resolver for the domain-verification tests (Proxy APIs) + image: alpinelinux/unbound:latest@sha256:8d2611fe8fcbd8e26b6f88e2eb0c3b803368195d50cfa0c30fdfaa5087076709 + container_name: appwrite-dns restart: unless-stopped logging: driver: json-file options: max-file: "5" max-size: 10m - command: - - -conf - - /mnt/resources/Corefile + # The image entrypoint writes its own config; this fixture supplies one. + entrypoint: ["unbound", "-d", "-c", "/mnt/resources/unbound.conf"] networks: appwrite: + # _APP_DNS points at this address. ipv4_address: 172.16.238.100 volumes: - - ./tests/resources/coredns:/mnt/resources:ro + - ./tests/resources/dns:/mnt/resources:ro maildev: image: appwrite/mailcatcher:1.1.1 container_name: appwrite-mailcatcher diff --git a/tests/resources/coredns/Corefile b/tests/resources/coredns/Corefile deleted file mode 100644 index c8f552d38a..0000000000 --- a/tests/resources/coredns/Corefile +++ /dev/null @@ -1,109 +0,0 @@ -# Forward unknown queries to Docker's embedded DNS for service name resolution, -# with Cloudflare as fallback for external names. -# Bind to our static IP to avoid conflict with Docker's DNS proxy on 127.0.0.11. -. { - bind 172.16.238.100 - forward . 127.0.0.11 1.1.1.1 -} - -# Zones configuration -webapp.com { - bind 172.16.238.100 - template IN A { - match "^webapp\.com\.$" - answer "{{ .Name }} 60 IN A 203.0.0.1" - fallthrough - } - - template IN CNAME { - match "^([a-z0-9-]+\.)?stage-site\.webapp\.com\.$" - answer "{{ .Name }} 60 IN CNAME sites.localhost." - fallthrough - } - - template IN CNAME { - match "^([a-z0-9-]+\.)?stage-function\.webapp\.com\.$" - answer "{{ .Name }} 60 IN CNAME cname.localhost." - fallthrough - } - - template IN CNAME { - match "^([a-z0-9-]+\.)?stage\.webapp\.com\.$" - answer "{{ .Name }} 60 IN CNAME cname.localhost." - fallthrough - } - - template IN CNAME { - match "^([a-z0-9-]+\.)?stage-wrong-cname\.webapp\.com\.$" - answer "{{ .Name }} 60 IN CNAME cname-wrong.tests.appwrite.io." - fallthrough - } - - template IN A { - match "^([a-z0-9-]+\.)?correct-a\.webapp\.com\.$" - answer "{{ .Name }} 60 IN A 203.0.0.1" - fallthrough - } - - template IN A { - match "^([a-z0-9-]+\.)?stage-wrong-caa\.webapp\.com\.$" - answer "{{ .Name }} 60 IN A 203.0.0.1" - fallthrough - } - - template IN CAA { - match "^([a-z0-9-]+\.)?stage-wrong-caa\.webapp\.com\.$" - answer "{{ .Name }} 60 IN CAA 0 issue \"unknown-issuer.org\"" - fallthrough - } - - template IN A { - match "^([a-z0-9-]+\.)?stage-correct-caa\.webapp\.com\.$" - answer "{{ .Name }} 60 IN A 203.0.0.1" - fallthrough - } - - template IN CAA { - match "^([a-z0-9-]+\.)?stage-correct-caa\.webapp\.com\.$" - answer "{{ .Name }} 60 IN CAA 0 issue \"digicert.com\"" - fallthrough - } - - # Keep this test zone authoritative. Forwarding missing fixture records to a - # public resolver makes verification depend on external DNS availability. - # Authoritative empty answers must carry the zone SOA in the authority - # section (RFC 2308 NODATA), otherwise the DNS client rejects the response. - template IN A { - match "^([a-z0-9-]+\.)*webapp\.com\.$" - authority "webapp.com. 60 IN SOA ns.webapp.com. hostmaster.webapp.com. 1 3600 600 86400 60" - rcode NOERROR - } - - template IN AAAA { - match "^([a-z0-9-]+\.)*webapp\.com\.$" - authority "webapp.com. 60 IN SOA ns.webapp.com. hostmaster.webapp.com. 1 3600 600 86400 60" - rcode NOERROR - } - - template IN CNAME { - match "^([a-z0-9-]+\.)*webapp\.com\.$" - authority "webapp.com. 60 IN SOA ns.webapp.com. hostmaster.webapp.com. 1 3600 600 86400 60" - rcode NOERROR - } - - template IN CAA { - match "^([a-z0-9-]+\.)*webapp\.com\.$" - authority "webapp.com. 60 IN SOA ns.webapp.com. hostmaster.webapp.com. 1 3600 600 86400 60" - rcode NOERROR - } -} - -# Zones configuration -wrong-a-webapp.com { - bind 172.16.238.100 - template IN A { - match "^([a-z0-9-]+\.)?wrong-a-webapp\.com\.$" - answer "{{ .Name }} 60 IN A 203.0.0.5" - fallthrough - } -} diff --git a/tests/resources/dns/forward.conf b/tests/resources/dns/forward.conf new file mode 100644 index 0000000000..55bcf0b586 --- /dev/null +++ b/tests/resources/dns/forward.conf @@ -0,0 +1,12 @@ +# Everything outside the fake zones goes to Docker's embedded DNS, so compose +# service names resolve, with a public resolver as fallback for external names. + +server: + # 127.0.0.11 is loopback inside this container; unbound refuses loopback + # upstreams unless told otherwise. + do-not-query-localhost: no + +forward-zone: + name: "." + forward-addr: 127.0.0.11 + forward-addr: 1.1.1.1 diff --git a/tests/resources/dns/unbound.conf b/tests/resources/dns/unbound.conf new file mode 100644 index 0000000000..7bb079904f --- /dev/null +++ b/tests/resources/dns/unbound.conf @@ -0,0 +1,35 @@ +# A stand-in for the public recursive resolver, used by the Proxy DNS +# verification tests to verify customer domains. Mirrors deploy/dns-mock in +# appwrite-labs/cloud. +# +# Unbound rather than CoreDNS because a recursive resolver is what the app +# thinks it is talking to: overrides are one `local-data` line per record +# (every RR type, no regex templates), and forwarding is the server's own job +# rather than a catch-all bolted inside an authoritative zone. +# +# zones.conf - the fake public zones. +# forward.conf - where every other query goes. + +server: + interface: 0.0.0.0 + port: 53 + do-ip6: no + access-control: 0.0.0.0/0 allow + # Test fixture: log what was asked, and never cache a stale answer between + # test cases. + verbosity: 1 + log-queries: yes + cache-max-ttl: 60 + cache-min-ttl: 0 + # No `private-address` entries: the fake zones answer with reserved addresses + # on purpose, and the forwarder resolves compose service names to private + # IPs. Configuring any private range here would strip both as rebinding + # attacks. + # + # No DNSSEC either: the fake zones are unsigned, and validating the upstream + # chain would only add a network dependency to a fixture. + val-permissive-mode: yes + + include: "/mnt/resources/zones.conf" + +include: "/mnt/resources/forward.conf" diff --git a/tests/resources/dns/zones.conf b/tests/resources/dns/zones.conf new file mode 100644 index 0000000000..4fae5b04c3 --- /dev/null +++ b/tests/resources/dns/zones.conf @@ -0,0 +1,53 @@ +# Fake public zones for the Proxy DNS verification tests. One line per record, +# so a case is added by adding the record it needs. +# +# Each test run prefixes its fixture hostnames with a unique label, so every +# fixture is a `redirect` zone: any name under it answers with the zone's own +# records. `static` zones answer only exact names; anything else under them is +# NXDOMAIN without a network round trip. +# +# Every zone that can answer negatively carries an SOA. utopia-php/dns rejects +# an authoritative negative answer (NXDOMAIN or NODATA) without an SOA in the +# authority section, and unbound only adds one when the zone defines it. CNAME +# zones cannot hold an SOA (a CNAME may not coexist with other data) and do not +# need one: every query type gets the CNAME, and the negative answer comes from +# the chased target's zone. + +local-zone: "webapp.com." static +local-data: "webapp.com. 60 IN SOA ns.webapp.com. hostmaster.webapp.com. 1 3600 600 86400 60" +local-data: "webapp.com. 60 IN A 203.0.0.1" + +# CNAME fixtures pointing at the configured platform targets. +local-zone: "stage.webapp.com." redirect +local-data: "stage.webapp.com. 60 IN CNAME cname.localhost." + +local-zone: "stage-site.webapp.com." redirect +local-data: "stage-site.webapp.com. 60 IN CNAME sites.localhost." + +local-zone: "stage-function.webapp.com." redirect +local-data: "stage-function.webapp.com. 60 IN CNAME cname.localhost." + +# Verification must reject a CNAME pointing somewhere else. +local-zone: "stage-wrong-cname.webapp.com." redirect +local-data: "stage-wrong-cname.webapp.com. 60 IN CNAME cname-wrong.tests.appwrite.io." + +# An A record matching the expected target. +local-zone: "correct-a.webapp.com." redirect +local-data: "correct-a.webapp.com. 60 IN SOA ns.webapp.com. hostmaster.webapp.com. 1 3600 600 86400 60" +local-data: "correct-a.webapp.com. 60 IN A 203.0.0.1" + +# CAA pair: one issuer the platform is not allowed to use, one it is. +local-zone: "stage-wrong-caa.webapp.com." redirect +local-data: "stage-wrong-caa.webapp.com. 60 IN SOA ns.webapp.com. hostmaster.webapp.com. 1 3600 600 86400 60" +local-data: "stage-wrong-caa.webapp.com. 60 IN A 203.0.0.1" +local-data: 'stage-wrong-caa.webapp.com. 60 IN CAA 0 issue "unknown-issuer.org"' + +local-zone: "stage-correct-caa.webapp.com." redirect +local-data: "stage-correct-caa.webapp.com. 60 IN SOA ns.webapp.com. hostmaster.webapp.com. 1 3600 600 86400 60" +local-data: "stage-correct-caa.webapp.com. 60 IN A 203.0.0.1" +local-data: 'stage-correct-caa.webapp.com. 60 IN CAA 0 issue "digicert.com"' + +# An A record that does not match the expected target. +local-zone: "wrong-a-webapp.com." redirect +local-data: "wrong-a-webapp.com. 60 IN SOA ns.wrong-a-webapp.com. hostmaster.wrong-a-webapp.com. 1 3600 600 86400 60" +local-data: "wrong-a-webapp.com. 60 IN A 203.0.0.5" diff --git a/tests/unit/Network/Validators/DNSTest.php b/tests/unit/Network/Validators/DNSTest.php index 45e11d7029..fa62f706aa 100644 --- a/tests/unit/Network/Validators/DNSTest.php +++ b/tests/unit/Network/Validators/DNSTest.php @@ -38,9 +38,9 @@ final class DNSTest extends TestCase $this->assertNotEmpty($validator->getDescription()); } - public function testCoreDNSFailure(): void + public function testFixtureResolverFailure(): void { - // CoreDNS is configured to return cname.localhost. for stage.webapp.com + // The test resolver (tests/resources/dns) returns cname.localhost. for stage.webapp.com $validator = new DNS('cname.localhost.', Record::TYPE_CNAME, ['172.16.238.100', '8.8.8.8']); $result = $validator->isValid('stage.webapp.com'); From 39ce2a5817edbf0a0ef1b62e75043dba11f8d92c Mon Sep 17 00:00:00 2001 From: Chirag Aggarwal Date: Fri, 4 Sep 2026 14:53:34 +0100 Subject: [PATCH 4/5] test: keep CNAME target lookups inside the fixture resolver When a fixture answers with a CNAME, unbound chases the target through its resolver path, which skips local-zone data and asks the forwarder. On the CI runner Docker DNS answers any *.localhost with ::1, which is _APP_DOMAIN_TARGET_AAAA, so the API rule on the site fixture verified instead of failing on the wrong CNAME. An empty authoritative localhost. zone that the resolver path consults makes every target NXDOMAIN locally, and the wrong CNAME fixture now points under localhost too so nothing leaves the container. --- tests/resources/dns/localhost.zone | 3 +++ tests/resources/dns/zones.conf | 16 +++++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 tests/resources/dns/localhost.zone diff --git a/tests/resources/dns/localhost.zone b/tests/resources/dns/localhost.zone new file mode 100644 index 0000000000..544aa59ade --- /dev/null +++ b/tests/resources/dns/localhost.zone @@ -0,0 +1,3 @@ +$TTL 60 +localhost. IN SOA ns.localhost. hostmaster.localhost. 1 3600 600 86400 60 +localhost. IN NS ns.localhost. diff --git a/tests/resources/dns/zones.conf b/tests/resources/dns/zones.conf index 4fae5b04c3..5a9882ec87 100644 --- a/tests/resources/dns/zones.conf +++ b/tests/resources/dns/zones.conf @@ -29,7 +29,7 @@ local-data: "stage-function.webapp.com. 60 IN CNAME cname.localhost." # Verification must reject a CNAME pointing somewhere else. local-zone: "stage-wrong-cname.webapp.com." redirect -local-data: "stage-wrong-cname.webapp.com. 60 IN CNAME cname-wrong.tests.appwrite.io." +local-data: "stage-wrong-cname.webapp.com. 60 IN CNAME cname-wrong.localhost." # An A record matching the expected target. local-zone: "correct-a.webapp.com." redirect @@ -51,3 +51,17 @@ local-data: 'stage-correct-caa.webapp.com. 60 IN CAA 0 issue "digicert.com"' local-zone: "wrong-a-webapp.com." redirect local-data: "wrong-a-webapp.com. 60 IN SOA ns.wrong-a-webapp.com. hostmaster.wrong-a-webapp.com. 1 3600 600 86400 60" local-data: "wrong-a-webapp.com. 60 IN A 203.0.0.5" + +# The platform targets the fixtures point at live under localhost. When a +# fixture answers with a CNAME, unbound chases the target through its resolver +# path, which skips local-zone data and would otherwise ask the forwarder. The +# runner's Docker DNS answers any *.localhost with 127.0.0.1 and ::1, and ::1 +# is _APP_DOMAIN_TARGET_AAAA, so a wrong CNAME would verify. An auth-zone is +# consulted by that path: the empty zone makes every target NXDOMAIN with an +# SOA, locally. +auth-zone: + name: "localhost." + zonefile: "/mnt/resources/localhost.zone" + for-downstream: yes + for-upstream: yes + fallback-enabled: no From 228c715b6e44d1852875cff07363b0b2040cc37f Mon Sep 17 00:00:00 2001 From: Chirag Aggarwal Date: Fri, 4 Sep 2026 14:55:17 +0100 Subject: [PATCH 5/5] test: drop commentary from the DNS fixture --- docker-compose.override.yml | 4 +--- tests/resources/dns/forward.conf | 5 ----- tests/resources/dns/unbound.conf | 21 --------------------- tests/resources/dns/zones.conf | 27 --------------------------- 4 files changed, 1 insertion(+), 56 deletions(-) diff --git a/docker-compose.override.yml b/docker-compose.override.yml index 0c627983f0..9ca64790b6 100644 --- a/docker-compose.override.yml +++ b/docker-compose.override.yml @@ -301,7 +301,7 @@ services: volumes: - ./app:/usr/src/code/app - ./src:/usr/src/code/src - dns: # Stand-in public resolver for the domain-verification tests (Proxy APIs) + dns: image: alpinelinux/unbound:latest@sha256:8d2611fe8fcbd8e26b6f88e2eb0c3b803368195d50cfa0c30fdfaa5087076709 container_name: appwrite-dns restart: unless-stopped @@ -310,11 +310,9 @@ services: options: max-file: "5" max-size: 10m - # The image entrypoint writes its own config; this fixture supplies one. entrypoint: ["unbound", "-d", "-c", "/mnt/resources/unbound.conf"] networks: appwrite: - # _APP_DNS points at this address. ipv4_address: 172.16.238.100 volumes: - ./tests/resources/dns:/mnt/resources:ro diff --git a/tests/resources/dns/forward.conf b/tests/resources/dns/forward.conf index 55bcf0b586..e3c44c8c4c 100644 --- a/tests/resources/dns/forward.conf +++ b/tests/resources/dns/forward.conf @@ -1,9 +1,4 @@ -# Everything outside the fake zones goes to Docker's embedded DNS, so compose -# service names resolve, with a public resolver as fallback for external names. - server: - # 127.0.0.11 is loopback inside this container; unbound refuses loopback - # upstreams unless told otherwise. do-not-query-localhost: no forward-zone: diff --git a/tests/resources/dns/unbound.conf b/tests/resources/dns/unbound.conf index 7bb079904f..21122b0e63 100644 --- a/tests/resources/dns/unbound.conf +++ b/tests/resources/dns/unbound.conf @@ -1,33 +1,12 @@ -# A stand-in for the public recursive resolver, used by the Proxy DNS -# verification tests to verify customer domains. Mirrors deploy/dns-mock in -# appwrite-labs/cloud. -# -# Unbound rather than CoreDNS because a recursive resolver is what the app -# thinks it is talking to: overrides are one `local-data` line per record -# (every RR type, no regex templates), and forwarding is the server's own job -# rather than a catch-all bolted inside an authoritative zone. -# -# zones.conf - the fake public zones. -# forward.conf - where every other query goes. - server: interface: 0.0.0.0 port: 53 do-ip6: no access-control: 0.0.0.0/0 allow - # Test fixture: log what was asked, and never cache a stale answer between - # test cases. verbosity: 1 log-queries: yes cache-max-ttl: 60 cache-min-ttl: 0 - # No `private-address` entries: the fake zones answer with reserved addresses - # on purpose, and the forwarder resolves compose service names to private - # IPs. Configuring any private range here would strip both as rebinding - # attacks. - # - # No DNSSEC either: the fake zones are unsigned, and validating the upstream - # chain would only add a network dependency to a fixture. val-permissive-mode: yes include: "/mnt/resources/zones.conf" diff --git a/tests/resources/dns/zones.conf b/tests/resources/dns/zones.conf index 5a9882ec87..7a1a8787ac 100644 --- a/tests/resources/dns/zones.conf +++ b/tests/resources/dns/zones.conf @@ -1,23 +1,7 @@ -# Fake public zones for the Proxy DNS verification tests. One line per record, -# so a case is added by adding the record it needs. -# -# Each test run prefixes its fixture hostnames with a unique label, so every -# fixture is a `redirect` zone: any name under it answers with the zone's own -# records. `static` zones answer only exact names; anything else under them is -# NXDOMAIN without a network round trip. -# -# Every zone that can answer negatively carries an SOA. utopia-php/dns rejects -# an authoritative negative answer (NXDOMAIN or NODATA) without an SOA in the -# authority section, and unbound only adds one when the zone defines it. CNAME -# zones cannot hold an SOA (a CNAME may not coexist with other data) and do not -# need one: every query type gets the CNAME, and the negative answer comes from -# the chased target's zone. - local-zone: "webapp.com." static local-data: "webapp.com. 60 IN SOA ns.webapp.com. hostmaster.webapp.com. 1 3600 600 86400 60" local-data: "webapp.com. 60 IN A 203.0.0.1" -# CNAME fixtures pointing at the configured platform targets. local-zone: "stage.webapp.com." redirect local-data: "stage.webapp.com. 60 IN CNAME cname.localhost." @@ -27,16 +11,13 @@ local-data: "stage-site.webapp.com. 60 IN CNAME sites.localhost." local-zone: "stage-function.webapp.com." redirect local-data: "stage-function.webapp.com. 60 IN CNAME cname.localhost." -# Verification must reject a CNAME pointing somewhere else. local-zone: "stage-wrong-cname.webapp.com." redirect local-data: "stage-wrong-cname.webapp.com. 60 IN CNAME cname-wrong.localhost." -# An A record matching the expected target. local-zone: "correct-a.webapp.com." redirect local-data: "correct-a.webapp.com. 60 IN SOA ns.webapp.com. hostmaster.webapp.com. 1 3600 600 86400 60" local-data: "correct-a.webapp.com. 60 IN A 203.0.0.1" -# CAA pair: one issuer the platform is not allowed to use, one it is. local-zone: "stage-wrong-caa.webapp.com." redirect local-data: "stage-wrong-caa.webapp.com. 60 IN SOA ns.webapp.com. hostmaster.webapp.com. 1 3600 600 86400 60" local-data: "stage-wrong-caa.webapp.com. 60 IN A 203.0.0.1" @@ -47,18 +28,10 @@ local-data: "stage-correct-caa.webapp.com. 60 IN SOA ns.webapp.com. hostmaster.w local-data: "stage-correct-caa.webapp.com. 60 IN A 203.0.0.1" local-data: 'stage-correct-caa.webapp.com. 60 IN CAA 0 issue "digicert.com"' -# An A record that does not match the expected target. local-zone: "wrong-a-webapp.com." redirect local-data: "wrong-a-webapp.com. 60 IN SOA ns.wrong-a-webapp.com. hostmaster.wrong-a-webapp.com. 1 3600 600 86400 60" local-data: "wrong-a-webapp.com. 60 IN A 203.0.0.5" -# The platform targets the fixtures point at live under localhost. When a -# fixture answers with a CNAME, unbound chases the target through its resolver -# path, which skips local-zone data and would otherwise ask the forwarder. The -# runner's Docker DNS answers any *.localhost with 127.0.0.1 and ::1, and ::1 -# is _APP_DOMAIN_TARGET_AAAA, so a wrong CNAME would verify. An auth-zone is -# consulted by that path: the empty zone makes every target NXDOMAIN with an -# SOA, locally. auth-zone: name: "localhost." zonefile: "/mnt/resources/localhost.zone"