simp-beaker-helpers 1.21.3 → 1.23.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.fips_fixtures +1 -0
- data/.fixtures.yml +6 -1
- data/.github/workflows.local.json +6 -0
- data/.github/workflows/pr_acceptance.yml +55 -0
- data/.github/workflows/pr_glci.yml +190 -0
- data/.github/workflows/pr_glci_cleanup.yml +105 -0
- data/.github/workflows/pr_glci_manual.yml +143 -0
- data/.github/workflows/pr_tests.yml +90 -0
- data/.github/workflows/tag_deploy_rubygem.yml +192 -0
- data/.gitlab-ci.yml +37 -37
- data/CHANGELOG.md +56 -0
- data/Gemfile +1 -1
- data/README.md +63 -5
- data/lib/simp/beaker_helpers.rb +164 -61
- data/lib/simp/beaker_helpers/inspec.rb +16 -12
- data/lib/simp/beaker_helpers/ssg.rb +36 -12
- data/lib/simp/beaker_helpers/version.rb +1 -1
- data/lib/simp/rake/beaker.rb +14 -2
- data/simp-beaker-helpers.gemspec +5 -1
- data/spec/acceptance/nodesets/docker.yml +12 -10
- data/spec/acceptance/suites/default/enable_fips_spec.rb +6 -4
- data/spec/acceptance/suites/default/install_simp_deps_repo_spec.rb +17 -5
- data/spec/acceptance/suites/fips_from_fixtures/00_default_spec.rb +11 -3
- data/spec/acceptance/suites/inspec/00_default_spec.rb +54 -0
- data/spec/acceptance/suites/inspec/metadata.yml +2 -0
- data/spec/acceptance/suites/inspec/nodesets +1 -0
- data/spec/acceptance/suites/puppet_collections/00_default_spec.rb +1 -1
- data/spec/acceptance/suites/ssg/00_default_spec.rb +40 -0
- data/spec/acceptance/suites/ssg/metadata.yml +2 -0
- data/spec/acceptance/suites/ssg/nodesets +1 -0
- data/spec/lib/simp/beaker_helpers_spec.rb +1 -3
- metadata +54 -40
- data/.travis.yml +0 -42
@@ -10,6 +10,21 @@ module Simp::BeakerHelpers
|
|
10
10
|
attr_reader :profile_dir
|
11
11
|
attr_reader :deps_root
|
12
12
|
|
13
|
+
def self.enable_repo_on(suts)
|
14
|
+
parallel = (ENV['BEAKER_SIMP_parallel'] == 'yes')
|
15
|
+
block_on(suts, :run_in_parallel => parallel) do |sut|
|
16
|
+
repo_manifest = create_yum_resource(
|
17
|
+
'chef-current',
|
18
|
+
{
|
19
|
+
:baseurl => "https://packages.chef.io/repos/yum/current/el/#{fact_on(sut,'os.release.major')}/$basearch",
|
20
|
+
:gpgkeys => ['https://packages.chef.io/chef.asc']
|
21
|
+
}
|
22
|
+
)
|
23
|
+
|
24
|
+
apply_manifest_on(sut, repo_manifest, :catch_failures => true)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
13
28
|
# Create a new Inspec helper for the specified host against the specified profile
|
14
29
|
#
|
15
30
|
# @param sut
|
@@ -81,18 +96,7 @@ module Simp::BeakerHelpers
|
|
81
96
|
tmpdir = Dir.mktmpdir
|
82
97
|
begin
|
83
98
|
Dir.chdir(tmpdir) do
|
84
|
-
|
85
|
-
# Work around for breaking changes in beaker-docker
|
86
|
-
if @sut.host_hash[:docker_container]
|
87
|
-
container_id = @sut.host_hash[:docker_container].id
|
88
|
-
else
|
89
|
-
container_id = @sut.host_hash[:docker_container_id]
|
90
|
-
end
|
91
|
-
|
92
|
-
%x(docker cp "#{container_id}:#{sut_inspec_results}" .)
|
93
|
-
else
|
94
|
-
scp_from(@sut, sut_inspec_results, '.')
|
95
|
-
end
|
99
|
+
scp_from(@sut, sut_inspec_results, '.')
|
96
100
|
|
97
101
|
local_inspec_results = File.basename(sut_inspec_results)
|
98
102
|
|
@@ -12,7 +12,7 @@ module Simp::BeakerHelpers
|
|
12
12
|
GIT_REPO = 'https://github.com/ComplianceAsCode/content.git'
|
13
13
|
end
|
14
14
|
|
15
|
-
# If this is not set, the
|
15
|
+
# If this is not set, the highest numeric tag will be used
|
16
16
|
GIT_BRANCH = nil
|
17
17
|
|
18
18
|
if ENV['BEAKER_ssg_branch']
|
@@ -25,19 +25,20 @@ module Simp::BeakerHelpers
|
|
25
25
|
'git',
|
26
26
|
'openscap-python',
|
27
27
|
'openscap-utils',
|
28
|
-
'python-
|
29
|
-
'python-
|
28
|
+
'python-jinja2',
|
29
|
+
'python-lxml'
|
30
30
|
]
|
31
31
|
|
32
32
|
EL8_PACKAGES = [
|
33
|
-
'python3',
|
34
|
-
'python3-pyyaml',
|
35
33
|
'cmake',
|
36
34
|
'git',
|
35
|
+
'make',
|
37
36
|
'openscap-python3',
|
38
37
|
'openscap-utils',
|
38
|
+
'python3',
|
39
|
+
'python3-jinja2',
|
39
40
|
'python3-lxml',
|
40
|
-
'python3-
|
41
|
+
'python3-pyyaml'
|
41
42
|
]
|
42
43
|
|
43
44
|
OS_INFO = {
|
@@ -79,7 +80,7 @@ module Simp::BeakerHelpers
|
|
79
80
|
'7' => {
|
80
81
|
'required_packages' => EL_PACKAGES,
|
81
82
|
'ssg' => {
|
82
|
-
'profile_target' => '
|
83
|
+
'profile_target' => 'centos7',
|
83
84
|
'build_target' => 'centos7',
|
84
85
|
'datastream' => 'ssg-centos7-ds.xml'
|
85
86
|
}
|
@@ -87,7 +88,7 @@ module Simp::BeakerHelpers
|
|
87
88
|
'8' => {
|
88
89
|
'required_packages' => EL8_PACKAGES,
|
89
90
|
'ssg' => {
|
90
|
-
'profile_target' => '
|
91
|
+
'profile_target' => 'centos8',
|
91
92
|
'build_target' => 'centos8',
|
92
93
|
'datastream' => 'ssg-centos8-ds.xml'
|
93
94
|
}
|
@@ -265,7 +266,7 @@ module Simp::BeakerHelpers
|
|
265
266
|
"contains(@idref,'#{exl}')"
|
266
267
|
end.join(' or ')
|
267
268
|
|
268
|
-
xpath_query << ')' if exclusions.size >
|
269
|
+
xpath_query << ')' if exclusions.size > 0
|
269
270
|
end
|
270
271
|
|
271
272
|
xpath_query << ')]'
|
@@ -299,8 +300,26 @@ module Simp::BeakerHelpers
|
|
299
300
|
result_id = rule_result.attributes['idref'].value.to_s
|
300
301
|
result_value = [
|
301
302
|
'Title: ' + doc.xpath("//Rule[@id='#{result_id}']/title/text()").first.to_s,
|
302
|
-
' ID: ' + result_id
|
303
|
-
]
|
303
|
+
' ID: ' + result_id,
|
304
|
+
]
|
305
|
+
|
306
|
+
if result.child.content == 'fail'
|
307
|
+
references = {}
|
308
|
+
|
309
|
+
doc.xpath("//Rule[@id='#{result_id}']/reference").each do |ref|
|
310
|
+
references[ref['href']] ||= []
|
311
|
+
references[ref['href']] << ref.text
|
312
|
+
end
|
313
|
+
|
314
|
+
result_value << ' References:'
|
315
|
+
references.each_pair do |src, items|
|
316
|
+
result_value << " * #{src}"
|
317
|
+
result_value << " * #{items.join(', ')}"
|
318
|
+
end
|
319
|
+
result_value << ' Description: ' + doc.xpath("//Rule[@id='#{result_id}']/description").text.gsub("\n","\n ")
|
320
|
+
end
|
321
|
+
|
322
|
+
result_value = result_value.join("\n")
|
304
323
|
|
305
324
|
if result.child.content == 'fail'
|
306
325
|
stats[:failed] << result_value.red
|
@@ -365,7 +384,12 @@ module Simp::BeakerHelpers
|
|
365
384
|
if GIT_BRANCH
|
366
385
|
on(@sut, %(cd scap-content; git checkout #{GIT_BRANCH}))
|
367
386
|
else
|
368
|
-
on(@sut, %(cd scap-content; git
|
387
|
+
tags = on(@sut, %(cd scap-content; git tag -l)).output
|
388
|
+
target_tag = tags.lines.map(&:strip)
|
389
|
+
.select{|x| x.start_with?(/v\d+\./)}
|
390
|
+
.sort.last
|
391
|
+
|
392
|
+
on(@sut, %(cd scap-content; git checkout #{target_tag}))
|
369
393
|
end
|
370
394
|
|
371
395
|
# Work around the issue where the profiles now strip out derivative
|
data/lib/simp/rake/beaker.rb
CHANGED
@@ -196,6 +196,7 @@ module Simp::Rake
|
|
196
196
|
default_suite = ordered_suites.delete('default')
|
197
197
|
ordered_suites.unshift(default_suite) if default_suite
|
198
198
|
|
199
|
+
suite_start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
199
200
|
ordered_suites.each do |ste|
|
200
201
|
|
201
202
|
next unless (suites[ste]['default_run'] == true)
|
@@ -225,8 +226,14 @@ module Simp::Rake
|
|
225
226
|
|
226
227
|
nodesets.each do |nodeset_yml|
|
227
228
|
unless File.file?(nodeset_yml)
|
228
|
-
|
229
|
-
|
229
|
+
# Get here if user has specified a non-existent nodeset or the
|
230
|
+
# implied `default` nodeset does not exist.
|
231
|
+
if suite_config['fail_fast']
|
232
|
+
fail("*** Suite #{name} Nodeset '#{File.basename(nodeset_yml, '.yml')}' Not Found ***")
|
233
|
+
else
|
234
|
+
$stdout.puts("=== Suite #{name} Nodeset '#{File.basename(nodeset_yml, '.yml')}' Not Found, Skipping ===")
|
235
|
+
next
|
236
|
+
end
|
230
237
|
end
|
231
238
|
|
232
239
|
ENV['BEAKER_setfile'] = nodeset_yml
|
@@ -255,6 +262,11 @@ module Simp::Rake
|
|
255
262
|
$stdout.puts("\n\n=== Suite '#{name}' Complete ===\n\n")
|
256
263
|
end
|
257
264
|
end
|
265
|
+
suite_end_time = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
266
|
+
|
267
|
+
suite_run_time = ((suite_end_time - suite_start_time)/60).round(2)
|
268
|
+
|
269
|
+
$stdout.puts("== Total Runtime: #{suite_run_time} minutes ==\n\n")
|
258
270
|
|
259
271
|
unless failures.keys.empty?
|
260
272
|
$stdout.puts("The following tests had failures:")
|
data/simp-beaker-helpers.gemspec
CHANGED
@@ -18,10 +18,14 @@ Gem::Specification.new do |s|
|
|
18
18
|
s.metadata = {
|
19
19
|
'issue_tracker' => 'https://simp-project.atlassian.net'
|
20
20
|
}
|
21
|
+
|
22
|
+
s.required_ruby_version = '>= 2.3.0'
|
23
|
+
|
21
24
|
s.add_runtime_dependency 'beaker' , ['>= 4.17.0', '< 5.0.0']
|
22
25
|
s.add_runtime_dependency 'beaker-rspec' , '~> 6.2'
|
23
26
|
s.add_runtime_dependency 'beaker-puppet' , ['>= 1.18.14', '< 2.0.0']
|
24
|
-
s.add_runtime_dependency 'beaker-docker' , '
|
27
|
+
s.add_runtime_dependency 'beaker-docker' , ['>= 0.8.3', '< 2.0.0']
|
28
|
+
s.add_runtime_dependency 'docker-api' , ['>= 2.1.0', '< 3.0.0']
|
25
29
|
s.add_runtime_dependency 'beaker-vagrant' , ['>= 0.6.4', '< 2.0.0']
|
26
30
|
s.add_runtime_dependency 'beaker-puppet_install_helper', '~> 0.9'
|
27
31
|
s.add_runtime_dependency 'highline' , '~> 2.0'
|
@@ -1,29 +1,31 @@
|
|
1
1
|
HOSTS:
|
2
|
-
el7:
|
2
|
+
el7.test.net:
|
3
3
|
roles:
|
4
4
|
- el7
|
5
5
|
- master
|
6
|
-
platform:
|
6
|
+
platform: el-7-x86_64
|
7
7
|
hypervisor: docker
|
8
|
-
image: simpproject/
|
9
|
-
docker_cmd: '/
|
8
|
+
image: simpproject/simp_beaker_el7
|
9
|
+
docker_cmd: '["/sbin/init"]'
|
10
10
|
|
11
|
-
el8:
|
11
|
+
el8.test.net:
|
12
12
|
roles:
|
13
13
|
- el8
|
14
|
-
platform:
|
14
|
+
platform: el-8-x86_64
|
15
15
|
hypervisor: docker
|
16
|
-
image: simpproject/
|
16
|
+
image: simpproject/simp_beaker_el8
|
17
17
|
docker_cmd: '["/sbin/init"]'
|
18
18
|
|
19
19
|
CONFIG:
|
20
|
-
docker_preserve_image: true
|
21
20
|
log_level: verbose
|
22
21
|
type: aio
|
23
|
-
<% if ENV['
|
24
|
-
|
22
|
+
<% if ENV['BEAKER_PUPPET_ENVIRONMENT'] -%>
|
23
|
+
puppet_environment: <%= ENV['BEAKER_PUPPET_ENVIRONMENT'] %>
|
25
24
|
<% end -%>
|
26
25
|
ssh:
|
26
|
+
password: root
|
27
|
+
auth_methods:
|
28
|
+
- password
|
27
29
|
keepalive: true
|
28
30
|
keepalive_interval: 10
|
29
31
|
host_key:
|
@@ -9,13 +9,15 @@ hosts.each do |host|
|
|
9
9
|
end
|
10
10
|
|
11
11
|
it 'has fips enabled' do
|
12
|
-
|
13
|
-
|
12
|
+
if host[:hypervisor] == 'docker'
|
13
|
+
skip('Not supported on docker')
|
14
|
+
else
|
15
|
+
expect(fips_enabled(host)).to be true
|
16
|
+
end
|
14
17
|
end
|
15
18
|
else
|
16
19
|
it 'has fips disabled' do
|
17
|
-
|
18
|
-
expect(stdout).to eq('0')
|
20
|
+
expect(fips_enabled(host)).to be false
|
19
21
|
end
|
20
22
|
end
|
21
23
|
end
|
@@ -1,12 +1,12 @@
|
|
1
1
|
require 'spec_helper_acceptance'
|
2
2
|
|
3
3
|
hosts.each do |host|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
end
|
4
|
+
expect_failures = false
|
5
|
+
if hosts_with_role(hosts, 'el8').include?(host)
|
6
|
+
expect_failures = true
|
7
|
+
end
|
9
8
|
|
9
|
+
describe '#install_simp_repos' do
|
10
10
|
it 'should install yum utils' do
|
11
11
|
host.install_package('yum-utils')
|
12
12
|
end
|
@@ -21,6 +21,18 @@ hosts.each do |host|
|
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
|
+
context 'when targeting a release type' do
|
25
|
+
it 'adjusts the SIMP release target' do
|
26
|
+
set_simp_repo_release(host, 'rolling')
|
27
|
+
expect(file_content_on(host, '/etc/yum/vars/simpreleasetype').strip).to eq('rolling')
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'lists the simp rpm' do
|
31
|
+
skip "#{host} is not supported yet" if expect_failures
|
32
|
+
on(host, 'yum list simp')
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
24
36
|
context 'when passed a disabled list ' do
|
25
37
|
before(:all) { install_simp_repos(host, ['simp-community-simp'] ) }
|
26
38
|
|
@@ -18,6 +18,7 @@ new_fixtures = {
|
|
18
18
|
}
|
19
19
|
}
|
20
20
|
|
21
|
+
new_fixtures['fixtures']['repositories']['crypto_policy'] = 'https://github.com/simp/pupmod-simp-crypto_policy'
|
21
22
|
new_fixtures['fixtures']['repositories']['fips'] = 'https://github.com/simp/pupmod-simp-fips'
|
22
23
|
new_fixtures['fixtures']['repositories']['augeasproviders_core'] = 'https://github.com/simp/augeasproviders_core'
|
23
24
|
new_fixtures['fixtures']['repositories']['augeasproviders_grub'] = 'https://github.com/simp/augeasproviders_grub'
|
@@ -54,12 +55,19 @@ describe 'FIPS pre-installed' do
|
|
54
55
|
hosts.each do |host|
|
55
56
|
context "on #{host}" do
|
56
57
|
it 'does not create an alternate apply directory' do
|
57
|
-
|
58
|
+
if host[:hypervisor] == 'docker'
|
59
|
+
skip('Not supported on docker')
|
60
|
+
else
|
61
|
+
on(host, 'test ! -d /root/.beaker_fips/modules')
|
62
|
+
end
|
58
63
|
end
|
59
64
|
|
60
65
|
it 'has fips enabled' do
|
61
|
-
|
62
|
-
|
66
|
+
if host[:hypervisor] == 'docker'
|
67
|
+
skip('Not supported on docker')
|
68
|
+
else
|
69
|
+
expect(fips_enabled(host)).to be true
|
70
|
+
end
|
63
71
|
end
|
64
72
|
end
|
65
73
|
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'spec_helper_acceptance'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
test_name 'Inspec STIG Profile'
|
5
|
+
|
6
|
+
describe 'Inspec STIG Profile' do
|
7
|
+
|
8
|
+
profiles_to_validate = ['disa_stig']
|
9
|
+
|
10
|
+
hosts.each do |host|
|
11
|
+
profiles_to_validate.each do |profile|
|
12
|
+
context "for profile #{profile}" do
|
13
|
+
context "on #{host}" do
|
14
|
+
profile_path = File.join(
|
15
|
+
fixtures_path,
|
16
|
+
'inspec_profiles',
|
17
|
+
"#{fact_on(host, 'operatingsystem')}-#{fact_on(host, 'operatingsystemmajrelease')}-#{profile}"
|
18
|
+
)
|
19
|
+
|
20
|
+
unless File.exist?(profile_path)
|
21
|
+
it 'should run inspec' do
|
22
|
+
skip("No matching profile available at #{profile_path}")
|
23
|
+
end
|
24
|
+
else
|
25
|
+
before(:all) do
|
26
|
+
Simp::BeakerHelpers::Inspec.enable_repo_on(hosts)
|
27
|
+
@inspec = Simp::BeakerHelpers::Inspec.new(host, profile)
|
28
|
+
|
29
|
+
# If we don't do this, the variable gets reset
|
30
|
+
@inspec_report = { :data => nil }
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'should run inspec' do
|
34
|
+
@inspec.run
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'should have an inspec report' do
|
38
|
+
@inspec_report[:data] = @inspec.process_inspec_results
|
39
|
+
|
40
|
+
expect(@inspec_report[:data]).to_not be_nil
|
41
|
+
|
42
|
+
@inspec.write_report(@inspec_report[:data])
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'should have a report' do
|
46
|
+
expect(@inspec_report[:data][:report]).to_not be_nil
|
47
|
+
puts @inspec_report[:data][:report]
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
spec/acceptance/suites/inspec/../../nodesets
|
@@ -13,7 +13,7 @@ end
|
|
13
13
|
hosts.each do |host|
|
14
14
|
describe 'make sure puppet version is valid' do
|
15
15
|
context "on #{host}" do
|
16
|
-
client_puppet_version = on(host, 'puppet --version').output.strip
|
16
|
+
client_puppet_version = on(host, 'puppet --version').output.lines.last.strip
|
17
17
|
|
18
18
|
it "should be running puppet version #{target_version}" do
|
19
19
|
expect(Gem::Version.new(client_puppet_version)).to be >= Gem::Version.new(target_version)
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'spec_helper_acceptance'
|
2
|
+
|
3
|
+
test_name 'SSG STIG Validation'
|
4
|
+
|
5
|
+
describe 'run the SSG against the STIG profile' do
|
6
|
+
|
7
|
+
hosts.each do |host|
|
8
|
+
context "on #{host}" do
|
9
|
+
before(:all) do
|
10
|
+
@ssg = Simp::BeakerHelpers::SSG.new(host)
|
11
|
+
|
12
|
+
# If we don't do this, the variable gets reset
|
13
|
+
@ssg_report = { :data => nil }
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'should run the SSG' do
|
17
|
+
profile = 'xccdf_org.ssgproject.content_profile_stig'
|
18
|
+
|
19
|
+
@ssg.evaluate(profile)
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'should have an SSG report' do
|
23
|
+
# Validate that the filter works
|
24
|
+
filter = '_rule_audit'
|
25
|
+
host_exclusions = ['ssh_']
|
26
|
+
|
27
|
+
@ssg_report[:data] = @ssg.process_ssg_results(filter, host_exclusions)
|
28
|
+
|
29
|
+
expect(@ssg_report[:data]).to_not be_nil
|
30
|
+
|
31
|
+
@ssg.write_report(@ssg_report[:data])
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'should have a report' do
|
35
|
+
expect(@ssg_report[:data][:report]).to_not be_nil
|
36
|
+
puts @ssg_report[:data][:report]
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|