1*1d223a62Smanu Using Racoon with Privilege Separation 2*1d223a62Smanu Tue Mar 25 16:37:09 MDT 2008 3*1d223a62Smanu 4*1d223a62Smanu 5*1d223a62SmanuRacoon can run in a chroot'd environment. When so instructed, it runs as two 6*1d223a62Smanuprocesses, one of which handles a small number of simple requests and runs as 7*1d223a62Smanuroot in the full native filesystem, and another which runs as a less 8*1d223a62Smanuprivileged user in a chroot'd environment and which handles all the other and 9*1d223a62Smanuvery complex business of racoon. 10*1d223a62Smanu 11*1d223a62SmanuBecause racoon does many complex things there are many opportunities for 12*1d223a62Smanucoding errors to lead to compromises and so this separation is important. If 13*1d223a62Smanusomeone breaks into your system using racoon and you have enabled privilege 14*1d223a62Smanuseparation, they will find themselves in a very limited environment and unable 15*1d223a62Smanuto do much damage. They may be able to alter the host's security associations 16*1d223a62Smanuor obtain the private keys stored on that system using file descriptors 17*1d223a62Smanuavailable to the unprivileged instance of racoon, and from there they will be 18*1d223a62Smanuable to alter security associations on other hosts in disruptive or dangerous 19*1d223a62Smanuways if you have generate_policy enabled on those hosts. But that's because 20*1d223a62Smanuin its current form generate_policy is itself dangerous and requires that you 21*1d223a62Smanutrust anyone with the credentials to use it. 22*1d223a62Smanu 23*1d223a62SmanuThey will also be able to execute any scripts you have placed in the scripts 24*1d223a62Smanudirectory, although racoon will prevent them from mis-using the traditional 25*1d223a62Smanuenvironment variables PATH, LD_LIBRARY_PATH, and IFS. But if you have 26*1d223a62Smanuintroduced vulnerabilities into your scripts you may want to re-visit them. 27*1d223a62SmanuThe thing to watch for is blindly trusting the environment variables passed 28*1d223a62Smanuin by racoon - assume they could be set to anything by a malicious entity and 29*1d223a62Smanucheck them for suitability before using them. 30*1d223a62Smanu 31*1d223a62SmanuAll these possibilities are present when privilege separation is not enabled, 32*1d223a62Smanuand they are greatly reduced when it is enabled because the resources 33*1d223a62Smanuavailable to the attacker are less. 34*1d223a62Smanu 35*1d223a62Smanu***** 36*1d223a62Smanu 37*1d223a62SmanuThe basic concept with racoon's privilege separation is that a minimal 38*1d223a62Smanuenvironment containing all the files racoon needs to operate - with the 39*1d223a62Smanuexception of private keys, scripts, and system-wide authentication services - 40*1d223a62Smanuis placed in a stripped-down copy of the original environment. The private 41*1d223a62Smanukeys and scripts are left in the original environment where only the 42*1d223a62Smanuprivileged instance of racoon will have access to them. 43*1d223a62Smanu 44*1d223a62SmanuHere are basic instructions for setting up racoon to run with privilege 45*1d223a62Smanuseparation: 46*1d223a62Smanu 47*1d223a62Smanu 48*1d223a62SmanuFirst, create a user/group for racoon to run under. For example, user:group 49*1d223a62Smanuike:ike. The account should not have a usable password or real home 50*1d223a62Smanudirectory, so copy the general format of another system-services type account 51*1d223a62Smanusuch as 'daemon'. 52*1d223a62Smanu 53*1d223a62SmanuYou already have files in, e.g. /usr/local/etc/racoon - perhaps racoon.conf, a 54*1d223a62Smanucerts directory containing certificates, a scripts directory, and other 55*1d223a62Smanumiscellaneous files such as welcome messages. Perform the following steps: 56*1d223a62Smanu 57*1d223a62Smanucd /usr/local/etc/racoon 58*1d223a62Smanumkdir root 59*1d223a62Smanumv certs root 60*1d223a62Smanumkdir certs 61*1d223a62Smanumv root/certs/*.key certs 62*1d223a62Smanu 63*1d223a62SmanuIf you want to be able to switch back and forth between using and not using 64*1d223a62Smanuprivsep, do this too: 65*1d223a62Smanu 66*1d223a62Smanucd /usr/local/etc/racoon/certs 67*1d223a62Smanufor i in ../root/certs/* 68*1d223a62Smanudo 69*1d223a62Smanu ln -s $i . 70*1d223a62Smanudone 71*1d223a62Smanu 72*1d223a62SmanuNow root/certs contains certificates and certs contains the keys. The idea is 73*1d223a62Smanuthat the public certificates are in the chroot'd area 74*1d223a62Smanu(/usr/local/etc/racoon/root) and the keys are available only to the privileged 75*1d223a62Smanuinstance of racoon. 76*1d223a62Smanu 77*1d223a62SmanuMove any other racoon configuration data into /usr/local/etc/racoon/root, 78*1d223a62Smanuwith the exception of the scripts directory and racoon.conf. 79*1d223a62Smanu 80*1d223a62SmanuAll the files in /usr/local/etc/racoon/root should be owned by root and the 81*1d223a62Smanuike:ike user you created should not have write access to any directories or 82*1d223a62Smanufiles (unless you are using something like 'path backupsa', but you get the 83*1d223a62Smanuidea). 84*1d223a62Smanu 85*1d223a62SmanuCreate the device nodes: 86*1d223a62Smanu 87*1d223a62Smanumkdir root/dev 88*1d223a62Smanu 89*1d223a62SmanuDo whatever your OS requires to populate the new dev directory with a 90*1d223a62Smanuminimal set of devices, e.g. mknod, MAKEDEV, or mount devfs... In freebsd 91*1d223a62Smanuthis is done by adding a line to /etc/fstab: 92*1d223a62Smanu 93*1d223a62Smanudevfs /usr/local/etc/racoon/root/dev devfs rw 0 0 94*1d223a62Smanu 95*1d223a62Smanuand then adding a line like this to /etc/rc.conf: 96*1d223a62Smanu 97*1d223a62Smanudevfs_set_rulesets="/usr/local/etc/racoon/root/dev=devfsrules_basic" 98*1d223a62Smanu 99*1d223a62Smanuand then adding the following lines to /etc/devfs.rules: 100*1d223a62Smanu 101*1d223a62Smanu[devfsrules_basic=10] 102*1d223a62Smanuadd include $devfsrules_hide_all 103*1d223a62Smanuadd include $devfsrules_unhide_basic 104*1d223a62Smanu 105*1d223a62Smanuand then either rebooting or entering "mount -a && /etc/rc.d/devfs start". 106*1d223a62Smanu 107*1d223a62SmanuWhen done with that: 108*1d223a62Smanu 109*1d223a62Smanumkdir -p root/usr/local/etc 110*1d223a62Smanuln -s ../../../ root/usr/local/etc/racoon 111*1d223a62Smanu 112*1d223a62SmanuThis dummy hierarchy keeps the config file consistent between both copies of 113*1d223a62Smanuracoon. Of course, you could actually put the certs directory and any other 114*1d223a62Smanuconfiguration data down in the hierarchy but I prefer to leave it at the root 115*1d223a62Smanuand link to it as shown. You may end up with something like this: 116*1d223a62Smanu 117*1d223a62Smanuroot# ls -FC /usr/local/etc/racoon/root 118*1d223a62Smanucerts/ dev/ usr/ 119*1d223a62Smanu 120*1d223a62Smanuroot# ls -l /usr/local/etc/racoon/root/usr/local/etc 121*1d223a62Smanulrwxr-xr-x 1 root wheel 9 Mar 7 22:13 racoon -> ../../../ 122*1d223a62Smanu 123*1d223a62Smanuroot# ls -FC /usr/local/etc/racoon/root/usr/local/etc/racoon/ 124*1d223a62Smanucerts/ dev/ usr/ 125*1d223a62Smanu 126*1d223a62SmanuPresumably your racoon.conf already contains something like: 127*1d223a62Smanu 128*1d223a62Smanupath certificate "/usr/local/etc/racoon/certs"; 129*1d223a62Smanupath script "/usr/local/etc/racoon/scripts"; 130*1d223a62Smanu 131*1d223a62SmanuIf so, great. If not, add them. Then, finally, add the privsep section: 132*1d223a62Smanu 133*1d223a62Smanuprivsep { 134*1d223a62Smanu user "ike"; 135*1d223a62Smanu group "ike"; 136*1d223a62Smanu chroot "/usr/local/etc/racoon/root"; 137*1d223a62Smanu} 138*1d223a62Smanu 139*1d223a62SmanuApply the patches posted to the list and rebuild racoon (the patches will be 140*1d223a62Smanuincorporated into the release subsequent to the date of this memo, so if you 141*1d223a62Smanuuse that or a later release you can skip this step). 142*1d223a62Smanu 143*1d223a62SmanuRestart racoon and hopefully things will work. As of the date of this memo, 144*1d223a62Smanure-loading the configuration file with racoonctl will not work with privsep 145*1d223a62Smanuenabled. However, the problem is not insurmountable and if you figure it out 146*1d223a62Smanulet us know. 147*1d223a62Smanu 148*1d223a62SmanuI have not tested privsep with many of racoon's features such as XAUTH or 149*1d223a62Smanuscripts, so if you have trouble with them and work anything out please reply 150*1d223a62Smanuto the list so that your discoveries may be incorporated into this document. 151*1d223a62Smanu 152*1d223a62SmanuLast modified: $Date: 2008/03/28 04:18:52 $ 153