\: 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}