System Compliance Analysis
With Chef Inspec
Last updated
With Chef Inspec
Last updated
Chef InSpec is a framework for testing and auditing applications and infrastructure. Chef InSpec compares the actual state of the system with the desired state defined in a chef recepe written in ruby. Chef InSpec detects violations and displays findings in the form of a report, but puts you in control of remediation.
Inspec Profiles: contain a whole inspec definition.
Controls contain tests (like in ansible tasks contain the atomic tasks)
Inspect does not need to be installed on remote machines.
Alternatives to inspect are: puppet, chef, ansible, OpenSCA.
wget dpkg -i inspec_4.18.114-1_amd64.deb
On the executing machine, run echo "StrictHostKeyChecking no" >> ~/.ssh/config
to prevent the ssh agent from prompting YES or NO question. Then run a baseline profile:
We want to run Inspec on the prod machine $DEPLOYMENT_SERVER. On the executing machine (here our gitlab server) we need to configure a variable $DEPLOYMENT_SERVER_SSH_KEY and store the ssh key of the prod machine to it.
Create a folder, enter and initialize a new profile for a ubuntu machine:
mkdir inspec-profile && cd inspec-profile
inspec init profile ubuntu --chef-license accept
add some tests to the generated control file:
run the profile
inspec check ubuntu
run profile against remote machine
inspec exec ubuntu -t ssh://root@prod-LQc4TsDQ -i ~/.ssh/id_rsa --chef-license accept
We want to implement a verification that the firewall and ssh on the prod machine are correctly configured.
So again create a folder and initialize the files
mkdir inspec-profile && cd inspec-profile
inspec init profile pcidss --chef-license accept
Copy paste the following controls to the example.rb file
And we can run this profile by using this command:
This code basically checks whether shadow file is owned by root or not more rules here:
Chef implementaiton of PCI /DSS rules are defined here