Skip to content

Commit f911b83

Browse files
committed
handle "google.internal." zones temporarily
If we let "{nonexisting}.google.internal." get handled by the Cloud Run host nameserver, it returns a SERVFAIL, which prevents trying other "search" domains from being tried. Adding a temporary workaround that _only_ handles "metadata.google.internal." for A question (and ignoring other question types) and properly NXDOMAIN-ing the non-existing domains. This is to address #18. Signed-off-by: Ahmet Alp Balkan <[email protected]>
1 parent 323cc4a commit f911b83

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

runsd/dns.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,15 @@ type dnsHijack struct {
3232
func (d *dnsHijack) handler() dns.Handler {
3333
mux := dns.NewServeMux()
3434
mux.HandleFunc(d.domain, d.handleLocal)
35+
36+
// TODO(ahmetb) issue#18: Cloud Run’s host DNS server is responding to
37+
// nonexistent.google.internal. queries with SERVFAIL instead of NXDOMAIN
38+
// and this prevents iterating over other "search" domains in resolv.conf.
39+
// So, temporarily handling this zone ourselves instead of proxying.
40+
// NOTE: This bug is not visible if the Service is running in a VPC access
41+
// connector. Internal bug/179796872.
42+
mux.HandleFunc("google.internal.", d.tempHandleMetadataZone)
43+
3544
mux.HandleFunc(".", d.recurse)
3645
return mux
3746
}
@@ -45,6 +54,31 @@ func dnsLogger(d dns.HandlerFunc) dns.HandlerFunc {
4554
}
4655
}
4756

57+
func (d *dnsHijack) tempHandleMetadataZone(w dns.ResponseWriter, msg *dns.Msg) {
58+
for _, q := range msg.Question {
59+
if q.Name != "metadata.google.internal." {
60+
nxdomain(w, msg)
61+
return
62+
}
63+
}
64+
r := new(dns.Msg)
65+
r.SetReply(msg)
66+
for _, q := range msg.Question {
67+
if q.Qtype == dns.TypeA {
68+
r.Answer = append(r.Answer, &dns.A{
69+
Hdr: dns.RR_Header{
70+
Name: q.Name,
71+
Rrtype: dns.TypeA,
72+
Class: dns.ClassINET,
73+
Ttl: 300,
74+
},
75+
A: net.IPv4(169, 254, 169, 254),
76+
})
77+
}
78+
}
79+
w.WriteMsg(r)
80+
}
81+
4882
func (d *dnsHijack) newServer(net, addr string) *dns.Server {
4983
return &dns.Server{
5084
Addr: addr,

0 commit comments

Comments
 (0)