Skip to content

Commit

Permalink
(SIMP-6708) Create and ensure inspec tests work by module (#52)
Browse files Browse the repository at this point in the history
* Create CentOS-7-disa_stig
* Delete CentOS-7-disa_stig
* Create 00_Control_Selector.rb
* Add files via upload
* Create 00_Control_Selector.rb
* Create inspec.yml
* Update .fixtures.yml
* Added inspec profile to run Aide specific tests
* Fix Red hat inspec profile
* Adds capability to run inspec compliance tests
* Delete 00_Control_Selector.rb
* Update Inspec.yml
* Created redhat symlink
* Updated method for choosing hosts
* Added nodeset symlink
* Ensure that STIG mode is enforced during compliance checks
* run puppet after reboot for auditd cleanup
* update SSG checks
* Version Bump
* Skipped a failing test and added a ticket to look into it on the backlog.
  • Loading branch information
ischmidt1235 authored and jeannegreulich committed Nov 1, 2019
1 parent b2d89e3 commit 4ae47cc
Show file tree
Hide file tree
Showing 15 changed files with 278 additions and 10 deletions.
5 changes: 5 additions & 0 deletions .fixtures.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,10 @@ fixtures:
simplib: https://github.com/simp/pupmod-simp-simplib
stdlib: https://github.com/simp/puppetlabs-stdlib
systemd: https://github.com/simp/puppet-systemd
disa_stig-el7-baseline:
repo: https://github.com/simp/inspec-profile-disa_stig-el7
branch: master
target: spec/fixtures/inspec_deps/inspec_profiles/profiles

symlinks:
aide: "#{source_dir}"
13 changes: 7 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@
.yardoc
dist/
pkg/
spec/fixtures/
spec/rp_env/
!/spec/hieradata/default.yaml
!/spec/fixtures/site.pp
spec/fixtures/**
!spec/fixtures/site.pp
!spec/fixtures/inspec_profiles
.bundle/
.rspec_system
.vagrant/
.bundle/
Gemfile.lock
vendor/
doc/
junit/
log/
doc/
sec_results/
vendor/
6 changes: 6 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -195,3 +195,9 @@ pup6-fips:
<<: *acceptance_base
script:
- 'BEAKER_fips=yes bundle exec rake beaker:suites'

pup6-compliance:
<<: *pup_6
<<: *compliance_base
script:
- 'BEAKER_fips=yes bundle exec rake beaker:suites[compliance]'
6 changes: 6 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
* Wed Aug 14 2019 Trevor Vaughan <tvaughan@onyxpoint.com> - 6.3.1-0
- With contributions from ischmidt1235 on GitHub
- Add InSpec compliance tests
- Fix bug in Compliance Engine data
- Add SCAP compliance tests

* Thu Jun 06 2019 Steven Pritchard <steven.pritchard@onyxpoint.com> - 6.3.0-0
- Add v2 compliance_markup data
- Drop support for Puppet 4
Expand Down
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ end
group :system_tests do
gem 'beaker'
gem 'beaker-rspec'
gem 'simp-beaker-helpers', ENV.fetch('SIMP_BEAKER_HELPERS_VERSION', '~> 1.12')
gem 'simp-beaker-helpers', ENV.fetch('SIMP_BEAKER_HELPERS_VERSION', ['>= 1.14.5', '< 2.0'])
end
2 changes: 1 addition & 1 deletion SIMP/compliance_profiles/checks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ checks:
oval:com.puppet.forge.simp.aide.default_rules:
settings:
parameter: aide::default_rules
value: nil
value: ''
type: puppet-class-parameter
controls:
nist_800_53:rev4: true
Expand Down
2 changes: 1 addition & 1 deletion metadata.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "simp-aide",
"version": "6.3.0",
"version": "6.3.1",
"author": "SIMP Team",
"summary": "manages AIDE",
"license": "Apache-2.0",
Expand Down
11 changes: 10 additions & 1 deletion spec/acceptance/nodesets/default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,22 @@ HOSTS:
platform: el-6-x86_64
box: centos/6
hypervisor: <%= hypervisor %>
yum_repos:
chef-current:
baseurl: 'https://packages.chef.io/repos/yum/current/el/7/$basearch'
gpgkeys:
- https://packages.chef.io/chef.asc
el7:
roles:
- client
platform: el-7-x86_64
box: centos/7
hypervisor: <%= hypervisor %>

yum_repos:
chef-current:
baseurl: 'https://packages.chef.io/repos/yum/current/el/7/$basearch'
gpgkeys:
- https://packages.chef.io/chef.asc
CONFIG:
log_level: verbose
synced_folder : disabled
Expand Down
58 changes: 58 additions & 0 deletions spec/acceptance/suites/compliance/00_simp_profile_install_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
require 'spec_helper_acceptance'

test_name 'aide STIG enforcement of simp profile'

describe 'aide STIG enforcement of simp profile' do

let(:manifest) {
<<-EOS
include 'aide'
EOS
}

let(:hieradata) { <<-EOF
---
simp_options::pki: true
simp_options::pki::source: '/etc/pki/simp-testing/pki'
compliance_markup::enforcement:
- disa_stig
EOF
}

hosts.each do |host|

let(:hiera_yaml) { <<-EOM
---
version: 5
hierarchy:
- name: Common
path: common.yaml
- name: Compliance
lookup_key: compliance_markup::enforcement
defaults:
data_hash: yaml_data
datadir: "#{hiera_datadir(host)}"
EOM
}

context 'when enforcing the STIG' do
it 'should work with no errors' do
create_remote_file(host, host.puppet['hiera_config'], hiera_yaml)
write_hieradata_to(host, hieradata)

apply_manifest_on(host, manifest, :catch_failures => true)
end

it 'should reboot and then run puppet for audit updates' do
host.reboot

apply_manifest_on(host, manifest, :catch_failures => true)
end

it 'should be idempotent' do
apply_manifest_on(host, manifest, :catch_changes => true)
end
end
end
end
65 changes: 65 additions & 0 deletions spec/acceptance/suites/compliance/01_simp_profile_inspec_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
require 'spec_helper_acceptance'
require 'json'

test_name 'Check Inspec for simp profile'

describe 'run inspec against the appropriate fixtures for simp audit profile' do

profiles_to_validate = ['disa_stig']

hosts.each do |host|
profiles_to_validate.each do |profile|
context "for profile #{profile}" do
context "on #{host}" do
profile_path = File.join(
fixtures_path,
'inspec_profiles',
"#{fact_on(host, 'operatingsystem')}-#{fact_on(host, 'operatingsystemmajrelease')}-#{profile}"
)

unless File.exist?(profile_path)
it 'should run inspec' do
skip("No matching profile available at #{profile_path}")
end
else
before(:all) do
@inspec = Simp::BeakerHelpers::Inspec.new(host, profile)
@inspec_report = {:data => nil}
end

it 'should run inspec' do
@inspec.run
end

it 'should have an inspec report' do
@inspec_report[:data] = @inspec.process_inspec_results

info = [
'Results:',
" * Passed: #{@inspec_report[:data][:passed]}",
" * Failed: #{@inspec_report[:data][:failed]}",
" * Skipped: #{@inspec_report[:data][:skipped]}"
]

puts info.join("\n")

@inspec.write_report(@inspec_report[:data])
end

it 'should have run some tests' do
expect(@inspec_report[:data][:failed] + @inspec_report[:data][:passed]).to be > 0
end

it 'should not have any failing tests' do
if @inspec_report[:data][:failed] > 0
puts @inspec_report[:data][:report]
end

expect( @inspec_report[:data][:failed] ).to eq(0)
end
end
end
end
end
end
end
63 changes: 63 additions & 0 deletions spec/acceptance/suites/compliance/10_stig_profile_oscap_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
require 'spec_helper_acceptance'

test_name 'Check SCAP for stig profile'

describe 'run the SSG against the appropriate fixtures for stig aide profile' do

hosts.each do |host|
context "on #{host}" do
before(:all) do
@os_str = fact_on(host, 'operatingsystem') + ' ' + fact_on(host, 'operatingsystemrelease')

@ssg_supported = true

begin
@ssg = Simp::BeakerHelpers::SSG.new(host)
rescue
@ssg_supported = false
end

# If we don't do this, the variable gets reset
@ssg_report = { :data => nil }
end

it 'should run the SSG' do
pending("SSG support for #{@os_str}") unless @ssg_supported

profile = 'xccdf_org.ssgproject.content_profile_stig'

@ssg.evaluate(profile)
end

it 'should have an SSG report' do
pending("SSG support for #{@os_str}") unless @ssg_supported

# Filter on records containing '_aide_'
# This isn't perfect, but it should be partially OK
@ssg_report[:data] = @ssg.process_ssg_results('rule_aide_')

expect(@ssg_report[:data]).to_not be_nil

@ssg.write_report(@ssg_report[:data])
end

it 'should have run some tests' do
pending("SSG support for #{@os_str}") unless @ssg_supported

expect(@ssg_report[:data][:failed].count + @ssg_report[:data][:passed].count).to be > 0
end

it 'should not have any failing tests' do
pending("SSG support for #{@os_str}") unless @ssg_supported

if @ssg_report[:data][:failed].count > 0
puts @ssg_report[:data][:report]
end

# TODO: See if we can get the SSG to update to a more reasonable set of checks
pending('SSG Checks Getting Fixed')
expect(@ssg_report[:data][:score]).to eq(100)
end
end
end
end
1 change: 1 addition & 0 deletions spec/acceptance/suites/compliance/nodesets
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
skips = {
'V-71975' => "Skipping: No mail server is configured. SIMP-7220 ticket created"
}
overrides = []
subsystems = [ 'aide' ]

require_controls 'disa_stig-el7-baseline' do
skips.each_pair do |ctrl, reason|
control ctrl do
describe "Skip #{ctrl}" do
skip "Reason: #{skips[ctrl]}" do
end
end
end
end

@conf['profile'].info[:controls].each do |ctrl|
next if (overrides + skips.keys).include?(ctrl[:id])

tags = ctrl[:tags]
if tags && tags[:subsystems]
subsystems.each do |subsystem|
if tags[:subsystems].include?(subsystem)
control ctrl[:id]
end
end
end
end

## Overrides ##

# # USEFUL DESCRIPTION
# control 'V-IDENTIFIER' do
# # Enhancement, leave this out if you just want to add a different test
# overrides << self.to_s
#
# only_if { file('whatever').exist? }
# end
end
14 changes: 14 additions & 0 deletions spec/fixtures/inspec_profiles/CentOS-7-disa_stig/inspec.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: EL7 Aide STIG
title: Aide STIG for EL 7
supports:
- os-family: redhat
maintainer: SIMP Team
copyright: Onyx Point, Inc.
copyright_email: simp@onyxpoint.com
license: Apache-2.0
summary: |
A collection of InSpec tests for the aide subsystem
version: 0.0.1
depends:
- name: disa_stig-el7-baseline
path: ../../inspec_deps/inspec_profiles/profiles/disa_stig-el7-baseline
1 change: 1 addition & 0 deletions spec/fixtures/inspec_profiles/RedHat-7-disa_stig

0 comments on commit 4ae47cc

Please sign in to comment.