UniFi

Total Time Required

20 minutes

Difficulty

Easy

Required Knowledge

Crowdsec, UniFi

Drawing

Prerequisites

This stack monitors...

... 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

  1. Untick "Admin Permissions"

  2. 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 management

    OTHER ROLES

    None

  3. Save your username and password to your text editor

  4. Click on Create

We are randomly generating the username and password as this account has full write access (although only in LAN) to your UniFi controller - you do not want to use simple credentials for this level of access

Forward Logs

  1. Set Syslog to SIEM server or external

  2. Set the server address to the IP of the machine that will run this stack

  3. Click on Apply Changes

Enable Firewall zones

  1. Enable Firewall zones

Deploy Compose stack

Fill out the below env file and deploy your stack

https://github.com/trentnbauer/HomelabPublic/blob/main/docker-compose/crowdsec-unifi.yml

Host Firewall

  1. SSH into your host

  2. 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

  1. Exec into the Crowdsec engine container

  2. Run the below command

  3. Restart the engine and blocklist containers

  4. Check the engine container logs, you should see something similar to the below

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

  1. 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

  1. Locate the UniFi in the enrollment list

  2. Enrol the engine

  3. Wait 5 minutes

Check UniFi firewall rules exit

  1. 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.

  1. Stop the Crowdsec UniFi stack

  2. Click on Manage, and tick all of the CS- rules

  3. Click on Delete and then proceed

  4. Browse to https://unifi/network/default/settings/networks and scroll down to lists

  5. Click on Manage, and tick all of the CS- rules

  6. Click 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

  1. Update the compose env file variable MAX_DECISION - you will need to reduce the number

  2. Restart the stack and see how you go

The env file is set to 4000, which I believe is much lower than the cap - IF you have issues, I would suggest halving this and seeing how it goes. You can slowly increase it once its happy.

Last updated