diff options
author | 2018-09-25 11:41:05 -0700 | |
---|---|---|
committer | 2018-09-25 18:41:05 +0000 | |
commit | 8d4378d7123079c58b32365c4f7dccca4870a236 (patch) | |
tree | 00c0e94e75d62f9e4b50c60b214d2cb2b976e354 | |
parent | b89006dda105c8ee30fe04f4d1706286e605b292 (diff) | |
download | coredns-8d4378d7123079c58b32365c4f7dccca4870a236.tar.gz coredns-8d4378d7123079c58b32365c4f7dccca4870a236.tar.zst coredns-8d4378d7123079c58b32365c4f7dccca4870a236.zip |
plugin/route53: add fallthrough (#2132)
Automatically submitted.
-rw-r--r-- | plugin/route53/README.md | 19 | ||||
-rw-r--r-- | plugin/route53/route53.go | 6 | ||||
-rw-r--r-- | plugin/route53/route53_test.go | 33 | ||||
-rw-r--r-- | plugin/route53/setup.go | 6 | ||||
-rw-r--r-- | plugin/route53/setup_test.go | 3 |
5 files changed, 65 insertions, 2 deletions
diff --git a/plugin/route53/README.md b/plugin/route53/README.md index f62ea42e6..07bd2bd77 100644 --- a/plugin/route53/README.md +++ b/plugin/route53/README.md @@ -16,6 +16,7 @@ The route53 plugin can be used when coredns is deployed on AWS or elsewhere. route53 [ZONE:HOSTED_ZONE_ID...] { [aws_access_key AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY] upstream [ADDRESS...] + fallthrough [ZONES...] } ~~~ @@ -29,6 +30,12 @@ route53 [ZONE:HOSTED_ZONE_ID...] { to external hosts (eg. used to resolve CNAMEs). If no **ADDRESS** is given, CoreDNS will resolve against itself. **ADDRESS** can be an IP, an IP:port or a path to a file structured like resolv.conf (**NB**: Currently a bug (#2099) is preventing the use of self-resolver). + are used. +* `fallthrough` If zone matches and no record can be generated, pass request to the next plugin. + If **[ZONES...]** is omitted, then fallthrough happens for all zones for which the plugin + is authoritative. If specific zones are listed (for example `in-addr.arpa` and `ip6.arpa`), then only + queries for those zones will be subject to fallthrough. +* **ZONES** zones it should be authoritative for. If empty, the zones from the configuration block ## Examples @@ -47,6 +54,16 @@ Enable route53 with explicit aws credentials: . { route53 example.org.:Z1Z2Z3Z4DZ5Z6Z7 { aws_access_key AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY - } + } +} +~~~ + +Enable route53 with fallthrough: + +~~~ txt +. { + route53 example.org.:Z1Z2Z3Z4DZ5Z6Z7 example.gov.:Z654321543245 { + fallthrough example.gov. + } } ~~~ diff --git a/plugin/route53/route53.go b/plugin/route53/route53.go index affa3e3de..3e1a2ddea 100644 --- a/plugin/route53/route53.go +++ b/plugin/route53/route53.go @@ -10,6 +10,7 @@ import ( "github.com/coredns/coredns/plugin" "github.com/coredns/coredns/plugin/file" + "github.com/coredns/coredns/plugin/pkg/fall" "github.com/coredns/coredns/plugin/pkg/upstream" "github.com/coredns/coredns/request" @@ -22,6 +23,7 @@ import ( // Route53 is a plugin that returns RR from AWS route53. type Route53 struct { Next plugin.Handler + Fall fall.F zoneNames []string client route53iface.Route53API @@ -103,6 +105,10 @@ func (h *Route53) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg m.Answer, m.Ns, m.Extra, result = z.z.Lookup(state, qname) h.zMu.RUnlock() + if len(m.Answer) == 0 && h.Fall.Through(qname) { + return plugin.NextOrFailure(h.Name(), h.Next, ctx, w, r) + } + switch result { case file.Success: case file.NoData: diff --git a/plugin/route53/route53_test.go b/plugin/route53/route53_test.go index a358386d4..a0fa38838 100644 --- a/plugin/route53/route53_test.go +++ b/plugin/route53/route53_test.go @@ -7,8 +7,10 @@ import ( "testing" "github.com/coredns/coredns/plugin/pkg/dnstest" + "github.com/coredns/coredns/plugin/pkg/fall" "github.com/coredns/coredns/plugin/pkg/upstream" "github.com/coredns/coredns/plugin/test" + crequest "github.com/coredns/coredns/request" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/request" @@ -75,7 +77,29 @@ func TestRoute53(t *testing.T) { if err != nil { t.Fatalf("Failed to create Route53: %v", err) } - r.Next = test.ErrorHandler() + r.Fall = fall.Zero + r.Fall.SetZonesFromArgs([]string{"gov."}) + r.Next = test.HandlerFunc(func(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error) { + state := crequest.Request{W: w, Req: r} + qname := state.Name() + m := new(dns.Msg) + rcode := dns.RcodeServerFailure + if qname == "example.gov." { + m.SetReply(r) + rr, err := dns.NewRR("example.gov. 300 IN A 2.4.6.8") + if err != nil { + t.Fatalf("Failed to create Resource Record: %v", err) + } + m.Answer = []dns.RR{rr} + + m.Authoritative, m.RecursionAvailable = true, true + rcode = dns.RcodeSuccess + } + + m.SetRcode(r, rcode) + w.WriteMsg(m) + return rcode, nil + }) err = r.Run(ctx) if err != nil { t.Fatalf("Failed to initialize Route53: %v", err) @@ -156,6 +180,13 @@ func TestRoute53(t *testing.T) { expectedCode: dns.RcodeSuccess, wantNS: []string{"org. 300 IN SOA ns-1536.awsdns-00.co.uk. awsdns-hostmaster.amazon.com. 1 7200 900 1209600 86400"}, }, + // 9. No record found. Fallthrough. + { + qname: "example.gov", + qtype: dns.TypeA, + expectedCode: dns.RcodeSuccess, + wantAnswer: []string{"example.gov. 300 IN A 2.4.6.8"}, + }, } for ti, tc := range tests { diff --git a/plugin/route53/setup.go b/plugin/route53/setup.go index ef55e59b4..765a2ceee 100644 --- a/plugin/route53/setup.go +++ b/plugin/route53/setup.go @@ -6,6 +6,7 @@ import ( "github.com/coredns/coredns/core/dnsserver" "github.com/coredns/coredns/plugin" + "github.com/coredns/coredns/plugin/pkg/fall" clog "github.com/coredns/coredns/plugin/pkg/log" "github.com/coredns/coredns/plugin/pkg/upstream" @@ -36,6 +37,8 @@ func init() { func setup(c *caddy.Controller, f func(*credentials.Credentials) route53iface.Route53API) error { keys := map[string]string{} credential := credentials.NewEnvCredentials() + var fall fall.F + up, _ := upstream.New(nil) for c.Next() { args := c.RemainingArgs() @@ -75,6 +78,8 @@ func setup(c *caddy.Controller, f func(*credentials.Credentials) route53iface.Ro if err != nil { return c.Errf("invalid upstream: %v", err) } + case "fallthrough": + fall.SetZonesFromArgs(c.RemainingArgs()) default: return c.Errf("unknown property '%s'", c.Val()) } @@ -86,6 +91,7 @@ func setup(c *caddy.Controller, f func(*credentials.Credentials) route53iface.Ro if err != nil { return c.Errf("failed to create Route53 plugin: %v", err) } + h.Fall = fall if err := h.Run(ctx); err != nil { return c.Errf("failed to initialize Route53 plugin: %v", err) } diff --git a/plugin/route53/setup_test.go b/plugin/route53/setup_test.go index a5491a935..139da1fa0 100644 --- a/plugin/route53/setup_test.go +++ b/plugin/route53/setup_test.go @@ -53,6 +53,9 @@ func TestSetupRoute53(t *testing.T) { aws_access_key ACCESS_KEY_ID SEKRIT_ACCESS_KEY upstream 1.2.3.4 }`) + c = caddy.NewTestController("dns", `route53 example.org:12345678 { + fallthrough +}`) if err := setup(c, f); err != nil { t.Fatalf("Unexpected errors: %v", err) } |