From a64ff8cc0a263f00c817612c2c4aca79328335ab Mon Sep 17 00:00:00 2001 From: Chris O'Haver Date: Mon, 12 Aug 2019 14:43:22 -0400 Subject: [PATCH] fix NXDOMAIN/NODATA fallthough case (#3118) --- plugin/kubernetes/handler.go | 4 +++- plugin/kubernetes/handler_test.go | 24 ++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/plugin/kubernetes/handler.go b/plugin/kubernetes/handler.go index a7df99d90..6ff8040a4 100644 --- a/plugin/kubernetes/handler.go +++ b/plugin/kubernetes/handler.go @@ -54,7 +54,9 @@ func (k Kubernetes) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.M fallthrough default: // Do a fake A lookup, so we can distinguish between NODATA and NXDOMAIN - _, err = plugin.A(ctx, &k, zone, state, nil, plugin.Options{}) + fake := state.NewWithQuestion(state.QName(), dns.TypeA) + fake.Zone = state.Zone + _, err = plugin.A(ctx, &k, zone, fake, nil, plugin.Options{}) } if k.IsNameError(err) { diff --git a/plugin/kubernetes/handler_test.go b/plugin/kubernetes/handler_test.go index a517e8b89..a979386b9 100644 --- a/plugin/kubernetes/handler_test.go +++ b/plugin/kubernetes/handler_test.go @@ -349,6 +349,30 @@ var dnsTestCases = []test.Case{ test.SOA("cluster.local. 5 IN SOA ns.dns.cluster.local. hostmaster.cluster.local. 1499347823 7200 1800 86400 5"), }, }, + // NS query for qname != zone (existing domain) + { + Qname: "testns.svc.cluster.local.", Qtype: dns.TypeNS, + Rcode: dns.RcodeSuccess, + Ns: []dns.RR{ + test.SOA("cluster.local. 5 IN SOA ns.dns.cluster.local. hostmaster.cluster.local. 1499347823 7200 1800 86400 5"), + }, + }, + // NS query for qname != zone (non existing domain) + { + Qname: "foo.cluster.local.", Qtype: dns.TypeNS, + Rcode: dns.RcodeNameError, + Ns: []dns.RR{ + test.SOA("cluster.local. 5 IN SOA ns.dns.cluster.local. hostmaster.cluster.local. 1499347823 7200 1800 86400 5"), + }, + }, + // NS query for qname != zone (non existing domain) + { + Qname: "foo.svc.cluster.local.", Qtype: dns.TypeNS, + Rcode: dns.RcodeNameError, + Ns: []dns.RR{ + test.SOA("cluster.local. 5 IN SOA ns.dns.cluster.local. hostmaster.cluster.local. 1499347823 7200 1800 86400 5"), + }, + }, } func TestServeDNS(t *testing.T) {