3.1 Creating an empty jail
The first step to creating your empty jail is to create a set of directories
to hold your daemon, data files, and libraries. Lets first attack our
Sun RPCBIND example. We've chosen /var/rpcbind
as our jail home. Here's how we'll set up our directory structure:
mkdir /var/rpcbind
mkdir /var/rpcbind/dev
mkdir /var/rpcbind/etc
mkdir /var/rpcbind/tmp
mkdir -p /var/rpcbind/usr/lib
Since this daemon will be chrooted, it wil need access to certain /dev devices,
some datafiles in etc, its own tmp directory, and a library directory. These
will all be filled with appropriate files by the time we're done.
Now onto our Eudora Qpopper example. Since qpopper's jail is going to be built
around our mailspool, the jail will need to start in /var/mail. We need to
go ahead and create our initial directories:
mkdir /var/mail/dev
mkdir /var/mail/etc
mkdir -p /var/mail/usr/lib
mkdir -p /var/mail/usr/local/lib
mkdir -p /var/mail/usr/sbin
mkdir -p /var/mail/usr/share/lib/zoneinfo/US
But we're not done yet. Our popper is expecting the mail to be in /var/mail. When
it's chrooted, the path / is /var/mail...so when it tries to access /var/mail it
will get a file not found! How do we circumvent this problem? We need to symlink
/var/mail/var/mail to /var/mail which is, relatively speaking, / ...
mkdir /var/mail/var
ln -s / /var/mail/var/mail
Now when our chrooted popper goes to access /var/mail, it'll be pointed to /, which is the real
/var/mail!
Our final products should look like:
Sun RPCBIND
drwxr-xr-x 7 root other 512 Aug 1 18:31 ./
drwxr-xr-x 34 root sys 512 Aug 1 18:07 ../
drwxr-xr-x 2 root other 512 Aug 1 18:16 dev/
drwxr-xr-x 2 root other 512 Aug 1 18:10 etc/
drwxr-xr-x 2 root other 512 Aug 1 18:31 tmp/
drwxr-xr-x 6 root other 512 Jul 28 15:55 usr/
drwxr-xr-x 3 root other 512 Aug 1 18:19 var/
Eudora Qpopper
drwxrwxrwt 7 root mail 512 Oct 18 19:36 ./
drwxr-xr-x 34 root sys 512 Aug 1 18:07 ../
drwxr-xr-x 2 root other 512 Jul 29 13:33 dev/
drwxr-xr-x 2 root other 512 Jul 28 16:18 etc/
- Some mailboxes mixed in here -
drwxr-xr-x 6 root other 512 Jul 28 15:55 usr/
drwxr-xr-x 2 root other 512 Aug 1 18:06 var/
3.2 Copying program and data files, configuring cron
Now that our directory structure is set up, lets copy over our program and data files.
Since we're going to be running rpcbind from an init script, it's not necessary to
copy the actual binary over for that. We will, hoever, need to copy the popper
over as it will be run from inetd. If inetd expects the file to be in /usr/sbin,
you will need to create a usr/sbin in your jail (/var/mail/usr/sbin) and copy
the daemon's executable to there. Copy all the /etc files we previously discussed
over and make sure the permissions are identical. For files you will want to update
frequently, create cron jobs to update them. When you're finished, your structure
should look similar to this:
Sun RPCBIND
% ls -l /var/rpcbind/etc
-r--r--r-- 1 root other 90 Jul 28 16:18 hosts
-rw-r--r-- 1 root other 1239 Jul 28 16:09 netconfig
-rw-r--r-- 1 root other 835 Jul 28 15:32 nsswitch.conf
-rw-r--r-- 1 root other 140 Jul 28 16:14 resolv.conf
-r--r--r-- 1 root other 3649 Jul 28 16:14 services
Eudora Qpopper
% ls -l /var/mail/etc
-r--r--r-- 1 root other 90 Jul 28 16:18 hosts
-rw------- 1 root other 73 Oct 18 19:15 hosts.allow
-rw------- 1 root other 9 Jul 28 15:58 hosts.deny
-rw-r--r-- 1 root other 1239 Jul 28 16:09 netconfig
-rw-r--r-- 1 root other 835 Jul 28 15:32 nsswitch.conf
-r--r--r-- 1 root other 815 Oct 18 19:15 passwd
-rw-r--r-- 1 root other 140 Jul 28 16:14 resolv.conf
-r--r--r-- 1 root other 3649 Jul 28 16:14 services
-r-------- 1 root other 502 Oct 18 19:15 shadow
The cron jobs we came up with look like this. Whatever works for you...
0,30 * * * * cp -p /etc/passwd /var/mail/etc/passwd
0,30 * * * * cp -p /etc/shadow /var/mail/etc/shadow
0 0 * * * cp -p /etc/hosts.* /var/mail/etc/
0 0 0 * * cp -p /etc/services /var/rpcbind/etc
0 0 0 * * cp -p /etc/resolv.conf /var/mail/etc
3.6 The Final product
Our final, working projects looks like this:
Sun RPCBIND
d none /var/rpcbind 0755 root other
d none /var/rpcbind/dev 0755 root other
c none /var/rpcbind/dev/conslog 21 0 0666 root other
c none /var/rpcbind/dev/log 21 5 0640 root other
c none /var/rpcbind/dev/msglog 97 1 0600 root other
c none /var/rpcbind/dev/null 13 2 0666 root other
c none /var/rpcbind/dev/udp 41 0 0666 root other
c none /var/rpcbind/dev/tcp 42 0 0666 root other
c none /var/rpcbind/dev/ticlts 105 2 0666 root other
c none /var/rpcbind/dev/ticotsord 105 1 0666 root other
c none /var/rpcbind/dev/ticots 105 0 0666 root other
d none /var/rpcbind/var 0755 root other
d none /var/rpcbind/var/run 0755 root other
d none /var/rpcbind/var/run/rpc_door 1777 root root
d none /var/rpcbind/tmp 0755 root other
d none /var/rpcbind/usr 0755 root other
d none /var/rpcbind/usr/share 0755 root other
d none /var/rpcbind/usr/share/lib 0755 root other
d none /var/rpcbind/usr/share/lib/zoneinfo 0755 root other
d none /var/rpcbind/usr/share/lib/zoneinfo/US 0755 root other
f none /var/rpcbind/usr/share/lib/zoneinfo/US/Eastern 0644 root bin
d none /var/rpcbind/usr/lib 0755 root other
f none /var/rpcbind/usr/lib/ld.so.1 0755 root other
f none /var/rpcbind/usr/lib/libnsl.so.1 0755 root other
f none /var/rpcbind/usr/lib/libsocket.so.1 0755 root other
f none /var/rpcbind/usr/lib/libresolv.so.2 0755 root other
f none /var/rpcbind/usr/lib/libmail.so.1 0755 root other
f none /var/rpcbind/usr/lib/librt.so.1 0755 root other
f none /var/rpcbind/usr/lib/libcrypt_i.so.1 0755 root other
f none /var/rpcbind/usr/lib/libc.so.1 0755 root other
f none /var/rpcbind/usr/lib/libdl.so.1 0755 root other
f none /var/rpcbind/usr/lib/libmp.so.2 0755 root other
f none /var/rpcbind/usr/lib/libaio.so.1 0755 root other
f none /var/rpcbind/usr/lib/libgen.so.1 0755 root other
f none /var/rpcbind/usr/lib/nss_files.so.1 0755 root other
f none /var/rpcbind/usr/lib/nss_nis.so.1 0755 root other
f none /var/rpcbind/usr/lib/libpthread.so.1 0755 root other
f none /var/rpcbind/usr/lib/libthread.so.1 0755 root other
f none /var/rpcbind/usr/lib/nss_dns.so.1 0755 root other
f none /var/rpcbind/usr/lib/straddr.so 0755 root other
d none /var/rpcbind/usr/sbin 0755 root other
f none /var/rpcbind/usr/sbin/rpcbind 0555 root other
d none /var/rpcbind/usr/local 0755 root other
d none /var/rpcbind/usr/local/sbin 0755 root other
d none /var/rpcbind/usr/local/lib 0755 root other
d none /var/rpcbind/etc 0755 root other
f none /var/rpcbind/etc/nsswitch.conf 0644 root other
f none /var/rpcbind/etc/netconfig 0644 root other
f none /var/rpcbind/etc/services 0444 root other
f none /var/rpcbind/etc/resolv.conf 0644 root other
f none /var/rpcbind/etc/hosts 0444 root other
Eudora Qpopper
d none /var/mail 1777 root mail
d none /var/mail/usr 0755 root other
d none /var/mail/usr/share 0755 root other
d none /var/mail/usr/share/lib 0755 root other
d none /var/mail/usr/share/lib/zoneinfo 0755 root other
d none /var/mail/usr/share/lib/zoneinfo/US 0755 root other
f none /var/mail/usr/share/lib/zoneinfo/US/Eastern 0644 root bin
d none /var/mail/usr/lib 0755 root other
f none /var/mail/usr/lib/ld.so.1 0755 root other
f none /var/mail/usr/lib/libnsl.so.1 0755 root other
f none /var/mail/usr/lib/libsocket.so.1 0755 root other
f none /var/mail/usr/lib/libresolv.so.2 0755 root other
f none /var/mail/usr/lib/libmail.so.1 0755 root other
f none /var/mail/usr/lib/librt.so.1 0755 root other
f none /var/mail/usr/lib/libcrypt_i.so.1 0755 root other
f none /var/mail/usr/lib/libc.so.1 0755 root other
f none /var/mail/usr/lib/libdl.so.1 0755 root other
f none /var/mail/usr/lib/libmp.so.2 0755 root other
f none /var/mail/usr/lib/libaio.so.1 0755 root other
f none /var/mail/usr/lib/libgen.so.1 0755 root other
f none /var/mail/usr/lib/nss_files.so.1 0755 root other
f none /var/mail/usr/lib/nss_nis.so.1 0755 root other
f none /var/mail/usr/lib/libpthread.so.1 0755 root other
f none /var/mail/usr/lib/libthread.so.1 0755 root other
f none /var/mail/usr/lib/nss_dns.so.1 0755 root other
d none /var/mail/usr/sbin 0755 root other
f none /var/mail/usr/sbin/in.pop3 0755 root other
d none /var/mail/usr/local/lib 0755 root other
d none /var/mail/etc 0755 root other
f none /var/mail/etc/passwd 0444 root other
f none /var/mail/etc/shadow 0400 root other
f none /var/mail/etc/hosts.allow 0600 root other
f none /var/mail/etc/nsswitch.conf 0644 root other
f none /var/mail/etc/hosts.deny 0600 root other
f none /var/mail/etc/netconfig 0644 root other
f none /var/mail/etc/services 0444 root other
f none /var/mail/etc/resolv.conf 0644 root other
f none /var/mail/etc/hosts 0444 root other
d none /var/mail/var 0755 root other
s none /var/mail/var/mail=/
d none /var/mail/dev 0755 root other
c none /var/mail/dev/udp 41 0 0666 root other
c none /var/mail/dev/null 13 2 0666 root other
c none /var/mail/dev/conslog 21 0 0666 root other
c none /var/mail/dev/log 21 5 0640 root other
c none /var/mail/dev/msglog 97 1 0600 root other
Daemons I've personally chrooted without problems:
- popper
- rpcbind
- named (It's pretty much built-in)
- stunnel
- Apache web server
- nscd
- SecurID Server
- RADIUS
- Squid
- syslogd
Daemons that theoretically should be chrootable, though I haven't tried:
- portmap
- lpd (with slight creativity)
- gated
- routed
- identd
- comsat
- talkd
- tftpd
- sadmind
- Many other processes that should probably just be turned off