<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Okeoghene Akwerigbe</title>
    <description>The latest articles on DEV Community by Okeoghene Akwerigbe (@okeoghene_akwerigbe_a07a5).</description>
    <link>https://dev.to/okeoghene_akwerigbe_a07a5</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3903163%2Faca72602-9ff7-43c7-b286-a725297498f3.png</url>
      <title>DEV Community: Okeoghene Akwerigbe</title>
      <link>https://dev.to/okeoghene_akwerigbe_a07a5</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/okeoghene_akwerigbe_a07a5"/>
    <language>en</language>
    <item>
      <title>Multi-Layered Defense: Building an Intelligent, Dual-Trigger Firewall</title>
      <dc:creator>Okeoghene Akwerigbe</dc:creator>
      <pubDate>Wed, 29 Apr 2026 13:40:45 +0000</pubDate>
      <link>https://dev.to/okeoghene_akwerigbe_a07a5/multi-layered-defense-building-an-intelligent-dual-trigger-firewall-27kc</link>
      <guid>https://dev.to/okeoghene_akwerigbe_a07a5/multi-layered-defense-building-an-intelligent-dual-trigger-firewall-27kc</guid>
      <description>&lt;p&gt;In modern DevOps, a simple rate-limiter isn't enough. If you set a hard limit of "10 requests per second," what happens when your product goes viral and legitimate customers hit that limit? You end up blocking the exact people you want to serve. Professional security requires intelligence: systems that adapt to your traffic patterns and can tell the difference between a busy hour and a malicious botnet.&lt;/p&gt;

&lt;p&gt;For my &lt;strong&gt;HNG Stage 3&lt;/strong&gt; project, I decided to move beyond basic firewalls. I built a Python-based &lt;strong&gt;Anomaly Detection Engine&lt;/strong&gt; that uses a &lt;strong&gt;Dual-Trigger System&lt;/strong&gt; to protect a server in real-time.&lt;/p&gt;

&lt;p&gt;Here is a deep dive into the architecture, the math, and the automation behind it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. The Architecture: Real-Time Log Tailing&lt;/strong&gt;&lt;br&gt;
The foundation of the engine is a continuous loop that monitors the server's pulse. Instead of acting as a proxy that traffic must pass through (which can slow things down), this engine sits entirely out of the way.&lt;/p&gt;

&lt;p&gt;It uses a Python script to "tail" Nginx JSON access logs asynchronously. The moment a request hits Nginx, my script reads the log entry, extracts the IP address, and immediately begins evaluating it. This means the engine is lightweight and doesn't add any latency to the actual web application.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzudjtlmgtseh9s8e66yv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzudjtlmgtseh9s8e66yv.png" alt="Python Script tailing logs running" width="800" height="165"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. The Dual-Trigger System&lt;/strong&gt;&lt;br&gt;
What makes this engine robust is that it doesn't rely on a single point of failure. It evaluates every IP address through two distinct logic paths simultaneously.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Trigger A: The Statistical "Brain" (Z-Score)&lt;/strong&gt;&lt;br&gt;
This trigger is designed to catch "stealthy" attacks—bots that scrape your site slowly to avoid triggering basic alarms. It works by calculating a &lt;strong&gt;Baseline Mean&lt;/strong&gt; (your historical average traffic) and a &lt;strong&gt;Standard Deviation&lt;/strong&gt; (the normal "wobble" or fluctuation of your traffic).&lt;/p&gt;

&lt;p&gt;The engine evaluates incoming traffic using the Z-Score formula:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fw0al4zgdprkddqvcaxzg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fw0al4zgdprkddqvcaxzg.png" alt="Z-Score formula" width="800" height="115"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In statistics, 99.7% of all normal activity falls within a Z-Score of 3.0. Therefore, if an IP's traffic generates a Z-Score of 3.0 (which my engine frequently caught during testing), the system mathematically proves this isn't a normal user—it’s an anomaly.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Trigger B: The Volumetric "Shield" (Rate Multiplier)&lt;/strong&gt;&lt;br&gt;
While the Z-Score is brilliant for complex patterns, it takes a few seconds of data to calculate. What if an attacker tries to crash the server instantly with a massive flood of traffic?&lt;/p&gt;

&lt;p&gt;That is where the &lt;strong&gt;Rate Multiplier&lt;/strong&gt; comes in. This is a fail-safe configured with a multiplier of 5. It constantly compares the current traffic to the baseline. If your normal traffic is 1.0 request per second, and an IP suddenly spikes to over 5.0 requests per second, this trigger trips immediately. It acts as an emergency brake before the Z-Score even has time to finish its math.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frvmzmhqqgmjdw4vv4sa6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frvmzmhqqgmjdw4vv4sa6.png" alt="Screenshot showing Rate Multiplier and Z-score" width="800" height="177"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Automated Response: iptables and Docker Routing&lt;/strong&gt;&lt;br&gt;
Detecting a threat is only half the battle; the system must neutralize it without human intervention.&lt;/p&gt;

&lt;p&gt;When a trigger fires, the Python engine communicates directly with the Linux kernel's firewall (iptables). However, because modern applications run inside Docker containers, standard firewall rules often fail. Docker aggressively rewrites network rules, which means blocking an IP on the standard INPUT chain won't work—the traffic will slip right past it.&lt;/p&gt;

&lt;p&gt;To solve this, my engine targets the DOCKER-USER chain. By inserting a DROP rule here, the malicious IP is blocked at the lowest possible kernel level before the traffic is even allowed to route toward the Docker container.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Escalation Ladder&lt;/strong&gt;&lt;br&gt;
Security shouldn't be entirely unforgiving. I programmed an automated background worker (the "Unbanner") to manage a backoff schedule:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;First Offense:&lt;/strong&gt; The IP is banned for exactly 10 minutes to cool off.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Repeat Offenses:&lt;/strong&gt; If the IP returns and attacks again, the penalty increases to 30 minutes, and then 2 hours .&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Final Strike:&lt;/strong&gt; On the fourth offense, the engine flags the IP as purely hostile and issues a PERMANENT ban (999,999 minutes).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. Full Visibility: Live Dashboards &amp;amp; Instant Alerts&lt;/strong&gt;&lt;br&gt;
You can't secure what you can't see. To ensure the engine was performing correctly, I built a full observability suite.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Live Metrics:&lt;/strong&gt; A web dashboard that plots a sliding window of the Current Requests Per Second against the Baseline Mean, making it incredibly easy to visualize traffic spikes in real-time.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Active Threats:&lt;/strong&gt; A "Currently Banned" panel that lists the IPs currently sitting in the iptables penalty box.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Slack Webhooks:&lt;/strong&gt; Every time a block occurs, the engine constructs a JSON payload and fires it to a Slack channel. The alert details the offending IP, the exact trigger that caught them (e.g., Rate Multiplier), and how long they are banned for.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fh5pvlt5x6ih8e19i25e8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fh5pvlt5x6ih8e19i25e8.png" alt="Dashboard" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;br&gt;
Building this engine fundamentally changed how I view server security. Moving from static, hard-coded rules to dynamic, math-driven logic allows us to build systems that scale securely. The &lt;strong&gt;Dual-Trigger System&lt;/strong&gt; covers both bases: the Z-Score outsmarts the slow, sneaky attacks, while the Rate Multiplier stops brute-force floods dead in their tracks.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Check out the live metrics dashboard at:&lt;/strong&gt; metrics.okeakwerigbe.name.ng&lt;/p&gt;

</description>
      <category>ai</category>
      <category>devops</category>
      <category>python</category>
      <category>security</category>
    </item>
  </channel>
</rss>
