This HOWTO will cover how to configure chroot()ed BIND under Ubuntu 12.04 Server. We want to chroot() BIND for security reasons - having software operate out of chroot() jails closes an avenue for exploit. I will be configuring a chroot() of /var/chroot/named.
First, install the bind9 and dnsutils packages. The former will provide the BIND software itself, whilst dnsutils provides utilities such as dig and nslookup that can be used to perform queries or troubleshoot your installation:
|
1 2 |
$ sudo -i # apt-get install bind9 dnsutils |
This will give us BIND 9.8.1-P1 at the time of writing this article:
|
1 2 |
# named -v BIND 9.8.1-P1 |
It will also start BIND - so shut it down before proceeding:
|
1 |
# /etc/init.d/bind9 stop |
Modify /etc/default/bind9. This file contains an OPTIONS variable whose contents are passed as options to named when it’s started. Add the -t option - which specifies the path to the chroot() jail:
|
1 2 3 |
# vi /etc/default/bind9 ... OPTIONS="-u bind -t /var/chroot/named" |
Create the appropriate directories for the chroot() tree:
|
1 |
# mkdir -p /var/chroot/named/{dev,etc,var/{cache/bind,run/bind/run}} |
Move the default BIND configuration files to the chroot(), maintaining a symlink to the original location:
|
1 2 |
# mv /etc/bind /var/chroot/named/etc # ln -s /var/chroot/named/etc/bind /etc/bind |
Create the null and random devices under the chroot(), and fix permissions:
|
1 2 3 |
# mknod /var/chroot/named/dev/null c 1 3 # mknod /var/chroot/named/dev/random c 1 8 # chmod 666 /var/chroot/named/dev/* |
Change ownership of the chroot() to the appropriate user and group, in our case bind:bind:
|
1 |
# chown -R bind:bind /var/chroot/named |
libgost.so from openssl-1.0.0 needs to be available under the chroot(), so create a bind mount for it. Add the folllowing to /etc/fstab:
|
1 2 3 |
# vi /etc/fstab ... /usr/lib/x86_64-linux-gnu/openssl-1.0.0/engines /var/chroot/named/usr/lib/x86_64-linux-gnu/openssl-1.0.0/engines none defaults,bind,auto,nodev,noexec,nosuid 0 0 |
Create the mountpoint under the chroot(), and mount:
|
1 2 |
# mkdir -p /var/chroot/named/usr/lib/x86_64-linux-gnu/openssl-1.0.0/engines # mount !$ |
We’ll need to create a syslog socket inside the chroot() so that BIND can find /dev/log where it expects it to be. Create /etc/rsyslog.d/60-bind-chroot.conf as follows:
|
1 2 3 |
# vi /etc/rsyslog.d/60-bind-chroot.conf $AddUnixListenSocket /var/chroot/named/dev/log # /etc/init.d/rsyslog restart |
The final step is to update our AppArmor configuration to allow reads and mmap calls on libgost.so, and reads on the BIND configuration files. Update the local AppArmor configuration as follows:
|
1 2 3 4 |
# vi /etc/apparmor.d/local/usr.sbin.named ... /var/chroot/named/usr/lib/x86_64-linux-gnu/openssl-1.0.0/engines/libgost.so rm, /var/chroot/named/etc/bind/** r, |
Reload the AppArmor profiles:
|
1 |
# /etc/init.d/apparmor reload |
Now, we can start our chroot()ed BIND
|
1 |
# /etc/init.d/bind9 start |
and test:
|
1 2 3 4 5 6 |
# dig +short A www.google.com @localhost 74.125.237.148 74.125.237.144 74.125.237.145 74.125.237.146 74.125.237.147 |