summaryrefslogtreecommitdiffstats
path: root/doc/server/plugins/generators/tgenshi/iptables.txt
blob: 310f9ffab3ea4506c7fd15fe191f69c5e70dd545 (plain)
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
.. -*- mode: rst -*-

.. _server-plugins-generators-tgenshi-iptables:

iptables
========

* Setup a TGenshi base iptables file that contains the basic rules you
  want every host to have
* Create a custom dir that has group and host specific rules you want
  to apply
* To be safe you should have a client side IptablesDeadmanScript if you
  intend on having bcfg2 bounce iptables upon rule updates

.. note:: When updating files in the ``includes`` directory, you will
          need to `touch` the TGenshi template to regenerate the
          template contents.

/repository/TGenshi/etc/sysconfig/iptables/template.newtxt
----------------------------------------------------------

::

    {% python
        from genshi.builder import tag
        import os,sys
        import Bcfg2.Options

        opts = { 'repo': Bcfg2.Options.SERVER_REPOSITORY }
        setup = Bcfg2.Options.OptionParser(opts)
        setup.parse('--')
        repo = setup['repo']
        basedir = '%s' % (repo)

        # for instance: /var/lib/bcfg2/custom/etc/sysconfig/iptables/
        bcfg2BaseDir = basedir + '/includes' + name + '/'


        def checkHostFile(hostName, type):
            fileName = bcfg2BaseDir + type + '.H_' + hostName
            if os.path.isfile(fileName)==True :
               return fileName
            else:
               return fileName

        def checkGroupFile(groupName, type):
            fileName = bcfg2BaseDir + type + '.G_' + groupName
            if os.path.isfile(fileName)==True :
               return fileName
            else:
               return fileName

    %}\
    # BCFG2 GENERATED IPTABLES
    # DO NOT CHANGE THIS
    # $$Id$$
    # $$HeadURL$$
    # Templates live in ${bcfg2BaseDir}
    # Manual customization of this file will get reverted.
    # ----------------------------- FILTER --------------------------------- #
    # Default CHAINS for FILTER:
    *filter
    :INPUT DROP [0:0]
    :FORWARD DROP [0:0]
    :OUTPUT ACCEPT [0:0]
    :NO-SMTP - [0:0]

    #Default rules
    #discard malicious packets
    -A INPUT -p tcp --tcp-flags ALL ACK,RST,SYN,FIN -j DROP
    -A INPUT -p tcp --tcp-flags SYN,FIN SYN,FIN -j DROP
    -A INPUT -p tcp --tcp-flags SYN,RST SYN,RST -j DROP
    #Allow incoming ICMP
    -A INPUT -p icmp -m icmp -j ACCEPT
    #Accept localhost traffic
    -A INPUT -i lo -j ACCEPT
    # Allow already established sessions to remain
    -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT

    # Deny inbound SMTP delivery (still allows outbound connections)
    -A INPUT -m state --state NEW -m tcp -p tcp --tcp-flags FIN,SYN,RST,ACK SYN --dport 25 -j NO-SMTP
    -A NO-SMTP -j LOG --log-prefix " Incoming SMTP (denied) "
    -A NO-SMTP -j DROP

    # Allow SSH Access
    :SSH - [0:0]
    -A INPUT -p tcp -m state --state NEW -m tcp --tcp-flags FIN,SYN,RST,ACK SYN --dport 22 -j SSH
    -A SSH -s 192.168.0.0/255.255.0.0 -j ACCEPT

    # Allow Ganglia Access
    -A INPUT -m state --state NEW -m tcp -p tcp --tcp-flags FIN,SYN,RST,ACK SYN --src 192.168.1.1 --dport 8649 -j ACCEPT
    # Gmetad access to gmond
    -A INPUT -m state --state NEW -m tcp -p tcp --tcp-flags FIN,SYN,RST,ACK SYN --src 192.168.1.1 --dport 8649 -j ACCEPT
    # Gmond UDP multicast
    -A INPUT -m state --state NEW -m udp -p udp --dport 8649 -j ACCEPT

    {% if metadata.groups %}\
    # group custom FILTER rules:
    {% for group in metadata.groups %}\
    {% include ${checkGroupFile(group,'custom-filter')} %}\
    {% end %}\
    {% end %}\

    # host-specific FILTER rules:
    {% include ${checkHostFile(metadata.hostname, 'custom-filter')} %}\

    COMMIT
    # ------------------------------- NAT ---------------------------------- #
    *nat

    # Default CHAINS for NAT:
    :PREROUTING ACCEPT [0:0]
    :OUTPUT ACCEPT [0:0]
    :POSTROUTING ACCEPT [0:0]

    {% if metadata.groups %}\
    # group NAT for PREROUTING:
    {% for group in metadata.groups %}\
    {% include ${checkGroupFile(group,'nat-prerouting')} %}\
    {% end %}\
    {% end %}\

    {% if metadata.groups %}\
    # group NAT for OUTPUT:
    {% for group in metadata.groups %}\
    {% include ${checkGroupFile(group,'nat-output')} %}\
    {% end %}\
    {% end %}\

    {% if metadata.groups %}\
    # group NAT for POSTROUTING:
    {% for group in metadata.groups %}\
    {% include ${checkGroupFile(group,'nat-postrouting')} %}\
    {% end %}\
    {% end %}\

    {% if metadata.groups %}\
    # group custom NAT rules:
    {% for group in metadata.groups %}\
    {% include ${checkGroupFile(group,'custom-nat')} %}\
    {% end %}\
    {% end %}\

    # host-specific NAT ruls:
    {% include ${checkHostFile(metadata.hostname, 'custom-nat')} %}\
    COMMIT
    # ----------------------------- MANGLE -------------------------------- #
    *mangle

    # Default CHAINS for MANGLE:
    :PREROUTING ACCEPT [0:0]
    :INPUT ACCEPT [0:0]
    :FORWARD ACCEPT [0:0]
    :OUTPUT ACCEPT [0:0]
    :POSTROUTING ACCEPT [0:0]

    {% if metadata.groups %}\
    # group MANGLE for PREROUTING:
    {% for group in metadata.groups %}\
    {% include ${checkGroupFile(group,'mangle-prerouting')} %}\
    {% end %}\
    {% end %}\

    {% if metadata.groups %}\
    # group MANGLE for INPUT:
    {% for group in metadata.groups %}\
    {% include ${checkGroupFile(group,'mangle-input')} %}\
    {% end %}\
    {% end %}\

    {% if metadata.groups %}\
    # group MANGLE for FORWARD:
    {% for group in metadata.groups %}\
    {% include ${checkGroupFile(group,'mangle-forward')} %}\
    {% end %}\
    {% end %}\

    {% if metadata.groups %}\
    # group MANGLE for OUTPUT:
    {% for group in metadata.groups %}\
    {% include ${checkGroupFile(group,'mangle-output')} %}\
    {% end %}\
    {% end %}\

    {% if metadata.groups %}\
    # group MANGLE for POSTROUTING rules:
    {% for group in metadata.groups %}\
    {% include ${checkGroupFile(group,'mangle-postrouting')} %}\
    {% end %}\
    {% end %}\

    {% if metadata.groups %}\
    # group custom MANGLE rules:
    {% for group in metadata.groups %}\
    {% include ${checkGroupFile(group,'custom-mangle')} %}\
    {% end %}\
    {% end %}\

    # host-specific MANGLE rules:
    {% include ${checkHostFile(metadata.hostname, 'custom-mangle')} %}\
    COMMIT

/var/lib/bcfg2/custom/etc/sysconfig/iptables/custom-filter.G_mysql-server
-------------------------------------------------------------------------

::

    :MYSQL - [0:0]
    -A INPUT -p tcp -m state --state NEW -m tcp --dport 3306 --tcp-flags FIN,SYN,RST,ACK SYN -j MYSQL
    -A MYSQL -s 192.168.0.0/255.255.0.0 -j ACCEPT

For a host that is in the mysql-server group you get an iptables file
that looks like the following::

    # BCFG2 GENERATED IPTABLES
    # DO NOT CHANGE THIS
    # $Id: template.newtxt 5402 2009-08-19 22:50:06Z unixmouse$
    # $HeadURL: https://svn.fakecompany.net/bcfg2/trunk/repository/TGenshi/etc/sysconfig/iptables/template.newtxt $
    # Templates live in /var/lib/bcfg2/custom/etc/sysconfig/iptables/
    # Manual customization of this file will get reverted.
    # ----------------------------- FILTER --------------------------------- #
    # Default CHAINS for FILTER:
    *filter
    :INPUT DROP [0:0]
    :FORWARD DROP [0:0]
    :OUTPUT ACCEPT [0:0]
    :NO-SMTP - [0:0]

    #Default rules
    #discard malicious packets
    -A INPUT -p tcp --tcp-flags ALL ACK,RST,SYN,FIN -j DROP
    -A INPUT -p tcp --tcp-flags SYN,FIN SYN,FIN -j DROP
    -A INPUT -p tcp --tcp-flags SYN,RST SYN,RST -j DROP
    # Allow incoming ICMP
    -A INPUT -p icmp -m icmp -j ACCEPT
    # Accept localhost traffic
    -A INPUT -i lo -j ACCEPT
    # Allow already established sessions to remain
    -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT

    # Deny inbound SMTP delivery (still allows outbound connections)
    -A INPUT -m state --state NEW -m tcp -p tcp --tcp-flags FIN,SYN,RST,ACK SYN --dport 25 -j NO-SMTP
    -A NO-SMTP -j LOG --log-prefix " Incoming SMTP (denied) "
    -A NO-SMTP -j DROP

    # Allow SSH Access
    :SSH - [0:0]
    -A INPUT -p tcp -m state --state NEW -m tcp --tcp-flags FIN,SYN,RST,ACK SYN --dport 22 -j SSH
    -A SSH -s 192.168.0.0/255.255.0.0 -j ACCEPT

    # Allow Ganglia Access
    -A INPUT -m state --state NEW -m tcp -p tcp --tcp-flags FIN,SYN,RST,ACK SYN --src 192.168.1.1 --dport 8649 -j ACCEPT
    #Gmetad access to gmond
    -A INPUT -m state --state NEW -m tcp -p tcp --tcp-flags FIN,SYN,RST,ACK SYN --src 192.168.1.1 --dport 8649 -j ACCEPT
    #Gmond UDP multicast
    -A INPUT -m state --state NEW -m udp -p udp --dport 8649 -j ACCEPT

    # group custom FILTER rules:
    :MYSQL - [0:0]
    -A INPUT -p tcp -m state --state NEW -m tcp --dport 3306 --tcp-flags FIN,SYN,RST,ACK SYN -j MYSQL
    -A MYSQL -s 192.168.0.0/255.255.0.0 -j ACCEPT

    # host-specific FILTER rules:

    COMMIT
    # ------------------------------- NAT ---------------------------------- #
    *nat

    # Default CHAINS for NAT:
    :PREROUTING ACCEPT [0:0]
    :OUTPUT ACCEPT [0:0]
    :POSTROUTING ACCEPT [0:0]

    # group NAT for PREROUTING:

    # group NAT for OUTPUT:

    # group NAT for POSTROUTING:

    # group custom NAT rules:

    # host-specific NAT rules:
    COMMIT
    # ----------------------------- MANGLE -------------------------------- #
    *mangle

    # Default CHAINS for MANGLE:
    :PREROUTING ACCEPT [0:0]
    :INPUT ACCEPT [0:0]
    :FORWARD ACCEPT [0:0]
    :OUTPUT ACCEPT [0:0]
    :POSTROUTING ACCEPT [0:0]

    # group MANGLE for PREROUTING:

    # group MANGLE for INPUT:
    # group MANGLE for FORWARD:

    # group MANGLE for OUTPUT:

    # group MANGLE for POSTROUTING rules:

    # group custom MANGLE rules:

    # host-specific MANGLE rules:
    COMMIT