fix: write A records as host-record so CNAMEs resolve - #2
Open
doonga wants to merge 1 commit into
Open
Conversation
dnsmasq only resolves a `cname=` whose target is a name it already knows from host-record, /etc/hosts or a DHCP lease. Names defined with `address=/name/ip` are not valid CNAME targets, so any CNAME pointing at an A record created by this webhook failed to resolve. Write A records as `host-record=name,ip` instead. The reader still parses the legacy `address=/name/ip` form so external-dns can reconcile and remove records written by earlier versions. Note that host-record matches only the exact name, where address= also matched every subdomain, and host-record additionally creates a PTR record. Adds test-host-record.js covering both directions: the formats written for A, CNAME and TXT records, and reading back host-record, cname, txt-record and legacy address= entries. It calls writeRecord — now exported — rather than applyChanges, so the test never restarts firerouter_dns. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
A CNAME created by this webhook does not resolve when its target is an A record that the webhook also created.
dnsmasq resolves
cname=alias,targetonly whentargetis a name it already knows fromhost-record,/etc/hosts, or a DHCP lease. A name defined withaddress=/name/ipis not a valid CNAME target, so the alias silently fails to resolve even though the A record itself answers correctly.This affects any setup where external-dns publishes an A record for a gateway or ingress and then points service hostnames at it with CNAMEs — a common pattern with Gateway API and
--source=gateway-httproute.Fix
Write A records as
host-record=name,iprather thanaddress=/name/ip.The reader still parses the legacy
address=/name/ipform, so external-dns can continue to see, reconcile, and delete records written by earlier versions.Behavior changes
Two differences worth being explicit about:
host-recordmatches only the exact name, whereaddress=additionally matched every subdomain of it. Exact matching is the correct semantic for external-dns, which manages exact names — but it is a change for anyone who was relying on the implicit wildcard.host-recordalso creates a PTR record, so reverse lookups for these names now resolve.Migration
Existing
address=files are rewritten tohost-recordthe next time external-dns changes that record. A record that never changes keeps the old form — and its CNAMEs keep failing — until something touches it.Testing
Added
test-host-record.js, following the existingtest-*.jsconvention (standalone script, no runner required):It exercises the real service against a temp directory, covering both the formats written and the formats read back, including a legacy
address=file to prove backward compatibility. It exits non-zero on failure, so it can be wired into CI if you ever want that.writeRecordis exported so the test can cover record formatting directly.applyChangesends by restartingfirerouter_dns, which a test has no business doing on a Firewalla — callingwriteRecordavoids that entirely.Also verified end to end on a live Firewalla with external-dns driving the webhook: A records land as
host-record, and CNAMEs pointing at them now resolve through to the address (hostnames redacted):Before the change the second lookup returned only the CNAME, with no address behind it.