1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
|
# modules/shorewall/manifests/init.pp - manage firewalling with shorewall 3.x
# Copyright (C) 2007 David Schmitt <david@schmitt.edv-bus.at>
# See LICENSE for the full license granted to you.
#
# Based on the work of ADNET Ghislain <gadnet@aqueos.com> from AQUEOS
# at https://reductivelabs.com/trac/puppet/wiki/AqueosShorewall
#
# Changes:
# * FHS Layout: put configuration in /var/lib/puppet/modules/shorewall and
# adjust CONFIG_PATH
# * remove shorewall- prefix from defines in the shorewall namespace
# * refactor the whole define structure
# * manage all shorewall files
# * add 000-header and 999-footer files for all managed_files
# * added rule_section define and a few more parameters for rules
# * add managing for masq, proxyarp, blacklist, nat, rfc1918
modules_dir { "shorewall": }
class shorewall {
package { shorewall: ensure => installed }
service { shorewall: ensure => running, enable => true, }
# private
define managed_file () {
$dir = "/var/lib/puppet/modules/shorewall/${name}.d"
concatenated_file { "/var/lib/puppet/modules/shorewall/$name":
dir => $dir,
mode => 0600,
}
file {
"${dir}/000-header":
source => "puppet://$servername/shorewall/boilerplate/${name}.header",
mode => 0600, owner => root, group => root,
notify => Exec["concat_${dir}"];
"${dir}/999-footer":
source => "puppet://$servername/shorewall/boilerplate/${name}.footer",
mode => 0600, owner => root, group => root,
notify => Exec["concat_${dir}"];
}
}
# private
define entry ($line) {
$target = "/var/lib/puppet/modules/shorewall/${name}"
$dir = dirname($target)
file { $target:
content => "${line}\n",
mode => 0600, owner => root, group => root,
notify => Exec["concat_${dir}"],
}
}
# This file has to be managed in place, so shorewall can find it
file { "/etc/shorewall/shorewall.conf":
# use OS specific defaults, but use gentoo if no other is found
source => [
"puppet://$servername/shorewall/shorewall.conf.$operatingsystem.$lsbdistcodename",
"puppet://$servername/shorewall/shorewall.conf.$operatingsystem",
"puppet://$servername/shorewall/shorewall.conf.gentoo" ],
mode => 0644, owner => root, group => root,
}
# See http://www.shorewall.net/3.0/Documentation.htm#Zones
managed_file{ zones: }
define zone($type, $options = '-', $in = '-', $out = '-', $parent = '-', $order = 100) {
$real_name = $parent ? { '-' => $name, default => "${name}:${parent}" }
entry { "zones.d/${order}-${name}":
line => "${real_name} ${type} ${options} ${in} ${out}"
}
}
# See http://www.shorewall.net/3.0/Documentation.htm#Interfaces
managed_file{ interfaces: }
define interface($zone, $broadcast = 'detect', $options = 'tcpflags,blacklist,norfc1918,routefilter,nosmurfs,logmartians') {
entry { "interfaces.d/${name}":
line => "${zone} ${name} ${broadcast} ${options}",
}
}
# See http://www.shorewall.net/3.0/Documentation.htm#Hosts
managed_file { hosts: }
define host($zone, $options = 'tcpflags,blacklist,norfc1918') {
entry { "hosts.d/${name}":
line => "${zone} ${name} ${options}"
}
}
# See http://www.shorewall.net/3.0/Documentation.htm#Policy
managed_file { policy: }
define policy($sourcezone, $destinationzone, $policy, $shloglevel = '-', $limitburst = '-', $order) {
entry { "policy.d/${order}-${name}":
line => "# ${name}\n${sourcezone} ${destinationzone} ${policy} ${shloglevel} ${limitburst}",
}
}
# See http://www.shorewall.net/3.0/Documentation.htm#Rules
managed_file { rules: }
define rule_section($order) {
entry { "rules.d/${order}-${name}":
line => "SECTION ${name}",
}
}
# mark is new in 3.4.4
define rule($action, $source, $destination, $proto = '-',
$destinationport = '-', $sourceport = '-', $originaldest = '-',
$ratelimit = '-', $user = '-', $mark = '', $order)
{
entry { "rules.d/${order}-${name}":
line => "${action} ${source} ${destination} ${proto} ${destinationport} ${sourceport} ${originaldest} ${ratelimit} ${user} ${mark}",
}
}
# See http://www.shorewall.net/3.0/Documentation.htm#Masq
managed_file{ masq: }
# mark is new in 3.4.4
define masq($interface, $address, $proto = '-', $port = '-', $ipsec = '-', $mark = '') {
entry { "masq.d/${name}":
line => "${interface} ${name} ${address} ${proto} ${port} ${ipsec} ${mark}"
}
}
# See http://www.shorewall.net/3.0/Documentation.htm#ProxyArp
managed_file { proxyarp: }
define proxyarp($interface, $external, $haveroute = yes, $persistent = no) {
entry { "proxyarp.d/${name}":
line => "${name} ${interface} ${external} ${haveroute} ${persistent}"
}
}
# See http://www.shorewall.net/3.0/Documentation.htm#NAT
managed_file { nat: }
define nat($interface, $internal, $all = 'no', $local = 'yes') {
entry { "nat.d/${name}":
line => "${name} ${interface} ${internal} ${all} ${local}"
}
}
# See http://www.shorewall.net/3.0/Documentation.htm#Blacklist
managed_file { blacklist: }
define blacklist($proto = '-', $port = '-') {
entry { "blacklist.d/${name}":
line => "${name} ${proto} ${port}",
}
}
# See http://www.shorewall.net/3.0/Documentation.htm#rfc1918
managed_file { rfc1918: }
define rfc1918($action = 'logdrop') {
entry { "rfc1918.d/${name}":
line => "${name} ${action}"
}
}
# See http://www.shorewall.net/3.0/Documentation.htm#Routestopped
managed_file { routestopped: }
define routestopped($host = '-', $options = '') {
entry { "routestopped.d/${name}":
line => "${name} ${host} ${options}",
}
}
}
|