Dev.to Security 🔐 Cybersecurity 👁 0 📖 28 min read

Real-Time Security Analysis and Automated Device-Response Pipeline: Local Development Setup

Security Operations Platform Project Summary (6W Pitch Framework) Who (Target Customers and Core Roles): Designed for security operations teams at large enterprises, with an AI full-stack engineer leading

Security Operations Platform

Project Summary (6W Pitch Framework)

  • Who (Target Customers and Core Roles): Designed for security operations teams at large enterprises, with an AI full-stack engineer leading the core architecture design and business-domain development.
  • What (Core Product and Problems Addressed): An integrated enterprise-grade security operations management platform that addresses delayed processing of high-volume security alerts and fragmented risk management. It provides unified capabilities for cybersecurity monitoring, asset management, vulnerability remediation, and AI-powered intelligent analysis.
  • Why (Core Differentiators and Competitive Advantages): Implements a three-tier data delivery strategy combining scheduled tasks, Redis caching, and real-time aggregation with cache backfilling on misses, reducing core API response times to under 50 ms. It enables a fully automated closed loop from risk identification to protection response.
  • Where (Use Cases and Deployment Environments): Supports multi-scenario enterprise security operations, firewall integration, and domain security monitoring. It also provides Docker-based container orchestration for isolated multi-environment deployments and dynamic switching between data sources.
  • When (Timeliness and Real-Time Capabilities): Processes more than 100,000 raw alerts from network security devices in real time each day. It supports five-minute scheduled aggregation and cache refresh cycles, while completing full-table aggregation across more than 150 tables containing tens of thousands of records within three seconds.
  • How (Technical Approach and Delivery Model): Uses a microservices architecture to separate business modules and reuse shared capability libraries. It establishes a real-time analysis and automated device-response pipeline powered by Kafka, InfluxDB, a rules engine.

Business

  • AI: Integrates AI Agents to perform intelligent attack-path analysis, three-dimensional risk assessment across systems, assets, and vulnerabilities, and automated generation of remediation recommendations.
  • Automation: Provides a public IP blacklist analysis API that enables firewall devices to retrieve data, creating a fully automated process from risk identification to protection response.
  • Concurrency: Supports real-time processing across more than 150 business tables and over 100,000 alerts per day. Core monitoring API response times were reduced from over two seconds to under 50 ms, while Redis-only APIs support more than 500 queries per second.
  • Availability: Automatically falls back to database queries when the cache becomes unavailable, ensuring 99.9% system availability.
  • Localization: Enables seamless switching between the Dameng database and the PostgreSQL.
  • Efficiency: Improves development and delivery efficiency through independent microservice iteration and reuse of shared capability libraries.

Tech Stack

  • Backend: Spring Boot 3.2.6
  • Frontend: Vue 3
  • Database: InfluxDB
  • Cache: Redis
  • Middleware: Kafka
  • Containerization: Docker

This guide builds a local development version of a real-time security analysis and automated device-response pipeline using Kafka, InfluxDB, a Spring Boot rules engine, and a simulated firewall adapter. It is designed for development and technical demonstration on one workstation.

The pipeline receives security events through an HTTP API, publishes them to Kafka, stores time-series observations in InfluxDB, evaluates explicit security rules, creates response decisions, and sends approved block commands to a local firewall simulator. The simulator does not change the host firewall. It records commands in memory and exposes them through HTTP so the full workflow can be tested safely.

The implementation uses Java 17, Spring Boot 3.2.6, Apache Kafka, InfluxDB 2, Maven, and Docker Compose. It uses plain JSON messages to keep the local setup readable. A shared event envelope, deterministic identifiers, idempotent consumers, explicit rule versions, and separate Kafka topics preserve the engineering principles required by an enterprise-grade design.

This local guide does not include production acceptance criteria or production acceptance tests.

Step 1: Prepare the Local Development Environment

Install the following tools:

  • Java Development Kit 17
  • Apache Maven 3.9 or later
  • Docker Desktop or Docker Engine with Docker Compose v2
  • Git
  • curl or another HTTP client
  • An IDE such as IntelliJ IDEA or Visual Studio Code

Confirm the installed versions:

java -version
mvn -version
docker --version
docker compose version
git --version
curl --version

Java must report major version 17. Maven must run with Java 17. Docker must be running before the infrastructure containers are started.

Create the project structure:

mkdir real-time-security-pipeline
cd real-time-security-pipeline

mkdir -p src/main/java/com/example/security/config
mkdir -p src/main/java/com/example/security/controller
mkdir -p src/main/java/com/example/security/dto
mkdir -p src/main/java/com/example/security/service
mkdir -p src/main/resources
mkdir -p src/test/java/com/example/security/service

The local architecture uses these logical stages:

  • The ingestion API accepts a security event.
  • The ingestion service publishes the event to the security.events.raw.v1 Kafka topic.
  • The analysis consumer writes the observation to InfluxDB.
  • The rules engine evaluates the event and recent security context.
  • A successful rule match is published to security.response.decisions.v1.
  • The response consumer converts the decision into a device command.
  • The firewall simulator records the block without touching the workstation firewall.
  • The response consumer publishes the result to security.response.results.v1.

These stages are separated so that ingestion, analysis, policy, and enforcement can fail or scale independently.

Step 2: Create the Docker Compose Infrastructure

Create compose.yaml in the project root:

services:
  kafka:
    image: bitnami/kafka:3.7
    container_name: security-kafka
    ports:
      - "9092:9092"
    environment:
      KAFKA_CFG_NODE_ID: 1
      KAFKA_CFG_PROCESS_ROLES: broker,controller
      KAFKA_CFG_CONTROLLER_QUORUM_VOTERS: 1@kafka:9093
      KAFKA_CFG_LISTENER_SECURITY_PROTOCOL_MAP: CONTROLLER:PLAINTEXT,INTERNAL:PLAINTEXT,EXTERNAL:PLAINTEXT
      KAFKA_CFG_LISTENERS: INTERNAL://:29092,CONTROLLER://:9093,EXTERNAL://:9092
      KAFKA_CFG_ADVERTISED_LISTENERS: INTERNAL://kafka:29092,EXTERNAL://localhost:9092
      KAFKA_CFG_INTER_BROKER_LISTENER_NAME: INTERNAL
      KAFKA_CFG_CONTROLLER_LISTENER_NAMES: CONTROLLER
      KAFKA_CFG_AUTO_CREATE_TOPICS_ENABLE: "false"
      KAFKA_CFG_NUM_PARTITIONS: 3
      ALLOW_PLAINTEXT_LISTENER: "yes"
    volumes:
      - kafka_data:/bitnami/kafka
    healthcheck:
      test: ["CMD-SHELL", "/opt/bitnami/kafka/bin/kafka-topics.sh --bootstrap-server localhost:9092 --list >/dev/null 2>&1"]
      interval: 10s
      timeout: 5s
      retries: 20

  kafka-init:
    image: bitnami/kafka:3.7
    container_name: security-kafka-init
    depends_on:
      kafka:
        condition: service_healthy
    entrypoint:
      - /bin/bash
      - -ec
      - |
        KAFKA=/opt/bitnami/kafka/bin/kafka-topics.sh
        BOOTSTRAP=kafka:29092
        $$KAFKA --bootstrap-server $$BOOTSTRAP --create --if-not-exists --topic security.events.raw.v1 --partitions 3 --replication-factor 1
        $$KAFKA --bootstrap-server $$BOOTSTRAP --create --if-not-exists --topic security.response.decisions.v1 --partitions 3 --replication-factor 1
        $$KAFKA --bootstrap-server $$BOOTSTRAP --create --if-not-exists --topic security.response.results.v1 --partitions 3 --replication-factor 1
        $$KAFKA --bootstrap-server $$BOOTSTRAP --create --if-not-exists --topic security.events.dead-letter.v1 --partitions 1 --replication-factor 1
        $$KAFKA --bootstrap-server $$BOOTSTRAP --list

  influxdb:
    image: influxdb:2.7
    container_name: security-influxdb
    ports:
      - "8086:8086"
    environment:
      DOCKER_INFLUXDB_INIT_MODE: setup
      DOCKER_INFLUXDB_INIT_USERNAME: admin
      DOCKER_INFLUXDB_INIT_PASSWORD: local_admin_password
      DOCKER_INFLUXDB_INIT_ORG: security-local
      DOCKER_INFLUXDB_INIT_BUCKET: security-events
      DOCKER_INFLUXDB_INIT_ADMIN_TOKEN: local-development-token-change-me
      DOCKER_INFLUXDB_INIT_RETENTION: 168h
    volumes:
      - influxdb_data:/var/lib/influxdb2
    healthcheck:
      test: ["CMD", "influx", "ping", "--host", "http://localhost:8086"]
      interval: 10s
      timeout: 5s
      retries: 20

volumes:
  kafka_data:
  influxdb_data:

The Kafka container uses KRaft mode and does not require ZooKeeper. The external listener is available to the Spring Boot process at localhost:9092. The internal listener is used by the topic initialization container.

InfluxDB is initialized with one organization, one bucket, a seven-day local retention period, and a development token. The token is intentionally simple for local use. Do not reuse it in a shared environment or commit a real credential to source control.

Start the infrastructure:

docker compose up -d

Check the container state:

docker compose ps

Wait until Kafka and InfluxDB are healthy. The kafka-init container should complete successfully after creating the four topics.

Inspect the topics:

docker exec -it security-kafka \
  /opt/bitnami/kafka/bin/kafka-topics.sh \
  --bootstrap-server localhost:9092 \
  --list

The output should include:

security.events.raw.v1
security.response.decisions.v1
security.response.results.v1
security.events.dead-letter.v1

Confirm InfluxDB health:

curl -s http://localhost:8086/health

Open http://localhost:8086 in a browser if the local InfluxDB user interface is needed. Sign in with admin and local_admin_password.

Step 3: Create the Spring Boot Project

Create pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>3.2.6</version>
        <relativePath/>
    </parent>

    <groupId>com.example</groupId>
    <artifactId>real-time-security-pipeline</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>real-time-security-pipeline</name>

    <properties>
        <java.version>17</java.version>
        <influxdb-client.version>7.2.0</influxdb-client.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.kafka</groupId>
            <artifactId>spring-kafka</artifactId>
        </dependency>
        <dependency>
            <groupId>com.influxdb</groupId>
            <artifactId>influxdb-client-java</artifactId>
            <version>${influxdb-client.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-validation</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.kafka</groupId>
            <artifactId>spring-kafka-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
</project>

Create src/main/resources/application.yml:

server:
  port: 8080

spring:
  application:
    name: real-time-security-pipeline
  kafka:
    bootstrap-servers: localhost:9092
    producer:
      acks: all
      properties:
        enable.idempotence: true
        max.in.flight.requests.per.connection: 5
      key-serializer: org.apache.kafka.common.serialization.StringSerializer
      value-serializer: org.springframework.kafka.support.serializer.JsonSerializer
    consumer:
      group-id: security-pipeline-local
      auto-offset-reset: earliest
      enable-auto-commit: false
      key-deserializer: org.apache.kafka.common.serialization.StringDeserializer
      value-deserializer: org.springframework.kafka.support.serializer.JsonDeserializer
      properties:
        spring.json.trusted.packages: com.example.security.dto
        spring.json.use.type.headers: true
    listener:
      ack-mode: record
      missing-topics-fatal: true

management:
  endpoints:
    web:
      exposure:
        include: health,info,metrics
  endpoint:
    health:
      show-details: always

app:
  kafka:
    raw-events-topic: security.events.raw.v1
    decisions-topic: security.response.decisions.v1
    results-topic: security.response.results.v1
    dead-letter-topic: security.events.dead-letter.v1
  influx:
    url: http://localhost:8086
    token: local-development-token-change-me
    org: security-local
    bucket: security-events
  rules:
    blocked-port: 22
    minimum-severity: HIGH
    block-duration-minutes: 30
    protected-tenant: tenant-a
  firewall:
    base-url: http://localhost:8080/local-firewall

logging:
  level:
    com.example.security: INFO
    org.apache.kafka: WARN

The local rule blocks a source address when all of the following are true:

  • The event belongs to tenant-a.
  • The event severity is HIGH or CRITICAL.
  • The destination port is 22.
  • The source is not in the local allowlist.

The rule is deliberately simple so every pipeline stage remains visible. The code separates rule matching from response authorization so more context can be added later without coupling detection directly to a firewall API.

Create src/main/java/com/example/security/SecurityPipelineApplication.java:

package com.example.security;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class SecurityPipelineApplication {

    public static void main(String[] args) {
        SpringApplication.run(SecurityPipelineApplication.class, args);
    }
}

Step 4: Define the Event and Response Contracts

Create src/main/java/com/example/security/dto/SecurityEvent.java:

package com.example.security.dto;

import jakarta.validation.constraints.Max;
import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Pattern;

import java.time.Instant;

public record SecurityEvent(
    @NotBlank String eventId,
    @NotBlank @Pattern(regexp = "[a-zA-Z0-9-]{1,64}") String tenantId,
    @NotBlank String deviceId,
    @NotBlank String sourceIp,
    @NotBlank String destinationIp,
    @NotNull @Min(1) @Max(65535) Integer destinationPort,
    @NotBlank String protocol,
    @NotBlank String severity,
    @NotBlank String eventType,
    @NotNull Instant eventTime,
    Instant ingestedAt,
    Integer schemaVersion
) {
    public SecurityEvent withIngestionMetadata(Instant ingestionTime) {
        return new SecurityEvent(
            eventId,
            tenantId,
            deviceId,
            sourceIp,
            destinationIp,
            destinationPort,
            protocol,
            severity.toUpperCase(),
            eventType,
            eventTime,
            ingestionTime,
            schemaVersion == null ? 1 : schemaVersion
        );
    }
}

Create src/main/java/com/example/security/dto/ResponseDecision.java:

package com.example.security.dto;

import java.time.Instant;
import java.util.List;

public record ResponseDecision(
    String decisionId,
    String eventId,
    String tenantId,
    String ruleId,
    String ruleVersion,
    String action,
    String sourceIp,
    String targetDeviceId,
    int durationMinutes,
    String reason,
    List<String> evidence,
    Instant decidedAt
) {
}

Create src/main/java/com/example/security/dto/DeviceCommandResult.java:

package com.example.security.dto;

import java.time.Instant;

public record DeviceCommandResult(
    String commandId,
    String decisionId,
    String tenantId,
    String deviceId,
    String sourceIp,
    String action,
    String status,
    String detail,
    Instant completedAt
) {
}

Create src/main/java/com/example/security/dto/FirewallBlockRequest.java:

package com.example.security.dto;

public record FirewallBlockRequest(
    String commandId,
    String decisionId,
    String tenantId,
    String sourceIp,
    int durationMinutes,
    String reason
) {
}

Create src/main/java/com/example/security/dto/FirewallBlock.java:

package com.example.security.dto;

import java.time.Instant;

public record FirewallBlock(
    String commandId,
    String decisionId,
    String tenantId,
    String sourceIp,
    String reason,
    Instant createdAt,
    Instant expiresAt,
    String status
) {
}

Each contract carries identifiers that allow an event, decision, command, and result to be correlated. eventId prevents the same raw observation from being treated as a new security fact during retries. decisionId identifies the rule outcome. commandId provides idempotency at the enforcement boundary.

Step 5: Configure Kafka and InfluxDB Clients

Create src/main/java/com/example/security/config/InfrastructureConfig.java:

package com.example.security.config;

import com.influxdb.client.InfluxDBClient;
import com.influxdb.client.InfluxDBClientFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestClient;

@Configuration
public class InfrastructureConfig {

    @Bean(destroyMethod = "close")
    InfluxDBClient influxDBClient(
        @Value("${app.influx.url}") String url,
        @Value("${app.influx.token}") String token,
        @Value("${app.influx.org}") String org,
        @Value("${app.influx.bucket}") String bucket
    ) {
        return InfluxDBClientFactory.create(
            url,
            token.toCharArray(),
            org,
            bucket
        );
    }

    @Bean
    RestClient restClient(RestClient.Builder builder) {
        return builder.build();
    }
}

Spring Boot configures the Kafka producer and consumers from application.yml. The InfluxDB client receives the local URL, token, organization, and default bucket. The RestClient is used by the device-response adapter to call the local firewall simulator.

Create src/main/java/com/example/security/config/KafkaErrorConfig.java:

package com.example.security.config;

import org.apache.kafka.common.TopicPartition;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.kafka.core.KafkaOperations;
import org.springframework.kafka.listener.CommonErrorHandler;
import org.springframework.kafka.listener.DeadLetterPublishingRecoverer;
import org.springframework.kafka.listener.DefaultErrorHandler;
import org.springframework.util.backoff.FixedBackOff;

@Configuration
public class KafkaErrorConfig {

    @Bean
    CommonErrorHandler kafkaErrorHandler(
        KafkaOperations<Object, Object> kafkaOperations,
        @Value("${app.kafka.dead-letter-topic}") String deadLetterTopic
    ) {
        DeadLetterPublishingRecoverer recoverer =
            new DeadLetterPublishingRecoverer(
                kafkaOperations,
                (record, exception) -> new TopicPartition(deadLetterTopic, 0)
            );

        return new DefaultErrorHandler(
            recoverer,
            new FixedBackOff(1000L, 2L)
        );
    }
}

The local error handler retries a failed consumer record twice with a one-second pause. After the retries are exhausted, the record is published to the dead-letter topic. The dead-letter topic is not a substitute for fixing the failure. It preserves the record and error context so the event is not silently lost.

Step 6: Implement Event Ingestion

Create src/main/java/com/example/security/service/EventIngestionService.java:

package com.example.security.service;

import com.example.security.dto.SecurityEvent;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.stereotype.Service;

import java.time.Clock;
import java.time.Instant;
import java.util.concurrent.TimeUnit;

@Service
public class EventIngestionService {

    private final KafkaTemplate<String, Object> kafkaTemplate;
    private final String rawEventsTopic;
    private final Clock clock = Clock.systemUTC();

    public EventIngestionService(
        KafkaTemplate<String, Object> kafkaTemplate,
        @Value("${app.kafka.raw-events-topic}") String rawEventsTopic
    ) {
        this.kafkaTemplate = kafkaTemplate;
        this.rawEventsTopic = rawEventsTopic;
    }

    public SecurityEvent ingest(SecurityEvent request) {
        Instant now = clock.instant();
        SecurityEvent event = request.withIngestionMetadata(now);

        String partitionKey = event.tenantId() + ":" + event.sourceIp();
        try {
            kafkaTemplate.send(rawEventsTopic, partitionKey, event)
                .get(5, TimeUnit.SECONDS);
        } catch (Exception ex) {
            Thread.currentThread().interrupt();
            throw new IllegalStateException("Failed to publish security event", ex);
        }
        return event;
    }
}

The partition key combines the tenant and source IP. Events for the same tenant and source are routed consistently, which preserves their order within a Kafka partition. Unrelated sources can be handled concurrently.

Create src/main/java/com/example/security/controller/SecurityEventController.java:

package com.example.security.controller;

import com.example.security.dto.SecurityEvent;
import com.example.security.service.EventIngestionService;
import jakarta.validation.Valid;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;

@Valid
@RestController
@RequestMapping("/api/v1/security-events")
public class SecurityEventController {

    private final EventIngestionService ingestionService;

    public SecurityEventController(EventIngestionService ingestionService) {
        this.ingestionService = ingestionService;
    }

    @PostMapping
    @ResponseStatus(HttpStatus.ACCEPTED)
    public SecurityEvent ingest(@Valid @RequestBody SecurityEvent event) {
        return ingestionService.ingest(event);
    }
}

The API returns HTTP 202 after Kafka acknowledges the message. This means the event has entered the asynchronous pipeline. It does not mean analysis or device response has completed.

Step 7: Store Security Observations in InfluxDB

Create src/main/java/com/example/security/service/SecurityObservationStore.java:

package com.example.security.service;

import com.example.security.dto.SecurityEvent;
import com.influxdb.client.InfluxDBClient;
import com.influxdb.client.WriteApiBlocking;
import com.influxdb.client.domain.WritePrecision;
import com.influxdb.client.write.Point;
import org.springframework.stereotype.Service;

@Service
public class SecurityObservationStore {

    private final WriteApiBlocking writeApi;

    public SecurityObservationStore(InfluxDBClient influxDBClient) {
        this.writeApi = influxDBClient.getWriteApiBlocking();
    }

    public void write(SecurityEvent event) {
        Point point = Point.measurement("security_event")
            .addTag("tenant_id", event.tenantId())
            .addTag("device_id", event.deviceId())
            .addTag("severity", event.severity())
            .addTag("event_type", event.eventType())
            .addField("source_ip", event.sourceIp())
            .addField("destination_ip", event.destinationIp())
            .addField("destination_port", event.destinationPort())
            .addField("protocol", event.protocol())
            .addField("event_id", event.eventId())
            .time(event.eventTime(), WritePrecision.NS);

        writeApi.writePoint(point);
    }
}

The local model uses bounded classification values such as tenant, device, severity, and event type as tags. IP addresses and event identifiers are stored as fields to avoid creating a new indexed series for every unique value. This is an important InfluxDB design choice because uncontrolled tag cardinality creates avoidable memory and query pressure.

The event timestamp is used as the point time. This preserves the time at which the security activity occurred rather than only the time at which the application processed it.

Step 8: Implement the Rules Engine

Create src/main/java/com/example/security/service/SecurityRuleEngine.java:

package com.example.security.service;

import com.example.security.dto.ResponseDecision;
import com.example.security.dto.SecurityEvent;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.nio.charset.StandardCharsets;
import java.time.Clock;
import java.time.Instant;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.UUID;

@Service
public class SecurityRuleEngine {

    private static final String RULE_ID = "SSH_HIGH_SEVERITY_BLOCK";
    private static final String RULE_VERSION = "1.0.0";

    private final int blockedPort;
    private final String minimumSeverity;
    private final int blockDurationMinutes;
    private final String protectedTenant;
    private final Clock clock = Clock.systemUTC();

    private final Set<String> allowedSources = Set.of(
        "192.0.2.10",
        "192.0.2.11"
    );

    public SecurityRuleEngine(
        @Value("${app.rules.blocked-port}") int blockedPort,
        @Value("${app.rules.minimum-severity}") String minimumSeverity,
        @Value("${app.rules.block-duration-minutes}") int blockDurationMinutes,
        @Value("${app.rules.protected-tenant}") String protectedTenant
    ) {
        this.blockedPort = blockedPort;
        this.minimumSeverity = minimumSeverity;
        this.blockDurationMinutes = blockDurationMinutes;
        this.protectedTenant = protectedTenant;
    }

    public Optional<ResponseDecision> evaluate(SecurityEvent event) {
        if (!protectedTenant.equals(event.tenantId())) {
            return Optional.empty();
        }
        if (event.destinationPort() != blockedPort) {
            return Optional.empty();
        }
        if (!meetsSeverity(event.severity(), minimumSeverity)) {
            return Optional.empty();
        }
        if (allowedSources.contains(event.sourceIp())) {
            return Optional.empty();
        }

        String decisionSeed = event.eventId() + ":" + RULE_ID + ":" + RULE_VERSION;
        String decisionId = UUID.nameUUIDFromBytes(
            decisionSeed.getBytes(StandardCharsets.UTF_8)
        ).toString();
        Instant decidedAt = clock.instant();

        ResponseDecision decision = new ResponseDecision(
            decisionId,
            event.eventId(),
            event.tenantId(),
            RULE_ID,
            RULE_VERSION,
            "TEMPORARY_IP_BLOCK",
            event.sourceIp(),
            event.deviceId(),
            blockDurationMinutes,
            "High-severity SSH activity matched the automated containment policy",
            List.of(
                "severity=" + event.severity(),
                "destinationPort=" + event.destinationPort(),
                "eventType=" + event.eventType(),
                "eventTime=" + event.eventTime()
            ),
            decidedAt
        );
        return Optional.of(decision);
    }

    private boolean meetsSeverity(String actual, String minimum) {
        return severityRank(actual) >= severityRank(minimum);
    }

    private int severityRank(String severity) {
        return switch (severity.toUpperCase()) {
            case "LOW" -> 1;
            case "MEDIUM" -> 2;
            case "HIGH" -> 3;
            case "CRITICAL" -> 4;
            default -> 0;
        };
    }
}

The rule engine returns a decision object rather than calling a firewall. This preserves separation between analytical truth and enforcement authority. The decision identifier is deterministic for one event and one rule version. If Kafka redelivers the event, the same decision identifier is generated.

The local allowlist exists to demonstrate negative evidence. Events from 192.0.2.10 and 192.0.2.11 do not produce automated blocks even when other conditions match.

Create src/main/java/com/example/security/service/SecurityAnalysisConsumer.java:

package com.example.security.service;

import com.example.security.dto.ResponseDecision;
import com.example.security.dto.SecurityEvent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.stereotype.Service;

@Service
public class SecurityAnalysisConsumer {

    private static final Logger log = LoggerFactory.getLogger(SecurityAnalysisConsumer.class);

    private final SecurityObservationStore observationStore;
    private final SecurityRuleEngine ruleEngine;
    private final KafkaTemplate<String, Object> kafkaTemplate;
    private final String decisionsTopic;

    public SecurityAnalysisConsumer(
        SecurityObservationStore observationStore,
        SecurityRuleEngine ruleEngine,
        KafkaTemplate<String, Object> kafkaTemplate,
        @Value("${app.kafka.decisions-topic}") String decisionsTopic
    ) {
        this.observationStore = observationStore;
        this.ruleEngine = ruleEngine;
        this.kafkaTemplate = kafkaTemplate;
        this.decisionsTopic = decisionsTopic;
    }

    @KafkaListener(
        topics = "${app.kafka.raw-events-topic}",
        groupId = "security-analysis-local"
    )
    public void analyze(SecurityEvent event) {
        observationStore.write(event);

        ruleEngine.evaluate(event).ifPresentOrElse(
            decision -> publishDecision(decision),
            () -> log.info(
                "Event {} did not authorize an automated response",
                event.eventId()
            )
        );
    }

    private void publishDecision(ResponseDecision decision) {
        String key = decision.tenantId() + ":" + decision.targetDeviceId();
        kafkaTemplate.send(decisionsTopic, key, decision);
        log.info(
            "Published response decision {} for source {}",
            decision.decisionId(),
            decision.sourceIp()
        );
    }
}

The consumer first writes the observation to InfluxDB and then evaluates the rule. If the InfluxDB write fails, the Kafka error handler retries the record. After retries are exhausted, it sends the record to the dead-letter topic instead of silently continuing with incomplete analytical history.

Step 9: Implement the Local Firewall Simulator

Create src/main/java/com/example/security/service/LocalFirewallService.java:

package com.example.security.service;

import com.example.security.dto.FirewallBlock;
import com.example.security.dto.FirewallBlockRequest;
import org.springframework.stereotype.Service;

import java.time.Clock;
import java.time.Instant;
import java.time.temporal.ChronoUnit;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

@Service
public class LocalFirewallService {

    private final Map<String, FirewallBlock> blocksByCommand = new ConcurrentHashMap<>();
    private final Clock clock = Clock.systemUTC();

    public FirewallBlock block(FirewallBlockRequest request) {
        return blocksByCommand.computeIfAbsent(request.commandId(), ignored -> {
            Instant createdAt = clock.instant();
            Instant expiresAt = createdAt.plus(
                request.durationMinutes(),
                ChronoUnit.MINUTES
            );
            return new FirewallBlock(
                request.commandId(),
                request.decisionId(),
                request.tenantId(),
                request.sourceIp(),
                request.reason(),
                createdAt,
                expiresAt,
                "ACTIVE"
            );
        });
    }

    public List<FirewallBlock> list() {
        return blocksByCommand.values().stream()
            .sorted(Comparator.comparing(FirewallBlock::createdAt))
            .toList();
    }

    public void clear() {
        blocksByCommand.clear();
    }
}

The simulator keys records by commandId. Repeating the same command returns the existing block instead of creating another one. This models idempotent behavior at the device boundary.

Create src/main/java/com/example/security/controller/LocalFirewallController.java:

package com.example.security.controller;

import com.example.security.dto.FirewallBlock;
import com.example.security.dto.FirewallBlockRequest;
import com.example.security.service.LocalFirewallService;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/local-firewall")
public class LocalFirewallController {

    private final LocalFirewallService firewallService;

    public LocalFirewallController(LocalFirewallService firewallService) {
        this.firewallService = firewallService;
    }

    @PostMapping("/blocks")
    @ResponseStatus(HttpStatus.CREATED)
    public FirewallBlock createBlock(@RequestBody FirewallBlockRequest request) {
        return firewallService.block(request);
    }

    @GetMapping("/blocks")
    public List<FirewallBlock> listBlocks() {
        return firewallService.list();
    }

    @DeleteMapping("/blocks")
    @ResponseStatus(HttpStatus.NO_CONTENT)
    public void clearBlocks() {
        firewallService.clear();
    }
}

These endpoints exist only for local development. They must not be interpreted as a real firewall integration. The simulator never modifies Linux, macOS, Windows, Docker, router, or cloud firewall rules.

Step 10: Implement the Automated Device-Response Consumer

Create src/main/java/com/example/security/service/DeviceResponseConsumer.java:

package com.example.security.service;

import com.example.security.dto.DeviceCommandResult;
import com.example.security.dto.FirewallBlock;
import com.example.security.dto.FirewallBlockRequest;
import com.example.security.dto.ResponseDecision;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestClient;

import java.nio.charset.StandardCharsets;
import java.time.Clock;
import java.time.Instant;
import java.util.UUID;

@Service
public class DeviceResponseConsumer {

    private static final Logger log = LoggerFactory.getLogger(DeviceResponseConsumer.class);

    private final RestClient restClient;
    private final KafkaTemplate<String, Object> kafkaTemplate;
    private final String firewallBaseUrl;
    private final String resultsTopic;
    private final Clock clock = Clock.systemUTC();

    public DeviceResponseConsumer(
        RestClient restClient,
        KafkaTemplate<String, Object> kafkaTemplate,
        @Value("${app.firewall.base-url}") String firewallBaseUrl,
        @Value("${app.kafka.results-topic}") String resultsTopic
    ) {
        this.restClient = restClient;
        this.kafkaTemplate = kafkaTemplate;
        this.firewallBaseUrl = firewallBaseUrl;
        this.resultsTopic = resultsTopic;
    }

    @KafkaListener(
        topics = "${app.kafka.decisions-topic}",
        groupId = "device-response-local"
    )
    public void execute(ResponseDecision decision) {
        String commandId = deterministicCommandId(decision);

        FirewallBlockRequest request = new FirewallBlockRequest(
            commandId,
            decision.decisionId(),
            decision.tenantId(),
            decision.sourceIp(),
            decision.durationMinutes(),
            decision.reason()
        );

        FirewallBlock block = restClient.post()
            .uri(firewallBaseUrl + "/blocks")
            .body(request)
            .retrieve()
            .body(FirewallBlock.class);

        if (block == null) {
            throw new IllegalStateException("Firewall simulator returned no result");
        }

        Instant completedAt = clock.instant();
        DeviceCommandResult result = new DeviceCommandResult(
            commandId,
            decision.decisionId(),
            decision.tenantId(),
            decision.targetDeviceId(),
            decision.sourceIp(),
            decision.action(),
            "VERIFIED",
            "Temporary source IP block recorded by local firewall simulator",
            completedAt
        );

        String key = result.tenantId() + ":" + result.deviceId();
        kafkaTemplate.send(resultsTopic, key, result);

        log.info(
            "Verified local response command {} for source {}",
            result.commandId(),
            result.sourceIp()
        );
    }

    private String deterministicCommandId(ResponseDecision decision) {
        String seed = decision.decisionId()
            + ":"
            + decision.targetDeviceId()
            + ":"
            + decision.action();
        return UUID.nameUUIDFromBytes(
            seed.getBytes(StandardCharsets.UTF_8)
        ).toString();
    }
}

The response consumer creates a deterministic command identifier from the decision, device, and action. If Kafka redelivers the decision after a process interruption, the simulator receives the same command identifier and returns the existing result.

Create src/main/java/com/example/security/service/DeviceResultConsumer.java:

package com.example.security.service;

import com.example.security.dto.DeviceCommandResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Service;

@Service
public class DeviceResultConsumer {

    private static final Logger log = LoggerFactory.getLogger(DeviceResultConsumer.class);

    @KafkaListener(
        topics = "${app.kafka.results-topic}",
        groupId = "device-result-audit-local"
    )
    public void record(DeviceCommandResult result) {
        log.info(
            "Command result: commandId={}, decisionId={}, status={}, sourceIp={}, deviceId={}",
            result.commandId(),
            result.decisionId(),
            result.status(),
            result.sourceIp(),
            result.deviceId()
        );
    }
}

This consumer represents the feedback path. In a larger system, it would update incident state, suppression state, audit storage, and an analyst dashboard. For the local setup, it logs the verified outcome.

Step 11: Build and Start the Application

Compile the project:

mvn clean test

Start the application:

mvn spring-boot:run

Confirm health:

curl -s http://localhost:8080/actuator/health

Confirm that the local firewall simulator is empty:

curl -s http://localhost:8080/local-firewall/blocks

The response should be an empty JSON array.

If the application fails to connect to Kafka immediately after Docker starts, check container health and restart the application after Kafka becomes healthy:

docker compose ps
docker compose logs kafka

If InfluxDB authentication fails, verify that the token in application.yml exactly matches DOCKER_INFLUXDB_INIT_ADMIN_TOKEN in compose.yaml.

Step 12: Test a Matching Security Event

Send a critical SSH event for tenant-a:

curl -i -X POST http://localhost:8080/api/v1/security-events \
  -H 'Content-Type: application/json' \
  -d '{
    "eventId": "event-0001",
    "tenantId": "tenant-a",
    "deviceId": "firewall-hk-01",
    "sourceIp": "203.0.113.50",
    "destinationIp": "10.10.20.15",
    "destinationPort": 22,
    "protocol": "TCP",
    "severity": "CRITICAL",
    "eventType": "SUSPICIOUS_SSH_ACCESS",
    "eventTime": "2026-11-19T10:15:00Z",
    "schemaVersion": 1
  }'

The API should return HTTP 202. The asynchronous flow then performs the following work:

  • Kafka stores the raw event.
  • The analysis consumer writes the observation to InfluxDB.
  • The rule engine matches the critical SSH policy.
  • A deterministic response decision is published.
  • The response consumer calls the firewall simulator.
  • The simulator records a 30-minute block.
  • A verified command result is published and logged.

Wait one or two seconds and inspect the simulator:

curl -s http://localhost:8080/local-firewall/blocks

The response should contain one active block for 203.0.113.50.

Inspect the application log. It should include messages indicating that a response decision was published and a local response command was verified.

Step 13: Verify Idempotent Event Processing

Send the exact same event-0001 payload again:

curl -i -X POST http://localhost:8080/api/v1/security-events \
  -H 'Content-Type: application/json' \
  -d '{
    "eventId": "event-0001",
    "tenantId": "tenant-a",
    "deviceId": "firewall-hk-01",
    "sourceIp": "203.0.113.50",
    "destinationIp": "10.10.20.15",
    "destinationPort": 22,
    "protocol": "TCP",
    "severity": "CRITICAL",
    "eventType": "SUSPICIOUS_SSH_ACCESS",
    "eventTime": "2026-11-19T10:15:00Z",
    "schemaVersion": 1
  }'

Inspect the simulator again:

curl -s http://localhost:8080/local-firewall/blocks

There should still be one block for the deterministic command identifier. The event can be delivered more than once, but repeating it does not create multiple firewall records.

The InfluxDB point also uses the same event timestamp with the same tag set. For this local model, a repeated write updates the same logical point rather than producing an additional series. A larger design should define idempotency according to the source system's event identity and timestamp precision.

Step 14: Test Events That Must Not Trigger a Response

Send a medium-severity SSH event:

curl -i -X POST http://localhost:8080/api/v1/security-events \
  -H 'Content-Type: application/json' \
  -d '{
    "eventId": "event-0002",
    "tenantId": "tenant-a",
    "deviceId": "firewall-hk-01",
    "sourceIp": "203.0.113.60",
    "destinationIp": "10.10.20.15",
    "destinationPort": 22,
    "protocol": "TCP",
    "severity": "MEDIUM",
    "eventType": "SSH_LOGIN_FAILURE",
    "eventTime": "2026-11-19T10:16:00Z",
    "schemaVersion": 1
  }'

The event is stored in Kafka and InfluxDB, but it does not authorize an automated block because it is below the configured minimum severity.

Send a critical event to HTTPS port 443:

curl -i -X POST http://localhost:8080/api/v1/security-events \
  -H 'Content-Type: application/json' \
  -d '{
    "eventId": "event-0003",
    "tenantId": "tenant-a",
    "deviceId": "firewall-hk-01",
    "sourceIp": "203.0.113.70",
    "destinationIp": "10.10.20.15",
    "destinationPort": 443,
    "protocol": "TCP",
    "severity": "CRITICAL",
    "eventType": "SUSPICIOUS_HTTPS_ACCESS",
    "eventTime": "2026-11-19T10:17:00Z",
    "schemaVersion": 1
  }'

This event does not match the local SSH rule because its destination port is not 22.

Send a critical SSH event from an allowlisted source:

curl -i -X POST http://localhost:8080/api/v1/security-events \
  -H 'Content-Type: application/json' \
  -d '{
    "eventId": "event-0004",
    "tenantId": "tenant-a",
    "deviceId": "firewall-hk-01",
    "sourceIp": "192.0.2.10",
    "destinationIp": "10.10.20.15",
    "destinationPort": 22,
    "protocol": "TCP",
    "severity": "CRITICAL",
    "eventType": "APPROVED_SECURITY_SCAN",
    "eventTime": "2026-11-19T10:18:00Z",
    "schemaVersion": 1
  }'

This event also does not trigger automated blocking. The source address is present in the local allowlist, demonstrating that negative evidence can override a pattern that otherwise matches.

Step 15: Query Security Events in InfluxDB

Use the InfluxDB command-line tool inside the container:

docker exec -it security-influxdb influx query \
  --host http://localhost:8086 \
  --org security-local \
  --token local-development-token-change-me \
  'from(bucket: "security-events")
    |> range(start: -24h)
    |> filter(fn: (r) => r._measurement == "security_event")
    |> filter(fn: (r) => r.tenant_id == "tenant-a")'

The query returns field-oriented rows for the events written by the consumer.

Query only critical observations:

docker exec -it security-influxdb influx query \
  --host http://localhost:8086 \
  --org security-local \
  --token local-development-token-change-me \
  'from(bucket: "security-events")
    |> range(start: -24h)
    |> filter(fn: (r) => r._measurement == "security_event")
    |> filter(fn: (r) => r.tenant_id == "tenant-a")
    |> filter(fn: (r) => r.severity == "CRITICAL")'

The browser-based InfluxDB Data Explorer can run the same Flux queries. Select the security-events bucket and narrow the result by measurement, tenant, severity, device, or event type.

The local rules engine currently evaluates the event payload directly. InfluxDB provides event-time history for investigation and future temporal rules. A next development iteration can calculate rolling counts such as distinct destinations contacted by one source within five minutes and publish that derived feature back to Kafka for rule evaluation.

Step 16: Inspect Kafka Records and Consumer Progress

Inspect raw events:

docker exec -it security-kafka \
  /opt/bitnami/kafka/bin/kafka-console-consumer.sh \
  --bootstrap-server localhost:9092 \
  --topic security.events.raw.v1 \
  --from-beginning \
  --max-messages 4

Inspect response decisions:

docker exec -it security-kafka \
  /opt/bitnami/kafka/bin/kafka-console-consumer.sh \
  --bootstrap-server localhost:9092 \
  --topic security.response.decisions.v1 \
  --from-beginning \
  --max-messages 1

Inspect command results:

docker exec -it security-kafka \
  /opt/bitnami/kafka/bin/kafka-console-consumer.sh \
  --bootstrap-server localhost:9092 \
  --topic security.response.results.v1 \
  --from-beginning \
  --max-messages 1

Inspect consumer groups:

docker exec -it security-kafka \
  /opt/bitnami/kafka/bin/kafka-consumer-groups.sh \
  --bootstrap-server localhost:9092 \
  --list

Describe the analysis consumer group:

docker exec -it security-kafka \
  /opt/bitnami/kafka/bin/kafka-consumer-groups.sh \
  --bootstrap-server localhost:9092 \
  --describe \
  --group security-analysis-local

The LAG column shows the number of records that have not yet been processed. On the local machine, lag should normally return to zero quickly after the application processes the test events.

Step 17: Verify Failure and Recovery Behavior

Stop InfluxDB:

docker compose stop influxdb

Send another matching event with a new event identifier. The analysis consumer cannot complete the observation write. The Kafka error handler retries twice and then publishes the failed record to the dead-letter topic. No automated device response should occur because the analysis stage did not complete successfully.

Inspect the dead-letter topic:

docker exec -it security-kafka \
  /opt/bitnami/kafka/bin/kafka-console-consumer.sh \
  --bootstrap-server localhost:9092 \
  --topic security.events.dead-letter.v1 \
  --from-beginning \
  --max-messages 1

Restart InfluxDB:

docker compose start influxdb

Wait until it is healthy:

docker compose ps

Dead-letter records are not replayed automatically in this sample. Automatic replay can create repeated failures or unintended actions. For local development, correct the dependency or payload problem first, inspect the dead-letter record, and then submit a new event with a new event identifier.

To test device-response failure without changing code, stop the Spring Boot application after a decision is published but before it is consumed, then restart it. Kafka retains the decision, and the response consumer processes it after startup. Deterministic command identifiers prevent duplicate simulator records if the decision is delivered again.

Step 18: Add Focused Rule Tests

Create src/test/java/com/example/security/service/SecurityRuleEngineTest.java:

package com.example.security.service;

import com.example.security.dto.ResponseDecision;
import com.example.security.dto.SecurityEvent;
import org.junit.jupiter.api.Test;

import java.time.Instant;
import java.util.Optional;

import static org.assertj.core.api.Assertions.assertThat;

class SecurityRuleEngineTest {

    private final SecurityRuleEngine engine = new SecurityRuleEngine(
        22,
        "HIGH",
        30,
        "tenant-a"
    );

    @Test
    void authorizesCriticalSshEvent() {
        SecurityEvent event = event(
            "event-test-1",
            "tenant-a",
            "203.0.113.50",
            22,
            "CRITICAL"
        );

        Optional<ResponseDecision> result = engine.evaluate(event);

        assertThat(result).isPresent();
        assertThat(result.orElseThrow().action())
            .isEqualTo("TEMPORARY_IP_BLOCK");
        assertThat(result.orElseThrow().durationMinutes())
            .isEqualTo(30);
    }

    @Test
    void ignoresMediumSeverityEvent() {
        SecurityEvent event = event(
            "event-test-2",
            "tenant-a",
            "203.0.113.60",
            22,
            "MEDIUM"
        );

        assertThat(engine.evaluate(event)).isEmpty();
    }

    @Test
    void ignoresAllowlistedSource() {
        SecurityEvent event = event(
            "event-test-3",
            "tenant-a",
            "192.0.2.10",
            22,
            "CRITICAL"
        );

        assertThat(engine.evaluate(event)).isEmpty();
    }

    @Test
    void createsSameDecisionIdForSameEventAndRuleVersion() {
        SecurityEvent event = event(
            "event-test-4",
            "tenant-a",
            "203.0.113.70",
            22,
            "HIGH"
        );

        String first = engine.evaluate(event).orElseThrow().decisionId();
        String second = engine.evaluate(event).orElseThrow().decisionId();

        assertThat(first).isEqualTo(second);
    }

    private SecurityEvent event(
        String eventId,
        String tenantId,
        String sourceIp,
        int destinationPort,
        String severity
    ) {
        return new SecurityEvent(
            eventId,
            tenantId,
            "firewall-hk-01",
            sourceIp,
            "10.10.20.15",
            destinationPort,
            "TCP",
            severity,
            "SUSPICIOUS_ACCESS",
            Instant.parse("2026-11-19T10:15:00Z"),
            Instant.parse("2026-11-19T10:15:01Z"),
            1
        );
    }
}

Run the tests:

mvn test

The tests verify the local policy boundary and deterministic decision identifier. They are development tests only and are not production acceptance tests.

Step 19: Adjust Local Rules Safely

Change the destination port rule in application.yml if another protocol should be demonstrated:

app:
  rules:
    blocked-port: 3389

This changes the test policy from SSH to Remote Desktop Protocol. Restart the application before sending new test events.

Change the minimum severity:

app:
  rules:
    minimum-severity: CRITICAL

Only critical events will then authorize a response.

Change the temporary block duration:

app:
  rules:
    block-duration-minutes: 10

The simulator will record a ten-minute expiration for newly created commands. Existing in-memory blocks are unchanged.

When rule logic changes materially, increment RULE_VERSION in SecurityRuleEngine. The version becomes part of the deterministic decision identifier and the audit context. A changed rule should not silently reuse the identity of an earlier decision model.

Keep allowlists owned and explicit. For the local sample, the allowlist is hard-coded for readability. In a larger development project, store it in a versioned configuration source with an owner, review date, and expiration policy.

Step 20: Reset and Stop the Local Environment

Clear all simulated firewall blocks:

curl -i -X DELETE http://localhost:8080/local-firewall/blocks

Stop the Spring Boot application with Ctrl+C.

Stop Kafka and InfluxDB while preserving local data:

docker compose stop

Restart the containers later:

docker compose start

Remove the containers while preserving their named volumes:

docker compose down

Remove the containers and all local Kafka and InfluxDB data:

docker compose down -v

After the volumes are removed, the next docker compose up -d initializes Kafka topics and InfluxDB again.

The completed local pipeline demonstrates the full closed loop without changing a real network device. Security observations enter through an API, Kafka preserves and distributes the events, InfluxDB stores event-time history, the rules engine evaluates explicit policy, the response consumer creates an idempotent command, the firewall simulator records a temporary block, and the result returns through Kafka as verified feedback. This separation provides a safe development foundation for adding richer temporal analysis, asset context, vulnerability context, AI-assisted investigation, and vendor-specific device adapters in later iterations.

📰 Read the original article on Dev.to Security

Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.