Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Various updates to match authoritative behavior of BIND9 #22

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

pinheadmz
Copy link
Collaborator

@pinheadmz pinheadmz commented Jul 7, 2020

Closes #5
Closes #21
Closes #16
Closes #15

A few edge cases aren't complete, indicated by skip in some of the tests.
Test cases were designed to match results from adding the same record set to named and querying.

Changes summary:

zone: only serve wildcard if there was otherwise no match

if *.domain. exists in the zone along with sub.domain., do not return the wildcard record as an answer for domain. or sub.domain or sub.otherdomain.

zone: return CNAME records for any type requested

sub.domain. CNAME domain.

We should return this CNAME record whenever sub.domain is requested, no matter what the requested type is.

zone: glue requested type, default A / AAAA

Assuming "glue" exists:

sub.domain. CNAME domain.
domain. TXT "return this string"
domain. A 10.20.30.40

When sub.domain. is queried, the corresponding type should be returned as "glue" (it goes in the answer section though, not additional). We return A/AAAA records by default. In other words, the CNAME glue is treated like its own request, including adding SOA to authority section if no answer is available. So sub.domain. TXT would return the CNAME record along with the TXT record.

zone: wildcard matches more than one label

*.domain. TXT "wow such zone file"

This record should be matched against sub.domain. TXT but also foo.bar.sub.domain. TXT.

zone: filter out wildcards that do not match

*.domain. TXT "wow such zone file"

This record should NOT be returned for a query for another.domain. because it does not match.

zone: add SOA if authoritative but no answers. Applies to CNAME glue

Always sets the aa flag if we have a corresponding SOA in the zone, even if we don't include an actual SOA record (which we usually don't if an answer is present). This will also apply to "glue" from CNAME matches:

(results from named)

Record matching requested type present for target of CNAME:

$ dig @127.0.0.1 -p 5300 subdomain-glue.coolness. a

; <<>> DiG 9.16.3 <<>> @127.0.0.1 -p 5300 subdomain-glue.coolness. a
; (1 server found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 22759
;; flags: qr aa rd; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 1
;; WARNING: recursion requested but not available

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
; COOKIE: 49555c2cbce32a34010000005f04854da468d429742abd77 (good)
;; QUESTION SECTION:
;subdomain-glue.coolness.       IN      A

;; ANSWER SECTION:
subdomain-glue.coolness. 21600  IN      CNAME   coolness.
coolness.               21600   IN      A       10.20.30.40

;; Query time: 0 msec
;; SERVER: 127.0.0.1#5300(127.0.0.1)
;; WHEN: Tue Jul 07 10:23:09 EDT 2020
;; MSG SIZE  rcvd: 110

Record matching requested type NOT present for target of CNAME:

$ dig @127.0.0.1 -p 5300 subdomain-glue.coolness. dnskey

; <<>> DiG 9.16.3 <<>> @127.0.0.1 -p 5300 subdomain-glue.coolness. dnskey
; (1 server found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 39596
;; flags: qr aa rd; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 1
;; WARNING: recursion requested but not available

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
; COOKIE: 0881e1c766abc5dc010000005f04855092e02236a58a19af (good)
;; QUESTION SECTION:
;subdomain-glue.coolness.       IN      DNSKEY

;; ANSWER SECTION:
subdomain-glue.coolness. 21600  IN      CNAME   coolness.

;; AUTHORITY SECTION:
coolness.               300     IN      SOA     ns1.dns.live. root.coolness. 2020061644 21600 3600 2419200 86400

;; Query time: 0 msec
;; SERVER: 127.0.0.1#5300(127.0.0.1)
;; WHEN: Tue Jul 07 10:23:12 EDT 2020
;; MSG SIZE  rcvd: 147

zone: no-authority no-records answer should be as quiet as possible

Match behavior from named if the request is totally wrong for our zone (unless we are root)

$ dig @127.0.0.1 -p 5300 wefwefwefwe

; <<>> DiG 9.16.3 <<>> @127.0.0.1 -p 5300 wefwefwefwe
; (1 server found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: REFUSED, id: 12103
;; flags: qr rd; QUERY: 1, ANSWER: 0, AUTHORITY: 0, ADDITIONAL: 1
;; WARNING: recursion requested but not available

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
; COOKIE: e4870ba35d143d46010000005f048e4a5c2dbf97b1ebef58 (good)
;; QUESTION SECTION:
;wefwefwefwe.                   IN      A

;; Query time: 0 msec
;; SERVER: 127.0.0.1#5300(127.0.0.1)
;; WHEN: Tue Jul 07 11:01:30 EDT 2020
;; MSG SIZE  rcvd: 68

zone: add zsk property and enable ad-hoc signing

Self-explanatory. Enables loading a ZSK into the AuthServer to sign wildcard records upon request.

@pinheadmz pinheadmz mentioned this pull request Jul 7, 2020
@james-stevens
Copy link

Applies to CNAME glue

A CNAME can't be GLUE, by definition. Only NS, A & AAAA can be GLUE

@pinheadmz
Copy link
Collaborator Author

Thanks, I was putting "glue" in quotes for this reason, JJ used the term in the code to refer to data that belongs to the target of a CNAME (i.e. it is returned like the A records that get glued to an NS record)

@pinheadmz pinheadmz force-pushed the cname1 branch 2 times, most recently from 61775b3 to cbc448c Compare July 8, 2020 13:34
@NetOpWibby
Copy link

NetOpWibby commented Jul 28, 2021

LGTM

EDIT: NVM, I found the Handshake fork.

@lukeburns
Copy link

This is nice! What's the status?

@pinheadmz
Copy link
Collaborator Author

Status: needs review. I've learned a lot more about DNS since I wrote this PR and probably need to make sure it all still makes sense. This branch is included in handout.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants