Ubiquiti Unifi Cloud Gateway Response Integration

Ubiquiti Unifi Cloud Gateway Response Integration

This article shows how to leverage the Lumu Defender API and the Ubiquiti Unifi Cloud Gateway features to mitigate security risks.


Response integration between Unifi Cloud Gateway and Lumu

Requirements

  • Ubiquiti Unifi Cloud Gateway
    • You need a Ubiquiti Unifi Cloud Gateway with administrative access to the Network application on 9.0.114 version or above.
  • Lumu Defender API key
    • To retrieve an API token, please refer to the Defender API document.
  • Script host.
    • A scripting host is required to deploy the integration. This host must have Internet visibility over Lumu Defender API endpoints and your Ubiquiti Unifi device. According to the deployment model you select, you will need a host with:
      • Python 3.12+
        or
      • A Docker-enabled host.
  • Script package
    • Contact the Lumu support team to request the package we created to deploy the required files.

Contacted hosts

The integration script communicates with the following domains. Please ensure traffic is allowed before deploying the integration:
  • Lumu services
    • defender.lumu.io (HTTPS and WSS traffic)
  • Ubiquiti Unifi Cloud Gateway devices
    • The integration must be able to connect to the Unifi device via HTTPS

Integration overview

The integration uses Unifi Traffic rules to block outbound traffic related to Lumu-detected adversarial contacts. It manages a rule per IOC type, IP addresses, and Domains, updating them based on Lumu-reported detections and updates.

Preliminary Setup - Ubiquiti Unifi Cloud Gateway

To set up the integration, you must prepare your Ubiquiti Unifi Cloud Gateway devices to communicate with the Lumu integration. To do this, you need the following:
  • Create a dedicated integration role for managing the Unifi Network application (optional, but recommended).
  • Create a dedicated integration local user attached to the integration rule (optional, but recommended).
  • Ensure network visibility between the integration host and the Ubiquiti Unifi Cloud gateway devices.
To run these steps, you must access the Network application. You can open it following one of these methods. Select the method of your preference:
  • Log in to the Network application directly on the Unifi device.
If you use the Unifi Site Manager:
1. Open your Web browser and access the Unifi Site Manager. Log in if the Site Manager requests it.
2. In the Site Manager window, look for the site where your Unifi devices are attached to, then, click on the site.


3. Now, you are on the Network application.


If you log in to the Network application directly on the Unifi device, you will be directed to the same screen from the previous step. You can follow the instructions in the next sections from this screen.

Create a dedicated integration role

Notes
We encourage you to create a dedicated integration role with only the required permissions to ensure the least privilege principle in your Unifi devices.
Follow these steps from the Network application dashboard.
1. Head to the left navigation bar and look for the Settings button (the Gear icon). Click on it.

2. Head to the Settings navigation bar on the left. Click on the Admin & Users menu.

3. In the Admins window, click the Manage Roles(1) button next to the search bar. The Manage Roles section will appear on the right side of the Window. Click on the Create New Role(2) menu to create your integration role.

4. Create your integration role by following these guidelines:
a. Enter a distinctive Role Name(1).
b. Select the Permissions(2) for each application. Ensure that the Network application has Full Management selected. The rest of the applications must be set to None.
c. When finished, save your integration role by clicking on the Create button.

Create a dedicated integration user

Notes
We encourage you to create a dedicated integration user with the integration role created above. This will aid you in preserving the least privilege principle and trace all activities performed by the integration.
From the Admins window (check step 2 of the Create a dedicated integration role section), follow these steps to create your dedicated integration user:
1. Click on the Create New Admin button located next to the search bar.

2. Fill in the information in the Create New Admin section on the right side of the window. Follow these guidelines:
a. Type your integration Username(1)
b. Give your integration user a secure Password(2)
c. Ensure the Restrict to Local Access Only(3) toggle is enabled.
d. Enable the Use a Predefined Role(4) toggle and
e. Select the Role(5) you created in the Create a dedicated integration role section.
e. When you are ready, save your integration user by clicking the Create(6) button.

Notes
The integration operates with local users instead of Unifi Accounts.
Notes
Ensure you store your integration user credentials in a safe place. This information will be needed to configure your integration.

Ensure network visibility between the integration host and the Ubiquiti Unifi Cloud gateway devices

Ensure the device you will use to deploy the integration can reach the Ubiquiti Unifi devices you want to integrate. In case you need changes in your network to allow communications between the integration components, contact your network administrator.

Preliminary setup - Lumu portal

The integration set-up process needs you to collect this information from Lumu portal:

  • Lumu Defender API key
  • Company UUID

Log in to your Lumu portal and run the following procedures to collect these data.

Collect the Lumu Defender API key

To collect the Lumu Defender API key, please refer to the Defender API document.

Collect your Lumu company UUID

To collect your Lumu company UUID, log in to your Lumu portal. Once you are in the main window, copy the string below your company name.

Preliminary Setup - Choose your integration environment

There are 2 environment options to deploy the script, select the one that best fits your current infrastructure.
  • Run it as a Python script executing the install.sh bash file
    • Creates a Python virtual run time and its dependencies for you
    • Installs the crontab line in the host
  • Run it as a Docker container.
Whichever alternative you select, you must unpack the integration package shared by our Support team.
Unpack the deployment package provided by Lumu in your preferred path/folder. Keep in mind this location, as it will be required for further configurations. From now on, we will refer to this folder as <app_lumu_root>.
Notes
If you use the install script, use the uninstall.sh bash file to remove the integration from the host

Prepare your integration environment

You can deploy your integration using the following alternatives:
  • Run your integration on Python
  • Run your integration on Docker
Follow the instructions based on the selected deployment method.

Prepare Python on your environment

Notes
If Docker is your chosen deployment method, you may skip this step.
If Python is your chosen deployment method, you will need to create a Virtual environment for each integration to avoid conflicts between them and your operating system tools. Make sure you follow the steps in our Preparing Environment for Custom Integrations article.

Prepare Docker on your environment

Notes
If you chose Python as your deployment method, you may skip this step.
If Docker is your chosen deployment method, you must follow the Docker installation documentation that corresponds to your OS. Ensure you follow the Post-installation steps for Linux before deploying the integration.
Notes
For Windows users, follow the Install Docker Desktop for Windows documentation to install the Docker Engine.

Set up the configuration files

To set up the integration, you need to add and edit two configuration files:
  • companies.yml: this file contains the information collected from the Lumu portal.
  • integrations.yml: this file contains the information collected from your Ubiquiti Unifi device.
Notes
Inside the integration package, you will find sample files you can use to build your configuration files. These files are companies_template.yml and integration_template.yml.
Notes
All the parameters in red should be replaced with the real data necessary for your integration deployment. For example, the parameter “COMPANY-UUID” should end up as something similar to “aa11bb22bb33-123a-456b-789c-11aa22bb33cc”. Follow these indications for all similar parameters.

Complete the companies file

The companies file is in charge of defining how the integration connects to Lumu and extracts the information of the incidents and related indicators of compromise.

  1. -

      lumu:

        uuid: "COMPANY_UUID"

        defender_key: "DEFENDER_API_KEY"

        hash_type: "sha1" # Supported hash types: sha256, sha1, md5

        ioc_types: # Supported IOC types: ip, domain, url, hash. Select one, multiple, or all of them

          - ip

          - domain

          - url

          - hash

        adversary: # Supported adversary types: C2C, Malware, Mining, Spam, Phishing, Anonymizer. Select one, multiple, or all of them

          - C2C

          - Malware

          - Mining

          - Spam

          - Phishing

          - Anonymizer

        days: 3 # Min 1, max 3

    -

      COMPANY 2

    -

      COMPANY 3

    -

      ...

Within this file, COMPANY_UUID and DEFENDER_API_KEY fields are mandatory. Please use the values captured in the previous steps. The ioc_types values must match the IOC types required by the integration, in this case, ip and domain.

Complete the integrations file

The integrations file contains the information required for the integration to connect and interact with your Ubiquiti Unifi Cloud Gateway devices:

  1. - lumu:

        uuid: "COMPANY_UUID"

        adversary: # Supported adversary types: C2C, Malware, Mining, Spam, Phishing, Anonymizer. Select one, multiple, or all

          - C2C

          - Malware

          - Mining

          - Spam

          - Phishing

          - Anonymizer

        days: 3 # Number of days to collect adversary data from the IOC Manager

      app:

        name: "INTEGRATION_NAME"

        clean: false # Flag used if you want to revert all changes made by the integration component. Supported values are true or false

        ioc_types: # Supported IOC types: ip, domain. Select one, multiple, or all of them

          - ip

          - domain

        api:

          username: UNIFI_USERNAME

          password: UNIFI_PASSWORD

          host: UNIFI_IP_OR_HOSTNAME

          site: UNIFI_SITE_NAME # Site name. If not defined, the integration will use "default"


  • COMPANY_UUID with the Company UUID given in the Complete the companies file section.
  • INTEGRATION_NAME with a distinctive name for the integration. We recommend using the customer name here. If you have multiple Unifi devices, use a unique name related to the device, for example, Customer S.A. - Main datacenter.
  • UNIFI_USERNAME with the username created in the Create a dedicated integration user section.
  • UNIFI_PASSWORD with the password given to the user created in the Create a dedicated integration user section.
  • UNIFI_IP_OR_HOSTNAME with the IP address or the hostname of your Unifi device. If you use a hostname, ensure your integration device can resolve this value to its IP address.
  • UNIFI_SITE_NAME with your Unifi deployment assigned site. If you are not sure, use default as its value.

Notes
You must fill in the configuration data carefully. If there are any mistakes or missing data, you’ll receive errors. Please refer to the Troubleshooting and known issues section at the end of this article for further reference.

Deploy Integration as Python script

To deploy the integration as script, you need to run the install.sh script inside the integration package.
Notes
Make sure the install.sh script has the execution permission before running it.
To run the installation script, locate yourself in the app_lumu_root folder, then execute this line through CLI.

./install.sh all

The installation script will set up the Python environment and two different cron jobs.
Notes
If you want to modify the default running interval set up by the installation script, you can modify the latest crob job entries based on your environment requirements.
Notes
If you want to restart or uninstall the integration run the ./restart all and ./uninstall all respectively.

Script details

To use the script, you must locate yourself on the path selected for deployment (<app_lumu_root>). Use the following command to show all options available for the package:

python run.py -h

Usage: run [-h] [--config CONFIG] [--ioc-manager-db-path IOC_MANAGER_DB_PATH] [-v] [-l {screen,file}] [--hours HOURS]

Options Description
-h, --help show this help message and exit
--config CONFIG Configuration file for the integration (default: integrations.yml)
--ioc-manager-db-path IOC_MANAGER_DB_PATH IOC Manager dabatase path (default: ioc.db). This is the database where the IOC information comes from.
--logging {screen,file} Select where you want to output logs (default: screen)
--verbose, -v Use this flag to increase log verbosity
--hours HOURS Number of hours to expire records in the database

Usage Examples

  • Task: query IOCs related to Lumu incidents with default options

To query all ip addresses and domains related to Lumu incidents triggered in the days defined in your configuration files, run the following command.

python3 run.py

  • Task: Clean records

To clean the existing records from your Ubiquiti Unifi Cloud Gateway device, just set up the clean flag in the integrations.yml file to true.

clean: true

Then, run the integration script as follows:

python3 run.py [--config CONFIG] [--ioc-manager-db-path IOC_MANAGER_DB_PATH]

Notes
The Traffic rules created and managed by the integration will be permanently deleted.

  • Other tasks

According to your needs, you can combine the examples shown. If you need more details on the steps executed by the integration script, you can add the –logging {file, screen} and –verbose arguments. These arguments can be used for troubleshooting.

Deploy as a Docker container (Optional)

If you have a Docker environment, you can select this option to run the integration as a Docker process. To deploy and run your integration as a docker container, locate yourself at the <app_lumu_root> folder, and follow these instructions:

1. Build the container by running the following command.

docker build \
      --tag img-lumu-unifi-response \
      --file DockerfileAllInOne .

Notes
Do not forget the dot "."

2. Run the container by using the following command.

docker run -d \
      -v ./companies.yml:/app/companies.yml \
      -v ./integrations.yml:/app/integrations.yml \
      --restart unless-stopped \
      --log-driver json-file \
      --log-opt max-size=30m \
      --log-opt max-file=3 \
      --name lumu-unifi-response \
      img-lumu-unifi-response

With this mode, your integration will run every 5 minutes.

Troubleshooting

For troubleshooting purposes, you can run the following commands:

To log in to your container using an interactive shell:

docker exec -it lumu-unifi-response bash

To collect integration logs:

docker logs -f lumu-unifi-response

Expected results

The integration is running correctly if you find the following rules among your Ubiquiti Unifi Traffic rules:
  • Lumu IOCs (IPs)
  • Lumu IOCs (Domains)
To check if your Ubiquiti Unifi device has these rules, head to the Network application and follow these steps:
1. Head to the left navigation bar. Click on the Settings menu (the Gear icon).

2. Head to the Settings navigation bar. Click on the Security menu.

3. The Lumu rules are listed under the Traffic & Firewall Rules window. Ensure the Simple option and the All toggle are enabled.

Notes
The integration will set the rules to block outbound traffic from all sources behind the Firewall to the added destinations.

Troubleshooting and known issues

To identify failures in the script execution, use the -v flag. The script execution log will show more detailed information.

The application logs will be redirected to the lumu.log file. The file errors.log stores only the errors to make them easier to find and aid the troubleshooting process.

Input Validation

If you receive errors like this:

ValidationError: 1 validation error for CompanyPyModel
app.api.gh
Extra inputs are not permitted [type=extra_forbidden, input_value='kh', input_type=str]

It means you are using the wrong key parameters or values. Review your configuration files and run the integration again.

Another instance is running

If you receive the following error.

Stopping the integration 39, it might have another older instance running, check if is feasible or not
older pid: 25 - cwd: /app - since: 2024-10-04 14:50:01.560000
cmdline: /usr/local/bin/python3 /app/run.py

There could be another instance running. To check this, open the pid.pid file in the integration folder. This file stores the process ID if it’s running.

        • Related Articles

        • Akamai SIA Custom Response Integration

          This article shows how to leverage the Lumu Defender API and Akamai SIA (ETP) Configuration API to mitigate security risks. Requirements An Akamai SIA subscription. An Akamai Control Center access is required for setting up and collecting Akamai ...
        • Acronis Cyber Protect Cloud Custom Response Integration

          This article shows how to leverage Acronis Cyber Protect Cloud API and Lumu Defender API to enhance your Response capabilities. Response integration between Acronis Cyber Protect Cloud and Lumu Requirements An Acronis Cyber Protect Cloud subscription ...
        • Imperva Cloud WAF Custom Response Integration

          This article shows how to leverage the Lumu Defender API and Imperva Cloud WAF API to mitigate security risks. Response integration between Imperva Cloud WAF and Lumu Requirements Imperva Cloud WAF You need an Imperva Cloud WAF admin console to ...
        • Netskope Log Streaming Custom Data Collection Integration

          In this article, you will find out how to configure your Netskope Log Streaming subscription and its Lumu Custom Data Collection integration to pull, transform, and inject the Web Transactions by Netskope Log Streaming into Lumu to enhance the ...
        • Illumio Custom Data Collection Integration

          Learn how to enhance the detection & response capabilities of your organization by integrating Illumio with Lumu’s data collection capabilities to pull, transform and inject the activity network logs recorded by Illumio into Lumu. Requirements An ...