|
| 1 | + |
| 2 | +class iptables::ruleset::failsafe_ssh ( |
| 3 | + $chains = [ 'INPUT', 'OUTPUT' ], |
| 4 | + $target = 'ACCEPT', |
| 5 | + $order = 11, |
| 6 | + $port = 22, |
| 7 | + $log = false, |
| 8 | + $lookup_alternative_port = true, |
| 9 | + $log_prefix = $iptables::log_prefix, |
| 10 | + $log_limit_burst = $iptables::log_limit_burst, |
| 11 | + $log_limit = $iptables::log_limit, |
| 12 | + $log_level = $iptables::log_level, |
| 13 | +) { |
| 14 | + |
| 15 | + $discard = iptables_declare_multiple('iptables::rule', |
| 16 | + $chains, 'example42-failsafe-ssh-###name###', |
| 17 | + { |
| 18 | + table => 'filter', |
| 19 | + chain => '###name###', |
| 20 | + target => $target, |
| 21 | + protocol => 'tcp', |
| 22 | + port => $port, |
| 23 | + order => $order, |
| 24 | + log => $log, |
| 25 | + log_prefix => $log_prefix, |
| 26 | + log_limit_burst => $log_limit_burst, |
| 27 | + log_limit => $log_limit, |
| 28 | + log_level => $log_level |
| 29 | + }) |
| 30 | + |
| 31 | + # If openssh has been configured to use a different class we'll |
| 32 | + # usee that too. |
| 33 | + # We could combine the two rule statements into one by using a |
| 34 | + # multiport match, but not all kernels support this, so for a |
| 35 | + # failsafe we're not taking any chances. |
| 36 | + if any2bool($lookup_alternative_port) and defined(Class['openssh']) and $openssh::port != $port { |
| 37 | + $discard_1 = iptables_declare_multiple('iptables::rule', |
| 38 | + $chains, 'example42-failsafe-ssh-###name###-otherPort', |
| 39 | + { |
| 40 | + table => 'filter', |
| 41 | + chain => '###name###', |
| 42 | + target => $target, |
| 43 | + protocol => 'tcp', |
| 44 | + port => $openssh::port, |
| 45 | + order => $order, |
| 46 | + log => $log, |
| 47 | + log_prefix => $log_prefix, |
| 48 | + log_limit_burst => $log_limit_burst, |
| 49 | + log_limit => $log_limit, |
| 50 | + log_level => $log_level |
| 51 | + }) |
| 52 | + } |
| 53 | + |
| 54 | +} |
0 commit comments