InSpec: Auditing and Testing Framework
For more information on project states and SLAs, see this documentation. Chef InSpec is an open-source testing framework for infrastructure with a human- and machine-readable language for specifying compliance, security and policy requirements.
# Disallow insecure protocols by testing
describe package('telnetd') do
it { should_not be_installed }
end
describe inetd_conf do
its("telnet") { should eq nil }
end
Chef InSpec makes it easy to run your tests wherever you need. More options are found in our CLI docs.
…
Chef InSpec requires Ruby ( >= 3.1.0 ).
All currently supported versions of Chef InSpec (5.0 and later) require accepting the EULA to use. Please visit the license acceptance page on the Chef docs site for more information.
The Chef InSpec package is available for MacOS, RedHat, Ubuntu and Windows. Download the latest package at Chef InSpec Downloads or install Chef InSpec via script:
# RedHat, Ubuntu, and macOS
curl https://chefdownload-commercial.chef.io/install.sh?license_id=<LICENSE_ID> | sudo bash -s -- -P inspec
# Windows
. { iwr -useb https://chefdownload-commercial.chef.io/install.ps1?license_id=<LICENSE_ID> } | iex; install -project inspec
Replace <LICENSE_ID> with your license ID.
For more information about the install scripts, see the Chef Install Script documentation.
Installing Chef InSpec from source may require installing ruby build tools to manage gem dependencies. (A compiler-free variant is available with reduced functionality; use inspec-core-bin and inspec-core.)
To install build tools, use your package manager.
For CentOS/RedHat/Fedora:
yum -y install ruby ruby-devel make gcc gcc-c++
For Ubuntu:
apt-get -y install ruby ruby-dev gcc g++ make
To install the inspec executable, which requires accepting the Chef License, run:
gem install inspec-bin
You may also use inspec as a library, with no executable. This does not require accepting the license. To install the library as a gem, run:
gem install inspec
Download the image and define a function for convenience:
For Linux:
docker pull chef/inspec
function inspec { docker run -it --rm -v $(pwd):/share chef/inspec "$@"; }
For Windows (PowerShell):
docker pull chef/inspec
function inspec { docker run -it --rm -v "$(pwd):/share" chef/inspec $args; }
If you call inspec from your shell, it automatically mounts the current directory into the Docker container. Therefore you can easily use local tests and key files. Note: Only files in the current directory and sub-directories are available within the container.
$ ls -1
vagrant
test.rb
$ inspec exec test.rb -t ssh://[email protected]:11022 -i vagrant
..
Finished in 0.04321 seconds (files took 0.54917 seconds to load)
2 examples, 0 failures
To scan the docker containers running on the host using the containerized InSpec, we need to bind-mount the Unix socket /var/run/docker.sock from the host machine to the InSpec Container.
docker pull chef/inspec
function inspec { docker run -it --rm -v $(pwd):/share -v /var/run/docker.sock:/var/run/docker.sock chef/inspec "$@"; }
/var/run/docker.sock is the Unix socket the Docker daemon listens on by default.
Note that installing from OS packages from the download page is the preferred method.
That requires bundler:
bundle install
bundle exec inspec help
To install it as a gem locally, run:
gem build inspec.gemspec
gem install inspec-*.gem
On Windows, you need to install Ruby with Ruby Development Kit to build dependencies with its native extensions.
Currently, this method of installation only supports Linux. See the Chef Habitat site for more information.
Download the hab binary from the Chef Habitat site.
hab pkg install chef/inspec --binlink
inspec
You should now be able to run:
…
describe port(80) do
it { should_not be_listening }
end
describe port(443) do
it { should be_listening }
its('protocols') {should include 'tcp'}
end
kitchen.yml file to verify that only Vagrant is configured as the driver. The %w() formatting will
pass rubocop linting and allow you to access nested mappings.describe yaml('.kitchen.yml') do
its(%w(driver name)) { should eq('vagrant') }
end
Also have a look at our examples for:
control 'or-test' do
impact 1.0
title 'This is a OR test'
describe.one do
describe ssh_config do
its('Protocol') { should eq('3') }
end
describe ssh_config do
its('Protocol') { should eq('2') }
end
end
end
Run tests against different targets:
…
Verify your configuration and detect
id=$( docker run -dti ubuntu:14.04 /bin/bash )
inspec detect -t docker://$id
Which will provide you with:
{"family":"ubuntu","release":"14.04","arch":null}
Remote Targets
| Platform | Versions | Architectures |
|---|---|---|
| AIX | 6.1, 7.1, 7.2 | ppc64 |
| CentOS | 6, 7, 8 | i386, x86_64 |
| Debian | 9, 10 | i386, x86_64 |
| FreeBSD | 9, 10, 11 | i386, amd64 |
| macOS | 12.0 | x86_64, amd64 |
| Oracle Enterprise Linux | 6, 7, 8 | i386, x86_64 |
| Red Hat Enterprise Linux | 7, 8, 9 | i386, x86_64 |
| Solaris | 10, 11 | sparc, x86 |
| Windows* | 8, 8.1, 10, 2012, 2012R2, 2016, 2019 | x86, x86_64 |
| Ubuntu Linux | x86, x86_64 | |
| SUSE Linux Enterprise Server | 12, 15 | x86_64 |
| Scientific Linux | 6, 7 | i386, x86_64 |
| Fedora | x86_64 | |
| OpenSUSE | 15 | x86_64 |
| OmniOS | x86_64 | |
| Gentoo Linux | x86_64 | |
| Arch Linux | x86_64 | |
| HP-UX | 11.31 | ia64 |
| Alpine Linux | x86_64 |
*For Windows, PowerShell 5.0 or above is required.
In addition, runtime support is provided for:
| Platform | Versions | Arch |
|---|---|---|
| macOS | 12 | x86_64, arm64 |
| Debian | 9, 10 | x86_64, aarch64 |
| RHEL | 7, 8, 9 | x86_64, aarch64 |
| Fedora | 29+ | x86_64, aarch64 |
| Ubuntu | 16.04+ | x86_64, aarch64 |
| Windows | 8+ | x86_64 |
| Windows | 2012+ | x86_64 |
Documentation
Learn Chef:
Relationship to other tools (RSpec, Serverspec):
You may share your Chef InSpec Profiles in the Tools & Plugins section of the Chef Supermarket. Sign in and add the details of your profile.
You may also browse the Supermarket for shared Compliance Profiles.
Chef InSpec was originally created by Christoph Hartmann (@chris-rock) and Dominik Richter (@arlimus).
Chef InSpec is inspired by the wonderful Serverspec project. Kudos to mizzy and all contributors!
The AWS resources were inspired by inspec-aws from arothian.
The Chef InSpec community and maintainers are very active and helpful. This project benefits greatly from this activity.
If you'd like to chat with the community and maintainers directly join us in the #inspec channel on the Chef Community Slack.
As a reminder, all participants are expected to follow the Code of Conduct.
We offer unit and integration tests.
unit tests ensure the intended behaviour of the implementationintegration tests run against Docker-based VMs via test-kitchen and kitchen-inspecbundle exec rake test
If you like to run only one test file:
bundle exec m test/unit/resources/user_test.rb
You may also run a single test within a file by line number:
bundle exec m test/unit/resources/user_test.rb -l 123
`
No open issues yet, or sync has not completed.