UniFi
Total Time Required
20 minutes
Difficulty
Easy
Required Knowledge
Crowdsec, UniFi
Prerequisites
Crowdsec account
Your UniFi Firewall is on the supported list (may work with unsupported)
This stack monitors...
Syslog data from UniFi controller
Crowdsec blocklists (if subscribed)
Crowdsec whitelists
... And changes
UniFi firewall
UniFi changes
Service account
You will need to generate a service account for the UniFi bouncer to log into and use
Navigate to https://unifi/network/default/admins/
Untick "Admin Permissions"
Create a new user and fill out the below
First name
Crowdsec
Last name
Bouncer
Admin
True
Restrict to local access
True
Username
<randomly generated>
Password
<randomly generated>
Use a predifined role
False
Unifi
Full managemen
OTHER ROLES
None
Save your username and password to your text editor
Click on Create
We are randomly generating the username and password as this account has full write access (although only LAN) to your UniFi controller - you do not want to use simple credentials for this level of access
Forward Logs
Set Syslog to SIEM server or external
Set the server address to the IP of the machine that will run this stack
Click on Apply Changes
Enable Firewall zones
Navigate to https://unifi/network/default/settings/zones
Enable Firewall zones
this will import your existing firewall rules and port forwards to the new Firewall zones, but please test and ensure your critical infrastructure is still working
Deploy Compose stack
Fill out the below env file and deploy your stack
Host Firewall
SSH into your host
Allow your syslog port through the firewall (by default 514)
If you need to change your syslog port, don't forget to update UniFi at Forward Logs and your .env file Deploy Compose stack
Register the blocklist container
Exec into the Crowdsec engine container
Run the below command
This allows the blocklist container to authenticate to the Crowdsec engine. You may need to restart the blocklist and crowdsec engine containers after this
Confirm the bouncer has logged into the account
Navigate to https://unifi/network/default/admins/
Review the list and find Crowdsec Bouncer - the last activity should state "now"
If not, review the bouncer and engine container logs
Enroll the engine
Navigate to https://app.crowdsec.net/security-engines
Locate the UniFi in the enrollment list
Enrol the engine
Wait 5 minutes
Check UniFi firewall rules exit
Navigate to https://unifi/network/default/settings/zones
You will have a stack of "cs-unifi-bouncer" rules
Known Issues
UniFi network appliance crashing
This will show as
Slowness accessing UniFi network software
Alerts for router being offline
Router showing as offline in at
There is a known bug where too many blocked IPs crashes the UniFi network application
You will first need to remove the firewall rules and lists
This is a bit of a nightmare as the network application will crash often while you are doing this.
Click on Manage, and tick all of the
CS-rulesClick on Delete and then proceed
Browse to https://unifi/network/default/settings/networks and scroll down to lists
Click on Manage, and tick all of the
CS-rulesClick on Delete and then proceed
Or follow this: https://github.com/wolffcatskyy/crowdsec-blocklist-import?tab=readme-ov-file#recovery-network-app-crash
Adjust the blocklist limit
Update the compose env file variable
MAX_DECISIONRestart the stack and see how you go
This setting defaults to 8000 - I would suggest halving this and seeing how it goes. You can slowly increase it once its happy.
Last updated