The tools required is FreeRadius, Google Authenticator PAM, AD.
Installing FreeRADIUS and Google Authenticator PAM
While there are several RADIUS software out there, FreeRADIUS is one of the most popular RADIUS software of choice in Linux. Since it has PAM library, this is also perfect for integrating it with Google Authenticator PAM.
Installing FreeRADIUS and Google Authenticator on Alma Linux/CentOS/Redhat is very easy. All we need is to issue one line command. I added NTP package here since my Google Authenticator configuration is TOTP based. If one went through the installation properly, there might not be a need for this so long as the system is syncing to the time correctly.
In Alma Linux/CentOS/Redhat:
$ sudo dnf install freeradius freeradius-utils google-authenticator -y
$ sudo apt-get install freeradius libpam-google-authenticator -y
Configuring FreeRADIUS
sudo chkconfig radiusd on
After the package installation, the next step is to set up FreeRADIUS by editing configuration files. There are four config files we need to edit to complete this setup. By no means, one needs to follow the order.
First config file
The first config file that we need to edit is the /etc/freeradius/radiusd.conf
file. There are two ways in configuring this and it seems that the most popular option is the one with FreeRADIUS running as root. For some people, this is not acceptable so I included instructions below where we’ll leave it as the default configuration.
OPTION 1 – RUN AS ROOT
According to my limited research, the need to change the user and group to root is because of how both FreeRADIUS and Google Authenticator PAM works. My observation seems to indicate that FreeRADIUS will also need to access the secret key (.google_authenticator
) in each user’s home directory – I could be totally wrong with this. My Linux boxes have encrypted home directories so only the owner and root can access these. That said, letting FreeRADIUS run as root will have access to the necessary files.
$ sudo vi /etc/freeradius/radiusd.conf
We’ll now need to find the lines user = and group =. The default configuration is set to freerad. Change both of them to root.
user = root
group = root
OPTION 2 – USE DEFAULT CONFIGURATION
As mentioned, we can just leave the file as default. I will explain more about this once we get to the section where we need to edit the /etc/pam.d/radiusd
file.
Second config file
The the next config file that we need to edit is the /etc/freeradius/users
file. This file will instruct FreeRADIUS to use PAM libraries to authenticate users as the default.
$ sudo vi /etc/freeradius/users
Add the lines found below. I usually like to add lines at the end of the file. Add the line after all the commented text of the file, just before the DEFAULT Framed Protocol == PPP
line. This will ensure that this line will take precedence. I found out the hard way when I was troubleshooting an issue with L2TP over IPsec authentication.
# Instruct FreeRADIUS to use PAM to authenticate users
DEFAULT Auth-Type := PAM
Third config file
The second to the last config file on our list to be edited is the /etc/freeradius/sites-enabled/default
file. This file tells FreeRADIUS to enable PAM authentication. We just need to edit one line here.
$ sudo vi /etc/freeradius/sites-enabled/default
Once the file is open, look for the following lines:
# Pluggable Authentication Modules.
# pam
We now need to uncomment the pam line to enable it. It should look like this now:
# Pluggable Authentication Modules.
pam
Fourth config file
Finally, the last FreeRADIUS config file that we need to change is the /etc/freeradius/clients.conf
. This is where we can set up our secret key that is used by the clients to connect to the RADIUS server. Please change the default secret key to random alphanumeric characters. Use a key generator to generate the secret to make things life a little easier. For demo purposes, I will be using the default secret. To change the secret, look for secret = testing123
line.
$ sudo vi /etc/freeradius/clients.conf
<-- Output omitted for brevity -->
secret = my_super_awesome_strong_secret
client rtr {
ipaddr = 192.168.200.1
secret = my_super_awesome_strong_secret
}
As usual in Linux, when a configuration file has been changed, then the service needs to be restarted for the changes to take effect. To restart FreeRADIUS daemon, issue the sudo service freeradius restart command.
Configuring FreeRADIUS PAM
Since we instructed FreeRADIUS to use PAM to authenticate users, we need to configure the /etc/pam.d/radiusd
file and instruct it to integrate Google Authenticator PAM. By default, the file will look something like this:
<-- Output omitted for brevity -->
@include common-auth
@include common-account
@include common-password
@include common-session
Option 1
If you picked the first option in the FreeRADIUS configuration section, then you need to comment those four lines above and add two lines. The file should look like this:
#@include common-auth
#@include common-account
#@include common-password
#@include common-session
auth requisite pam_google_authenticator.so forward_pass
auth required pam_unix.so use_first_pass
Option 2
If you left the /etc/freeradius/radiusd.conf
file alone, then it becomes a little bit more complicated setup. Also, you will notice that my instructions are what I will consider a workaround to AppArmor (I am guessing this is the real issue). You will see why later in the next section, after the generating Google Authenticator secret key. Anyway, the /etc/pam.d/radiusd
file should look like this:
#@include common-auth
#@include common-account
#@include common-password
#@include common-session
auth requisite pam_google_authenticator.so forward_pass secret=/etc/freeradius/${USER}/.google_authenticator user=freerad
auth required pam_unix.so use_first_pass
Google Authenticator Secret Key
I’ve already covered the generation of the secret key in my previous post, so look for the generating Google Authenticator secret key section. Once you are done generating secret keys, come back to this page. If you picked the first option throughout this tutorial, then skip this section and go to the verification section.
If you picked the second option, then we’ll need to do additional steps to make this work. Again, you do not have to follow the order in which they are listed here.
We first need to create a directory equal to the user account that we’re working on. In this scenario, we’ll use user account named test.
$ sudo mkdir /etc/freeradius/test
Then, we need to change the owner of the directory that we just created.
$ sudo chown freerad:freerad /etc/freeradius/test
The second to the last step is to copy the secret key to the directory that we just created.
$ sudo cp .google_authenticator /etc/freeradius/test/.google_authenticator
Finally, we need to change the owner of the file.
$ sudo chown freerad:freerad /etc/freeradius/test/.google_authenticator
If I ever learn more about AppArmor, then I will update this blog post because I think this is the real issue why it’s failing. I did try creating an AppArmor profile, but testing shows that I was still failing. When I looked at the /var/log/auth.log
file, I saw an error message that looked like this:
Oct 10 21:24:53 radius radiusd(pam_google_authenticator)[18433]: Failed to update secret file "/etc/freeradius/test/.google_authenticator"
Verification
We now need to test to make sure that we can successfully authenticate. FreeRADIUS software package includes a simple tool that we can use to directly query the daemon with requests. The command format is radtest test <password+google authenticator token> localhost 18120 <RADIUS secret key>
. The password and Google Authenticator token should not have space in between. Below shows the syntax that I used to test my configuration and the test result.
$ radtest test testing1234803732 localhost 18120 testing123
Sending Access-Request of id 79 to 127.0.0.1 port 1812
User-Name = "test"
User-Password = "testing1234803732"
NAS-IP-Address = 127.0.1.1
NAS-Port = 18120
Message-Authenticator = 0x00000000000000000000000000000000
rad_recv: Access-Accept packet from host 127.0.0.1 port 1812, id=79, length=20
FortiGate config
On the Fortigate, we need to configure the VPN authentication using RADIUS server:
User&Authentication
RADIUS Servers:
Create a Server with below config:
Primary Server:
IP: IP_of_FREERADIUS
Secret: create one here same as Fourth config
User Groups:
Create a User Group with below config:
Type: Firewall
Remote Groups: +Add, select RADIUS server created above.
VPN:
IPSec:
When you create a IPsec VPN tunnels: in the XAUTH:
Type: Auto Server
User Group: Choose, select the group you created above.
SSL VPN:
Authentication/Portal Mapping: Users/Groups click + select the User group above.
Ref:
https://github.com/rharmonson/richtech/wiki/CentOS-7-Minimal-&-Two-factor-Authentication-using-FreeRADIUS-3,-SSSD-1.12,-&-Google-Authenticator