imperva / incapsula-logs-downloader

A Python script for downloading log files from Incapsula
MIT License
30 stars 35 forks source link

Imperva Connector

A Python script for downloading log files from Imperva CloudWAF

Dependencies

This script requires Python 3 The script has the following pythondependencies that may require additional installation modules, according to the operating system that is used.

Note: the encryption libraries are not needed if decryption is not being used.

A requirements.txt file is included in the script directory, so that the following can be used to install requirements and dependencies:

pip install -r requirements.txt

Getting Started

Executing The Script

An example for calling the script is below:

python LogsDownloader.py \
  -c path_to_config_folder \
  -l path_to_system_logs_folder \
  -v system_logs_level

Running The Script As A Service

SysVinit

You can run the script as a service on Linux systems by using the configuration file - linux_service_configuration/incapsulaLogs.conf

You should modify the following parameters in the configuration file according to your environment:

  1. $USER$ - The user that will execute the script
  2. $GROUP$ - The group name that will execute the script
  3. $PYTHON_SCRIPT$ - The path to the LogsDownloader.py file, followed by the parameters for execution of the script

On your system, copy the incapsulaLogs.conf file and place it under the /etc/init/ directory

sudo cp incapsulaLogs.conf /etc/init/incapsulaLogs.conf
sudo initctl reload-configuration
sudo ln -s /etc/init/incapsulaLogs.conf /etc/init.d/incapsulaLogs
sudo service incapsulaLogs start

You can use start/stop/status as any other Linux service

Docker

A dockerfile is provided to build your own image locally. At this time, a dockerhub image is not available.

Configuration

The connector script will look for the following environment variables, and fall back to the configuration file if the environment variable is not set:

Note - In order to use a custom CA file, you will need to either build a docker image with the file embedded, or mount a persistent data volume to the image and provide the full path to the file as this variable value.

Encrypted Logs

The recommended method would be to mount a persistent data volume at /etc/incapsula/logs/config/keys that contains numbered subfolders with key files as detailed in Preparations for using the script.

You can also use the dockerfile in this repo to build the image with your keys baked in.