Exporting security logs to external systems

Integration with external security monitoring systems.

Introduction

To integrate with SIEM, Local log collection module (Vector, shturval-log-collector) must be enabled in the cluster. Log redirection is configured via ShturvalServicePatch, which applies to the service specification shturval-log-collector; The general procedure for working with custom values is described in the section How to manage CustomValues ​​of services.

Vector uses:

  • sources — data sources;
  • transforms — data transformation and filtering;
  • sinks — recipients to which logs are sent.

What logs can be sent

In customvalues.shturval specify the types of logs that need to be redirected. Supported:

  • auditd — system audit logs;
  • journald — logs containerd, kubelet, shturvald;
  • k8s_audit — Kubernetes API audit logs;
  • k8s_events — Kubernetes events;
  • k8s_logs — container logs.

The shturval block must list all log types that require redirection. For each log type, set recipients to sinks. If you need to change records before sending, set transforms.


General setup procedure

  1. Prepare ShturvalServicePatch for shturval-log-collector.
  2. In customvalues.shturval specify the log types, transforms if necessary and sinks with connection parameters.
  3. Upload the manifest to the cluster via import manifests.
  4. Wait for the changes to apply.

Sending to SIEM via socket

In this example, k8s_audit, journald, and k8s_logs are sent to the SIEM. To change the list of sent logs, remove the unnecessary block with the log type from the shturval block.

For releases 2.11-2.14, the inputs values in the supplied platform-logs sink did not change: k8s_audit and journald use critical_level, and k8s_logs uses post_transforms_system_namespaces.

apiVersion: ops.shturval.tech/v1beta2
kind: ShturvalServicePatch
metadata:
  name: <resource name>
spec:
  shturvalServiceConfigName: shturval-log-collector
  customvalues:
    shturval:
      k8s_audit:
        enable: true
        sinks:
          siem:
            type: socket
            inputs:
              - critical_level
            address: "<your parameter value>"
            mode: <your parameter value>
            encoding:
              codec: json
      journald:
        sinks:
          siem:
            type: socket
            inputs:
              - critical_level
            address: "<your parameter value>"
            mode: <your parameter value>
            encoding:
              codec: json
      k8s_logs:
        transforms:
          filter_backend:
            condition: |
              .kubernetes.pod_namespace == "shturval-backend" &&
              (
                (.kubernetes.container_name == "opa" && starts_with(string!(.kubernetes.pod_name), "shturval-backend-")) ||
                (.kubernetes.container_name == "authn" && starts_with(string!(.kubernetes.pod_name), "authn-"))
              )              
            inputs:
              - post_transforms_system_namespaces
            type: filter
        sinks:
          siem:
            type: socket
            inputs:
              - filter_backend
            address: "<your parameter value>"
            mode: <your parameter value>
            encoding:
              codec: json
ParameterDescriptionData typeExample
metadata.nameName ShturvalServicePatchstringshturval-log-collector-siem
addressSIEM socket: IP address and portstring10.11.12.13:514
modeConnection protocolstringudp

Vector supports confirmation of data delivery. In case of incorrect delivery, a re-send is performed, which reduces the impact of the UDP protocol features.


Send to Loki

Prepare ShturvalServicePatch for application to the ssc Local Log Collection Module (shturval-log-collector) specification. In customvalues add the shturval block with the required parameters.

apiVersion: ops.shturval.tech/v1beta2
kind: ShturvalServicePatch
metadata:
  name: shturval-log-collector-logs-to-loki
spec:
  shturvalServiceConfigName: shturval-log-collector
  customvalues:
    shturval:
      platform_logs_enable: true
      k8s_logs:
        enable: true
        sinks:
          loki_external:
            type: loki
            inputs:
              - post_transforms_system_namespaces
            endpoint: <your parameter value>
            path: /loki/api/v1/push
            compression: snappy
            tenant_id: "<your parameter value>"
            encoding:
              codec: json
            tls:
              verify_certificate: false
            labels:
              __tenant_id__: "<your parameter value>"
              resourceRealm: "<your parameter value>"
              log_type: "kubernetes"
      k8s_audit:
        enable: true
        sinks:
          loki_external:
            type: loki
            inputs:
              - critical_level
            endpoint: <your parameter value>
            path: /loki/api/v1/push
            compression: snappy
            tenant_id: "<your parameter value>"
            encoding:
              codec: json
            tls:
              verify_certificate: false
            labels:
              __tenant_id__: "<your parameter value>"
              resourceRealm: "<your parameter value>"
              log_type: "k8s_audit"
      k8s_events:
        enable: true
        sinks:
          loki_external:
            type: loki
            inputs:
              - critical_level
            endpoint: <your parameter value>
            path: /loki/api/v1/push
            compression: snappy
            tenant_id: "<your parameter value>"
            encoding:
              codec: json
            tls:
              verify_certificate: false
            labels:
              __tenant_id__: "<your parameter value>"
              resourceRealm: "<your parameter value>"
              log_type: "k8s_events"
      journald:
        enable: true
        sinks:
          loki_external:
            type: loki
            inputs:
              - critical_level
            endpoint: <your parameter value>
            path: /loki/api/v1/push
            compression: snappy
            tenant_id: "<your parameter value>"
            encoding:
              codec: json
            tls:
              verify_certificate: false
            labels:
              __tenant_id__: "<your parameter value>"
              resourceRealm: "<your parameter value>"
              log_type: "journald"
      auditd:
        enable: true
        sinks:
          loki_external:
            type: loki
            inputs:
              - auditd
            endpoint: <your parameter value>
            path: /loki/api/v1/push
            compression: snappy
            tenant_id: "<your parameter value>"
            encoding:
              codec: json
            tls:
              verify_certificate: false
            labels:
              __tenant_id__: "<your parameter value>"
              resourceRealm: "<your parameter value>"
              log_type: "auditd"
ParameterDescriptionData typeExample
metadata.nameName ShturvalServicePatchstringshturval-log-collector-logs-to-loki
platform_logs_enableEnables sending platform logsbooleantrue
<log-type>.enableEnables sendingof the selected log type: auditd, journald, k8s_audit, k8s_events, k8s_logsbooleantrue
loki_external.typeData recipient typestringloki
loki_external.inputsList of log sources or transformations to send to Lokiarraypost_transforms_system_namespaces
loki_external.endpointLoki URLstringhttps://loki.example.com
loki_external.pathAPI path for sending logs to Lokistring/loki/api/v1/push
loki_external.compressionData compression algorithm before sendingstringsnappy
loki_external.tenant_idTenant ID in Lokistringtenant-example
loki_external.encoding.codecLog encoding formatstringjson
loki_external.tls.verify_certificateVerifying TLS certificate upon connectionbooleanfalse
loki_external.labels.__tenant_id__Tenant label for log entriesstringtenant-example
loki_external.labels.resourceRealmLabel of the environment or cluster from which logs are sentstringcluster-example
loki_external.labels.log_typeLog Type Labelstringkubernetes

In the example above, the following logs will be sent to Loki: auditd, journald, k8s_audit, k8s_events and k8s_logs. To change the list of sent logs, remove the unnecessary block with the log type from shturval.

Load the prepared ShturvalServicePatch into the cluster via import manifests. After downloading, it will take some time for the changes to take effect.


Posting to Elasticsearch or OpenSearch

General template

apiVersion: ops.shturval.tech/v1beta2
kind: ShturvalServicePatch
metadata:
  name: <resource name>
spec:
  shturvalServiceConfigName: shturval-log-collector
  customvalues:
    shturval:
      <your value>: # Type of logs to redirect
        enable: true
        transforms: {}
        sinks:
          elastic_logs:
            type: <your parameter value>
            auth:
              user: <your parameter value>
              password: <your parameter value>
              strategy: <your parameter value>
            endpoints:
              - <your parameter value>
            tls:
              verify_certificate: true
            api_version: <your parameter value>
            buffer:
              max_size: <your parameter value>
              type: <your parameter value>
ParameterDescriptionData typeExample
metadata.nameName ShturvalServicePatchstringshturval-log-collector-logs
elastic_logs.typeData recipient typestringelasticsearch
elastic_logs.auth.userAccount name to connect to Elasticsearchstringusername
elastic_logs.auth.passwordAccount password for connecting to Elasticsearchstring1234qwe
elastic_logs.auth.strategyElasticsearch Authentication Strategystringbasic
elastic_logs.endpointsList of URLs to connect toarrayhttps://elastic.bank.local:9200/
elastic_logs.api_versionElasticsearch API Versionstringv8
elastic_logs.buffer.max_sizeBuffer size for storing logs before sendingint268435488
elastic_logs.buffer.typeBuffer type for storing logs before sendingstringdisk

audit

apiVersion: ops.shturval.tech/v1beta2
kind: ShturvalServicePatch
metadata:
  name: shturval-log-collector-auditd
spec:
  shturvalServiceConfigName: shturval-log-collector
  customvalues:
    shturval:
      auditd:
        sinks:
          elastic_logs:
            type: elasticsearch
            inputs:
              - auditd
            bulk:
              index: "{{ .Values.CLUSTER_NAME }}_auditd-%Y.%m.%d"
            auth:
              user: my_username
              password: "my_password"
              strategy: basic
            endpoints:
              - "https://external-elastic.address:9200"
            tls:
              verify_certificate: false
            api_version: "v8"
            buffer:
              max_size: 268435488
              type: disk

k8s_audit

apiVersion: ops.shturval.tech/v1beta2
kind: ShturvalServicePatch
metadata:
  name: shturval-log-collector-kaudit
spec:
  shturvalServiceConfigName: shturval-log-collector
  customvalues:
    shturval:
      k8s_audit:
        sinks:
          elastic_logs:
            type: elasticsearch
            inputs:
              - critical_level
            bulk:
              index: "{{ .Values.CLUSTER_NAME }}_kaudit-%Y.%m.%d"
            auth:
              user: my_username
              password: "my_password"
              strategy: basic
            endpoints:
              - "https://external-elastic.address:9200"
            tls:
              verify_certificate: false
            api_version: "v8"
            buffer:
              max_size: 268435488
              type: disk

k8s_events

apiVersion: ops.shturval.tech/v1beta2
kind: ShturvalServicePatch
metadata:
  name: shturval-log-collector-kevents
spec:
  shturvalServiceConfigName: shturval-log-collector
  customvalues:
    shturval:
      k8s_events:
        sinks:
          elastic_logs:
            type: elasticsearch
            inputs:
              - critical_level
            bulk:
              index: "{{ .Values.CLUSTER_NAME }}_events-%Y.%m.%d"
            auth:
              user: my_username
              password: "my_password"
              strategy: basic
            endpoints:
              - "https://external-elastic.address:9200"
            tls:
              verify_certificate: false
            api_version: "v8"
            buffer:
              max_size: 268435488
              type: disk

k8s_logs

apiVersion: ops.shturval.tech/v1beta2
kind: ShturvalServicePatch
metadata:
  name: shturval-log-collector-klogs
spec:
  shturvalServiceConfigName: shturval-log-collector
  customvalues:
    shturval:
      k8s_logs:
        sinks:
          elastic_logs:
            type: elasticsearch
            inputs:
              - post_transforms_system_namespaces
            bulk:
              index: "{{ .Values.CLUSTER_NAME }}_logs-%Y.%m.%d"
            auth:
              user: my_username
              password: "my_password"
              strategy: basic
            endpoints:
              - "https://external-elastic.address:9200"
            tls:
              verify_certificate: false
            api_version: "v8"
            buffer:
              max_size: 268435488
              type: disk

journald

apiVersion: ops.shturval.tech/v1beta2
kind: ShturvalServicePatch
metadata:
  name: shturval-log-collector-journald
spec:
  shturvalServiceConfigName: shturval-log-collector
  customvalues:
    shturval:
      journald:
        sinks:
          elastic_logs:
            type: elasticsearch
            inputs:
              - critical_level
            bulk:
              index: "{{ .Values.CLUSTER_NAME }}_journald-%Y.%m.%d"
            auth:
              user: my_username
              password: "my_password"
              strategy: basic
            endpoints:
              - "https://external-elastic.address:9200"
            tls:
              verify_certificate: false
            api_version: "v8"
            buffer:
              max_size: 268435488
              type: disk

Sending to syslog

To redirect logs to syslog, prepare ShturvalServicePatch for shturval-log-collector and add the shturval block with the required parameters to customvalues.

apiVersion: ops.shturval.tech/v1beta2
kind: ShturvalServicePatch
metadata:
  name: shturval-log-collector-syslog
spec:
  shturvalServiceConfigName: shturval-log-collector
  customvalues:
    shturval:
      k8s_audit:
        sinks:
          syslog:
            type: socket
            inputs:
              - critical_level
            address: <your parameter value>
            mode: <your parameter value>
ParameterDescriptionData typeExample
k8s_audit.sinks.syslog.inputsTransform name in the k8s-audit pipeline; in the supplied values, this is critical_levelarraycritical_level
k8s_audit.sinks.syslog.addressSyslog server addressstring11.12.13.14:5000
k8s_audit.sinks.syslog.modeTransfer protocol typestringtcp

The example uses socket. Other ways to configure redirection to the syslog server are described in Vector documentation.


Loading manifest

Load the prepared ShturvalServicePatch into the cluster via import manifests.

Screenshot: import ShturvalServicePatch for SIEM

Import ShturvalServicePatch for SIEM

Screenshot: importing ShturvalServicePatch for log redirection

Import ShturvalServicePatch to redirect logs

Screenshot: import ShturvalServicePatch for syslog

Import ShturvalServicePatch for syslog

Once ShturvalServicePatch is loaded, it will take some time for the changes to take effect.


Application check

To check that ShturvalServicePatch is applied:

  1. In the cluster, open the Services and Repositories section.
  2. Go to the Installed services page.
  3. Find Local log collection module (shturval-log-collector) and open service management.
  4. Check the Service tab: after applying the patch, the status should update to Patched.
  5. Check the Applied ShturvalServicePatch tab: the list should show the loaded ShturvalServicePatch.
Screenshots: applied ShturvalServicePatch

Patched status

Applied ShturvalServicePatch


See also