> For the complete documentation index, see [llms.txt](https://docs.cennso.com/cennso/netcap/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/cennso/netcap/latest/concepts/netcapturestorage.md).

# `NetCaptureStorage` CR

`NetCaptureStorage` CR specifies the storage location for collected PCAP files. The supported locations are:

- Local disk
- SFTP server
- S3 storage

The following sections describe all configurable parameters available in the `NetCaptureStorage` CR. For a step-by-step guide on how to perform the configuration, see the [Configure PCAP capturing](https://docs.cennso.com/cennso/netcap/latest/guides/pcap-k8s.md) guide.

## Local storage

You can store PCAPs locally in the Core Cluster. In this case, PCAPs are saved on the Kubernetes worker node disk, by default at `/root/dumps`. This path is mounted into the NetCap Sink pod, so the data stays available even if the pod restarts.

To define a subdirectory of `/root/dumps`, set **spec.forProvider.local.path** to your subdirectory name. The resulting local path will be `/root/dumps/{SUBDIRECTORY_NAME}`.
To configure a local storage:

### Local storage (CMC)

### CMC

1. Create a new `NetCapture Storage` or edit the existing one.
2. Switch to the **Specification** tab and choose the **Local Storage** storage type.
3. Enter the path for the subdirectory in the **Path** text field.
4. Click **Create** to finalize.

### Local storage (CLI)

### CLI

Create the following `NetCaptureStorage` custom resource and apply it to your cluster:

```yaml
apiVersion: netcap.cennso.com/v1alpha1
kind: NetCaptureStorage
metadata:
  name: local-storage
spec:
  forProvider:
    local:
      # Path to the directory where PCAP files will be stored
      path: my-pcaps
```

## SFTP server

To set an SFTP server as a location for your PCAP files, provide all required connection parameters in the **spec.forProvider.sftp** configuration section. NetCap uses [rclone](https://rclone.org/) to connect to an external SFTP server.

You can authenticate to the SFTP server in two ways:

- [Plain user and password](#plain-userpassword)
- [SSH keys](#key-based-authentication)

NetCap supports all the rclone connection parameters. For the full set of fields, please take a look at the [rclone SFTP documentation](https://rclone.org/sftp/).

### Plain user/password

You can provide the user and password as plain text in the `NetCaptureStorage` object. Follow the instructions:

#### Plain user/password (CMC)

### CMC

1. Create a new `NetCapture Storage` or edit the existing one.
2. Switch to the **Specification** tab and choose the **SFTP Server Connection** storage type.
3. Enter the username for the SSH connection in the **User** field.
4. In the **Authentication method** fields, choose the **Password** type.
5. Enter a plaintext password in the **Password** text field.
6. Click **Create** to finalize.

#### Plain user/password (CLI)

### CLI

```yaml
apiVersion: netcap.cennso.com/v1alpha1
kind: NetCaptureStorage
metadata:
  name: storage-sftp
spec:
  forProvider:
    sftp:
      # Hostname or IP address of the SFTP server.
      host: sftp-service.sftp
      # Port on which the SFTP server is running.
      port: 22
      # Remote path on the SFTP server where files will be uploaded.
      path: /upload
      credentials:
        # Username used to authenticate to the SFTP server.
        user: my-username
        # Password for SFTP authentication.
        pass: my-password
```

### Key-based authentication

You can use SSH keys to authenticate. To do this, provide the private SSH key in one of three ways:

- As an existing Kubernetes Secret
- In the NetCap Sink deployment
- In the **spec.forProvider.sftp.credentials.key_pem** parameter within the `NetCaptureStorage` CR

#### Define a key as a Kubernetes Secret

You can store a PEM-encoded private key as a Kubernetes secret created in the `cennso-system` namespace. For example:

```yaml
apiVersion: v1
kind: Secret
metadata:
  name: sftp-admin-privkey
  namespace: cennso-system
type: Opaque
stringData:
  testkey: |
      -----BEGIN OPENSSH PRIVATE KEY-----
      <...>
      -----END OPENSSH PRIVATE KEY-----
```

The secret name is `sftp-admin-privkey` with the SSH key stored under the **testkey** parameter.

Next, [install the NetCap extension on a Core Cluster](https://docs.cennso.com/cennso/netcap/latest/installation.md#install-netcap-components-on-a-core-cluster) and embed the reference to your secret in the `NetCapClusterDeployment` resource. Follow the instructions:

##### Define a key as a Kubernetes Secret (CMC)

### CMC

1. Create a new `NetCap Cluster Deployment` or edit the existing one.
2. Go to the **Specification** tab, expand the **SSH Keys** parameter, and click the **+ Add** button.
3. Provide a name for your SSH key in the **Name** field.
4. Enter a PEM-encoded private key in the **Value** field.
5. Click **Create** to confirm.

##### Define a key as a Kubernetes Secret (CLI)

### CLI

Create the following `NetCapClusterDeployment` custom resource and apply it to your cluster:

```yaml
apiVersion: netcap.cennso.com/v1alpha1
kind: NetCapClusterDeployment
metadata:
  name: netcap
  namespace: cennso-infra
spec:
  additionalSshPrivKeySecretNames:
    - sftp-admin-privkey
  connectionSecretRef:
    name: core-cluster-name
    namespace: cennso-infra
  compositionRef:
    name: netcap-core-cluster-deployment
```

Finally, provide a reference to your secret and the content of the private key in `NetCaptureStorage`:

#### CLI (CMC)

### CMC

1. Create a new `NetCapture Storage` or edit the existing one.
2. Switch to the **Specification** tab and choose the **SFTP Server Connection** storage type.
3. Under the **Authentication method** field, choose the **Key File** type.
4. Enter `sftp-admin-privkey/testkey` (a file path to your PEM-encoded private key) in the **Key File** text box.
5. Click **Create** to finalize.

#### CLI (CLI)

### CLI

```yaml
apiVersion: netcap.cennso.com/v1alpha1
kind: NetCaptureStorage
metadata:
  name: sftp-remote-ssh
spec:
  forProvider:
    sftp:
      path: "/upload"
      host: "sftp.example.com"
      port: 22
      credentials:
        user: "admin"
        key_file: sftp-admin-privkey/testkey
```

#### Define a key in the NetCap Sink deployment

You can add a secret private key directly in `NetCapClusterDeployment`:

##### Define a key in the NetCap Sink deployment (CMC)

### CMC

1. Create a new `NetCap Cluster Deployment` or edit the existing one.
2. Go to the **Specification** tab, expand the **SSH Keys** parameter, and click the **+ Add** button.
3. Provide a name for your SSH key in the **Name** field.
4. Enter a PEM-encoded private key in the **Value** field.
5. Click **Create** to confirm.

##### Define a key in the NetCap Sink deployment (CLI)

### CLI

```yaml
apiVersion: netcap.cennso.com/v1alpha1
kind: NetCapClusterDeployment
metadata:
  name: netcap
  namespace: cennso-infra
spec:
  additionalSshPrivKeys:
    - name: testkey
      value: |-
        -----BEGIN OPENSSH PRIVATE KEY-----
        <...>
        -----END OPENSSH PRIVATE KEY-----
  connectionSecretRef:
    name: core-cluster-name
    namespace: cennso-infra
  compositionRef:
    name: netcap-core-cluster-deployment
```

The NetCap Sink deployment takes care of creating a Kubernetes secret in the `cennso-system` namespace.

Next, configure `NetCaptureStorage` by setting **spec.forProvider.sftp.credentials.key_file** with `fromValues/testkey`, for example:

#### CLI (CMC)

### CMC

1. Create a new `NetCapture Storage` or edit the existing one.
2. Switch to the **Specification** tab and choose the **SFTP Server Connection** storage type.
3. Under the **Authentication method** field, choose the **Key File** type.
4. Enter `sftp-admin-privkey/testkey` (a file path to your PEM-encoded private key) in the **Key File** text box.
5. Click **Create** to finalize.

#### CLI (CLI)

### CLI

```yaml
apiVersion: netcap.cennso.com/v1alpha1
kind: NetCaptureStorage
metadata:
  name: sftp-remote-ssh
spec:
  forProvider:
    sftp:
      path: "/upload"
      host: "sftp.example.com"
      port: 22
      credentials:
        user: "admin"
        key_file: fromValues/testkey
```

#### Define a key as plain text

Another option is to define the raw PEM-encoded private key in the **spec.forProvider.sftp.credentials.key**. See the example:

##### Define a key as plain text (CMC)

### CMC

1. Create a new `NetCaptureStorage` or edit the existing one.
2. Switch to the **Specification** tab and choose a **SFTP Server Connection** storage type.
3. Under **Authentication method** parameter, choose the **Key PEM** type.
4. Paste the plain PEM-encoded private key in the **Key PEM** text field.
5. Click **Create** to finalize.

##### Define a key as plain text (CLI)

### CLI

```yaml
apiVersion: netcap.cennso.com/v1alpha1
kind: NetCaptureStorage
metadata:
  name: sftp-remote-ssh
spec:
  forProvider:
    sftp:
      path: "/upload"
      host: "sftp.example.com"
      port: 22
      credentials:
        user: "admin"
        key: |
          -----BEGIN OPENSSH PRIVATE KEY-----
          <...>
          -----END OPENSSH PRIVATE KEY-----
```

### Advanced configuration

If you need to pass any additional parameters to your SFTP configuration, use the **spec.forProvider.sftp.advanced** map. For example:

#### Advanced configuration (CMC)

### CMC

1. Create a new `NetCapture Storage` or edit the existing one.
2. Switch to the **Specification** tab and choose the **SFTP Server Connection** storage type.
3. Scroll down and expand **SFTP Advanced Connection Parameters**.
4. Click the **+ Add** button and add `key` and `value` for your advanced options.
5. Click **Create** to finalize.

#### Advanced configuration (CLI)

### CLI

```yaml
apiVersion: netcap.cennso.com/v1alpha1
kind: NetCaptureStorage
metadata:
  name: sftp-remote-ssh
spec:
  forProvider:
    sftp:
      path: "/upload"
      host: "sftp.example.com"
      port: 22
      credentials:
        user: "admin"
        key_file: sftp-admin-privkey/testkey
      advanced:
        adv-key: adv-value
        some-key: some-value
```

For the full set of fields, take a look at the [rclone SFTP documentation](https://rclone.org/sftp/).

## S3 storage

To set S3 as a storage location for your PCAP files, provide all required connection parameters in the **spec.forProvider.s3** configuration section. NetCap uses [rclone](https://rclone.org/) to connect to an external S3 server.

You can provide the S3 credentials in three ways:

- Plain values in the `NetCaptureStorage` CR
- [Kubernetes Secrets](#read-parameters-from-kubernetes-secrets)
- [Environment of the NetCap Sink container](#read-credentials-from-the-container-environment)

The following example uses plain values:

```yaml
apiVersion: netcap.cennso.com/v1alpha1
kind: NetCaptureStorage
metadata:
  name: storage-s3
spec:
  forProvider:
    s3:
      # Name of the target S3 bucket.
      bucket: testbucket
      # Name of the S3 provider (for example: "AWS", "Minio").
      provider: Minio
      # Access key for the S3 service.
      access_key_id: minio
      # Secret key for the S3 service.
      secret_access_key: minio123
      # Full URL of the S3-compatible service endpoint
      endpoint: http://minio.minio:9000
      # Region of the S3 bucket
      region: Europe
      # ACL for file uploads, such as "private", "public-read", etc.
      acl: private
```

### Configuration parameters

For a detailed description of configuration parameters for S3 connection defined in **spec.forProvider.s3**, go to the [rclone s3](https://rclone.org/s3) documentation.

- [access_key_id](https://rclone.org/s3/#s3-access-key-id)
- [secret_access_key](https://rclone.org/s3/#s3-secret-access-key)
- [acl](https://rclone.org/s3/#s3-acl)
- bucket - name where the PCAP files will be uploaded.
- [chunk_size](https://rclone.org/s3/#s3-chunk-size)
- endpoint - URL address of S3 server
- [provider](https://rclone.org/s3/#s3-provider)
- [region](https://rclone.org/s3/#s3-region)
- [server_side_encryption](https://rclone.org/s3/#s3-server-side-encryption)
- [storage_class](https://rclone.org/s3/#s3-storage-class)
- [sse_kms_key_id](https://rclone.org/s3/#s3-sse-kms-key-id)

### Read parameters from Kubernetes Secrets

You can read S3 parameters from Kubernetes Secrets created in the Management Cluster and keep plain-text values out of the `NetCaptureStorage` CR. Use the **spec.forProvider.s3.fromSecret** list. Each entry in the list sets one S3 parameter from one key of one Secret and takes the following fields:

- **name** is the S3 parameter to set, for example `access_key_id`.
- **secretRef.name** is the name of the Secret that holds the value.
- **secretRef.namespace** is the namespace of the Secret.
- **secretKey** is the key inside the Secret data. This field is optional. If you skip it, NetCap Provider uses the value of **name** as the key.

Create the Secrets on the Management Cluster, in the namespace you set in **secretRef.namespace**.

> [!IMPORTANT]
> Parameters from **fromSecret** take precedence over the plain-text fields in **spec.forProvider.s3**. If you set the same parameter in both places, NetCap Provider applies the value from the Secret.

The `NetCaptureStorage` CRD requires **spec.forProvider.s3.endpoint** and **spec.forProvider.s3.provider**. To read the endpoint from a Secret, keep the **endpoint** field in the CR and set it to an empty value.

NetCap Provider watches the referenced Secrets. When you update a Secret, NetCap Provider reads the new values and updates the traffic capture configuration.

If the Secret or the key does not exist, NetCap Provider reports an error and keeps the previous configuration.

To read S3 parameters from Secrets:

#### Read parameters from Kubernetes Secrets (CMC)

### CMC

1. Create a new `NetCapture Storage` or edit the existing one.
2. Switch to the **Specification** tab.
3. Choose the **S3 storage** storage type.
4. Expand **Parameters From Secrets**.
5. Click the **+ Add** button.
6. In the **Parameter** field, enter the name of the S3 parameter, for example `access_key_id`.
7. In the **Name** and **Namespace** fields under **Secret**, point to the Secret that holds the value.
8. In the **Secret Key** field, enter the key inside the Secret data. If the key has the same name as the parameter, leave the field empty.
9. Repeat steps 5 to 8 for every parameter you want to read from a Secret.
10. Click **Create** to finalize.

NetCap Provider reads the S3 parameters from the Secret on the next reconciliation.

#### Read parameters from Kubernetes Secrets (CLI)

### CLI

The following `NetCaptureStorage` Custom Resource reads the endpoint, bucket name, and credentials from the `pcap-object-storage-credentials` Secret in the `cennso-system` namespace:

```yaml
apiVersion: netcap.cennso.com/v1alpha1
kind: NetCaptureStorage
metadata:
  name: storage-s3
spec:
  forProvider:
    s3:
      provider: IBMCOS
      # The NetCaptureStorage CRD requires this field. The Secret supplies the value.
      endpoint: ""
      advanced:
        no_check_bucket: "true"
      fromSecret:
        # The public_endpoint key holds the endpoint value
        - name: endpoint
          secretKey: public_endpoint
          secretRef:
            name: pcap-object-storage-credentials
            namespace: cennso-system
        # The remaining keys carry the same names as the parameters
        - name: bucket
          secretRef:
            name: pcap-object-storage-credentials
            namespace: cennso-system
        - name: access_key_id
          secretRef:
            name: pcap-object-storage-credentials
            namespace: cennso-system
        - name: secret_access_key
          secretRef:
            name: pcap-object-storage-credentials
            namespace: cennso-system
```

### Read credentials from the container environment

Set **spec.forProvider.s3.env_auth** to `true` to keep the AWS credentials out of the `NetCaptureStorage` CR. NetCap Sink then takes them from the environment of its container. It reads the standard AWS credential variables, such as `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY`. When no variables are set, it falls back to instance metadata, which covers deployments that authenticate through an Identity and Access Management (IAM) role.

> [!IMPORTANT]
> **spec.forProvider.s3.env_auth** applies only when **spec.forProvider.s3.access_key_id** and **spec.forProvider.s3.secret_access_key** are both empty. If either parameter holds a value, including a value supplied through **fromSecret**, NetCap Sink uses that value and ignores the environment.

Supply the variables with **spec.sinkEnv** on the `NetCapClusterDeployment` CR. Any Secret they reference must exist in the `cennso-system` namespace of the Core Cluster, where `NetCapClusterDeployment` deploys NetCap Sink. For the deployment-side configuration, see [NetCap Sink environment variables and volumes](https://docs.cennso.com/cennso/netcap/latest/concepts/netcapclusterdeployment.md#netcap-sink-environment-variables-and-volumes).

To read the credentials from the container environment:

#### Read credentials from the container environment (CMC)

### CMC

1. Create a new `NetCapture Storage` or edit the existing one.
2. Switch to the **Specification** tab.
3. Choose the **S3 storage** storage type.
4. Select the **Env Auth** checkbox.
5. Leave the **Access Key ID** and **Secret Access Key** fields empty.
6. Click **Create** to finalize.

NetCap Sink takes the credentials from its container environment on the next reconciliation.

#### Read credentials from the container environment (CLI)

### CLI

The following `NetCaptureStorage` Custom Resource takes the AWS credentials from the NetCap Sink container environment:

```yaml
apiVersion: netcap.cennso.com/v1alpha1
kind: NetCaptureStorage
metadata:
  name: storage-s3
spec:
  forProvider:
    s3:
      provider: AWS
      endpoint: https://s3.eu-central-1.amazonaws.com
      bucket: pcap-archive
      region: eu-central-1
      # Take the credentials from the NetCap Sink container environment
      env_auth: true
```

### Advanced configuration

If your S3 configuration requires to pass any additional parameters, use the **spec.forProvider.s3.advanced** map, for example:

#### Advanced configuration (CMC)

### CMC

1. Create a new `NetCapture Storage` or edit the existing one.
2. Switch to the **Specification** tab and choose the **S3 storage** storage type.
3. Scroll down and expand **S3 Advanced Parameters**.
4. Click the **+ Add** button and add `key` and `value` for your advanced options.
5. Click **Create** to finalize.

#### Advanced configuration (CLI)

### CLI

```yaml
apiVersion: netcap.cennso.com/v1alpha1
kind: NetCaptureStorage
metadata:
  name: storage-s3
spec:
  forProvider:
    s3:
      bucket: testbucket
      provider: Minio
      access_key_id: minio
      secret_access_key: minio123
      endpoint: http://minio.minio:9000
      region: Europe
      acl: private
      advanced:
        adv-key: adv-value
        some-key: some-value
```

For the full set of fields, take a look at the [rclone S3 documentation](https://rclone.org/s3/).
