add wildcard warnings (#5030)
Signed-off-by: Chris O'Haver <cohaver@infoblox.com>
This commit is contained in:
parent
e5ea3341fa
commit
744468ea78
3 changed files with 33 additions and 0 deletions
|
@ -2,6 +2,8 @@ package kubernetes
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"strings"
|
||||||
|
"sync/atomic"
|
||||||
|
|
||||||
"github.com/coredns/coredns/plugin"
|
"github.com/coredns/coredns/plugin"
|
||||||
"github.com/coredns/coredns/request"
|
"github.com/coredns/coredns/request"
|
||||||
|
@ -27,6 +29,10 @@ func (k Kubernetes) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.M
|
||||||
err error
|
err error
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if wildQuestion(state.Name()) {
|
||||||
|
atomic.AddUint64(&wildCount, 1)
|
||||||
|
}
|
||||||
|
|
||||||
switch state.QType() {
|
switch state.QType() {
|
||||||
case dns.TypeA:
|
case dns.TypeA:
|
||||||
records, err = plugin.A(ctx, &k, zone, state, nil, plugin.Options{})
|
records, err = plugin.A(ctx, &k, zone, state, nil, plugin.Options{})
|
||||||
|
@ -85,8 +91,13 @@ func (k Kubernetes) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.M
|
||||||
m.Answer = append(m.Answer, records...)
|
m.Answer = append(m.Answer, records...)
|
||||||
m.Extra = append(m.Extra, extra...)
|
m.Extra = append(m.Extra, extra...)
|
||||||
w.WriteMsg(m)
|
w.WriteMsg(m)
|
||||||
|
|
||||||
return dns.RcodeSuccess, nil
|
return dns.RcodeSuccess, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func wildQuestion(name string) bool {
|
||||||
|
return strings.HasPrefix(name, "*.") || strings.HasPrefix(name, "any.") || strings.Contains(name, ".*.") || strings.Contains(name, ".any.")
|
||||||
|
}
|
||||||
|
|
||||||
// Name implements the Handler interface.
|
// Name implements the Handler interface.
|
||||||
func (k Kubernetes) Name() string { return "kubernetes" }
|
func (k Kubernetes) Name() string { return "kubernetes" }
|
||||||
|
|
|
@ -86,6 +86,7 @@ var (
|
||||||
errNoItems = errors.New("no items found")
|
errNoItems = errors.New("no items found")
|
||||||
errNsNotExposed = errors.New("namespace is not exposed")
|
errNsNotExposed = errors.New("namespace is not exposed")
|
||||||
errInvalidRequest = errors.New("invalid query name")
|
errInvalidRequest = errors.New("invalid query name")
|
||||||
|
wildCount uint64
|
||||||
)
|
)
|
||||||
|
|
||||||
// Services implements the ServiceBackend interface.
|
// Services implements the ServiceBackend interface.
|
||||||
|
|
|
@ -7,6 +7,8 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync/atomic"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/coredns/caddy"
|
"github.com/coredns/caddy"
|
||||||
"github.com/coredns/coredns/core/dnsserver"
|
"github.com/coredns/coredns/core/dnsserver"
|
||||||
|
@ -61,6 +63,25 @@ func setup(c *caddy.Controller) error {
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
|
|
||||||
|
wildWarner := time.NewTicker(10 * time.Second)
|
||||||
|
c.OnStartup(func() error {
|
||||||
|
go func() {
|
||||||
|
for {
|
||||||
|
select {
|
||||||
|
case <-wildWarner.C:
|
||||||
|
if wc := atomic.SwapUint64(&wildCount, 0); wc > 0 {
|
||||||
|
log.Warningf("%d deprecated wildcard queries received. Wildcard queries will no longer be supported in the next minor release.", wc)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
c.OnShutdown(func() error {
|
||||||
|
wildWarner.Stop()
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue