Puppet Class: cis_security_hardening::rules::ufw_outbound
- Defined in:
- manifests/rules/ufw_outbound.pp
Summary
Ensure outbound connections are configured (Not Scored)Overview
Configure the firewall rules for new outbound connections.
Rationale: If rules are not in place for new outbound connections all packets will be dropped by the default policy preventing network usage.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'manifests/rules/ufw_outbound.pp', line 22
class cis_security_hardening::rules::ufw_outbound (
Boolean $enforce = false,
Hash $firewall_rules = {},
) {
if $enforce {
$firewall_rules.each |$title, $data| {
if cis_security_hardening::hash_key($data, 'action') {
unless $data['action'] =~ /\W*/ {
fail("Illegal action: ${data['action']}")
}
$action = $data['action']
} else {
$action = ''
}
if cis_security_hardening::hash_key($data, 'queue') {
unless $data['queue'] =~ /\W*/ {
fail("Illegal queue: ${data['queue']}")
}
$queue = $data['queue']
} else {
$queue =''
}
if cis_security_hardening::hash_key($data, 'port') {
unless $data['port'] =~ /^\d+$/ {
fail("Illegal port: ${data['port']}")
}
$port = $data['port']
} else {
$port = ''
}
if ($data['queue'] == 'in') {
if(cis_security_hardening::hash_key($data, 'from')) {
unless $data['from'] =~ /^[a-zA-Z0-9\-_\.]+$/ {
fail("Illegal from value: ${data['from']}")
}
$from = "from ${data['from']} "
} else {
$from = ''
}
if (cis_security_hardening::hash_key($data, 'to')) {
unless $data['to'] =~ /^[a-zA-Z0-9\-_\.]+$/ {
fail("Illegal to value: ${data['to']}")
}
$to = "to ${data['to']} "
} else {
$to = ''
}
if cis_security_hardening::hash_key($data, 'proto') {
unless $data['proto'] in ['tcp', 'udp', 'icmp'] {
fail("Illegal protocol: ${data['proto']}")
}
$proto = $data['proto']
} else {
$proto = ''
}
if($from == '') and ($to == '') {
$cmd = "ufw allow ${port}/${proto}"
} else {
$cmd = "ufw ${action} proto ${proto} ${from}${to}port ${port}"
}
$check = "test -z \"$(ufw status verbose | grep -E -i '^${port}/${proto}.*ALLOW ${queue}')\""
} elsif ($data['queue'] == 'out') {
$cmd = "ufw ${action} ${queue} to ${data['to']} port ${port}"
$check = "test -z \"$(ufw status verbose | grep -E -i '^${port}.*ALLOW ${queue}')\""
} else {
fail("unknow ufw queue ${data['queue']}")
}
exec { $title:
command => $cmd,
path => ['/bin', '/usr/bin', '/sbin', '/usr/sbin'],
onlyif => $check,
}
}
}
}
|