rate limit iptables logging

We currently have the following rule in the post firewall section of our puppet code:

tripleo::firewall::rule{ '998 log all':
  proto => 'all',
  jump => 'LOG',
}

The problem is that with this rule we log every single packet which is rather suboptimal:
Jul 10 05:05:03 overcloud-controller-1 kernel: IN=vlan20 OUT= MAC=1a:1a:0a:72:8a:0c:ba:ac:11:55:28:28:08:00 SRC=172.16.2.10 DST=172.16.2.14 LEN=228 TOS=0x00 PREC=0x00 TTL=64 ID=59388 DF PROTO=UDP SPT=43036 DPT=5405 LEN=208
Jul 10 05:05:03 overcloud-controller-1 kernel: IN=vlan20 OUT= MAC=1a:1a:0a:72:8a:0c:ba:ac:11:55:28:28:08:00 SRC=172.16.2.10 DST=172.16.2.14 LEN=228 TOS=0x00 PREC=0x00 TTL=64 ID=59391 DF PROTO=UDP SPT=43036 DPT=5405 LEN=208
Jul 10 05:05:03 overcloud-controller-1 kernel: IN=vlan20 OUT= MAC=1a:1a:0a:72:8a:0c:ba:ac:11:55:28:28:08:00 SRC=172.16.2.10 DST=172.16.2.14 LEN=228 TOS=0x00 PREC=0x00 TTL=64 ID=59392 DF PROTO=UDP SPT=43036 DPT=5405 LEN=208
...

(undercloud) [stack@undercloud stonith-scalingup-issue]$ grep IN=vlan20 sosreport-overcloud-controller-1-20180710070209/var/log/messages |wc -l
8682

Let's start by ratelimiting this to a burst of 15 messages
and 20 messages per minute. According to [1] this means that
we will have 15 messages logged before the 20 messages per minute
limit kicks in.
Let's also add a parameter so that an operator can override this
in case the defaults are not suitable for her/him.

[1] https://netfilter.org/documentation/HOWTO/packet-filtering-HOWTO-7.html

Change-Id: Ie8fe28e582bdcf51b819d5ca7f979b0a21597768
Closes-Bug: #1781171
This commit is contained in:
Michele Baldessari 2018-07-11 15:44:02 +02:00
parent 2be2d8cbda
commit 3ad7c2d10a
1 changed files with 16 additions and 4 deletions

View File

@ -25,21 +25,33 @@
#
# [*firewall_settings*]
# (optional) Allow to add custom parameters to firewall rules
# Should be an hash.
# Should be a hash.
# Default to {}
#
# [*logging_settings*]
# (optional) Allow to add custom parameters to the logging firewall rule
# Should be a hash.
# Default to {}
#
class tripleo::firewall::post(
$debug = false,
$firewall_settings = {},
$logging_settings = {},
){
if $debug {
warning('debug is enabled, the traffic is not blocked.')
} else {
$default_logging_extras = {
'burst' => '15',
'limit' => '20/min',
}
$logging_extras = merge($default_logging_extras, $logging_settings)
tripleo::firewall::rule{ '998 log all':
proto => 'all',
jump => 'LOG',
tag => 'tripleo-firewall-postrule',
proto => 'all',
jump => 'LOG',
tag => 'tripleo-firewall-postrule',
extras => $logging_extras,
}
tripleo::firewall::rule{ '999 drop all':
proto => 'all',