<?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: Mohammed Armaan</title>
    <description>The latest articles on DEV Community by Mohammed Armaan (@mohammed_armaan_51c01b74e).</description>
    <link>https://dev.to/mohammed_armaan_51c01b74e</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.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3366382%2F7b73d190-49ce-42b4-b4ab-61838b0017a4.png</url>
      <title>DEV Community: Mohammed Armaan</title>
      <link>https://dev.to/mohammed_armaan_51c01b74e</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/mohammed_armaan_51c01b74e"/>
    <language>en</language>
    <item>
      <title>Automating CIS Level 1 Security Hardening &amp; Drift Compliance Across AWS EC2 Ubuntu Fleets</title>
      <dc:creator>Mohammed Armaan</dc:creator>
      <pubDate>Sat, 14 Nov 2026 03:50:25 +0000</pubDate>
      <link>https://dev.to/mohammed_armaan_51c01b74e/automating-cis-level-1-security-hardening-drift-compliance-across-aws-ec2-ubuntu-fleets-4ce</link>
      <guid>https://dev.to/mohammed_armaan_51c01b74e/automating-cis-level-1-security-hardening-drift-compliance-across-aws-ec2-ubuntu-fleets-4ce</guid>
      <description>&lt;p&gt;When you provision a fleet of &lt;strong&gt;Amazon EC2 Ubuntu 22.04 or 24.04 LTS&lt;/strong&gt; instances inside an AWS VPC, the &lt;strong&gt;AWS Shared Responsibility Model&lt;/strong&gt; draws a strict line: AWS secures the underlying physical data centers and hypervisor, while &lt;strong&gt;you&lt;/strong&gt; are responsible for securing the guest operating system.&lt;/p&gt;

&lt;p&gt;Out of the box, default cloud Linux images prioritize convenience over zero-trust security:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;OpenSSH often permits weak authentication defaults or generous retry limits (&lt;code&gt;MaxAuthTries&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;Kernel network parameters (&lt;code&gt;sysctl&lt;/code&gt;) may allow IP spoofing, ICMP redirects, or unhardened packet forwarding.&lt;/li&gt;
&lt;li&gt;Host-level firewalls (&lt;code&gt;UFW&lt;/code&gt;) sit inactive, relying purely on external security groups without defense-in-depth at the OS layer.&lt;/li&gt;
&lt;li&gt;Worse, when engineers manually SSH into an EC2 instance to debug an issue, &lt;strong&gt;configuration drift&lt;/strong&gt; silently weakens your security posture across the fleet.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In my previous articles, I covered &lt;a href="https://dev.to/mohammed_armaan_51c01b74e/how-i-built-a-shift-left-devsecops-pipeline-for-fastapi-kubernetes-and-caught-3-real-g8k"&gt;eliminating container CVEs in a shift-left FastAPI DevSecOps pipeline&lt;/a&gt; and &lt;a href="https://builder.aws.com/content/3LtoKaWNWXYLGeCJSoIJoGIM2gf/how-i-cut-aws-eks-infrastructure-costs-by-381percent-with-terraform-spot-nodes-and-an-automated-python-finops-gate-plus-argo-cd-gitops" rel="noopener noreferrer"&gt;cutting Amazon EKS &amp;amp; VPC infrastructure costs by 38.1% with Terraform and an automated Python FinOps gate&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;In this third guide (&lt;a href="https://github.com/mohammedarmaan936-sketch/ansible-linux-cis-hardening" rel="noopener noreferrer"&gt;&lt;strong&gt;&lt;code&gt;ansible-linux-cis-hardening&lt;/code&gt;&lt;/strong&gt;&lt;/a&gt;), I built an automated, idempotent &lt;strong&gt;Ansible CIS Ubuntu Level 1 Hardening Role&lt;/strong&gt; paired with a &lt;strong&gt;zero-dependency Python Compliance &amp;amp; Drift Scanner&lt;/strong&gt; inside a 4-stage &lt;strong&gt;GitHub Actions&lt;/strong&gt; pipeline to lock down AWS EC2 Ubuntu fleets automatically.&lt;/p&gt;




&lt;h2&gt;
  
  
  Architecture: How Fleet Hardening &amp;amp; CI/CD Drift Verification Work
&lt;/h2&gt;

&lt;p&gt;In a real AWS production environment, EC2 instances scale dynamically and change private IP addresses over time. Rather than maintaining static IP lists or manually SSH-ing into hosts, this platform combines &lt;strong&gt;AWS EC2 Tag-Based Targeting&lt;/strong&gt; with a &lt;strong&gt;4-Gate CI/CD Verification Pipeline&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;┌────────────────────────────────────────────────────────────────────────────────────┐
│                    GitHub Actions 4-Gate CI/CD Pipeline                            │
│                                                                                    │
│ [Gate 1: Lint] ──► [Gate 2: Dry-Run] ──► [Gate 3: Idempotency] ──► [Gate 4: Audit]  │
│  ansible-lint       Apply CIS Role        Re-run Playbook:          Python 100%    │
│  &amp;amp; YAML Syntax      on Ubuntu Host        Verify changed=0          Compliance    │
│                     Container                                            Audit    │
└────────────────────────────────────────────┬───────────────────────────────────────┘
                                             │ Verified Playbook &amp;amp; Role
                                             ▼
┌────────────────────────────────────────────────────────────────────────────────────┐
│                         AWS Cloud — EC2 Ubuntu Fleet                               │
│                                                                                    │
│  ┌──────────────────────┐  ┌──────────────────────┐  ┌──────────────────────┐      │
│  │ EC2 Web Fleet        │  │ EC2 Worker Nodes     │  │ EC2 Bastion/Ops      │      │
│  │ Tag: Role=web-prod   │  │ Tag: Role=eks-node   │  │ Tag: Env=prod        │      │
│  ├──────────────────────┤  ├──────────────────────┤  ├──────────────────────┤      │
│  │ • SSH Key-Only Auth  │  │ • Kernel sysctl Lock │  │ • UFW Default        │      │
│  │ • Root Login Blocked │  │ • ASLR &amp;amp; SYN Cookies │  │   Deny Incoming      │      │
│  │ • /etc/shadow 0600   │  │ • IP Forward = 0     │  │ • Audit Scanner      │      │
│  └──────────────────────┘  └──────────────────────┘  └──────────────────────┘      │
└────────────────────────────────────────────────────────────────────────────────────┘
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Layer 1: Enforcing 18+ CIS Level 1 Controls with an Idempotent Ansible Role
&lt;/h2&gt;

&lt;p&gt;The core automation lives inside &lt;code&gt;roles/cis_ubuntu_hardening/&lt;/code&gt;, broken into modular, idempotent task files covering four critical security domains across Ubuntu 22.04 and 24.04 EC2 instances:&lt;/p&gt;

&lt;h3&gt;
  
  
  1. OpenSSH Daemon Hardening (&lt;code&gt;tasks/ssh.yml&lt;/code&gt;)
&lt;/h3&gt;

&lt;p&gt;Brute-force credential stuffing and root SSH logins are the #1 attack vector against cloud Linux hosts. Our Ansible role enforces strict CIS Level 1 OpenSSH configurations inside &lt;code&gt;/etc/ssh/sshd_config&lt;/code&gt; and validates the config syntax (&lt;code&gt;sshd -t -f %s&lt;/code&gt;) before restarting the service:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"CIS 5.2.x | Enforce Hardened OpenSSH Daemon Configuration"&lt;/span&gt;
  &lt;span class="na"&gt;ansible.builtin.lineinfile&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;/etc/ssh/sshd_config&lt;/span&gt;
    &lt;span class="na"&gt;regexp&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"{{ item.regexp }}"&lt;/span&gt;
    &lt;span class="na"&gt;line&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"{{ item.line }}"&lt;/span&gt;
    &lt;span class="na"&gt;state&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;present&lt;/span&gt;
    &lt;span class="na"&gt;validate&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"/usr/sbin/sshd -t -f %s"&lt;/span&gt;
  &lt;span class="na"&gt;loop&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="s"&gt;regexp:&lt;/span&gt; &lt;span class="s1"&gt;'^#?PermitRootLogin'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;line:&lt;/span&gt; &lt;span class="s1"&gt;'PermitRootLogin no'&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="s"&gt;regexp:&lt;/span&gt; &lt;span class="s1"&gt;'^#?PasswordAuthentication'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;line:&lt;/span&gt; &lt;span class="s1"&gt;'PasswordAuthentication no'&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="s"&gt;regexp:&lt;/span&gt; &lt;span class="s1"&gt;'^#?PermitEmptyPasswords'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;line:&lt;/span&gt; &lt;span class="s1"&gt;'PermitEmptyPasswords no'&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="s"&gt;regexp:&lt;/span&gt; &lt;span class="s1"&gt;'^#?MaxAuthTries'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;line:&lt;/span&gt; &lt;span class="s1"&gt;'MaxAuthTries 3'&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="s"&gt;regexp:&lt;/span&gt; &lt;span class="s1"&gt;'^#?ClientAliveInterval'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;line:&lt;/span&gt; &lt;span class="s1"&gt;'ClientAliveInterval 300'&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="s"&gt;regexp:&lt;/span&gt; &lt;span class="s1"&gt;'^#?ClientAliveCountMax'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;line:&lt;/span&gt; &lt;span class="s1"&gt;'ClientAliveCountMax 2'&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="s"&gt;regexp:&lt;/span&gt; &lt;span class="s1"&gt;'^#?X11Forwarding'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;line:&lt;/span&gt; &lt;span class="s1"&gt;'X11Forwarding no'&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="na"&gt;notify&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Restart sshd&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  2. Kernel &amp;amp; Network Stack Hardening (&lt;code&gt;tasks/sysctl.yml&lt;/code&gt;)
&lt;/h3&gt;

&lt;p&gt;Even inside an AWS VPC with Security Groups, host-level network stacks must be hardened against man-in-the-middle ICMP redirects, source-routed packets, and SYN flood denial-of-service attacks.&lt;/p&gt;

&lt;p&gt;We enforce persistent kernel parameters across &lt;code&gt;/etc/sysctl.d/99-cis-hardening.conf&lt;/code&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;net.ipv4.tcp_syncookies = 1&lt;/code&gt; — Protects the EC2 instance against TCP SYN flood attacks.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;net.ipv4.ip_forward = 0&lt;/code&gt; — Prevents non-router EC2 instances from forwarding unauthorized packets between interfaces.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;net.ipv4.conf.all.accept_redirects = 0&lt;/code&gt; &amp;amp; &lt;code&gt;send_redirects = 0&lt;/code&gt; — Blocks malicious ICMP routing table manipulation.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;net.ipv4.conf.all.rp_filter = 1&lt;/code&gt; — Enforces Reverse Path Filtering to drop spoofed source IPs.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;kernel.randomize_va_space = 2&lt;/code&gt; — Enforces full Address Space Layout Randomization (ASLR) to mitigate buffer-overflow exploits.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  3. Host Firewall Defense-in-Depth (&lt;code&gt;tasks/firewall.yml&lt;/code&gt;)
&lt;/h3&gt;

&lt;p&gt;Relying solely on AWS Security Groups means a single overly permissive Terraform rule exposes every port on the instance.&lt;/p&gt;

&lt;p&gt;We configure UFW (Uncomplicated Firewall) directly on the EC2 host to enforce a zero-trust baseline:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Default Incoming Policy:&lt;/strong&gt; deny&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Default Outgoing Policy:&lt;/strong&gt; allow&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;SSH Rate-Limiting:&lt;/strong&gt; Explicitly rate-limits 22/tcp (&lt;code&gt;ufw limit 22/tcp&lt;/code&gt;) to throttle automated connection bursts.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  4. Filesystem &amp;amp; Identity Lockdown (&lt;code&gt;tasks/filesystem.yml&lt;/code&gt;)
&lt;/h3&gt;

&lt;p&gt;To prevent local privilege escalation if a container or application process is compromised, the role locks down critical identity files and disables legacy kernel filesystem modules:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Enforces &lt;code&gt;0600&lt;/code&gt; (&lt;code&gt;root:root&lt;/code&gt;) permissions on &lt;code&gt;/etc/shadow&lt;/code&gt; and &lt;code&gt;/etc/gshadow&lt;/code&gt; so password hashes can never be read by non-root users.&lt;/li&gt;
&lt;li&gt;Enforces &lt;code&gt;0644&lt;/code&gt; (&lt;code&gt;root:root&lt;/code&gt;) on &lt;code&gt;/etc/passwd&lt;/code&gt; and &lt;code&gt;/etc/group&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Disables unused legacy filesystems (&lt;code&gt;cramfs&lt;/code&gt;, &lt;code&gt;freevxfs&lt;/code&gt;, &lt;code&gt;jffs2&lt;/code&gt;, &lt;code&gt;hfs&lt;/code&gt;, &lt;code&gt;hfsplus&lt;/code&gt;, &lt;code&gt;udf&lt;/code&gt;) via &lt;code&gt;/etc/modprobe.d/cis-filesystems.conf&lt;/code&gt; and restricts core dumps.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Layer 2: Targeting Dynamic AWS EC2 Fleets at Scale
&lt;/h2&gt;

&lt;p&gt;In a 500-instance AWS environment, EC2 instances are frequently replaced by Auto Scaling Groups, changing their IP addresses.&lt;/p&gt;

&lt;p&gt;Rather than hardcoding static IPs in &lt;code&gt;inventory/hosts.ini&lt;/code&gt;, Ansible pairs with the AWS EC2 Dynamic Inventory plugin (&lt;code&gt;amazon.aws.aws_ec2&lt;/code&gt;) to query the AWS API in real time by resource tags.&lt;/p&gt;

&lt;p&gt;Whether we want to roll out CIS hardening across the entire cloud fleet or target a specific subset of 100 production web servers in rolling waves (&lt;code&gt;serial&lt;/code&gt;), we can scope execution dynamically:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Apply CIS Level 1 hardening across ALL tagged EC2 Ubuntu instances&lt;/span&gt;
ansible-playbook -i inventory/aws_ec2.yml site.yml

&lt;span class="c"&gt;# Target ONLY the web-server fleet using --limit&lt;/span&gt;
ansible-playbook -i inventory/aws_ec2.yml site.yml --limit tag_Role_web_prod

&lt;span class="c"&gt;# Target a canary slice of the first 100 servers (0 to 99) before full rollout&lt;/span&gt;
ansible-playbook -i inventory/aws_ec2.yml site.yml --limit &lt;span class="s1"&gt;'tag_Env_prod'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Layer 3: Automated Python Compliance &amp;amp; Drift Scanner (&lt;code&gt;cis_compliance_audit.py&lt;/code&gt;)
&lt;/h2&gt;

&lt;p&gt;Applying a security playbook once is only half the battle—how do you prove to security auditors (SOC 2, ISO 27001, or internal Cloud SecOps) that zero configuration drift has occurred?&lt;/p&gt;

&lt;p&gt;I built a zero-dependency Python 3 audit tool (&lt;code&gt;scripts/cis_compliance_audit.py&lt;/code&gt;) that inspects live Linux system state across all 18 CIS Level 1 controls, outputs a structured JSON compliance artifact, and fails the CI/CD pipeline (exit code 1) if compliance drops below 100%:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;CIS Control ID&lt;/th&gt;
&lt;th&gt;Security Check Audited&lt;/th&gt;
&lt;th&gt;Expected State&lt;/th&gt;
&lt;th&gt;Severity&lt;/th&gt;
&lt;th&gt;Status&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;CIS-5.2.8&lt;/td&gt;
&lt;td&gt;SSH PermitRootLogin disabled&lt;/td&gt;
&lt;td&gt;no&lt;/td&gt;
&lt;td&gt;CRITICAL&lt;/td&gt;
&lt;td&gt;PASS&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;CIS-5.2.12&lt;/td&gt;
&lt;td&gt;SSH PasswordAuthentication disabled&lt;/td&gt;
&lt;td&gt;no&lt;/td&gt;
&lt;td&gt;CRITICAL&lt;/td&gt;
&lt;td&gt;PASS&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;CIS-5.2.7&lt;/td&gt;
&lt;td&gt;SSH MaxAuthTries threshold&lt;/td&gt;
&lt;td&gt;&amp;lt;= 3&lt;/td&gt;
&lt;td&gt;HIGH&lt;/td&gt;
&lt;td&gt;PASS&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;CIS-3.1.1&lt;/td&gt;
&lt;td&gt;IPv4 Packet Forwarding (ip_forward)&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;HIGH&lt;/td&gt;
&lt;td&gt;PASS&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;CIS-3.3.8&lt;/td&gt;
&lt;td&gt;TCP SYN Cookies (tcp_syncookies)&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;HIGH&lt;/td&gt;
&lt;td&gt;PASS&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;CIS-3.3.2&lt;/td&gt;
&lt;td&gt;ICMP Redirect Acceptance (accept_redirects)&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;MEDIUM&lt;/td&gt;
&lt;td&gt;PASS&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;CIS-1.5.2&lt;/td&gt;
&lt;td&gt;Kernel ASLR (randomize_va_space)&lt;/td&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;HIGH&lt;/td&gt;
&lt;td&gt;PASS&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;CIS-6.1.2&lt;/td&gt;
&lt;td&gt;/etc/passwd permissions &amp;amp; owner&lt;/td&gt;
&lt;td&gt;0644 root:root&lt;/td&gt;
&lt;td&gt;CRITICAL&lt;/td&gt;
&lt;td&gt;PASS&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;CIS-6.1.3&lt;/td&gt;
&lt;td&gt;/etc/shadow permissions &amp;amp; owner&lt;/td&gt;
&lt;td&gt;0600 root:root&lt;/td&gt;
&lt;td&gt;CRITICAL&lt;/td&gt;
&lt;td&gt;PASS&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;CIS-1.1.1&lt;/td&gt;
&lt;td&gt;Unused Filesystems (cramfs, udf)&lt;/td&gt;
&lt;td&gt;install /bin/true&lt;/td&gt;
&lt;td&gt;MEDIUM&lt;/td&gt;
&lt;td&gt;PASS&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;
  
  
  Layer 4: The 4-Gate GitHub Actions Verification Pipeline
&lt;/h2&gt;

&lt;p&gt;Every commit and Pull Request in &lt;code&gt;.github/workflows/cis-hardening-ci.yml&lt;/code&gt; must pass four automated verification gates before any playbook change is allowed into main:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Gate 1 — Static Linting &amp;amp; Syntax Check:&lt;/strong&gt; Runs &lt;code&gt;yamllint&lt;/code&gt;, &lt;code&gt;ansible-lint&lt;/code&gt;, and &lt;code&gt;ansible-playbook --syntax-check&lt;/code&gt; to catch malformed YAML or deprecated Ansible modules.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Gate 2 — Live Ubuntu Container Convergence:&lt;/strong&gt; Spins up a clean Ubuntu container, executes &lt;code&gt;site.yml&lt;/code&gt; to apply all 18+ CIS hardening controls, and verifies zero failed tasks.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Gate 3 — Strict Idempotency Test (&lt;code&gt;changed=0&lt;/code&gt;):&lt;/strong&gt; Runs &lt;code&gt;ansible-playbook site.yml&lt;/code&gt; a second consecutive time against the already-hardened host. If any task reports &lt;code&gt;changed &amp;gt; 0&lt;/code&gt;, the pipeline fails—guaranteeing the role is 100% idempotent and safe to run on production EC2 cron schedules without disrupting running services.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Gate 4 — 100% CIS Compliance Gate:&lt;/strong&gt; Executes &lt;code&gt;python3 scripts/cis_compliance_audit.py&lt;/code&gt; against the hardened environment and enforces a 100.0% pass rate before unlocking the PR merge button.&lt;/p&gt;

&lt;h2&gt;
  
  
  Try It Yourself (Open-Source Repository)
&lt;/h2&gt;

&lt;p&gt;You can clone the full Ansible role, Python CIS compliance scanner, and 4-gate GitHub Actions pipeline to test locally in Docker or adapt for your own AWS EC2 Ubuntu fleets:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Part 3 Repository (Ansible Linux CIS Hardening &amp;amp; Drift Scanner):&lt;/strong&gt; &lt;a href="https://github.com/mohammedarmaan936-sketch/ansible-linux-cis-hardening" rel="noopener noreferrer"&gt;github.com/mohammedarmaan936-sketch/ansible-linux-cis-hardening&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Part 2 Repository (AWS EKS, Terraform, FinOps Gate &amp;amp; Argo CD):&lt;/strong&gt; &lt;a href="https://github.com/mohammedarmaan936-sketch/cloudpulse-eks-gitops-infra" rel="noopener noreferrer"&gt;github.com/mohammedarmaan936-sketch/cloudpulse-eks-gitops-infra&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Part 1 Repository (FastAPI Microservice &amp;amp; Hardened Docker CI/CD):&lt;/strong&gt; &lt;a href="https://github.com/mohammedarmaan936-sketch/cloudpulse-devsecops-service" rel="noopener noreferrer"&gt;github.com/mohammedarmaan936-sketch/cloudpulse-devsecops-service&lt;/a&gt;&lt;/p&gt;

</description>
      <category>devops</category>
      <category>devsecops</category>
      <category>linux</category>
      <category>ansible</category>
    </item>
    <item>
      <title>How I Cut AWS EKS Infrastructure Costs by 38.1% with Terraform, Spot Nodes, and an Automated Python FinOps Gate (Plus Argo CD GitOps)</title>
      <dc:creator>Mohammed Armaan</dc:creator>
      <pubDate>Tue, 10 Nov 2026 04:13:28 +0000</pubDate>
      <link>https://dev.to/mohammed_armaan_51c01b74e/how-i-cut-aws-eks-infrastructure-costs-by-381-with-terraform-spot-nodes-and-an-automated-python-jbo</link>
      <guid>https://dev.to/mohammed_armaan_51c01b74e/how-i-cut-aws-eks-infrastructure-costs-by-381-with-terraform-spot-nodes-and-an-automated-python-jbo</guid>
      <description>&lt;h1&gt;
  
  
  Production-Ready AWS EKS with Terraform, GitOps, DevSecOps &amp;amp; FinOps
&lt;/h1&gt;

&lt;p&gt;Spinning up a textbook production Kubernetes cluster on AWS is deceptively expensive.&lt;/p&gt;

&lt;p&gt;Between the Amazon EKS control plane ($73.00/month), redundant multi-AZ NAT Gateways ($65.70/month), On-Demand EC2 worker nodes ($60.74/month), and cross-AZ data transfer fees, an idle baseline cluster can easily burn $240.00/month before serving a single real user.&lt;/p&gt;

&lt;p&gt;Worse, once a team starts shipping Terraform changes through Pull Requests, a single unreviewed instance resize or additional NAT Gateway can increase the monthly AWS bill overnight.&lt;/p&gt;

&lt;p&gt;In &lt;a href="https://github.com/mohammedarmaan936-sketch/cloudpulse-devsecops-service" rel="noopener noreferrer"&gt;Part 1 of the CloudPulse series&lt;/a&gt;, I built a hardened, non-root FastAPI chaos microservice and a shift-left DevSecOps pipeline that eliminated 3 HIGH-severity container CVEs before publishing the verified image to GHCR.&lt;/p&gt;

&lt;p&gt;In Part 2, I built the production AWS landing zone, FinOps cost-governance gate, Argo CD GitOps controller, and Prometheus/Grafana observability stack to run that container in production.&lt;/p&gt;

&lt;p&gt;The result? A &lt;strong&gt;38.1% reduction in estimated baseline AWS infrastructure spending&lt;/strong&gt;, bringing monthly costs down from $240.00 to $148.60.&lt;/p&gt;

&lt;p&gt;This article breaks down the complete four-layer AWS architecture and how every component is enforced automatically through CI/CD.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Part 2 Repository:&lt;/strong&gt; &lt;a href="https://github.com/mohammedarmaan936-sketch/cloudpulse-eks-gitops-infra" rel="noopener noreferrer"&gt;cloudpulse-eks-gitops-infra&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  Architecture Overview: The Four Production Layers
&lt;/h2&gt;

&lt;p&gt;Why separate the application repository (&lt;code&gt;cloudpulse-devsecops-service&lt;/code&gt;) from the infrastructure repository (&lt;code&gt;cloudpulse-eks-gitops-infra&lt;/code&gt;)?&lt;/p&gt;

&lt;p&gt;Following the enterprise GitOps pattern prevents infinite CI/CD loops, isolates IAM permissions between application developers and platform engineers, and creates a clean audit trail where every infrastructure change is a standalone Git commit.&lt;/p&gt;

&lt;p&gt;Our infrastructure repository wraps the verified container image in four layers:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Layer 1 — AWS Cloud Networking, EKS Compute &amp;amp; IAM (Terraform)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A custom &lt;code&gt;10.0.0.0/16&lt;/code&gt; VPC across &lt;code&gt;ap-south-1a&lt;/code&gt; and &lt;code&gt;ap-south-1b&lt;/code&gt;, a KMS-encrypted Amazon EKS v1.31 cluster, EC2 Spot/hybrid managed node groups, and scoped IAM roles.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Layer 2 — Shift-Left FinOps &amp;amp; IaC Security Gates (GitHub Actions)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Automated &lt;code&gt;terraform validate&lt;/code&gt;, Trivy IaC scanning, Kubeconform strict schema checks, and a custom Python FinOps script that blocks Pull Requests exceeding a $250.00/month AWS budget.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Layer 3 — Zero-Touch GitOps &amp;amp; Self-Healing (Argo CD + Kubernetes HPA)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Continuous reconciliation watching &lt;code&gt;k8s/base/&lt;/code&gt; with &lt;code&gt;selfHeal: true&lt;/code&gt; and &lt;code&gt;prune: true&lt;/code&gt;, paired with a HorizontalPodAutoscaler scaling from 2 to 6 replicas during traffic surges.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Layer 4 — Real-Time Flash-Sale Observability (Prometheus + Grafana)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Custom PromQL telemetry tracking request rates, pod readiness, and flash-sale surge events with a 5-second dashboard refresh interval.&lt;/p&gt;




&lt;h2&gt;
  
  
  Layer 1: AWS VPC Networking, EKS Compute &amp;amp; IAM
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Building the AWS VPC with Terraform
&lt;/h3&gt;

&lt;p&gt;In &lt;code&gt;terraform/vpc.tf&lt;/code&gt;, we provision an isolated &lt;code&gt;10.0.0.0/16&lt;/code&gt; Virtual Private Cloud in &lt;code&gt;ap-south-1&lt;/code&gt;, spanning two Availability Zones.&lt;/p&gt;

&lt;p&gt;The network consists of:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;2 Public Subnets (&lt;code&gt;10.0.1.0/24&lt;/code&gt; and &lt;code&gt;10.0.2.0/24&lt;/code&gt;):&lt;/strong&gt; Tagged with &lt;code&gt;kubernetes.io/role/elb&lt;/code&gt; for public ingress load balancers and routed through an Internet Gateway.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;2 Private Subnets (&lt;code&gt;10.0.10.0/24&lt;/code&gt; and &lt;code&gt;10.0.20.0/24&lt;/code&gt;):&lt;/strong&gt; Tagged with &lt;code&gt;kubernetes.io/role/internal-elb&lt;/code&gt;, where EKS worker nodes run without direct public internet access.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Zero-Trust Security Groups &amp;amp; VPC Flow Logs:&lt;/strong&gt; The default VPC security group is stripped of all rules, control-plane ingress is restricted to HTTPS within the VPC CIDR, and network traffic is logged to Amazon CloudWatch Logs with KMS encryption and 30-day retention.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  AWS VPC Resource Map
&lt;/h3&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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fd1jj2ye76qwsrb6i58ml.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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fd1jj2ye76qwsrb6i58ml.png" alt="AWS VPC Resource Map" width="798" height="212"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is the AWS Console VPC Resource Map provisioned through Terraform, showing the VPC, public and private subnets across two Availability Zones, route tables, and Internet Gateway routing.&lt;/p&gt;

&lt;h3&gt;
  
  
  FinOps Networking Optimization: Shared Single-AZ NAT Gateway
&lt;/h3&gt;

&lt;p&gt;A standard multi-AZ NAT Gateway deployment costs $65.70/month in fixed hourly charges, in addition to cross-AZ data processing fees.&lt;/p&gt;

&lt;p&gt;For this workload tier, I implemented a &lt;strong&gt;Single-AZ Shared NAT Gateway + Elastic IP architecture&lt;/strong&gt;, routing egress traffic (container image pulls from &lt;code&gt;ghcr.io&lt;/code&gt; and AWS API calls) from both private subnets through a single optimized NAT tier.&lt;/p&gt;

&lt;p&gt;This architectural choice:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Cuts fixed NAT costs by 50% (-$32.85/month).&lt;/li&gt;
&lt;li&gt;Reduces cross-AZ data transfer overhead by 86.5% (-$22.11/month).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Hardened Amazon EKS v1.31 &amp;amp; Least-Privilege IAM
&lt;/h3&gt;

&lt;p&gt;Rather than relying on overly permissive default IAM policies, &lt;code&gt;terraform/iam.tf&lt;/code&gt; provisions three strictly scoped IAM roles:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. &lt;code&gt;control-plane-role&lt;/code&gt; (&lt;code&gt;eks.amazonaws.com&lt;/code&gt;)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Attached exclusively to &lt;code&gt;AmazonEKSClusterPolicy&lt;/code&gt; and &lt;code&gt;AmazonEKSVPCResourceController&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. &lt;code&gt;worker-node-role&lt;/code&gt; (&lt;code&gt;ec2.amazonaws.com&lt;/code&gt;)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Scoped strictly to worker node container runtime and CNI networking policies.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. &lt;code&gt;vpc-flow-log-role&lt;/code&gt; (&lt;code&gt;vpc-flow-logs.amazonaws.com&lt;/code&gt;)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Scoped only to publishing network audit streams to CloudWatch.&lt;/p&gt;

&lt;h3&gt;
  
  
  AWS IAM Roles Overview
&lt;/h3&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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fv979tav6piuksdzi3x47.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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fv979tav6piuksdzi3x47.png" alt="AWS IAM Roles Overview" width="800" height="418"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Three isolated IAM roles created through Terraform, separating control-plane, worker-node, and VPC Flow Logs permissions.&lt;/p&gt;

&lt;p&gt;In &lt;code&gt;terraform/eks.tf&lt;/code&gt;, the Amazon EKS v1.31 cluster (&lt;code&gt;cloudpulse-eks-prod&lt;/code&gt;) and its managed node group enforce defense-in-depth at the infrastructure layer.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;KMS Envelope Encryption&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Kubernetes secrets are encrypted at rest using a dedicated AWS KMS Customer Managed Key with automatic yearly key rotation enabled.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Private-Only API Endpoint &amp;amp; Control Plane Logging&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;All five EKS control-plane audit and diagnostic log streams are enabled by default.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Hardened EC2 Launch Templates&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Worker nodes enforce IMDSv2 (&lt;code&gt;http_tokens = "required"&lt;/code&gt; to block SSRF metadata attacks), run on encrypted &lt;code&gt;gp3&lt;/code&gt; EBS volumes with no public IPs, and utilize EC2 Spot (&lt;code&gt;t3.medium&lt;/code&gt;) capacity to cut compute spending by 60% (-$36.44/month).&lt;/p&gt;

&lt;h3&gt;
  
  
  AWS IAM Control Plane Role Verification
&lt;/h3&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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fqa3macow93wan0nwr7vj.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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fqa3macow93wan0nwr7vj.png" alt="AWS IAM Control Plane Role" width="800" height="445"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This screenshot verifies the control-plane role and its two attached AWS-managed policies: &lt;code&gt;AmazonEKSClusterPolicy&lt;/code&gt; and &lt;code&gt;AmazonEKSVPCResourceController&lt;/code&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  Layer 2: Shift-Left FinOps &amp;amp; IaC Security Gates
&lt;/h2&gt;

&lt;p&gt;Most teams only discover cloud cost drift when the AWS invoice arrives at the end of the month.&lt;/p&gt;

&lt;p&gt;To shift FinOps left, I wrote a zero-dependency Python 3 cost-governance scanner (&lt;code&gt;scripts/finops_cost_guard.py&lt;/code&gt;) that runs on every Pull Request inside &lt;code&gt;.github/workflows/iac-gitops-ci.yml&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Alongside Terraform validation (&lt;code&gt;terraform fmt&lt;/code&gt; and &lt;code&gt;validate&lt;/code&gt;), Trivy IaC security scanning (blocking HIGH or CRITICAL misconfigurations), and Kubeconform Kubernetes v1.31 schema validation, the FinOps guard parses &lt;code&gt;terraform/*.tf&lt;/code&gt; and calculates the monthly run rate before a single resource can be merged.&lt;/p&gt;

&lt;h3&gt;
  
  
  Baseline vs. Optimized AWS Cost Breakdown
&lt;/h3&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%2Fraw.githubusercontent.com%2Fmohammedarmaan936-sketch%2Fcloudpulse-eks-gitops-infra%2Fmain%2Fassets%2Ffinops-cost-receipt.svg" 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%2Fraw.githubusercontent.com%2Fmohammedarmaan936-sketch%2Fcloudpulse-eks-gitops-infra%2Fmain%2Fassets%2Ffinops-cost-receipt.svg" alt="CloudPulse FinOps Cost Receipt" width="100" height="100"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;AWS Resource&lt;/th&gt;
&lt;th&gt;Architecture Configuration&lt;/th&gt;
&lt;th&gt;Baseline Cost&lt;/th&gt;
&lt;th&gt;Optimized Cost&lt;/th&gt;
&lt;th&gt;FinOps Savings&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Amazon EKS Control Plane&lt;/td&gt;
&lt;td&gt;EKS v1.31 (&lt;code&gt;cloudpulse-eks-prod&lt;/code&gt;)&lt;/td&gt;
&lt;td&gt;$73.00&lt;/td&gt;
&lt;td&gt;$73.00&lt;/td&gt;
&lt;td&gt;$0.00&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;AWS NAT Gateway&lt;/td&gt;
&lt;td&gt;Single-AZ Shared NAT vs. Multi-AZ&lt;/td&gt;
&lt;td&gt;$65.70&lt;/td&gt;
&lt;td&gt;$32.85&lt;/td&gt;
&lt;td&gt;-$32.85 (-50.0%)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;EC2 Worker Nodes&lt;/td&gt;
&lt;td&gt;2x &lt;code&gt;t3.medium&lt;/code&gt; (Spot / Hybrid)&lt;/td&gt;
&lt;td&gt;$60.74&lt;/td&gt;
&lt;td&gt;$24.30&lt;/td&gt;
&lt;td&gt;-$36.44 (-60.0%)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Amazon EBS Storage&lt;/td&gt;
&lt;td&gt;100 GB Encrypted &lt;code&gt;gp3&lt;/code&gt; (2x 50GB)&lt;/td&gt;
&lt;td&gt;$8.00&lt;/td&gt;
&lt;td&gt;$8.00&lt;/td&gt;
&lt;td&gt;$0.00&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;CloudWatch Logs&lt;/td&gt;
&lt;td&gt;VPC Flow Logs + EKS Audit (30d)&lt;/td&gt;
&lt;td&gt;$6.00&lt;/td&gt;
&lt;td&gt;$6.00&lt;/td&gt;
&lt;td&gt;$0.00&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;AWS KMS Key&lt;/td&gt;
&lt;td&gt;Secrets Envelope Encryption&lt;/td&gt;
&lt;td&gt;$1.00&lt;/td&gt;
&lt;td&gt;$1.00&lt;/td&gt;
&lt;td&gt;$0.00&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Network Data Transfer&lt;/td&gt;
&lt;td&gt;Cross-AZ Optimization + Shared EIP&lt;/td&gt;
&lt;td&gt;$25.56&lt;/td&gt;
&lt;td&gt;$3.45&lt;/td&gt;
&lt;td&gt;-$22.11 (-86.5%)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;TOTAL MONTHLY SPEND&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;AWS &lt;code&gt;ap-south-1&lt;/code&gt;&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;$240.00&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;$148.60&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;-$91.40 (-38.1%)&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;If a developer opens a Pull Request that pushes estimated monthly spending past our $250.00/month policy ceiling, &lt;code&gt;finops_cost_guard.py&lt;/code&gt; exits with code &lt;code&gt;1&lt;/code&gt; and blocks the merge.&lt;/p&gt;

&lt;p&gt;At $148.60/month, we maintain $101.40/month (40.6%) of budget headroom to absorb HPA autoscaling bursts during peak traffic.&lt;/p&gt;

&lt;h3&gt;
  
  
  Automated CI/CD Governance
&lt;/h3&gt;

&lt;p&gt;The GitHub Actions pipeline executes four quality and governance checks:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Terraform Format &amp;amp; Validation:&lt;/strong&gt; Runs &lt;code&gt;terraform fmt -check&lt;/code&gt;, initializes Terraform without a backend, and executes &lt;code&gt;terraform validate&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;FinOps Cost Governance:&lt;/strong&gt; Scans Terraform configurations and enforces the $250.00/month budget policy.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Trivy IaC Security:&lt;/strong&gt; Scans infrastructure configurations for HIGH and CRITICAL security misconfigurations.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Kubernetes Manifest Validation:&lt;/strong&gt; Uses Kubeconform strict schema validation and Kustomize checks against Kubernetes v1.31.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Any failing gate blocks the Pull Request from being merged.&lt;/p&gt;




&lt;h2&gt;
  
  
  Layer 3: Argo CD GitOps Delivery, Self-Healing &amp;amp; HPA Autoscaling
&lt;/h2&gt;

&lt;p&gt;Once infrastructure passes all four CI gates, Argo CD (&lt;code&gt;argocd/application.yaml&lt;/code&gt;) takes over continuous delivery.&lt;/p&gt;

&lt;p&gt;Nobody runs manual &lt;code&gt;kubectl apply&lt;/code&gt; commands against production.&lt;/p&gt;

&lt;p&gt;The GitOps controller continuously watches the infrastructure repository and reconciles Kubernetes resources with the declared Git state.&lt;/p&gt;

&lt;p&gt;The Argo CD configuration:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;syncPolicy&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;automated&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;prune&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;      &lt;span class="c1"&gt;# Automatically deletes resources removed from Git
&lt;/span&gt;    &lt;span class="na"&gt;selfHeal&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;   &lt;span class="c1"&gt;# Reverts manual kubectl edits back to Git state
&lt;/span&gt;  &lt;span class="na"&gt;syncOptions&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="s"&gt;CreateNamespace=true&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Argo CD Application Tree &amp;amp; Sync Status
&lt;/h3&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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fky84kp644u1a6bwoqphu.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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fky84kp644u1a6bwoqphu.png" alt="Argo CD GitOps Synced" width="800" height="500"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The Argo CD Application Details Tree for &lt;code&gt;cloudpulse-production&lt;/code&gt; shows the deployed Kubernetes resources, including the Namespace, Service, Deployment, ReplicaSet, Pods, and HPA.&lt;/p&gt;

&lt;p&gt;The application is synced to the &lt;code&gt;main&lt;/code&gt; branch, with automated synchronization, pruning, and self-healing enabled.&lt;/p&gt;

&lt;h3&gt;
  
  
  Self-Healing &amp;amp; Dynamic Flash-Sale Scaling
&lt;/h3&gt;

&lt;p&gt;Inside &lt;code&gt;k8s/base/deployment.yaml&lt;/code&gt;, our pods run with strict Kubernetes security contexts:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;runAsNonRoot: true&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;runAsUser: 10001&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;readOnlyRootFilesystem: true&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;drop: ["ALL"]&lt;/code&gt; capabilities&lt;/li&gt;
&lt;li&gt;&lt;code&gt;seccompProfile: RuntimeDefault&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Liveness and readiness probes hit &lt;code&gt;GET /healthz&lt;/code&gt; on port &lt;code&gt;8000&lt;/code&gt; every 10 seconds.&lt;/p&gt;

&lt;p&gt;If a container returns HTTP 503 for three consecutive checks during an outage simulation (&lt;code&gt;/simulate-outage&lt;/code&gt;), Kubernetes replaces the unhealthy pod while healthy replicas continue serving traffic.&lt;/p&gt;

&lt;p&gt;Meanwhile, our HorizontalPodAutoscaler (&lt;code&gt;hpa.yaml&lt;/code&gt;) monitors CPU utilization against a 60% target threshold, scaling smoothly between:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;minReplicas: 2&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;maxReplicas: 6&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Kubernetes Cluster &amp;amp; HPA Verification
&lt;/h3&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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F5gtmolemmkml0abe1z4s.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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F5gtmolemmkml0abe1z4s.png" alt="Kubernetes Cluster and HPA Status" width="800" height="500"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This terminal snapshot demonstrates the Kubernetes workload validation, including node readiness, running application pods, replica availability, and HPA configuration.&lt;/p&gt;

&lt;p&gt;The local K3s validation environment is also used to reproduce the Kubernetes deployment topology without continuously running paid AWS infrastructure.&lt;/p&gt;




&lt;h2&gt;
  
  
  Layer 4: Real-Time Flash-Sale Observability
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Visualizing Traffic Surges with Prometheus &amp;amp; Grafana
&lt;/h3&gt;

&lt;p&gt;Every pod includes Prometheus scrape annotations:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;prometheus.io/scrape&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"true"&lt;/span&gt;
&lt;span class="na"&gt;prometheus.io/port&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"8000"&lt;/span&gt;
&lt;span class="na"&gt;prometheus.io/path&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"/metrics"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When we trigger a flash-sale traffic spike, Prometheus scrapes custom counters and Grafana (&lt;code&gt;monitoring/grafana-cloudpulse-dashboard.json&lt;/code&gt;) visualizes the surge through a 5-second rolling dashboard.&lt;/p&gt;

&lt;h3&gt;
  
  
  Grafana Production Telemetry Dashboard
&lt;/h3&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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fawqt33s8j8zes5zt4tgo.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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fawqt33s8j8zes5zt4tgo.png" alt="Grafana Telemetry Dashboard" width="800" height="500"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The dashboard tracks:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;32.6K&lt;/strong&gt; total HTTP requests served.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;51&lt;/strong&gt; flash-sale surge events triggered.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;HEALTHY (UP)&lt;/strong&gt; service availability.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;2&lt;/strong&gt; active Kubernetes pods ready.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The Active Flash-Sale Traffic Rate graph shows traffic ramping up to approximately 300 requests per second, with two distinct traffic peaks.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;/api/v1/checkout&lt;/code&gt; endpoint peaks at 194 requests per second, while &lt;code&gt;/healthz&lt;/code&gt; probe traffic reaches 1.35 requests per second.&lt;/p&gt;

&lt;p&gt;The dashboard uses PromQL queries to track request rates and surge events in real time.&lt;/p&gt;




&lt;h2&gt;
  
  
  Try It Yourself: Full Source Code
&lt;/h2&gt;

&lt;p&gt;To avoid burning money on idle AWS control planes outside live benchmarks, you can run the entire Terraform, Trivy, Kubeconform, and FinOps validation pipeline locally.&lt;/p&gt;

&lt;p&gt;You can also spin up the full topology on a local &lt;code&gt;k3d&lt;/code&gt; cluster with Argo CD and Grafana at zero AWS infrastructure cost.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Part 2 — AWS EKS, Terraform, FinOps Gate &amp;amp; Argo CD&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/mohammedarmaan936-sketch/cloudpulse-eks-gitops-infra" rel="noopener noreferrer"&gt;cloudpulse-eks-gitops-infra&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Part 1 — FastAPI Microservice &amp;amp; Hardened Docker CI/CD&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/mohammedarmaan936-sketch/cloudpulse-devsecops-service" rel="noopener noreferrer"&gt;cloudpulse-devsecops-service&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Both repositories contain the source code and configuration needed to explore the complete CloudPulse platform.&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;Built by &lt;a href="https://github.com/mohammedarmaan936-sketch" rel="noopener noreferrer"&gt;Mohammed Armaan Kazi&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Cloud Infrastructure • GitOps • Platform Engineering • DevSecOps • FinOps&lt;/p&gt;

</description>
      <category>aws</category>
      <category>terraform</category>
      <category>kubernetes</category>
      <category>grafana</category>
    </item>
    <item>
      <title>How I Built a Shift-Left DevSecOps Pipeline for FastAPI &amp; Kubernetes (And Caught 3 Real High-Severity CVEs with Trivy) published: true</title>
      <dc:creator>Mohammed Armaan</dc:creator>
      <pubDate>Mon, 02 Nov 2026 14:45:03 +0000</pubDate>
      <link>https://dev.to/mohammed_armaan_51c01b74e/how-i-built-a-shift-left-devsecops-pipeline-for-fastapi-kubernetes-and-caught-3-real-g8k</link>
      <guid>https://dev.to/mohammed_armaan_51c01b74e/how-i-built-a-shift-left-devsecops-pipeline-for-fastapi-kubernetes-and-caught-3-real-g8k</guid>
      <description>&lt;p&gt;When an e-commerce platform runs a flash sale, traffic can jump from 10 requests per second to 10,000 in under a minute. If your team hasn't tested how your containers and Kubernetes pods behave under a sudden traffic surge—or how Kubernetes self-heals when a pod returns &lt;code&gt;HTTP 503&lt;/code&gt;—production is the worst place to find out.&lt;/p&gt;

&lt;p&gt;Even before code reaches a Kubernetes cluster, there is a second problem: most CI pipelines only check if the code &lt;em&gt;runs&lt;/em&gt;, not if the container image is &lt;em&gt;secure&lt;/em&gt;. Warning-only security scans get ignored, leaked secrets hide in Git commit history, and default base images quietly ship with unpatched vulnerabilities.&lt;/p&gt;

&lt;p&gt;To solve both problems, I built &lt;strong&gt;CloudPulse&lt;/strong&gt;—a two-repository High-Availability Cloud Status &amp;amp; Incident Telemetry Platform designed around strict shift-left DevSecOps gates and GitOps delivery:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Part 1 (App &amp;amp; DevSecOps CI):&lt;/strong&gt; &lt;a href="https://github.com/mohammedarmaan936-sketch/cloudpulse-devsecops-service" rel="noopener noreferrer"&gt;cloudpulse-devsecops-service&lt;/a&gt; — FastAPI telemetry &amp;amp; chaos microservice, multistage Docker hardening, and a 3-stage GitHub Actions pipeline.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Part 2 (AWS EKS &amp;amp; GitOps Infra):&lt;/strong&gt; &lt;a href="https://github.com/mohammedarmaan936-sketch/cloudpulse-eks-gitops-infra" rel="noopener noreferrer"&gt;cloudpulse-eks-gitops-infra&lt;/a&gt; — Modular AWS VPC &amp;amp; EKS Terraform IaC, Argo CD GitOps continuous delivery, Kubernetes HPA auto-scaling, and Prometheus/Grafana observability.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Here is how I architected the pipeline, how our &lt;strong&gt;Trivy&lt;/strong&gt; security gate blocked a real build after catching &lt;strong&gt;3 HIGH severity CVEs&lt;/strong&gt;, and how I remediated them to reach a zero-CVE container build.&lt;/p&gt;




&lt;h2&gt;
  
  
  1. Designing a Microservice Built for Kubernetes Chaos Testing
&lt;/h2&gt;

&lt;p&gt;Instead of deploying a static "Hello World" container, &lt;code&gt;CloudPulse&lt;/code&gt; exposes real Prometheus telemetry (&lt;code&gt;cloudpulse_http_requests_total&lt;/code&gt;, &lt;code&gt;cloudpulse_flash_surge_events_total&lt;/code&gt;, &lt;code&gt;cloudpulse_service_health_status&lt;/code&gt;, and request latency histograms) alongside two interactive chaos endpoints:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;POST /simulate-surge&lt;/code&gt;:&lt;/strong&gt; Launches a non-blocking 30-second background task (&lt;code&gt;asyncio.create_task&lt;/code&gt;) that injects synthetic checkout traffic bursts into the Prometheus counters to trigger downstream Kubernetes HorizontalPodAutoscaler (HPA) scaling and Grafana alerts.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;POST /simulate-outage&lt;/code&gt;:&lt;/strong&gt; Flips the internal service health state so &lt;code&gt;GET /healthz&lt;/code&gt; returns &lt;code&gt;HTTP 503 Service Unavailable&lt;/code&gt;, allowing us to test Kubernetes Liveness and Readiness probe self-healing in real time.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Baseline Healthy State (&lt;code&gt;200 OK&lt;/code&gt;)
&lt;/h3&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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fs7f74v39td85a0v7kjho.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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fs7f74v39td85a0v7kjho.png" alt="CloudPulse Healthy Dashboard" width="800" height="500"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Active Flash-Sale Traffic Surge
&lt;/h3&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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fvad1d6wt713w66jsrpqe.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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fvad1d6wt713w66jsrpqe.png" alt="CloudPulse Flash Surge Active" width="800" height="500"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Simulated Server Outage (&lt;code&gt;503 OUTAGE&lt;/code&gt;)
&lt;/h3&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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fpmoggrfkn27tlvf3p72r.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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fpmoggrfkn27tlvf3p72r.png" alt="CloudPulse Outage Simulation" width="800" height="500"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  2. The 3-Stage Shift-Left DevSecOps Pipeline
&lt;/h2&gt;

&lt;p&gt;Every push and pull request to &lt;code&gt;main&lt;/code&gt; passes through three strict gates in &lt;code&gt;.github/workflows/devsecops.yml&lt;/code&gt; before any container image can be published to GitHub Container Registry (&lt;code&gt;ghcr.io&lt;/code&gt;).&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Station 1 — Code Quality &amp;amp; Unit Tests (&lt;code&gt;Ruff&lt;/code&gt; + &lt;code&gt;Pytest&lt;/code&gt;):&lt;/strong&gt; Lints Python syntax/import formatting and executes automated &lt;code&gt;TestClient&lt;/code&gt; tests verifying &lt;code&gt;/healthz&lt;/code&gt;, &lt;code&gt;/metrics&lt;/code&gt;, surge increments, and &lt;code&gt;200 &amp;lt;-&amp;gt; 503&lt;/code&gt; outage toggling.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Station 2 — Full-History Secret Scanning (&lt;code&gt;Gitleaks&lt;/code&gt;):&lt;/strong&gt; Runs &lt;code&gt;gitleaks-action@v2&lt;/code&gt; with &lt;code&gt;fetch-depth: 0&lt;/code&gt; to scan the entire Git commit history—not just the latest commit—so accidentally committed AWS keys or tokens block the build immediately.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Station 3 — Multistage Container Build, &lt;code&gt;Trivy&lt;/code&gt; CVE Gate &amp;amp; Smoke Test:&lt;/strong&gt; Builds the production Docker image, scans both OS packages and Python libraries with &lt;strong&gt;Trivy&lt;/strong&gt; (&lt;code&gt;exit-code: '1'&lt;/code&gt;, &lt;code&gt;severity: 'CRITICAL,HIGH'&lt;/code&gt;), spins up the live container to smoke-test &lt;code&gt;/healthz&lt;/code&gt; and &lt;code&gt;/metrics&lt;/code&gt; via &lt;code&gt;curl --fail&lt;/code&gt;, and pushes to &lt;code&gt;ghcr.io&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  3. Real-World Remediation: When Trivy Blocked the Pipeline
&lt;/h2&gt;

&lt;p&gt;Having &lt;code&gt;exit-code: '1'&lt;/code&gt; configured on Trivy immediately proved its value on our initial pipeline run.&lt;/p&gt;

&lt;p&gt;Even though our code passed all unit tests and used the official &lt;code&gt;python:3.12-slim&lt;/code&gt; base image, &lt;strong&gt;Trivy failed the build and blocked the image from publishing&lt;/strong&gt; after detecting three actionable HIGH severity vulnerabilities and vulnerable vendored SBOM metadata:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;CVE ID&lt;/th&gt;
&lt;th&gt;Package&lt;/th&gt;
&lt;th&gt;Vulnerability Summary&lt;/th&gt;
&lt;th&gt;Fixed Version&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;CVE-2025-62727&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;starlette&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;DoS via Range header merging&lt;/td&gt;
&lt;td&gt;&lt;code&gt;0.49.1&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;CVE-2026-48818&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;starlette&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;SSRF / NTLM credential theft in &lt;code&gt;StaticFiles&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;&lt;code&gt;1.1.0&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;CVE-2026-54283&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;starlette&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;request.form()&lt;/code&gt; limits bypassed enabling DoS&lt;/td&gt;
&lt;td&gt;&lt;code&gt;1.3.1&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Additionally, Trivy flagged embedded CycloneDX SBOM files (&lt;code&gt;bom.cdx.json&lt;/code&gt;) bundled inside &lt;code&gt;setuptools&lt;/code&gt; and &lt;code&gt;wheel&lt;/code&gt; in the base Python image that referenced older vulnerable package versions.&lt;/p&gt;

&lt;h3&gt;
  
  
  How We Fixed It for a 0-CVE Build
&lt;/h3&gt;

&lt;p&gt;First, we pinned &lt;code&gt;starlette&amp;gt;=1.3.1&lt;/code&gt; alongside upgraded &lt;code&gt;fastapi&lt;/code&gt; in &lt;code&gt;requirements.txt&lt;/code&gt; so transitive dependencies could no longer resolve to vulnerable versions.&lt;/p&gt;

&lt;p&gt;Second, we hardened our multistage &lt;code&gt;Dockerfile&lt;/code&gt; to patch OS packages, strip unused packaging tools and embedded &lt;code&gt;bom.cdx.json&lt;/code&gt; metadata from the runtime image, and execute Uvicorn under a locked-down non-root user (&lt;code&gt;appuser&lt;/code&gt;, UID &lt;code&gt;10001&lt;/code&gt;):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight docker"&gt;&lt;code&gt;&lt;span class="c"&gt;# Stage 1: Builder&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;python:3.12-slim&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;AS&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;builder&lt;/span&gt;
&lt;span class="k"&gt;WORKDIR&lt;/span&gt;&lt;span class="s"&gt; /build&lt;/span&gt;
&lt;span class="k"&gt;RUN &lt;/span&gt;python &lt;span class="nt"&gt;-m&lt;/span&gt; venv /opt/venv
&lt;span class="k"&gt;ENV&lt;/span&gt;&lt;span class="s"&gt; PATH="/opt/venv/bin:$PATH"&lt;/span&gt;
&lt;span class="k"&gt;COPY&lt;/span&gt;&lt;span class="s"&gt; requirements.txt .&lt;/span&gt;
&lt;span class="k"&gt;RUN &lt;/span&gt;pip &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;--no-cache-dir&lt;/span&gt; &lt;span class="nt"&gt;--upgrade&lt;/span&gt; pip setuptools wheel &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="se"&gt;\
&lt;/span&gt;    pip &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;--no-cache-dir&lt;/span&gt; &lt;span class="nt"&gt;-r&lt;/span&gt; requirements.txt &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="se"&gt;\
&lt;/span&gt;    find /opt/venv &lt;span class="nt"&gt;-name&lt;/span&gt; &lt;span class="s2"&gt;"bom.cdx.json"&lt;/span&gt; &lt;span class="nt"&gt;-delete&lt;/span&gt;

&lt;span class="c"&gt;# Stage 2: Hardened Runtime&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;python:3.12-slim&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;AS&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;runtime&lt;/span&gt;
&lt;span class="k"&gt;RUN &lt;/span&gt;apt-get update &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="se"&gt;\
&lt;/span&gt;    apt-get upgrade &lt;span class="nt"&gt;-y&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="se"&gt;\
&lt;/span&gt;    apt-get &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;-y&lt;/span&gt; &lt;span class="nt"&gt;--no-install-recommends&lt;/span&gt; curl &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="se"&gt;\
&lt;/span&gt;    &lt;span class="nb"&gt;rm&lt;/span&gt; &lt;span class="nt"&gt;-rf&lt;/span&gt; /var/lib/apt/lists/&lt;span class="k"&gt;*&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="se"&gt;\
&lt;/span&gt;    pip &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;--no-cache-dir&lt;/span&gt; &lt;span class="nt"&gt;--upgrade&lt;/span&gt; pip setuptools wheel &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="se"&gt;\
&lt;/span&gt;    &lt;span class="nb"&gt;rm&lt;/span&gt; &lt;span class="nt"&gt;-rf&lt;/span&gt; /usr/local/lib/python3.12/site-packages/setuptools&lt;span class="k"&gt;*&lt;/span&gt; &lt;span class="se"&gt;\
&lt;/span&gt;           /usr/local/lib/python3.12/site-packages/wheel&lt;span class="k"&gt;*&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="se"&gt;\
&lt;/span&gt;    find /usr/local/lib/python3.12 &lt;span class="nt"&gt;-name&lt;/span&gt; &lt;span class="s2"&gt;"bom.cdx.json"&lt;/span&gt; &lt;span class="nt"&gt;-delete&lt;/span&gt;

&lt;span class="k"&gt;RUN &lt;/span&gt;groupadd &lt;span class="nt"&gt;-g&lt;/span&gt; 10001 appuser &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="se"&gt;\
&lt;/span&gt;    useradd &lt;span class="nt"&gt;-u&lt;/span&gt; 10001 &lt;span class="nt"&gt;-g&lt;/span&gt; appuser &lt;span class="nt"&gt;-s&lt;/span&gt; /sbin/nologin &lt;span class="nt"&gt;-M&lt;/span&gt; appuser

&lt;span class="k"&gt;WORKDIR&lt;/span&gt;&lt;span class="s"&gt; /app&lt;/span&gt;
&lt;span class="k"&gt;COPY&lt;/span&gt;&lt;span class="s"&gt; --from=builder /opt/venv /opt/venv&lt;/span&gt;
&lt;span class="k"&gt;COPY&lt;/span&gt;&lt;span class="s"&gt; --chown=appuser:appuser app/ ./app/&lt;/span&gt;

&lt;span class="k"&gt;ENV&lt;/span&gt;&lt;span class="s"&gt; PATH="/opt/venv/bin:$PATH" \&lt;/span&gt;
    PYTHONDONTWRITEBYTECODE=1 \
    PYTHONUNBUFFERED=1

&lt;span class="k"&gt;USER&lt;/span&gt;&lt;span class="s"&gt; appuser&lt;/span&gt;
&lt;span class="k"&gt;EXPOSE&lt;/span&gt;&lt;span class="s"&gt; 8000&lt;/span&gt;
&lt;span class="k"&gt;HEALTHCHECK&lt;/span&gt;&lt;span class="s"&gt; --interval=30s --timeout=5s --start-period=5s --retries=3 \&lt;/span&gt;
    CMD curl -f http://localhost:8000/healthz || exit 1

&lt;span class="k"&gt;CMD&lt;/span&gt;&lt;span class="s"&gt; ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;On the next push (&lt;code&gt;commit 688dfa7&lt;/code&gt;), Trivy reported &lt;strong&gt;0 HIGH or CRITICAL vulnerabilities&lt;/strong&gt;, the container smoke tests passed, and the verified image was published to &lt;code&gt;ghcr.io&lt;/code&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  4. Downstream GitOps Delivery &amp;amp; Observability (Preview of Part 2)
&lt;/h2&gt;

&lt;p&gt;Because we separated our application repository from our infrastructure repository following enterprise GitOps practices, our second repository &lt;a href="https://github.com/mohammedarmaan936-sketch/cloudpulse-eks-gitops-infra" rel="noopener noreferrer"&gt;cloudpulse-eks-gitops-infra&lt;/a&gt; provisions the AWS VPC &amp;amp; EKS architecture with Terraform and uses &lt;strong&gt;Argo CD&lt;/strong&gt; (&lt;code&gt;selfHeal: true&lt;/code&gt;, &lt;code&gt;prune: true&lt;/code&gt;) to deploy the verified container.&lt;/p&gt;

&lt;p&gt;When we trigger the Flash-Sale Traffic Surge across the Kubernetes pods, &lt;strong&gt;Prometheus&lt;/strong&gt; scrapes the &lt;code&gt;/metrics&lt;/code&gt; endpoint and &lt;strong&gt;Grafana&lt;/strong&gt; visualizes the real-time request spike (~300 req/s) and pod readiness.&lt;/p&gt;




&lt;h2&gt;
  
  
  Explore the Full Source Code
&lt;/h2&gt;

&lt;p&gt;Both repositories—including the FastAPI source, unit tests, multistage &lt;code&gt;Dockerfile&lt;/code&gt;, GitHub Actions workflows, AWS EKS Terraform modules, Argo CD manifests, and Grafana dashboard JSON—are open source on GitHub.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Part 1 (App &amp;amp; DevSecOps CI/CD):&lt;/strong&gt; &lt;a href="https://github.com/mohammedarmaan936-sketch/cloudpulse-devsecops-service" rel="noopener noreferrer"&gt;cloudpulse-devsecops-service&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Part 2 (AWS EKS Terraform, Argo CD &amp;amp; Observability):&lt;/strong&gt; &lt;a href="https://github.com/mohammedarmaan936-sketch/cloudpulse-eks-gitops-infra" rel="noopener noreferrer"&gt;cloudpulse-eks-gitops-infra&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>devops</category>
      <category>kubernetes</category>
      <category>aws</category>
      <category>docker</category>
    </item>
  </channel>
</rss>
