> For the complete documentation index, see [llms.txt](https://docs.cennso.com/components/cgw/1.9/llms.txt) (all documentation: [llms.txt](https://docs.cennso.com/llms.txt)). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.cennso.com/components/cgw/1.9/configuration/traffic.md).

# Traffic capturing and exposure 

This document explains how to capture traffic using PCAP configuration and how to publish the captured traffic using `rclone`. 

## Capture traffic

To capture traffic in a pod, enable `pcap` and configure it using environment variables as described in the [PCAP container documentation](https://hub.docker.com/r/travelping/pcap/):

```yaml
pcap:
  enabled: true
  env:
    IFACE: "eth0"
    DURATION: "300"
    FILTER: "80"
    FILENAME: "http"
```

## Expose traffic

To publish traffic captured in the PCAP container, enable `rclone` and configure it using environment variables. Use `RCLONE_REMOTE_NAME` to specify the remote endpoint and `RCLONE_REMOTE_PATH` to specify the destination path.

`Rclone` is defined generically through the container environment. To find the name of the environment variable, first, take the long option name, strip the leading --, change - to _ make upper case and prepend RCLONE_. All available endpoints are described in the [official rclone documentation](https://rclone.org/commands/rclone_move/). The [inotify](https://linux.die.net/man/1/inotifywait) pattern watches for captures and moves them from the `/data/finished` directory.

You can configure Rclone to use different storage providers. The sections below provide examples on how to configure SFTP and S3 storage providers. 

### SFTP with password authentication

This container configuration example enables authentication for SFTP through username and password:

```yaml
rclone:
  enabled: true
  # Enables compression of PCAP files with lz4. 
  # It is highly recommended to set it to true to reduce disk space usage. 
  compression: true
  env:
    # Mandatory selector used when defining multiple devices
    RCLONE_REMOTE_NAME: "sftp"
    RCLONE_REMOTE_PATH: "name/directory"
    RCLONE_CONFIG_SFTP_TYPE: "sftp"
    # Hostname or IP of an SFTP server
    RCLONE_CONFIG_SFTP_HOST: "host.com" 
    RCLONE_CONFIG_SFTP_USER: "name"
    RCLONE_CONFIG_SFTP_PORT: "22"
    # Encoded password. Leave blank to use an SSH agent.
    RCLONE_CONFIG_SFTP_PASS: "password" 
```

### SFTP with private key authentication

You can also authenticate SFTP using private keys. To do so, set the **useSSHkeyFile** parameter to `true`. 
See the configuration example: 

```yaml
rclone:
  enabled: true
  # Enables compression of PCAP files with lz4. 
  # It is highly recommended to set it to true to reduce disk space usage. 
  compression: true
  useSSHkeyFile: true
  env:
    # Mandatory selector used when defining multiple devices
    RCLONE_REMOTE_NAME: "sftp"
    RCLONE_REMOTE_PATH: "name/directory"
    RCLONE_CONFIG_SFTP_TYPE: "sftp"
    # Hostname or IP of an SFTP server
    RCLONE_CONFIG_SFTP_HOST: "host.com" 
    RCLONE_CONFIG_SFTP_USER: "name"
    RCLONE_CONFIG_SFTP_PORT: "22"
    # This value is encoded. It is blank for agent.
    RCLONE_CONFIG_SFTP_KEY_FILE: "/etc/ssh/key.pem"
    RCLONE_CONFIG_SFTP_PASS: "" 
```

In this case, the `rclone-ssh-secret` secret is mounted to the `/etc/ssh` directory in a namespace with the rclone container. The secret name is specified through the `RCLONE_CONFIG_SFTP_KEY_FILE` environment variable. The `rclone-ssh-key` secret is not created automatically when deploying the Helm chart. You must prepare it manually. To do so, run this command:

```bash
kubectl create secret generic rclone-ssh-key --from-file=/path/to/key.pem -n <namespace>
```

### S3 storage provider

This container configuration example enables authorization for S3 through access-key and secret-access-key:

```yaml
rclone:
  enabled: true
  # Enables compression of PCAP files with lz4. 
  # It is highly recommended to set it to true to reduce disk space usage. 
  compression: true
  env:
    RCLONE_REMOTE_NAME: "s3"
    RCLONE_CONFIG_S3_TYPE: "s3" 
    RCLONE_CONFIG_S3_ENV_AUTH: "true"
    RCLONE_CONFIG_S3_ACCESS_KEY_ID: "<sensitive>"
    RCLONE_CONFIG_S3_SECRET_ACCESS_KEY: "<sensitive>"
    RCLONE_CONFIG_S3_REGION: "us-east-1"
    RCLONE_CONFIG_S3_ACL: "private"
    RCLONE_CONFIG_S3_FORCE_PATH_STYLE: "false"
```

If **RCLONE_CONFIG_S3_ENV_AUTH** is set to `false`, the **access_key_id** and **secret_access_key** must be provided in the rclone configuration file. Otherwise, **RCLONE_CONFIG_S3_ACCESS_KEY_ID** and **RCLONE_CONFIG_S3_SECRET_ACCESS_KEY** environment variables are used. For more information, read [rclone S3 authentication guide](https://rclone.org/s3/#authentication).

The [`rclone move`](https://rclone.org/commands/rclone_move/) command moves PCAP files out of the source path `data/finished`. This keeps the containers memory consumption manageable and enables file rotation. If the process crashes during files transfer, no data from the transferred files remains on the destination address. Also, the container log shows the `Terminated` status. If the files are duplicated in the source and destination path, the duplicated files are removed from the source path but not modified on the destination if [MD5/SHA](https://github.com/ncw/rclone#features) checksums and filenames are the same on both sides. 

>**CAUTION:** If you lose access to the destination, the conditions described above can cause data loss. Consider testing first using the `--dry-run` flag.
