\: 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-rc} {html_title}{Uruk rc file} {section}{5} \man_share } \${html}{\"pud::man::maketoc"} \sec{name}{NAME} \NAME{uruk-rc}{uruk resource file, defining access policy} \sec{synopsis}{SYNOPSIS} \par{\tt{\rcpath}} \sec{description}{DESCRIPTION} \rc is a shell script snippet, sourced in \uruk by /bin/sh. \par{\rc lists IP addresses, allowed to use services.} \sec{examples}{EXAMPLES} \cpar{default}{ The simplest valid \rc file is the empty file. This \rc file blocks all TCP and UDP connection attempts to services on our host: this is the default behaviour. } \cpar{simplest}{ The simplest \rc file which does allow traffic to our services looks like e.g.: \verbatim{\ interfaces=eth0 ips_eth0=default ip_eth0_default=192.168.26.27 net_eth0_default=192.168.0.0/16 ip6_eth0_default=2001:db8::1/64 net6_eth0_default=2001:db8::/32 services_eth0_default_tcp=local ports_eth0_default_tcp_local="0:65535" sources_eth0_default_tcp_local="0.0.0.0/0 ::/0" services_eth0_default_udp=local ports_eth0_default_udp_local="0:65535" sources_eth0_default_udp_local="0.0.0.0/0"} This \rc file allows all IPv4 and IPv6 UDP and TCP traffic from publicly routable IPs to eth0's IP. } \cpar{realistic}{ If you'd like to block traffic on wlan0 and allow traffic to ssh on your wired interface, and don't like to explicitly set your IPs in \rc: } \verbatim{\ # list of interfaces you'd like uruk to protect interfaces=eth0 wlan0 # set variables ip{,6}_eth0_default and net{,6}_eth0_default . /lib/uruk/init/autodetect-ips # names for eth0's 2 IPv4 addresses ips_eth0="default dhcp" # allow access to our sshd on eth0's primary IP on tcp port 443 # from anywhere services_eth0_default_tcp=ssh ports_eth0_default_tcp_ssh=443 sources_eth0_default_tcp_ssh="0.0.0.0/0 ::/0" # we get a static IPv4 via dhcp ip_eth0_dhcp=10.0.0.3 net_eth0_dhcp=10./8 services_eth0_dhcp_tcp=http ports_eth0_dhcp_tcp_http=http sources_eth0_dhcp_tcp_http=$net_eth0_dhcp # we leave services_wlan0_default_{tcp,udp} unset: don't allow any # incoming connections on wlan0's default IP } \cpar{autodetect-ips}{ The script autodetect-ips --as used in the previous example-- looks for files /etc/sysconfig/network-scripts/ifcfg-* (commonly found at e.g. Red Hat and Fedora systems) and /etc/network/interfaces (as found at e.g. Debian and Ubuntu systems), and, for each interface \it{nic}, and each found IPv4 and IPv6 address and network, sets variables \v{ip_}\it{nic}\v{_default}, \v{ip6_}\it{nic}\v{_default}, \v{net_}\it{nic}\v{_default} and \v{net6_}\it{nic}\v{_default} . Then it calls ip(8) and adds any other found \it{nic}, \v{ip} and \v{net} triplets (for IPv4 and, for IPv6, only addresses in scope "global"). } \par{ The script autodetect-ips is useful if you'd like to share your \rc file among different hosts. } \cpar{another example}{ For an even more reasonable \rc file, look at the well-commented example \rc file in \ttexpath. } \sec{IPv4 and IPv6}{IPv4 AND IPv6} \par{You can mix IPv4 and IPv6-addresses in sources_*. E.g.:} \verbatim{\ ips_eth0='default private' ip_eth0_default=1.2.3.4 ip6_eth0_default= services_eth0_default_tcp='mail local' sources_eth0_default_tcp_mail='10.0.0.0/24 192.0.32.0/24 192.168.6.26' sources_eth0_default_tcp_local='192.0.32.0/24 svejk.example.com 2001:db8::/32' ports_eth0_default_tcp_mail=smtp ports_eth0_default_tcp_local='ssh ftp'} \par{If svejk.example.com has both an IPv4 PTR record in DNS, as well as an IPv6 PTR record, connection attempts from svejk to the ssh and ftp TCP ports are allowed, via both IPv4 and IPv6.} \par{Uruk used to require variables sources6_* to be set to support ip6tables. Since uruk version 20140319 (The Alfama Release), this is no longer needed; setting sources_* suffices. To be precise, the semantics since uruk version 20140319 is: 1) If both sources_* and sources6_* are defined (even if they're just empty), each is used for its respective address family. (This ensures backwards compatibility.) 2) If sources6_* is undefined, sources_* is used for both v4 and v6. 3) In either case, v4 literals in v6 context and v6 literals in v4 context are silently (!) ignored.} \sec{Hooks}{HOOKS} Uruk offers hooks for inserting your own code between iptables invocations. Examples will show the usefulness of these hooks. \cpar{allowing broadcasts}{ In \rc, there is: \verbatim{\ rc_b=$etcdir/bootp} while the file \tt{bootp} reads \verbatim{\ iptables \-A INPUT \-m state \-\-state NEW \-i eth0 \\ \-\-protocol udp \-\-destination-port bootps \-j ACCEPT } . This enables one to add rules for packets with broadcast addresses in their destination. (Uruk has no support for this in its regular \rc.) } \cpar{allowing non-matching returntraffic}{ In \rc there is: \verbatim{\ rc_d=$etcdir/dns} while the file \tt{dns} reads \verbatim{\ for source in 10.5.0.27 10.56.0.40 do $iptables -A INPUT -i eth0 --protocol udp \\ --source "$source" --source-port domain \\ --destination "$ip_eth0" \\ --destination-port 30000: -j ACCEPT done} This allows one to allow (return)traffic, disregarding the state. (Uruk has no support for this in its regular \rc.) } \cpar{allowing NAT}{ In \rc there is: \verbatim{\ rc_a=${etcdir}/nat} while the file \tt{nat} reads \verbatim{\ $iptables -t nat -A POSTROUTING \\ --out-interface eth0 -j SNAT \\ --to-source $ip_eth0} This allows Network Address Translation. However, beware! Like all extensive use of hooks, this will break the \uruk_save script. If you make sure your active iptables rules are wiped, and invoke \uruk manually to load new rules, you're safe. Using the init script with its default settings is safe too. } \cpar{allowing IPv6 tunneling}{ In \rc there is: \verbatim{\ rc_b=${etcdir}/proto_41} while the file \tt{proto_41} reads \verbatim{\ $iptables -A INPUT -i ppp0 --protocol 41 --destination $ip_ppp0 -j ACCEPT} This allows IP protocol 41, typically used for this kind of tunneling. } \cpar{allowing any traffic on an interface}{ In \rc there is: \verbatim{\ interfaces_unprotect="lo eth2"} This allows any traffic on \tt{eth2} (and on \tt{lo}, the default), including any ICMP packets and packets from any source address. } \cpar{using multiple hooks at one entry point in the main uruk process}{ In case rc_a, rc_b, ... , or rc_i does not have a file as its value, but a directory, all files matching "$rc_x"/*.rc will get sourced. This helps configuration management in complex situations involving lots of uruk configuration files for lots of hosts. } \par{ See the section "THE GORY DETAILS: uruk INTERNALS" in \sibref{uruk}{uruk(8)} (or the \uruk source) to find out which hook (there are hooks rc_a, rc_b, ... , rc_i) to use. } \sec{Network interfaces with multiple IP addresses}{NETWORK INTERFACES WITH MULTIPLE IP ADDRESSES} Uruk supports situations where a network interface has more than one IP address attached. Variables \v{ips_}\it{nic} and \v{bcasts_}\it{nic} are used for this. \par{ If \v{ips_}\it{nic} is set, e.g. like \verbatim{\ ips_eth0="ip0 ip1 ip2"} we assume multiple (three in this example) IPs are assigned to \v{eth0}. If this variable is not set only one IP is supported on \v{eth0}. } \par{ In multiple-IP mode, IP addresses are listed as e.g. \verbatim{\ ip_eth0_ip0="137.56.247.16"} (If you're used to the Linux ifconfig(8) output, you could use the name \v{ip} for \v{eth0}, and \v{ip0} for \v{eth0:0}.) The \it{ports}, \it{services} and \it{sources} variables look like e.g. \verbatim{\ services_eth0_ip2_tcp=local ports_eth0_ip2_tcp_local=smtp sources_eth0_ip2_tcp_local=$localnet} and, similarly, \verbatim{\ net_eth0_ip1=192.168.0.0/16} Furthermore, for dropping broadcast packets, specify e.g. \verbatim{\ bcasts_eth0="ip0 ip2" # yes, possibly a subset of ips_eth0 bcast_eth0_ip0="10.0.0.255" bcast_eth0_ip2="10.0.255.255"} } As an additional feature, if you have multiple IP addresses that all need to get the same rules, you can assign them to a single name: \verbatim{\ ip_eth0_ip0="137.56.247.16 137.56.247.17 137.56.247.18"} \sec{logging and debugging}{LOGGING AND DEBUGGING} Uruk has support for logging network packets, and for debugging the uruk script. \cpar{Logging}{ By default, uruk logs denied packets. This is adjustable using the \it{loglevel} variable. The settings are: \begin{itemize}{ {contiguous}{1} {compact}{1} {type}{mark} } \item "zero": be silent; do not log any packet. \rc file features \v{loglevel=10}. \item "low": log denied packets, which are targeted at one of our IPs. \rc file features \v{loglevel=30}. \item "medium": log denied non-broadcast packets. This is the default: \it{loglevel} is unset or \rc file features \v{loglevel=50}. \item "fascist": log all packets. \rc file features \v{loglevel=90}. \end{itemize} \: \item "zero": be silent; do not log any packet. \it{loglevel} is greater than \: -1 and less than 20. \: \: \item "low": log denied packets, which are targeted at one of our IPs. \: \it{loglevel} is greater than 19 and less than 40. \: \: \item "medium": log denied non-broadcast packets. This is the default: \: \it{loglevel} is unset or \it{loglevel} is set and greater than 39 and less \: than 60. \: \: \item "high": log all denied packets. \: \: \item "fascist": log all packets. \it{loglevel} is greater than 80 and less than 99. \: \: loglevel= 0 < 20 (suggest: 10) zero: be silent \: 20 < 40 (suggest: 30) low: log denied packets, targeted at our IPs (wsl-mode) \: 40 < 60 ( 50) medium: log denied non-broadcasts (default) \: 60 < 80 ( 70) high: log denied packets \: 80 < 99 ( 90) fascist: log all packets } \cpar{Debugging}{ To debug the \uruk script, invoke uruk as \verbatim{\ sh -x /sbin/uruk} this shows what is done, along with executing it. (Like an uruk '-v' option.) } \par{ If you'd rather prefer not to execute, but just watch what would've been done, invoke uruk as \verbatim{\ URUK_IPTABLES='echo iptables' URUK_IP6TABLES='echo ip6tables' uruk} (Like an uruk '-n' option.) If you have this statement set, you can run \uruk under a non-priviliged user account. } \par{ If you'd like to test a new \rc file before installing it, run something like: \verbatim{\ URUK_CONFIG=/path/to/new/uruk/rc/file uruk} } \par{ Of course, all these tweaks can be combined. } \sec{variables}{VARIABLES} The uruk script honors the following variables in \rc files: \begin{itemize}{ {contiguous}{1} {compact}{1} {type}{mark} } \item "version" Uruk version compatibility of this \rc file \item "loglevel" \item "iptables" Full pathname of iptables executable. \item "ip6tables" Full pathname of ip6tables executable. \item "interfaces" List of network interfaces. \end{itemize} More variables are available. For now, you'll have to take a look at the example \rc file in \ttexpath for more details. \sec{environment variables}{ENVIRONMENT VARIABLES} See \sibref{uruk}{uruk(8)} for a list of honored environment variables. \sec{files}{FILES} \tt{\rcpath} \sec{see also}{SEE ALSO} A well-commented example \rc file is in \ttexpath. And see \sibref{uruk}{uruk(8)}, \sibref{uruk-save}{uruk-save(8)}. \sec{copyright}{COPYRIGHT} Copyright (C) 2005, 2007, 2008, 2010, 2011, 2012, 2013 \"man::author" \gplheader \sec{author}{AUTHOR} \"man::author" \end{pud::man}