Chef InSpec Compliance

My Compliance Automation Journey

The turning point in my Chef journey came when I was tasked with ensuring PCI-DSS compliance across 60+ servers. Manual compliance checks were consuming days of effort each quarter, and audits were stressful events involving spreadsheets, screenshots, and manual verification. I knew there had to be a better way.

That's when I discovered Chef InSpec - a compliance-as-code framework that transformed how I approached security and compliance. Instead of quarterly panic, I now have continuous compliance validation, automated evidence collection, and the confidence that comes from knowing my infrastructure's compliance posture in real-time.

What is Chef InSpec?

Chef InSpec is an open-source testing framework for infrastructure with a human-readable language for specifying compliance, security, and policy requirements. Unlike traditional compliance tools that simply scan and report, InSpec lets you write tests as code, integrate them into your CI/CD pipeline, and continuously validate your infrastructure.

Key Capabilities:

  • Write compliance tests in a simple, readable DSL

  • Test infrastructure locally or remotely (SSH, WinRM, Docker, cloud APIs)

  • Generate evidence reports in multiple formats (JSON, HTML, JUnit)

  • Integrate with Chef Automate for centralized compliance visibility

  • Use pre-built profiles for industry standards (CIS, DISA STIGs, PCI-DSS)

Why InSpec Changed My Compliance Approach

Before InSpec:

  • ❌ Quarterly manual audits taking 3-5 days

  • ❌ Compliance drift between audits going undetected

  • ❌ Difficult to prove continuous compliance

  • ❌ No consistency across different teams

  • ❌ Limited test coverage due to time constraints

After InSpec:

  • βœ… Continuous automated compliance validation

  • βœ… Compliance issues detected immediately

  • βœ… Automated evidence generation for auditors

  • βœ… Standardized tests across all teams

  • βœ… Comprehensive coverage with minimal effort

InSpec Architecture and Components

The InSpec DSL

InSpec uses a human-readable Domain Specific Language based on Ruby:

What I Love About This Syntax:

  • Reads like natural language

  • Easy for security teams to understand

  • No programming expertise required

  • Self-documenting tests

InSpec Resources

InSpec provides resources for testing various infrastructure components:

  • System Resources: file, directory, user, group, service, package

  • Network Resources: port, interface, bond, bridge

  • Security Resources: sshd_config, auditd, iptables, firewalld

  • Application Resources: nginx, apache, mysql, postgres

  • Cloud Resources: aws_s3_bucket, azure_virtual_machine, google_compute_instance

Getting Started with InSpec Shell

The InSpec shell is an interactive environment for developing and testing compliance code - I use it daily for rapid prototyping.

Launching InSpec Shell

Interactive Testing in InSpec Shell

My Typical Workflow:

Pro Tip: I use InSpec shell to test individual resources before writing full profiles. It's faster than the edit-run-debug cycle.

Using InSpec Shell with Controls

You can even test complete controls interactively:

Creating Your First InSpec Profile

Generating a Profile

Generated Structure:

Understanding inspec.yml

The inspec.yml file contains profile metadata:

Writing Controls

Edit controls/ssh.rb:

What I Include in Every Control:

  • impact - Severity rating (0.0-1.0)

  • title - Clear, descriptive name

  • desc - What the control tests

  • tag - Metadata for reporting and filtering

  • ref - Reference documentation

Running InSpec Profiles

Local Execution

Remote Execution

My Real-World Example

Running compliance checks across my web tier:

Generating Reports

InSpec supports multiple output formats for different audiences:

CLI Output (Default)

Output:

JSON Report

I use JSON reports for:

  • Integration with CI/CD pipelines

  • Custom dashboards and metrics

  • Feeding Chef Automate

  • Historical trend analysis

HTML Report

Perfect for:

  • Sharing with management

  • Audit evidence

  • Team reviews

JUnit XML (for CI/CD)

Working with InSpec Inputs

Inputs make profiles flexible and reusable across environments.

Defining Inputs

In controls/nginx.rb:

Providing Input Values

My Use Case: I maintain environment-specific input files (dev-inputs.yml, prod-inputs.yml) to test the same profile with different expectations.

Using Pre-Built Profiles from Chef Supermarket

Why reinvent the wheel? I leverage community profiles extensively.

Finding Profiles

Browse available profiles at Chef Supermarketarrow-up-right.

Popular Profiles I Use:

  • dev-sec/linux-baseline - Linux security baseline

  • dev-sec/ssh-baseline - SSH hardening

  • dev-sec/nginx-baseline - Nginx security

  • cis/cis-docker-benchmark - CIS Docker Benchmark

Running Supermarket Profiles

Customizing Supermarket Profiles

Create a wrapper profile to customize community profiles:

Edit inspec.yml:

Create controls/overrides.rb:

Real-World Compliance Scenario: PCI-DSS

Let me share how I use InSpec for PCI-DSS compliance:

The Challenge

I needed to ensure continuous PCI-DSS compliance for systems processing payment data:

  • Requirement 2.2: Secure system configurations

  • Requirement 8.2: User authentication controls

  • Requirement 10.2: Audit logging

The Solution

Created a custom PCI-DSS profile:

The Execution

The Results

  • Automated daily compliance validation

  • Immediate alerts on compliance drift

  • Pre-generated audit evidence

  • 90% reduction in audit preparation time

Best Practices from My Experience

1. Organize Controls Logically

2. Use Meaningful Impact Levels

3. Tag Everything

4. Provide Context

5. Test Before Deploy

Integration with CI/CD

InSpec fits perfectly into automated pipelines:

GitLab CI Example

What's Next?

You now understand how to: βœ… Use InSpec shell for interactive testing βœ… Create custom compliance profiles βœ… Run tests locally and remotely βœ… Generate reports for different audiences βœ… Leverage community profiles βœ… Integrate InSpec with CI/CD

Continue to Chef Automate Overview to see how InSpec integrates with centralized compliance reporting, or explore Best Practices for production deployment patterns.

Compliance as code isn't just about meeting audit requirements - it's about building confidence in your infrastructure's security posture every single day.


Ready to explore Chef Automate? Continue to Chef Automate Overview

Last updated