![[Alcatel logo]](/local-icons/alcatel.gif)
Installing BIND version 9 in a
chroot jail
revised 28-Jul-2005
DNS provides the core service of name to IP address mapping. It is
used throughout the Internet for translating human understood names
into the hardware routeable IP addresses. BIND (the Berkeley Internet
Name Daemon) is the most ubiquitous implimentaion of DNS. Over the
past years BIND has undergone many updates and has had it's share
of security problems. This trend is not expected to change in the
near future. So, extra security precautions are needed on the DNS
(BIND) servers that are directly exposed to the Internet.
In an effort to reduce the risk and contain the damage caused by,
as yet, unknown or undiscovered bugs in BIND, we can quarentine the
exececution environment into a chroot jail. A program that is started
using the chroot command is started with the filesystem root specified
on the command line. This will isolate the execution of that process
(and all subprocesses) to that directory and below. While it is
theoretically possible to break out of this sort of jail, it
is not part of the script-kiddie arsenal (yet); therefore,
this method provides a form of apriori bug protection
(if you will). Additionally we will take advantage of BINDs capibility
to run suid as a non-privilidged user.
This procedure covers creation of a chroot jail for the Solaris 7 OS.
(The addendum at the bottom of this document covers
the specifics for Debian Linux.)
To start off we need to decide where to house the jails for various
executables. (I am taking the generic approach in that there may be other
programs that could use this method for additional security.) I have
adopted /opt/jails as the base directory. In this case we'll put
BIND in /opt/jails/bind. Note: this procedure is only used to
protect BIND instances on external DNS servers.
- System File Preparation
- Create a psuedo-user called bind with the UID of 51000
in /etc/passwd and /etc/shadow.
(use /bin/false as the login shell)
- Create a group called bind with the GID of 51000 in
/etc/group
- mkdir /opt/jails
- chown root:other /opt/jails
- chmod 700 /opt/jails
- mkdir /opt/jails/etc
- chown root:other /opt/jails/etc
- chmod 700 /opt/jails/etc
- Create the BIND jail
- mkdir /opt/jails/bind
- chown bind:bind /opt/jails/bind
- chmod 755 /opt/jails/bind
- cd /opt/jails/bind
- mkdir bin dev etc opt tmp usr var
- chown root:other bin dev etc opt tmp usr var
- chmod 755 bin dev etc opt usr var
- chmod 777 tmp
- chmod o+s tmp
- mkdir opt/named usr/lib var/adm var/tmp
- chown bind:bind opt/named var/adm
- chmod 750 opt/named
- chown root:other usr/lib var/tmp
- chmod 755 usr/lib
- chmod 770 var/adm
- chmod 777 var/tmp
- chmod o+s var/tmp
- Fill in OS required portion of the BIND jail
- Setup bin directory
- cd /opt/jails/bind/bin
- cp /bin/sh .
- cp /bin/false .
- chown bin:bin sh false
- chmod 555 sh false
- Create the needed devices
- cd /opt/jails/bind/dev
- mknod conslog c 21 0
- mknod log c 21 5
- mknod null c 13 2
- mknod syscon c 0 0
- mknod zero c 13 12
- chmod 666 conslog null zero
- chmod 640 log
- chmod 620 syscon
- chown root:other log null zero
- chown root:sys conslog
- chown root:tty syscon
- Setup system configuration files
- cd /opt/jails/bind/etc
- cp /etc/group .
- remove all entries except root other bin
sys tty and bind
- cp /etc/hosts .
- cp /etc/nsswitch.conf .
- cp /etc/resolv.conf .
- cp /etc/passwd .
- remove all entries except root sys bind
- cp /etc/shadow .
- remove all entries except root sys bind
- lock all entries with the *LK* passwd string
- set the ageing info to 6445 for all entries
- chmod 444 group hosts nsswitch.conf passwd resolv.conf
- chmod 400 shadow
- chown root:sys group hosts nsswitch.conf
- chown root:other passwd resolv.conf shadow
- Copy the needed libraries
- cd /opt/jails/bind/usr/lib
- cp /usr/lib/ld.so.1 .
- cp /usr/lib/libc.so.1 .
- cp /usr/lib/libdl.so.1 .
- cp /usr/lib/libl.so.1 .
- cp /usr/lib/libmp.so.1 .
- cp /usr/lib/libmp.so.2 .
- cp /usr/lib/libnsl.so.1 .
- cp /usr/lib/libpthread.so.1 .
- cp /usr/lib/libsocket.so.1 .
- cp /usr/lib/libthread.so.1 .
- cp /usr/lib/nss_files.so.1 .
- chmod 755 *
- chown bin:bin l*
- Install the following BIND9 executables from omni. If you
have installed the ISCbind9 package (which you should have by now,
29-Jul-2005), then simply move (or copy) the whole
/opt/ISCbind9 directory into the .../opt directory of
the jail area.
- /usr/local/bind-9.1.0/bin/named/named to /opt/jails/bind/bin
- /usr/local/bind-9.1.0/bin/check/named-checkconf to /opt/jails/bind/bin
- /usr/local/bind-9.1.0/bin/check/named-checkzone to /opt/jails/bind/bin
- /usr/local/bind-9.1.0/contrib/chroot/S73bind to /opt/jails/bind/etc
- Strip the symbol tables off
- strip /opt/jails/bind/bin/named
- strip /opt/jails/bind/bin/named-checkconf
- strip /opt/jails/bind/bin/named-checkzone
- Install the zone data and config files into
/opt/jails/bind/opt/named - Note: this will describe the
general file layout and intent, but note the specifics of
how to create the zone data.
(see http:/// for configuration info)
- Create a symlink to the real configuration file, so BIND will
start....
- cd /opt/jails/bind/etc
- ln -s ../opt/named/named.conf named.conf
- The following directory structure will be used to house the
zone data and configuration files:
- conf - holds the include files for named.conf
- in-addr - holds the reverse DNS zone data files
- legacy - holds the legacy zone data, such as xylan.com
- master - holds the master zone data, such as ind, localhost
- slave - holds the secondary data, this comes from a primary server
- vanity - holds the vanity zone data, such as omnipcx.com
- mkdir conf
- mkdir in-addr
- mkdir legacy
- mkdir master
- mkdir slave
- mkdir vanity
- The generic named.conf file will hold configuration data that
is common across all zones that are served. While spcefic zone
configuration data will be held in include files that are
located in the conf directory. The naming convetion for the
include files is conf.DIR-NAME. Where DIR-NAME
is one of in-addr, legacy, master, or vanity. The common
common configuration shall include:
- ACLs to define internal hosts, DMZ hosts, classes of
nameservers.
- An ACL that describs the 'bogon' networks. I.E. those
IP blocks that are NOT valid in Internet space.
- recursion shall be disabled
- version data shall be forged to avoid divulging real BIND
version
- glue record fetching shall be disabled
- zone transfers shall be restricted to properly delegated
nameservers
- the 'bogon' networks shall be blackholed
- logging channels shall be enabled for both security and
lame-servers that report back to the syslog host
- Configure startup scripts
- Comment out the bind startup lines in /etc/init.d/inetsvc
- cp /opt/jails/etc/S73bind /etc/rc2.d
- Test BIND
- Post-install
- Ensure that chroot area is maintained at the current
revision levels for security patches that affect the
usr/lib and bin files.
- Maintain BIND executables as required.
 
Addendum 1 - Chroot jail for Debian Linux
The creation of the jail area is very similar in the Linux
environment. These directions are based on a Debian Sarge install
with the Bind-9.3.1-2 package. Several assumptions are made here:
the package automatically creates the bind user and group, the /opt
directory resides on a seperate filesystem. Note: we really should
use the Debian jailer package to automate the creation and maintainance
of the Bind jail, the process of updating the jail after package
upgrades is handled very nicely by the updatejail
utility. See the reference jailer configuration file:
jailer.conf.
The following lists the Debian packages used at the time this
document was updated (28-Jul-2005).
- libssl0.9.7 (0.9.7g-1)
- openssl (0.9.7g-1)
Note: when the Debian bind package is installed, the bind user and
group is created using adduser(). This will use 'the next higest'
unused system UID/GID, which will vary from machine to machine. This
is undesireable. You must change the UID and GID to 51000
and change the owner and group for the /etc/bind,
/var/cache/bind and /var/run/bind
directories (and files within). You must do this prior to
running the jailer tool.
The detailed steps are as follows:
- Create the basic jail structure
- mkdir -p /opt/jails/bind
- chown bind:bind /opt/jails/bind
- chmod 755 /opt/jails/bind
- cd /opt/jails/bind
- mkdir /opt/jails/bind/dev
- mkdir /opt/jails/bind/lib
- mkdir /opt/jails/bind/etc
- mknod /opt/jails/bind/dev/null c 1 3
- chown 0:0 /opt/jails/bind/dev/null
- chmod 666 /opt/jails/bind/dev/null
- mknod /opt/jails/bind/dev/random c 1 8
- chown 0:0 /opt/jails/bind/dev/random
- chmod 666 /opt/jails/bind/dev/random
- mkdir -p /opt/jails/bind/opt/bind
- mkdir -p /opt/jails/bind/usr/sbin
- mkdir -p /opt/jails/bind/usr/lib
- mkdir -p /opt/jails/bind/var/run/bind
- mkdir -p usr/share/zoneinfo/US
- cp -p /usr/share/zoneinfo/US/Pacific /opt/jails/bind/usr/share/zoneinfo/US
- ln -s /usr/share/zoneinfo/US/Pacific /opt/jails/bind/etc/localtime
- cp -p /etc/nsswitch.conf /opt/jails/bind/etc
- chmod 444 /opt/jails/bind/etc/nsswitch.conf
- cp -p /etc/ld.so.c* /opt/jails/bind/etc
- chattr +i /opt/jails/bind/etc/nsswitch.conf
- chattr +i /opt/jails/bind/usr/share/zoneinfo/US/Pacific
- cp /lib/libnsl.so.1 /opt/jails/bind/lib
- cp /lib/libpthread.so.0 /opt/jails/bind/lib
- cp /lib/libc.so.6 /opt/jails/bind/lib
- cp /lib/libdl.so.2 /opt/jails/bind/lib
- cp /lib/ld-linux.so.2 /opt/jails/bind/lib
- cp /lib/libnss_compat.so.2 /opt/jails/bind/lib
- cp /lib/libnss_db.so.2 /opt/jails/bind/lib
- cp /lib/libnss_dns.so.2 /opt/jails/bind/lib
- cp /lib/libnss_files.so.2 /opt/jails/bind/lib
- cp /lib/libnss_hesiod.so.2 /opt/jails/bind/lib
- cp /lib/libnss_nis.so.2 /opt/jails/bind/lib
- cp /lib/libnss_nisplus.so.2 /opt/jails/bind/lib
- chmod -w /opt/jails/bind/lib/*
- chattr +i /opt/jails/bind/lib/*
- mkdir -p /opt/jails/bind/var/log
- touch /opt/jails/bind/var/log/messages
- touch /opt/jails/bind/var/log/syslog
- chown bind:bind /opt/jails/bind/var/log/*
- chmod 664 /opt/jails/bind/var/log/*
- cp -p /etc/resolv.conf /opt/jails/bind/etc
- chmod 444 /opt/jails/bind/etc/resolv.conf
- chattr +i /opt/jails/bind/etc/resolv.conf
- Configure basic authentication mechanisms
You need to remove most of the entries from these files.
Specifically leave root, daemon, bin, sys, and bind in
passwd/shadow and leave wheel, root, daemon, tty,
and bind in group/gshadow
- cp -p /etc/passwd /opt/jails/bind/etc/passwd
- cp -p /etc/shadow /opt/jails/bind/etc/shadow
- cp -p /etc/group /opt/jails/bind/etc/group
- cp -p /etc/gshadow /opt/jails/bind/etc/gshadow
- chmod 400 /opt/jails/bind/etc/shadow
- chmod 400 /opt/jails/bind/etc/gshadow
- chmod 444 /opt/jails/bind/etc/passwd /opt/jails/bind/etc/group
- chattr +i /opt/jails/bind/etc/passwd
- chattr +i /opt/jails/bind/etc/group
- chattr +i /opt/jails/bind/etc/*shadow
- Add bind and support executables (libs also...)
- cp /usr/sbin/named /opt/jails/bind/usr/sbin
- cp /usr/sbin/lwresd /opt/jails/bind/usr/sbin
- chmod -w /opt/jails/bind/usr/sbin/*
- chattr +i /opt/jails/bind/usr/sbin/*
- mkdir -p /opt/jails/bind/usr/lib/i686/cmov
- cp -p /usr/lib/i686/cmov/lib* /opt/jails/bind/usr/lib/i686/cmov
- cp /usr/lib/liblwres.so.1 /opt/jails/bind/usr/lib
- cp /usr/lib/libdns.so.20 /opt/jails/bind/usr/lib
- cp /usr/lib/libbind9.so.0 /opt/jails/bind/usr/lib
- cp /usr/lib/libisccfg.so.1 /opt/jails/bind/usr/lib
- cp /usr/lib/libisccc.so.0 /opt/jails/bind/usr/lib
- cp /usr/lib/libisc.so.9 /opt/jails/bind/usr/lib
- chmod -R -w /opt/jails/bind/usr/lib
- chattr +i /opt/jails/bind/usr/lib/*
- chattr +i /opt/jails/bind/usr/lib/i686/cmov/*
- chown root:other bin dev etc opt tmp usr var
- chmod 755 bin dev etc opt usr var
- chmod 777 tmp
- chmod o+s tmp
- mkdir /opt/jails/bind/opt/named
- chown bind:bind /opt/jails/bind/opt/named
- chmod 750 /opt/jails/bind/opt/named
-
Configure the zone data and startup
- cp -pr /etc/bind /opt/jails/bind/opt/bind
- modify /etc/default/bind9 to include
the chroot, chdir, and configuration file paramters.
- modify /etc/init.d/bind9 for correct
chroot operation
 
References
- Secure BIND template by Rob Thomas
- chroot Jail for BIND on Solaris 7 by Rob Thomas
- chroot-BIND HOWTO by Scott Wunsch
- Run ISC BIND/DNS in a chroot jail