Cloud Engineer: Continuous Infrastructure Compliance-as-Code with Chef InSpec in CI/CD Pipelines

Hardening a Golden AMI, Docker container image, or Terraform cloud environment once before launch does not prevent configuration drift three months later when an emergency hotfix modifies `/etc/ssh/sshd_config`, opens an unintended security group port, or relaxes IAM permissions. As a Cloud Engineer and DevSecOps Architect, I embed executable Chef InSpec Compliance-as-Code profiles directly into GitHub Actions / GitLab CI pipelines so every Packer AMI build and Terraform staging deployment is audited against CIS Benchmarks and SOC 2 controls before promotion.

1. Writing Executable CIS & SOC 2 Host Hardening Controls in InSpec

Unlike declarative provisioning scripts (Ansible or shell scripts) that describe how to configure a server, InSpec profiles assert the actual runtime state of kernel parameters, systemd units, TLS cipher suites, and file permissions in human-readable Ruby DSL:

# controls/cis_linux_hardening.rb
control "cis-sshd-01" do
  impact 1.0
  title "Ensure SSH root login and password authentication are disabled"
  desc "CIS Distribution Independent Linux Benchmark v2.0.0 - 5.2.8 & 5.2.12"

  describe sshd_config do
    its("PermitRootLogin") { should cmp "no" }
    its("PasswordAuthentication") { should cmp "no" }
    its("PermitEmptyPasswords") { should cmp "no" }
    its("Protocol") { should cmp 2 }
    its("MaxAuthTries") { should cmp <= 4 }
  end
end

control "cis-kernel-network-02" do
  impact 0.8
  title "Ensure IPv4 packet forwarding and ICMP redirects are disabled on non-router hosts"

  describe kernel_parameter("net.ipv4.ip_forward") do
    its("value") { should eq 0 }
  end

  describe kernel_parameter("net.ipv4.conf.all.accept_redirects") do
    its("value") { should eq 0 }
  end
end

2. Auditing Cloud Resources (AWS & GCP) & Exporting JUnit / SARIF Audit Evidence

Using the `inspec-aws` and `inspec-gcp` cloud resource packs, the same pipeline verifies that production S3/GCS buckets enforce KMS encryption, RDS/Cloud SQL instances reject unencrypted connections, and zero security groups allow `0.0.0.0/0` ingress on administrative ports. Failing controls halt the deployment pipeline and archive signed JSON/JUnit evidence reports directly for auditors—integrating with our SOC 2, HIPAA & GDPR compliance architecture and multi-region AWS & GCP Terraform pipelines.

Need a Cloud Engineer to automate CIS Benchmark and SOC 2 compliance testing in your CI/CD pipelines? Book a 1-Day Engineering Sprint.


About the Author — Hire Aldian Fazrihady (Cloud Engineer, GCP Professional Cloud Architect, GCP Professional Data Engineer, Backend, AI & Full Stack Engineer)

Aldian Fazrihady is a Top-Rated Senior Cloud Engineer, GCP Professional Cloud Architect (Google Cloud Certified), GCP Professional Data Engineer (Google Cloud Certified), Backend Engineer (Python, Django, FastAPI, Go, PostgreSQL), AI Application Engineer (LLMs, RAG, MCP, Google ADK, LangGraph), and Full Stack Engineer (React, Next.js, TypeScript) with 15+ years of production software engineering experience.

Hire Aldian Fazrihady on Upwork | Book 1-Day Programming Service ($100 USD / Rp 1.000.000) | View Live AI Portfolio | Send a Direct Message

Related Engineering Articles

Engineering Role Pillar Guides & Category Hubs