> For the complete documentation index, see [llms.txt](https://docs.cennso.com/components/smc/latest/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/smc/latest/guides/traffic-capture.md).

# Traffic capturing and exposure

You can configure Session Management Controller (SMC) to capture and send traffic packets as PCAP files. To do so, you must configure dedicated containers to capture traffic in the `values.yaml` files. Then, the `rclone` service can send these data to further destinations.

The following example sets up PCAP captures with a shared storage of 30GB, acting on the `sx` and `rf` interfaces with different options:

```yaml
pcap:
  dirSize: 30Gi
  interfaces:
    sx:
      FILENAME: sx.pcap
      FILTER: "port 8805"
      IFACE: "sx"
      INTERVAL: 900
      MAXFILENUM: 672
    rf:
      FILENAME: rf.pcap
      FILTER: "port 3868"
      IFACE: "rf"
      INTERVAL: 900
      MAXFILENUM: 672
```

## PCAP capturing setup

For each of the `{NAME}` interfaces in the `pcap.interfaces` property, the Helm chart sets up a separate container to gather PCAP files. You can customize it using the `pcap.interfaces.{NAME}.{ENV_KEY}` environment variables as mentioned in the [configuration reference](https://docs.cennso.com/components/smc/latest/reference/chart-configuration.generated.md).

> [!NOTE]
> Each PCAP container takes a maximum of 0.1 CPU and 128 MB memory.

## `rclone` setup

To publish traffic captured by the PCAP container, enable `rclone` and `pcap`, and configure them 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 that corresponds to a command line option or a config file entry, take the long option name, strip the leading --, change - to _, make upper case, and prepend `RCLONE_` or `RCLONE_CONFIG_`, as explained in the [rclone documentation](https://rclone.org/docs/#environment-variables).

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.

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

```yaml
rclone:
  enabled: true
  env:
    RCLONE_REMOTE_NAME: "sftp" # Mandatory, when defining multiple devices, this is your selector.
    RCLONE_CONFIG_SFTP_TYPE: "sftp"
    RCLONE_CONFIG_SFTP_HOST: "host.com" # hostname or ip of sftp-server
    RCLONE_CONFIG_SFTP_USER: "name"
    RCLONE_CONFIG_SFTP_PORT: "22"
    RCLONE_CONFIG_SFTP_PASS: "password" # Encoded "password". Leave blank to use ssh-agent
```

SFTP can also be authorised using private keys. Setting `useSSHkeyFile` will look for the secret which name is configured by `.Values.rclone.secretName` in the appropriate namespace and mount it to `/etc/ssh` in the container's filesystem. Rclone will look for the file using `RCLONE_CONFIG_SFTP_KEY_FILE` - environment variable.

```yaml
rclone:
  enabled: true
  useSSHkeyFile: true
  env:
    RCLONE_REMOTE_PATH: "name/directory"
    RCLONE_REMOTE_NAME: "sftp" # Mandatory,
    RCLONE_CONFIG_SFTP_TYPE: "sftp"
    RCLONE_CONFIG_SFTP_HOST: "host.com" # hostname or ip of sftp-server
    RCLONE_CONFIG_SFTP_USER: "name"
    RCLONE_CONFIG_SFTP_PORT: "22"
    RCLONE_CONFIG_SFTP_PASS: "" # Encoded, blank for agent.
    RCLONE_CONFIG_SFTP_KEY_FILE: "/etc/ssh/key.pem"
```
Note that this secret `.Values.rclone.secretName` is not created automatically when deploying this helm chart, but needs to be manually prepared by the user like so:

```bash
kubectl create secret generic rclone-ssh-key --from-file=/path/to/key.pem -n {NAMESPACE}
```

This container example-configuration enables authorization for S3 through access-key and secret-access-key. `rclone.env` becomes a ConfigMap, so keep the access key and secret access key out of it. Instead, set `rclone.envSecretName` to the name of a Secret in the same namespace; the chart merges that Secret into the `rclone` container's environment alongside `rclone.env`:

```yaml
rclone:
  enabled: true
  envSecretName: rclone-s3-credentials
  env:
    RCLONE_CONFIG_S3_TYPE: "s3"
    RCLONE_CONFIG_S3_ENV_AUTH: "false"
    RCLONE_CONFIG_S3_REGION: "s3-<region>"
    RCLONE_CONFIG_S3_ACL: "private"
    RCLONE_CONFIG_S3_FORCE_PATH_STYLE: "false"
```

Both `envSecretName` and `secretEnvFrom` reference a Secret that must already exist in the same namespace — this chart only reads it.

A Secret's keys do not always already match the `RCLONE_*` env var names rclone expects. For example, a Secret named `pcap-object-storage-credentials` may expose keys named `bucket`, `access_key_id`, `secret_access_key`, `public_endpoint`, and `direct_endpoint` rather than `RCLONE_REMOTE_PATH` or `RCLONE_CONFIG_S3_ACCESS_KEY_ID`. For these, use `rclone.secretEnvFrom` instead of `rclone.envSecretName`: each entry maps one existing Secret key to one specific env var name, through `valueFrom.secretKeyRef`.

Configure an S3-compatible remote from such a Secret. If the storage provider exposes both a public and a private endpoint, use the private one (`direct_endpoint` here) so traffic to the bucket stays off the public network:

```yaml
rclone:
  enabled: true
  env:
    RCLONE_REMOTE_NAME: "s3"
    RCLONE_CONFIG_S3_TYPE: "s3"
  secretEnvFrom:
    - name: RCLONE_CONFIG_S3_ACCESS_KEY_ID
      secretName: pcap-object-storage-credentials
      secretKey: access_key_id
    - name: RCLONE_CONFIG_S3_SECRET_ACCESS_KEY
      secretName: pcap-object-storage-credentials
      secretKey: secret_access_key
    - name: RCLONE_CONFIG_S3_ENDPOINT
      secretName: pcap-object-storage-credentials
      secretKey: direct_endpoint
    - name: RCLONE_REMOTE_PATH
      secretName: pcap-object-storage-credentials
      secretKey: bucket
```

Note that a `secretEnvFrom` entry shadows a same-named key from `rclone.env` rather than replacing it: the chart still renders the `rclone.env` value into the ConfigMap consumed via `envFrom`, but Kubernetes gives a container's own `env` entries precedence over `envFrom`, so the `secretEnvFrom` value is what actually takes effect. In the example above, `RCLONE_REMOTE_PATH` from the Secret's `bucket` key wins over the chart's default `rclone.env.RCLONE_REMOTE_PATH: "data"`, which remains in the ConfigMap unused. To avoid confusion, do not set the same key in both `rclone.env` and `rclone.secretEnvFrom`.

Note that using `rclone_move` implies that transferred files will be removed from the source path `data/finished`. This keeps the container's memory-footprint manageable and enables file-cycling. If the process crashes during transfer no garbage data will remain on the destination address and you will notice a `Terminated` in the container logs. When attempting to push duplicate files they will be removed from the source path but not overwritten/modified on the destination if [MD5/SHA](https://github.com/ncw/rclone#features) checksums and file-name are the same on both ends. Be aware this can cause data loss, if you were to lose the access to the data at the destination. Consider testing first using the `--dry-run` flag.
