Website protection with OPNsense
with the Nginx plugin, OPNsense become a full-featured solid Web Application Firewall (WAF)
The OPNsense security platform can help you protect your network and your webservers with the Nginx plugin.
Installing OPNsense
In the old days, installing an open-source firewall was a tricky task, but today it can be done with a few clicks (or keystrokes). In this article, I’ll not describe the detailed OPNsense installation process, but you can watch this video that was extracted from my OPNsense course available in Udemy. The video is in the Portuguese language, but with the CC Youtube translation feature, you may be able to follow it without problems (if you don’t are a Portuguese speaker, of course) :-)
from my Udemy OPNsense course: check out here !
Depending on the platform you are installing the OPNsense, the steps may vary, following the official installation guide:
Plugin installation
To install the plugin, follow these simple steps:
- Access your OPNsense firewall web GUI: (https://<YOUR_IP>)
2. Go to the Menu: System: Firmware: Plugins
3. Find the os-nginx plugin and click the install option [+]
Initial configuration
Before the configuration, we need to understand some terms:
- Upstream Server: The real webserver that will host the web page/application;
- Upstream: The backend where will be configured the server(s);
- Location: The URL pattern that should have an Upstream configured;
- HTTP Server: The frontend that should have one or more Locations configured;
The configuration will start with the Upstream Server configuration:
To make the initial configuration, go to the Nginx configuration menu:
1. Upstream Server
The server params will depend on your webserver/application and network environment. To better website protection, it’s recommended that you set some limits in Maximum Connections/Failures and in the Fail Timeout.
2. Upstream
In the above example, we are not using TLS in the backend.
The configured Upstream will look like this:
3. Download the NAXSI (WAF) rules
About NAXSI: (extracted from: https://github.com/nbs-system/naxsi)
NAXSI means Nginx Anti XSS & SQL Injection.
Technically, it is a third party nginx module, available as a package for many UNIX-like platforms. This module, by default, reads a small subset of simple (and readable) rules containing 99% of known patterns involved in website vulnerabilities. For example,
<
,|
ordrop
are not supposed to be part of a URI.
Before proceeding with the configuration, we will need to download the Naxsi rules, which will be enabled later in our Location.
Go to the Submenu:
4. Location
Create a new Location:
- Description: Fill with something that makes sense to you;
- URL pattern: To match with your webserver root fill with “/”. To match with another path change it to something like “/anotherpath/”;
- Enable Security Rules: This option enables WAF protection. Combined with the Custom Security Policy you will be able to protect your website from the specified policies (group of rules);
- Learning mode: In this mode, the plugin will not block the requests that match with the selected policies, will only log the requests. It’s a good idea to adjust your own whitelist rule before starting to block requests.
5. HTTP Server
Finally, create your website frontend:
- Server Name: the FQDN name of your website;
- Locations: the Location created in the previous step;
- TLS Certificate / CA Certificate/ Enable Let’s Encrypt Plugin: If you want (you should) enable HTTPS (TLS) in your website, these options need to be configured with your TLS and CA certificate. If you already have a valid one, you can install and configure the Let’s Encrypt Plugin that will create those for you at no cost.
6. OPNsense configuration adjusts
We’ll need to adjust some WebGUI configurations to enable our Nginx service without port conflict problems.
!! Make sure that you have access to your OPNsense from your LAN interface or add the required rules before changing the following configurations !!
Go to the System: Setting: Administration menu
Back to the menu Services: Nginx: Configuration and enable the service:
The final step is to create the required Firewall Rules to allow the HTTP/HTTPS traffic on the desired network interface (probably the WAN).
Conclusion
I tried to cover in this article the basic configuration of this great plugin to the excellent OPNsense security platform to provide some website protection. It’s possible to get advanced protection with this plugin, but it will demand many others articles to explore all possibilities.
Thanks to the OPNsense team and community!
If you need some help with OPNsense, open source security or Cloud Managed Security Services: