In the previous post aws client vpn with multifactor authentication , I introduced how to deploy client vpn in aws using aws managed service. This time I introduce how to do “nearly” the same thing in GCP. However, GCP doesn’t have its own managed client vpn service, and the deployment steps are quite different.
What you can achieve after reading this post
- Basic setup of pfSense in GCP to act as an openvpn server
What is the expected result
- easy user management on pfSense
- Multi-factor authentication client VPN to connect to GCP
- All tunnel (once client is connected to vpn, all traffic passed through GCP, even the internet access)
- Launch pfSense in GCP.
- pfSense basic setup.
- FreeRADIUS installation and setup on pfSense
- Authentication server setup on pfSense
- OpenVPN setup on pfSense
- OpenVPN client exporter install
- Firewall rule to allow OpenVPN
- Add remote user(s)
- Setup client vpn software and test
1. Launch pfSense in GCP
There is no pfSense image available in GCP marketplace. Hence you need to download the image from official site, and create an image in GCP.
Once you created an image, use it to launch an instance. When you create an instance, most of the parameter can be left as default, but be sure to make your network settings as in below image:
In Command line, it would look like this:
$ gcloud compute --project <project_name> disks create "pfsense" --size "20" --zone "us-central1-a" --source-snapshot "pfsense-245p1" --type "pd-standard" $ gcloud beta compute --project=<project_name> instances create pfsense --zone=us-central1-a --machine-type=n1-standard-1 --subnet=default --address=<allocated_global_ip> --can-ip-forward --tags=openvpn-server --disk=name=pfsense,device-name=pfsense,mode=rw,boot=yes,auto-delete=yes
Next, we need to connect to serial interface of this instance to finish pre-configuration settings. Select the pfsense instance, and click “Edit”, then check “Enable connecting to serial ports”. Once checked and saved, you should be able to connect to serial port 1.
You will be asked several questions, select as in below image.
Soon after you will be greeted with pfSense menu. Select 8) Shell, and type
ifconfig vtnet0 mtu 1460, otherwise you will not be able to access web interface, and the connection would be quite unstable.
As a last step, we configure GCP Firewall to allow WEB GUI interface acccess. Go to Firewall and allow tcp/443(https), and udp/1194(openvpn) for the target tags you allocated to pfSense. In command line, it would look like below:
gcloud compute --project=<project_name> firewall-rules create allow-openvpn-server --direction=INGRESS --priority=1000 --network=default --action=ALLOW --rules=tcp:22,udp:119 --source-ranges=0.0.0.0/0 --target-tags=openvpn-server
2. pfSense Basic Setup
Navigate to the pfsense URL at https://<your_external_ip>/, and you should be greeted with pfSense setup wizard.
Once you finished the wizard, now you are in pfsense console!
3. FreeRADIUS installation and setup on pfSense
Go to Paackage Manager, and search “freeradius”. Click “Install” and it will install freeradius along with all dependencies.
Navigate to “Services” > “FreeRADIUS” to open freeradius configuration page.
We have two parts to configure here:
- Interfaces … this is to specify which interface this radius server serves the request. we will create one interface for authentication and another for accounting.
- NAS/Clients … this is to specify how the server receives the authentication request.
First, go to interfaces, and create two interfaces as shown below:
Next, create a cclient as shown in below image, do remember client shared secret, this will be used later.
4. Authentication server setup on pfSense
Next we need to create an authentication settings so that pfSense sends request to radius server upon client connection.
Navigate to “System” > “User management” > “Authentication Server”. Fill in the field as shown below. This shared secret is the one you used to setup radius server:
5. OpenVPN setup on pfSense
Authentication system is ready and we are going to configure VPN server. Navigate to “VPN” > “Open VPN” > “Servers”, and click “+Add”.
Fill in the field as shown in below image:
Most of the parameter can be kept as default, and some parameters you need to change are as below:
- Server mode: Remote Access (User Auth)
- Backend for authentication: <authentication server you created in previous step>
- IPv4 Tunnel Network: ANY network you are not using in your production network
- Redirect IPv4 Gateway … All traffic including internet browsing will be passed through this pfsense once client is connected. This can be useful if client needs to use one static global ip for any other access. If you don’t need this, you can uncheck this, and you can specify which subnet to be injected into the client.
6. OpenVPN client exporter install
Configuring client one by one is tedious task. In pfSense, there is a package called OpenVPN Client exporter, and it can be installed through package manager.
Once installation succeeded, you will see a new tab “client export” in OpenVPN. In “Hostname Resolution” select other, and fill in your global ip address in “Host Name”, then click “Save as default”. Once you saved, click “inline cconfiguration” and it will download the ovpn configuration file.
7. Add Firewall rule to allow OpenVPN
We need to create rules as listed below:
- Firewall rule to allow openvpn connectiion to the firewall from the internet
- Firewall rule to allow openvpn client to connecct to somewhere else
For the first rule, ccrete the firewall as below:
For the second rule, it depends on the usage. I made a extremely egnerous rules here to allow any communication. This means any communication even the one to the internet will also be allowed.
8. Add remote user(s)
Now it’s time to add users. Navigate to “Services” > “FreeRADIUS”, and add users.
- Username … user name of your choice
- Password … <blank>
- One-Time Password … checked
- OTP Auth Method … Google-Authenticator
- Init-Secret … Click “Generate OTP Secret”
- PIN … PIN of your choice
- QR Code … Click Generate QR Code, and ask user to scan this code to register this OTP on their phone.
8. Setup client vpn software and test
One you setup the client with the file you downloaded from the last step, you can use the credentiaal to connecct to VPN. Please note the password is PIN number followed by OTP.
If everything hasa been setup correctly, you should be able to communicte with the internal resources as well as you can connect to the internet through GCP.