How To Add Two-Factor Authentication To phpBB
This document describes how to add WiKID two-factor authentication to phpBB through Apache using mod_auth_xradius. Given the recent attack against phpBB and the exposure of it's users' passwords, we thought two-factor authentication might be timely.
Our configuration was as follows:
- Fedora Core 10
- Apache 2.2.2-10
- mod_auth_xradius. We recommend using mod_auth_xradius rather than mod_auth_radius. Documentation for mod_auth_xradius can be found in the README file and here.
- For two-factor authentication, we were using WiKID, in this case, the commercial version.
- We used the most recent version of phpBB available, 3.0.4.
Here's how it will work, when the user clicks on a two-factor protected link, they will be prompted for a username and password. The user generates the one-time passcode on their WiKID token and enters it into the password prompt. Apache will route the username and one-time password to the WiKID server via mod_auth_xradius. If the username and one-time password match what WiKID expects, the server will tell Apache to grant access. First, we add Apache to the WiKID Strong Authentication Server as a network client, then add radius to Apache. I assume you already have a WiKID domain and users setup.
So, start by adding a new Radius network client to the WiKID server for your web server:
- Log into WiKID server web interface (http://yourwikidserver/WiKIDAdim).
- Select Network Clients tab.
- Click on Create New Network Client.
- Fill in the requested information.
- For the IP Address, use the web server IP address
- For Protocol, select Radius
- Hit the Add button, and on the next page, enter a shared secret
- Do not enter anything into the Return Attribute box
- From the terminal or via ssh, run 'stop' and then 'start' to load the network client into the built-in WiKID radius server
That is it for the WiKID server.
Now to get Apache ready for two-factor authentication. We need to get and install mod_auth_xradius for Apache 2.x. First, we need to install httpd-devel so we can compile mod_auth_xradius:
# yum install httpd-devel
# wget http://www.outoforder.cc/downloads/mod_auth_xradius/mod_auth_xradius-0.4.6.tar.bz2
# bunzip2 mod_auth_xradius-0.4.6.tar.bz2
# tar -xvf mod_auth_xradius-0.4.6.tar
# cd mod_auth_xradius-0.4.6
# ./configure --with-apxs=/sbin/apxs
# make install
Be sure to check the location of apxs.
Now you need to add two more things to your httpd.conf. First add
# using mod_auth_xradius: LoadModule auth_xradius_module modules/mod_auth_xradius.so AuthXRadiusCache dbm conf/authxcache AuthXRadiusCacheTimeout 60
Check out the xradius docs for other options. It is important to cache the authentication results. If you don't, every http request will generate an authentication request every attempt to validate the one-time passcode except the first attempt will fail.
<directory "/phpBB3"> AuthType Basic AuthBasicProvider xradius AuthName "Please enter your username and WiKID one-time passcode for entry to this site." AuthXRadiusAddServer "wikid_server_address:1812" "wikidserver_shared_secret" AuthXRadiusTimeout 7 AuthXRadiusRetries 2 require valid-user </directory>
You will want to change wikid_server_address to the IP address of the WiKID server and wikidserver_shared_secret to the shared secret you configured above in the WiKID server.
There are limits to this setup. The main one being that phpBB apache authentication assumes the uses are already in the mysql database so the usersnames have to be the same in phpBB and in WiKID. A more robust integration using the WiKID PHP wAuth network client API could solve this issue. Additionally, using the PHP wAuth network client API or mod_ldap would allow for a completely open-source solution.