M8: per-key UPDATE rate limiting (token bucket)
Hamilton M8: a compromised TSIG key — or a misconfigured client retrying forever — must not be able to drive unbounded UPDATE traffic. Each UPDATE costs disk IOPS, a git commit, and a slot in the SOA serial counter (now 9999/day per zone). Without a cap, a few hours of runaway traffic could exhaust the SOA serial counter and brick the zone for the day. Implementation: per-key token bucket in ratelimit.go. Default 100 tokens / 60 seconds. New keys start full so legitimate clients see no delay at boot. Refill is continuous, capped at the burst value. Configurable in Corefile: rate-limit off # disable entirely rate-limit <burst> <period-secs> # e.g., rate-limit 200 60 Enforcement runs in ServeDNS after TSIG verification — a request that fails auth doesn't consume a token (and a forged TSIG can't be used to deny service to a real key holder, since we never reached the rate check). 100/min is well above ACME's needs: a worst-case full-renewal storm across our ~84 zones emits maybe 200 UPDATEs total over several minutes. Anything beyond is suspicious by definition. New tests covering: first-call allowed, burst exhaustion, refill behavior, per-key isolation, refill-cap (no idle-accumulation overflow).
This commit is contained in:
parent
6ab2b6af6d
commit
8d1477350a
4 changed files with 222 additions and 0 deletions
20
plugin.go
20
plugin.go
|
|
@ -19,6 +19,8 @@ package rfc2136
|
|||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/coredns/coredns/plugin"
|
||||
"github.com/miekg/dns"
|
||||
|
|
@ -62,6 +64,11 @@ type RFC2136 struct {
|
|||
// zones holds per-zone file handlers, keyed by canonical zone name.
|
||||
// Populated in setup; mutexes live inside each zoneFile.
|
||||
zones map[string]*zoneFile
|
||||
|
||||
// rateLimit caps UPDATE traffic per TSIG key (Hamilton M8). nil
|
||||
// disables rate limiting (test mode, or insecure deployments).
|
||||
// Populated in setup() once TSIG keys are known.
|
||||
rateLimit *rateLimiter
|
||||
}
|
||||
|
||||
// Name implements plugin.Handler.
|
||||
|
|
@ -88,6 +95,19 @@ func (p *RFC2136) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg
|
|||
_ = w.WriteMsg(resp)
|
||||
return dns.RcodeRefused, nil
|
||||
}
|
||||
// Hamilton M8: per-key rate limit. TSIG just authenticates the
|
||||
// sender — it doesn't prove the sender's behavior is sane. A
|
||||
// compromised key or a runaway client must not be able to
|
||||
// exhaust disk/git/serial-counter resources.
|
||||
if p.rateLimit != nil {
|
||||
if tsig := r.IsTsig(); tsig != nil && !p.rateLimit.allow(strings.ToLower(tsig.Hdr.Name), time.Now()) {
|
||||
log.Warningf("UPDATE rate-limited for key %q", tsig.Hdr.Name)
|
||||
resp := new(dns.Msg)
|
||||
resp.SetRcode(r, dns.RcodeRefused)
|
||||
_ = w.WriteMsg(resp)
|
||||
return dns.RcodeRefused, nil
|
||||
}
|
||||
}
|
||||
return p.handleUpdate(w, r, true)
|
||||
}
|
||||
return plugin.NextOrFailure(p.Name(), p.Next, ctx, w, r)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue