One of my friends had some issues with OpenVPN server using remote RADIUS authentication. So I did some tests and thought it is a good topic to blog!
I am also adding a video tutorial about this (first attempt, so forgive the mistakes!)
For this setup, I am using 2 servers:
- A DigitalOcean Ubuntu instance of $5, which will be the OpenVPN Access Server. Quoting from the website ” OpenVPN Access Server is a full featured secure network tunnelling VPN software solution that integrates OpenVPN server capabilities, enterprise management capabilities, simplified OpenVPN Connect UI, and OpenVPN Client software packages that accommodate Windows, MAC, Linux, Android, and iOS environments”
- A local Ubuntu server on Virtualbox, which will have dalo RADIUS configured. With daloRADIUS you can easily and quickly manage your FreeRADIUS deployment, with an easy to use GUI
Lets start:
On the DigitalOcean Server (from now on we will call this as the VPN server), lets configure OpenVPN Access Server. Its a super simple 3 step process.
- Download the package
sudo wget http://swupdate.openvpn.org/as/openvpn-as-2.0.7-Ubuntu12.amd_64.deb
- Install the package
dpkg -i openvpn-as-2.0.7-Ubuntu12.amd_64.deb
-
During the installation, OpenVPN will create a default admin user called ‘openvpn’. We need to set a password for that.
sudo passwd openvpn
And you are done!
After the installation, you can access the interface as below:
Admin UI: https://YourIpAddress:943/admin
Client UI: https://YourIPAddress:943/
Now lets configure the RADIUS server before we enable the authentication part on VPN server.
On the RADIUS server, follow the steps below:
- Install Free radius and additional libraries, tools etc
aptitude install freeradius freeradius-mysql freeradius-postgresql freeradius-dialupadmin freeradius-utils php5-gd php-pear php-db mysql-server php5-mysql
apt-get install build-essential binutils libssl-dev openssl libmysqlclient-dev
- After this, install PhpMyAdmin
apt-get install phpmyadmin
During the setup process when asked, select Apache2 and click “OK” to complete the setup and on the second screen select “YES” for the question “Configure database for phpmyadmin with dbconfig-common?”, enter MySQL password of your root account and for phpmyadmin. If it installed properly, you will be able to access it from a browser- http://yourserver_ip_address/phpmyadmin
- We need to install few more packages before proceeding with daloRADIUS installation.
apt-get install php-pear php5-gd php-db
- Also needs to install php pear
wget pear.php.net/go-pear.pharphp go-pear.phar
Just press ENTER to accept the default installation options.
- To avoid Apache’s error “Could not reliably determine the server’s fully qualified domain name” lets add one more thing.
vi /etc/apache2/httpd.conf
then add below line:
ServerName localhost *This is only for testing purpose. We need to change it to something that reflects the production environment.
- Restart Apache
apachectl restart
- Do the config test on Apache to make sure everything is ok
apachectl configtest
- Now lets download daloradius software:
wget http://downloads.sourceforge.net/project/daloradius/daloradius/daloradius0.9-9/daloradius-0.9-9.tar.gz
- Extract it
tar zxfv daloradius-0.9-9.tar.gz
- Move it to www directory
mv daloradius-0.9-9 /var/www/
-
Go to that directory cd /var/www/daloradius-0.9-9
- Now create MySQL database for FreeRADIUS which will be used by daloradius too
mysql -u root -p mysq>create database radiusdb; mysql> quit
-
While still inside the /var/www/daloradius-0.9-9/ folder issue the command below..
mysql -u root -p radiusdb < contrib/db/fr2-mysql-daloradius-and-freeradius.sql
- Login to mysql and confirm the database is successfully restored
Now lets configure freeradius
Lets first test freeradius and make sure its working fine.
-
vi /etc/freeradius/users
locate the line containing
#"John Doe" Cleartext-Password := "hello" and uncomment the line
-
Stop the freeradius service daemon. /etc/init.d/freeradius stop
- Stop freeradius and run the freeradius server in debug mode
/etc/init.d/freeradius stop
freeradius -XXX
The output should be something like this:
Sat Jun 27 00:21:35 2015 : Debug: Listening on authentication address * port 1812
Sat Jun 27 00:21:35 2015 : Debug: Listening on accounting address * port 1813
Sat Jun 27 00:21:35 2015 : Debug: Listening on authentication address 127.0.0.1 port 18120 as server inner-tunnel
Sat Jun 27 00:21:35 2015 : Debug: Listening on proxy address * port 1814
Sat Jun 27 00:21:35 2015 : Info: Ready to process requests.
- Press Control-C to stop the freeradius debug mode.
- Now start freeradius:
/etc/init.d/freeradius start
- Just to make sure all works fine, lets test freeradius authentication using a text file
radtest "John Doe" "hello" 127.0.0.1 0 testing123
If your setup is correct, you should be getting below output:
Sending Access-Request of id 244 to 127.0.0.1 port 1812
User-Name = "John Doe"
User-Password = "hello"
NAS-IP-Address = 127.0.1.1
NAS-Port = 0
- Now we need to set it up to use SQL database for authentication instead of the text file.
- Stop freeradius again:
/etc/init.d/freeradius stop
-
vi /etc/freeradius/radiusd.conf
Locate the following line and uncomment it, save and quit
$INCLUDE sql.conf
$INCLUDE sql/mysql/counter.conf
$INCLUDE sqlippool.conf
- Edit another file vi /etc/freeradius/sites-available/defaultlocate the following line under the “authorize” section and uncomment it
# sql
locate the line under the “session” section and uncomment that as well, save and exit the file editing.
# sql
- Now run freeradius again in debug mode
freeradius -XXX
- You should see below output if everything works fine:
Fri Jun 26 23:17:01 2015 : Debug: Listening on accounting address * port 1813
Fri Jun 26 23:17:01 2015 : Debug: Listening on authentication address 127.0.0.1 port 18120 as server inner-tunnel
Fri Jun 26 23:17:01 2015 : Debug: Listening on proxy address * port 1814
Fri Jun 26 23:17:01 2015 : Info: Ready to process requests.
Create Freeradius mysql account
- Login to mysql
mysql -u root -p
- Create user account
mysql> CREATE USER 'raddbuser'@'localhost';
- Set password
mysql> SET PASSWORD FOR 'raddbuser'@'localhost' = PASSWORD('radpass');
- Grant privilleges
mysql> GRANT ALL ON radiusdb.* to 'raddbuser'@'localhost';
- quit
mysql>quit
Update sql account details for Freeradius
- Edit the file /etc/freeradius/sql.conf
- Locate the following line and update the details accordingly
login = "radius"
password = "radpass"
radius_db = "radius"
and change it to…
login = "raddbuser"
password = "radpass"
radius_db = "radiusdb"
- Uncomment the line.
readclients = yes
- save and exit
Configure daloRadius MySQL Account
- Edit the file /var/www/daloradius-0.9-9/library/daloradius.conf.php
vi var/www/daloradius-0.9-9/library/daloradius.conf.php
- locate the lines
$configValues['CONFIG_DB_ENGINE'] = 'mysql';
$configValues['CONFIG_DB_HOST'] = 'localhost';
$configValues['CONFIG_DB_PORT'] = '3306';
$configValues['CONFIG_DB_USER'] = 'root';
$configValues['CONFIG_DB_PASS'] = '';
$configValues['CONFIG_DB_NAME'] = 'radius';
and change the value settings to.
$configValues['CONFIG_DB_ENGINE'] = 'mysql';
$configValues['CONFIG_DB_HOST'] = 'localhost';
$configValues['CONFIG_DB_PORT'] = '3306';
$configValues['CONFIG_DB_USER'] = 'raddbuser';
$configValues['CONFIG_DB_PASS'] = 'radpass';
$configValues[‘CONFIG_DB_NAME’] = ‘radiusdb’;
Save the file and exit..
Tip: Its better to rename the long daloradius name to a simple one.
cd /var/www/
mv daloradius-0.9-9 daloradius