plugin/acl: adding ability to drop queries (#5722)
Both block and filter actions write responses to the client based upon the source IP address of the UDP packet containing the query. An attacker spoofing the source IP address to that of their target, can elicit a response to be sent to the victim host, known as DNS Reflection. If an attacker is able to elicit a large response from a relatively small query, with a spoofed source IP address, they are able to increase the amount of data sent to the victim, known as DNS Amplification. Scaling this from one to many queries allows an attacker to perform an effective Denial of Service (DoS) attack against their target. Adding the drop action enables CoreDNS to ignore queries of a given type or network range from being processed and a response written, where an operator knows ahead of time, should not originate or be destined to. Signed-off-by: rsclarke <hey@rsclarke.dev> Signed-off-by: rsclarke <hey@rsclarke.dev>
This commit is contained in:
parent
faaf2b446e
commit
ead84e1fa8
6 changed files with 194 additions and 2 deletions
|
@ -25,7 +25,7 @@ acl [ZONES...] {
|
|||
```
|
||||
|
||||
- **ZONES** zones it should be authoritative for. If empty, the zones from the configuration block are used.
|
||||
- **ACTION** (*allow*, *block*, or *filter*) defines the way to deal with DNS queries matched by this rule. The default action is *allow*, which means a DNS query not matched by any rules will be allowed to recurse. The difference between *block* and *filter* is that block returns status code of *REFUSED* while filter returns an empty set *NOERROR*
|
||||
- **ACTION** (*allow*, *block*, *filter*, or *drop*) defines the way to deal with DNS queries matched by this rule. The default action is *allow*, which means a DNS query not matched by any rules will be allowed to recurse. The difference between *block* and *filter* is that block returns status code of *REFUSED* while filter returns an empty set *NOERROR*. *drop* however returns no response to the client.
|
||||
- **QTYPE** is the query type to match for the requests to be allowed or blocked. Common resource record types are supported. `*` stands for all record types. The default behavior for an omitted `type QTYPE...` is to match all kinds of DNS queries (same as `type *`).
|
||||
- **SOURCE** is the source IP address to match for the requests to be allowed or blocked. Typical CIDR notation and single IP address are supported. `*` stands for all possible source IP addresses.
|
||||
|
||||
|
@ -85,6 +85,16 @@ example.org {
|
|||
}
|
||||
~~~
|
||||
|
||||
Drop all DNS queries from 192.0.2.0/24:
|
||||
|
||||
~~~ corefile
|
||||
. {
|
||||
acl {
|
||||
drop net 192.0.2.0/24
|
||||
}
|
||||
}
|
||||
~~~
|
||||
|
||||
## Metrics
|
||||
|
||||
If monitoring is enabled (via the _prometheus_ plugin) then the following metrics are exported:
|
||||
|
@ -95,4 +105,6 @@ If monitoring is enabled (via the _prometheus_ plugin) then the following metric
|
|||
|
||||
- `coredns_acl_allowed_requests_total{server, view}` - counter of DNS requests being allowed.
|
||||
|
||||
- `coredns_acl_dropped_requests_total{server, zone, view}` - counter of DNS requests being dropped.
|
||||
|
||||
The `server` and `zone` labels are explained in the _metrics_ plugin documentation.
|
||||
|
|
|
@ -49,6 +49,8 @@ const (
|
|||
actionBlock
|
||||
// actionFilter returns empty sets for queries towards protected DNS zones.
|
||||
actionFilter
|
||||
// actionDrop does not respond for queries towards the protected DNS zones.
|
||||
actionDrop
|
||||
)
|
||||
|
||||
var log = clog.NewWithPlugin("acl")
|
||||
|
@ -67,6 +69,11 @@ RulesCheckLoop:
|
|||
|
||||
action := matchWithPolicies(rule.policies, w, r)
|
||||
switch action {
|
||||
case actionDrop:
|
||||
{
|
||||
RequestDropCount.WithLabelValues(metrics.WithServer(ctx), zone, metrics.WithView(ctx)).Inc()
|
||||
return dns.RcodeSuccess, nil
|
||||
}
|
||||
case actionBlock:
|
||||
{
|
||||
m := new(dns.Msg).
|
||||
|
|
|
@ -51,6 +51,7 @@ func TestACLServeDNS(t *testing.T) {
|
|||
wantRcode int
|
||||
wantErr bool
|
||||
wantExtendedErrorCode uint16
|
||||
expectNoResponse bool
|
||||
}{
|
||||
// IPv4 tests.
|
||||
{
|
||||
|
@ -205,6 +206,79 @@ func TestACLServeDNS(t *testing.T) {
|
|||
wantRcode: dns.RcodeRefused,
|
||||
wantExtendedErrorCode: dns.ExtendedErrorCodeBlocked,
|
||||
},
|
||||
{
|
||||
name: "Drop 1 DROPPED",
|
||||
config: `acl example.org {
|
||||
drop net 192.168.0.0/16
|
||||
}`,
|
||||
zones: []string{},
|
||||
args: args{
|
||||
domain: "www.example.org.",
|
||||
sourceIP: "192.168.0.2",
|
||||
qtype: dns.TypeA,
|
||||
},
|
||||
wantRcode: dns.RcodeSuccess,
|
||||
expectNoResponse: true,
|
||||
},
|
||||
{
|
||||
name: "Subnet-Order 1 REFUSED",
|
||||
config: `acl example.org {
|
||||
block net 192.168.1.0/24
|
||||
drop net 192.168.0.0/16
|
||||
}`,
|
||||
zones: []string{},
|
||||
args: args{
|
||||
domain: "www.example.org.",
|
||||
sourceIP: "192.168.1.2",
|
||||
qtype: dns.TypeA,
|
||||
},
|
||||
wantRcode: dns.RcodeRefused,
|
||||
wantExtendedErrorCode: dns.ExtendedErrorCodeBlocked,
|
||||
},
|
||||
{
|
||||
name: "Subnet-Order 2 DROPPED",
|
||||
config: `acl example.org {
|
||||
drop net 192.168.0.0/16
|
||||
block net 192.168.1.0/24
|
||||
}`,
|
||||
zones: []string{},
|
||||
args: args{
|
||||
domain: "www.example.org.",
|
||||
sourceIP: "192.168.1.1",
|
||||
qtype: dns.TypeA,
|
||||
},
|
||||
wantRcode: dns.RcodeSuccess,
|
||||
expectNoResponse: true,
|
||||
},
|
||||
{
|
||||
name: "Drop-Type 1 DROPPED",
|
||||
config: `acl example.org {
|
||||
drop type A
|
||||
allow net 192.168.0.0/16
|
||||
}`,
|
||||
zones: []string{},
|
||||
args: args{
|
||||
domain: "www.example.org.",
|
||||
sourceIP: "192.168.1.1",
|
||||
qtype: dns.TypeA,
|
||||
},
|
||||
wantRcode: dns.RcodeSuccess,
|
||||
expectNoResponse: true,
|
||||
},
|
||||
{
|
||||
name: "Drop-Type 2 ALLOWED",
|
||||
config: `acl example.org {
|
||||
drop type A
|
||||
allow net 192.168.0.0/16
|
||||
}`,
|
||||
zones: []string{},
|
||||
args: args{
|
||||
domain: "www.example.org.",
|
||||
sourceIP: "192.168.1.1",
|
||||
qtype: dns.TypeAAAA,
|
||||
},
|
||||
wantRcode: dns.RcodeSuccess,
|
||||
},
|
||||
{
|
||||
name: "Fine-Grained 1 REFUSED",
|
||||
config: `acl a.example.org {
|
||||
|
@ -402,6 +476,79 @@ func TestACLServeDNS(t *testing.T) {
|
|||
wantRcode: dns.RcodeRefused,
|
||||
wantExtendedErrorCode: dns.ExtendedErrorCodeBlocked,
|
||||
},
|
||||
{
|
||||
name: "Drop 1 DROPPED IPV6",
|
||||
config: `acl example.org {
|
||||
drop net 2001:0db8:85a3:0000:0000:8a2e:0370:7334
|
||||
}`,
|
||||
zones: []string{},
|
||||
args: args{
|
||||
domain: "www.example.org.",
|
||||
sourceIP: "2001:0db8:85a3:0000:0000:8a2e:0370:7334",
|
||||
qtype: dns.TypeAAAA,
|
||||
},
|
||||
wantRcode: dns.RcodeSuccess,
|
||||
expectNoResponse: true,
|
||||
},
|
||||
{
|
||||
name: "Subnet-Order 1 REFUSED IPv6",
|
||||
config: `acl example.org {
|
||||
block net 2001:db8:abcd:0012:8000::/66
|
||||
drop net 2001:db8:abcd:0012::0/64
|
||||
}`,
|
||||
zones: []string{},
|
||||
args: args{
|
||||
domain: "www.example.org.",
|
||||
sourceIP: "2001:db8:abcd:0012:8000::1",
|
||||
qtype: dns.TypeAAAA,
|
||||
},
|
||||
wantRcode: dns.RcodeRefused,
|
||||
wantExtendedErrorCode: dns.ExtendedErrorCodeBlocked,
|
||||
},
|
||||
{
|
||||
name: "Subnet-Order 2 DROPPED IPv6",
|
||||
config: `acl example.org {
|
||||
drop net 2001:db8:abcd:0012::0/64
|
||||
block net 2001:db8:abcd:0012:8000::/66
|
||||
}`,
|
||||
zones: []string{},
|
||||
args: args{
|
||||
domain: "www.example.org.",
|
||||
sourceIP: "2001:db8:abcd:0012:8000::1",
|
||||
qtype: dns.TypeAAAA,
|
||||
},
|
||||
wantRcode: dns.RcodeSuccess,
|
||||
expectNoResponse: true,
|
||||
},
|
||||
{
|
||||
name: "Drop-Type 1 DROPPED IPv6",
|
||||
config: `acl example.org {
|
||||
drop type A
|
||||
allow net 2001:db8:85a3:0000::0/64
|
||||
}`,
|
||||
zones: []string{},
|
||||
args: args{
|
||||
domain: "www.example.org.",
|
||||
sourceIP: "2001:0db8:85a3:0000:0000:8a2e:0370:7334",
|
||||
qtype: dns.TypeA,
|
||||
},
|
||||
wantRcode: dns.RcodeSuccess,
|
||||
expectNoResponse: true,
|
||||
},
|
||||
{
|
||||
name: "Drop-Type 2 ALLOWED IPv6",
|
||||
config: `acl example.org {
|
||||
drop type A
|
||||
allow net 2001:db8:85a3:0000::0/64
|
||||
}`,
|
||||
zones: []string{},
|
||||
args: args{
|
||||
domain: "www.example.org.",
|
||||
sourceIP: "2001:0db8:85a3:0000:0000:8a2e:0370:7334",
|
||||
qtype: dns.TypeAAAA,
|
||||
},
|
||||
wantRcode: dns.RcodeSuccess,
|
||||
},
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
|
@ -430,6 +577,9 @@ func TestACLServeDNS(t *testing.T) {
|
|||
if w.Rcode != tt.wantRcode {
|
||||
t.Errorf("Error: acl.ServeDNS() Rcode = %v, want %v", w.Rcode, tt.wantRcode)
|
||||
}
|
||||
if tt.expectNoResponse && w.Msg != nil {
|
||||
t.Errorf("Error: acl.ServeDNS() responded to client when not expected")
|
||||
}
|
||||
if tt.wantExtendedErrorCode != 0 {
|
||||
matched := false
|
||||
for _, opt := range w.Msg.IsEdns0().Option {
|
||||
|
|
|
@ -29,4 +29,11 @@ var (
|
|||
Name: "allowed_requests_total",
|
||||
Help: "Counter of DNS requests being allowed.",
|
||||
}, []string{"server", "view"})
|
||||
// RequestDropCount is the number of DNS requests being dropped.
|
||||
RequestDropCount = promauto.NewCounterVec(prometheus.CounterOpts{
|
||||
Namespace: plugin.Namespace,
|
||||
Subsystem: pluginName,
|
||||
Name: "dropped_requests_total",
|
||||
Help: "Counter of DNS requests being dropped.",
|
||||
}, []string{"server", "zone", "view"})
|
||||
)
|
||||
|
|
|
@ -56,8 +56,10 @@ func parse(c *caddy.Controller) (ACL, error) {
|
|||
p.action = actionBlock
|
||||
} else if action == "filter" {
|
||||
p.action = actionFilter
|
||||
} else if action == "drop" {
|
||||
p.action = actionDrop
|
||||
} else {
|
||||
return a, c.Errf("unexpected token %q; expect 'allow', 'block', or 'filter'", c.Val())
|
||||
return a, c.Errf("unexpected token %q; expect 'allow', 'block', 'filter' or 'drop'", c.Val())
|
||||
}
|
||||
|
||||
p.qtypes = make(map[uint16]struct{})
|
||||
|
|
|
@ -57,6 +57,13 @@ func TestSetup(t *testing.T) {
|
|||
}`,
|
||||
false,
|
||||
},
|
||||
{
|
||||
"Drop 1",
|
||||
`acl {
|
||||
drop type * net 192.168.0.0/16
|
||||
}`,
|
||||
false,
|
||||
},
|
||||
{
|
||||
"fine-grained 1",
|
||||
`acl a.example.org {
|
||||
|
@ -175,6 +182,13 @@ func TestSetup(t *testing.T) {
|
|||
}`,
|
||||
false,
|
||||
},
|
||||
{
|
||||
"Drop 1 IPv6",
|
||||
`acl {
|
||||
drop net 2001:db8:abcd:0012::0/64
|
||||
}`,
|
||||
false,
|
||||
},
|
||||
{
|
||||
"fine-grained 1 IPv6",
|
||||
`acl a.example.org {
|
||||
|
|
Loading…
Add table
Reference in a new issue