File: uruk.azm

package info (click to toggle)
uruk 20140627-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 1,088 kB
  • ctags: 70
  • sloc: sh: 1,770; makefile: 143; xml: 51
file content (379 lines) | stat: -rw-r--r-- 10,745 bytes parent folder | download | duplicates (6)
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
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
\: vim:syntax=tex
\: this file maintained at http://git.mdcc.cx/uruk.git
\: this is a manpage in zoem format.  see http://micans.org/zoem/ and man_zmm(7)

\import{pud/man.zmm}
\import{./include.zmm}

\begin{pud::man}{
 {name}{uruk}
 {html_title}{uruk}
 {section}{8}
 \man_share
}

\${html}{\"pud::man::maketoc"}

\sec{name}{NAME}
\NAME{uruk}{wrapper for Linux iptables, for managing firewall rules}

\sec{synopsis}{SYNOPSIS}

\uruk

\sec{description}{DESCRIPTION}

\uruk loads an \rc file (see \sibref{uruk-rc}{uruk-rc(5)}) which defines
network service access policy, and invokes \bf{iptables(8)} to set up firewall
rules implementing this policy.  By default the file \ttrcpath is used; one can
overrule this by specifying another file in the URUK_CONFIG environment
variable.  Under some circumstances, it's useful to use another command for
iptables; this can be achieved by setting the URUK_IPTABLES (and/or
URUK_IP6TABLES) environment variables.  See \sibref{uruk-rc}{uruk-rc(5)} for
details.

\sec{quick setup guide}{QUICK SETUP GUIDE}

Uruk will \it{not} "just work" out of the box.  It needs manual configuration.
For those of you who don't like reading lots of documentation:

\verbatim{\
 # cp \expath \\
     \rcpath
 # vi \rcpath
 # urukctl start}

\sec{getting started}{GETTING STARTED}

Once the \uruk script is installed, you want to go use it, of course.  We'll
give a detailed description of what to do here.

\par{

First, create an \rc file.  See \sibref{uruk-rc}{uruk-rc(5)} for info on how to
do this.  Once this file is created and installed (this script looks in
\ttrcpath by default), you're ready to run \uruk.  You might want to test your
\rc file by running \uruk in debug mode, see \sibref{uruk-rc}{uruk-rc(5)}.
There are at least 3 ways to load your \rc file.  We'll first describe a low
level one: using vanilla iptables.

}

\cpar{Vanilla iptables}{

After editing \rc, load your rules like this.  First flush your current rules:

\verbatim{\
 # iptables -F
 # ip6tables -F}

Then enable your \rc rules

\verbatim{\
 # uruk}

. Inspect the rules by doing:

\verbatim{\
 # iptables -L
 # ip6tables -L}

.

If you want to make these changes survive a reboot, use the init script as
shipped with this package.   If you'd rather write your own init script, the
\bf{iptables-restore(8)} and \bf{iptables-save(8)} commands from the iptables
package might be helpful.

}

\cpar{Using the Uruk init script}{

Assumed is the Uruk init script is installed as explained in the README file.
Optionally, install \tt{/etc/default/uruk} (or \tt{/etc/sysconfig/uruk}) and
tweak it.  An example file is in \tt{\defpath} (You might like to enable
support for \uruk_save.)  Now activate uruk by doing:

\verbatim{\
 # urukctl start}

Now your pre-uruk iptables rules (if any) are saved as the "inactive" ruleset.
While executing \tt{urukctl start}, your box is open during a short while.
If you don't like this, read below about \uruk_save.

}

\par{

When rebooting, everything will be fine: \ttinitpath stores
state in \tt{\statepath/iptables}, using
iptables-save(8), which comes with Linux iptables.

}

\cpar{Using Debian ifupdown}{

In case you have just one network interface which should get protected, you
could use \bf{interfaces(5)} from the Debian ifupdown package instead of the
init script.  Suppose you'd like to protect \tt{ppp0}, and would like not to
interfere with traffic on eth0: your other network interface.

First write an \rc file.  Be sure it features

\verbatim{\
 interfaces_unprotect="lo eth0"}

Then run:

\verbatim{\
 # mkdir -p \statepath/iptables

 # iptables -F

 # iptables-save -c > \statepath/iptables/down
 # uruk
 # iptables-save -c > \statepath/iptables/up}

Add

\verbatim{\
 pre-up iptables-restore < \statepath/iptables/up
 post-down iptables-restore < \statepath/iptables/down}

to your interfaces stanza, in your \tt{/etc/network/interfaces} .

}

\par{

Similar tricks might be possible on GNU/Linux systems from other distributions.
The author is interested.

}

\sec{loading a new rc file}{LOADING A NEW \rc FILE}

Need to change your rules?

\cpar{Using the Uruk init script}{

Do

\verbatim{\
 # vi \rcpath
 # urukctl force-reload}

While executing \tt{urukctl force-reload}, your box is open during a short
while.  If you don't like this, read below about \uruk_save.

}

\sec{the gory details uruk internals}{THE GORY DETAILS: uruk INTERNALS}

The \uruk script works like (and looks like) the list of statements below.  Of
course, take a look at \tt{\sbinpath/uruk} for the final word on the workings.

\begin{itemize}{
    {contiguous}{1}
    {compact}{1}
    {type}{arabic}
}
  \item \rc is sourced as a shell script
  \item Traffic on $interfaces_unprotect (just lo per default)
 is trusted:
    \verbatim{\
 $iptables -A INPUT -i $iface -j ACCEPT}
  \item $rc_a is sourced as a shell script, or, in case $rc_a is a directory, all
    files matching $rc_a/*.rc are sourced as shell scripts
  \item ESTABLISHED and RELATED packets are ACCEPT-ed:
    \verbatim{\
 $iptables -A INPUT -m conntrack --ctstate ESTABLISHED,RELATED \\
  -j ACCEPT}
  \item $rc_b is sourced
  \item $interfaces gets protected against spoofing: we don't allow anyone to
     spoof non-routeable addresses.  We block outgoing packets that don't have
     our address as source: they are either spoofed or something is
     misconfigured (NAT disabled, for instance). We want to be nice and don't
     send out garbage.
    \verbatim{\
 $iptables -A INPUT -i $iface --source $no_route_ip \\
  -j DROP}
     We drop all incoming packets which don't have us as destination:
    \verbatim{\
 $iptables -A OUTPUT -o $iface --source ! "$ip" \\
  -j DROP}
     And we always allow outgoing connections:
    \verbatim{\
 $iptables -A OUTPUT -m conntrack --ctstate NEW -o $iface \\
  -j ACCEPT}
  \item $rc_c is sourced
  \item Allow traffic to offered services, from trusted sources:
    \verbatim{\
 $iptables -A INPUT -m conntrack --ctstate NEW \\
  -i $iface --protocol $proto --source "$source" \\
  --destination "$ip" --destination-port "$port" \\
  -j ACCEPT}
  \item $rc_d is sourced
  \item Don't answer broadcast and multicast packets:
    \verbatim{\
 $iptables -A INPUT -i $iface --destination "$bcast" \\
  -j DROP}
  \item $rc_f is sourced
  \item Explicitly allow a subset of the ICMP types.  (We disallow all other
traffic later.)
    \verbatim{\
 $iptables -A INPUT --protocol icmp --icmp-type $type \\
  -j ACCEPT}
  \item $rc_g is sourced
  \item Log packets (which make it till here)
    \verbatim{\
 $iptables -A INPUT -j LOG --log-level debug \\
  --log-prefix 'iptables: '}
  \item $rc_h is sourced
  \item Reject all other packets
    \verbatim{\
 $iptables -A INPUT -j REJECT}
  \item $rc_i is sourced
\end{itemize}


\sec{using uruk-save as the initscript backend}{USING uruk-save AS THE INITSCRIPT BACKEND}

By default, \uruk_save is not used by the uruk init script.  You might want to
use it, though.  The \uruk_save script is faster and when using \uruk_save,
your box won't be open while loading new rules.  But beware: \uruk_save is not
as robust as using \uruk itself.

\par{

The script \urukctl (and thus the uruk init script) will use \uruk_save only if
asked to do so in \tt{/etc/default/uruk} (or \tt{/etc/sysconfig/uruk}).  If
this file features

\verbatim{\

 enable_uruk_save=true}

\uruk_save is used whenever appropriate.

See \sibref{uruk-save}{uruk-save(8)} for more details.

}

\sec{policy}{DEFAULT POLICY}

By default, \uruk drops packets which have unknown RFC 1918 private network
addresses in their source or destination.

\par{

It rejects packets with source nor destination for one of our IPs.

} \par{

Packets belonging to locally initiated sessions are allowed: we match state;
the local host can act as a client for any remote service.

} \par{

By default, \uruk drops all ICMP packets (except those for interfaces in
$interfaces_unprotect) with type other than

\begin{itemize}{
    {contiguous}{1}
    {compact}{1}
    {type}{mark}
}
  \item address-mask-reply
  \item address-mask-request
  \item destination-unreachable (this is a catch-all for a lot of types)
  \item echo-request
  \item echo-reply
  \item parameter-problem (catch-all for ip-header-bad and required-option-missing)
  \item timestamp-reply
  \item timestamp-request
  \item ttl-zero-during-transit
  \item ttl-zero-during-reassembly
\end{itemize}

} \par{

By default, the FORWARD chain is left untouched, so has policy ACCEPT.  (This
won't do much harm, since packet forwarding is disabled by default in the Linux
kernel.  However, if you don't mind being paranoid, you might want to add a

\verbatim{\
 iptables --policy FORWARD REJECT}

to your $rc_a uruk hook.  See \sibref{uruk-rc}{uruk-rc(5)}.)

} \par{

By default, \uruk logs all UDP and TCP packets which are blocked by the user
defined policies.  Loglevel is debug, logprefix is "iptables:".  See
also the notes on \it{loglevel} in \sibref{uruk-rc}{uruk-rc(5)}.

} \par{

Blocked TCP packets are answered with a tcp-reset.

}

\sec{warning}{WARNING}

In order to keep the \uruk script small and simple, the script does very little
error handling.  It does not check the contents of the \rc file in any way
before executing it.  When your \rc file contains bogus stuff, \uruk will very
likely behave in unexpected ways.  Caveat emptor.

\sec{environment}{ENVIRONMENT}

You can override some defaults in the shell before executing the uruk script.
\uruk honors the following variables:

\begin{itemize}{
    {contiguous}{1}
    {compact}{1}
    {type}{mark}
}

\item "URUK_CONFIG" Full pathname of \rc file; \ttrcpath by default.
\item "URUK_IPTABLES" Full pathname of iptables executable.
 \tt{/sbin/iptables} by default.  Overrides \it{iptables}.
\item "URUK_IP6TABLES" Full pathname of ip6tables executable, for
 IPv6 support.  Overrides \it{ip6tables}.
\item "URUK_INTERFACES_UNPROTECT" Default list of unprotected interfaces.
 Overrides \it{interfaces_unprotect}.  The default default is \v{lo}.

\end{itemize}

\sec{see also}{SEE ALSO}

\sibref{uruk-rc}{uruk-rc(5)}, \sibref{uruk-save}{uruk-save(8)}. The Uruk homepage is at
\httpref{http://mdcc.cx/uruk/} .

\par{
\bf{iptables(8)}, \bf{iptables-save(8)},
\bf{iptables-restore(8)},
\bf{ip6tables(8)}, \bf{ip6tables-save(8)},
\bf{ip6tables-restore(8)}, \httpref{http://www.netfilter.org/}
\: (no manpage online :( )

} \par{
\bf{interfaces(5)}, \httpref{http://packages.debian.org/ifupdown}.
}

\sec{copyright}{COPYRIGHT}

Copyright (C) 2003 Stichting LogReport Foundation logreport@logreport.org;
Copyright (C) 2003, 2004 Tilburg University http://www.uvt.nl/;
Copyright (C) 2003-2013 \"man::author"

\gplheader

\sec{author}{AUTHOR}

\"man::author"

\end{pud::man}