mirror of
https://github.com/coredns/coredns.git
synced 2025-12-06 02:15:11 -05:00
Resolve TXT records via CNAME (#3557)
* Add test case for TXT lookup via CNAME Signed-off-by: Jonathan Nagy <nagytech@users.noreply.github.com> * Return HostType of explicit TXT records Signed-off-by: Jonathan Nagy <nagytech@users.noreply.github.com> * Adapt TXT method lookup to allow lookup via CNAME Signed-off-by: Jonathan Nagy <nagytech@users.noreply.github.com> * Implement lookup of TXT records via CNAME Signed-off-by: Jonathan Nagy <nagytech@users.noreply.github.com>
This commit is contained in:
committed by
Miek Gieben
parent
acac649c1b
commit
e3266d24f7
@@ -58,6 +58,9 @@ var servicesCname = []*msg.Service{
|
||||
{Host: "cname6.region2.skydns.test", Key: "cname5.region2.skydns.test."},
|
||||
{Host: "endpoint.region2.skydns.test", Key: "cname6.region2.skydns.test."},
|
||||
{Host: "mainendpoint.region2.skydns.test", Key: "region2.skydns.test."},
|
||||
{Host: "cname2.region3.skydns.test", Key: "cname3.region3.skydns.test."},
|
||||
{Host: "cname1.region3.skydns.test", Key: "cname2.region3.skydns.test."},
|
||||
{Host: "region3.skydns.test", Key: "cname1.region3.skydns.test."},
|
||||
{Host: "", Key: "region3.skydns.test.", Text: "SOME-RECORD-TEXT"},
|
||||
{Host: "10.240.0.1", Key: "endpoint.region2.skydns.test."},
|
||||
}
|
||||
@@ -91,4 +94,13 @@ var dnsTestCasesCname = []test.Case{
|
||||
test.SOA("skydns.test. 303 IN SOA ns.dns.skydns.test. hostmaster.skydns.test. 1546424605 7200 1800 86400 30"),
|
||||
},
|
||||
},
|
||||
{
|
||||
Qname: "cname3.region3.skydns.test.", Qtype: dns.TypeTXT,
|
||||
Answer: []dns.RR{
|
||||
test.CNAME("cname3.region3.skydns.test. 300 IN CNAME cname2.region3.skydns.test."),
|
||||
test.CNAME("cname2.region3.skydns.test. 300 IN CNAME cname1.region3.skydns.test."),
|
||||
test.CNAME("cname1.region3.skydns.test. 300 IN CNAME region3.skydns.test."),
|
||||
test.TXT("region3.skydns.test. 300 IN TXT \"SOME-RECORD-TEXT\""),
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
@@ -177,11 +177,9 @@ func (e *Etcd) TTL(kv *mvccpb.KeyValue, serv *msg.Service) uint32 {
|
||||
}
|
||||
|
||||
// shouldInclude returns true if the service should be included in a list of records, given the qType. For all the
|
||||
// currently supported lookup types, the only one to allow for an empty Host field in the service are TXT records.
|
||||
// Similarly, the TXT record in turn requires the Text field to be set.
|
||||
// currently supported lookup types, the only one to allow for an empty Host field in the service are TXT records
|
||||
// which resolve directly. If a TXT record is being resolved by CNAME, then we expect the Host field to have a
|
||||
// value while the TXT field will be empty.
|
||||
func shouldInclude(serv *msg.Service, qType uint16) bool {
|
||||
if qType == dns.TypeTXT {
|
||||
return serv.Text != ""
|
||||
}
|
||||
return serv.Host != ""
|
||||
return (qType == dns.TypeTXT && serv.Text != "") || serv.Host != ""
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ func (e *Etcd) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (
|
||||
case dns.TypeAAAA:
|
||||
records, err = plugin.AAAA(ctx, e, zone, state, nil, opt)
|
||||
case dns.TypeTXT:
|
||||
records, err = plugin.TXT(ctx, e, zone, state, opt)
|
||||
records, err = plugin.TXT(ctx, e, zone, state, nil, opt)
|
||||
case dns.TypeCNAME:
|
||||
records, err = plugin.CNAME(ctx, e, zone, state, opt)
|
||||
case dns.TypePTR:
|
||||
|
||||
@@ -19,8 +19,12 @@ func (s *Service) HostType() (what uint16, normalized net.IP) {
|
||||
ip := net.ParseIP(s.Host)
|
||||
|
||||
switch {
|
||||
|
||||
case ip == nil:
|
||||
return dns.TypeCNAME, nil
|
||||
if len(s.Text) == 0 {
|
||||
return dns.TypeCNAME, nil
|
||||
}
|
||||
return dns.TypeTXT, nil
|
||||
|
||||
case ip.To4() != nil:
|
||||
return dns.TypeA, ip.To4()
|
||||
|
||||
Reference in New Issue
Block a user