puppet-tripleo/manifests/firewall/post.pp
Michele Baldessari 3ad7c2d10a 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
2018-07-16 14:32:58 +02:00

66 lines
1.8 KiB
Puppet

#
# Copyright (C) 2015 eNovance SAS <licensing@enovance.com>
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
# == Class: tripleo::firewall::post
#
# Firewall rules during 'post' Puppet stage
#
# === Parameters:
#
# [*debug*]
# (optional) Set log output to debug output
# Defaults to false
#
# [*firewall_settings*]
# (optional) Allow to add custom parameters to firewall rules
# 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',
extras => $logging_extras,
}
tripleo::firewall::rule{ '999 drop all':
proto => 'all',
action => 'drop',
extras => $firewall_settings,
tag => 'tripleo-firewall-postrule',
}
notice('At this stage, all network traffic is blocked.')
}
}