Skip to content

Commit c6400de

Browse files
use input instead of attribute (#74)
* use input instead of attribute In the last versions of Inspec and cinc-auditor, attribute is deprecated and input should be used. https://docs.chef.io/workstation/cookstyle/inspec_deprecations_attributehelper/ Signed-off-by: Michée Lengronne <michee.lengronne@coppint.com> * Update container_runtime.rb Signed-off-by: Michée Lengronne <michee.lengronne@coppint.com> * Update docker_daemon_configuration.rb Signed-off-by: Michée Lengronne <michee.lengronne@coppint.com> * Update docker_daemon_configuration_files.rb Signed-off-by: Michée Lengronne <michee.lengronne@coppint.com> * Update host_configuration.rb Signed-off-by: Michée Lengronne <michee.lengronne@coppint.com> * Update inspec.yml Signed-off-by: Michée Lengronne <michee.lengronne@coppint.com> * Create test.yml Signed-off-by: Michée Lengronne <michee.lengronne@coppint.com> * Update Rakefile Signed-off-by: Michée Lengronne <michee.lengronne@coppint.com> * Update Rakefile Signed-off-by: Michée Lengronne <michee.lengronne@coppint.com> * Update Gemfile Signed-off-by: Michée Lengronne <michee.lengronne@coppint.com> * Update .rubocop.yml Signed-off-by: Michée Lengronne <michee.lengronne@coppint.com> * Update Vagrantfile Signed-off-by: Michée Lengronne <michee.lengronne@coppint.com> * Update container_runtime.rb Signed-off-by: Michée Lengronne <michee.lengronne@coppint.com> * Update docker_daemon_configuration.rb Signed-off-by: Michée Lengronne <michee.lengronne@coppint.com> * Update host_configuration.rb Signed-off-by: Michée Lengronne <michee.lengronne@coppint.com> * Update container_images.rb Signed-off-by: Michée Lengronne <michee.lengronne@coppint.com> * Update container_images.rb Signed-off-by: Michée Lengronne <michee.lengronne@coppint.com> * Update host_configuration.rb Signed-off-by: Michée Lengronne <michee.lengronne@coppint.com> * Update Vagrantfile Signed-off-by: Michée Lengronne <michee.lengronne@coppint.com> * Update container_runtime.rb Signed-off-by: Michée Lengronne <michee.lengronne@coppint.com> * Update docker_helper.rb Signed-off-by: Michée Lengronne <michee.lengronne@coppint.com>
1 parent f4f3c02 commit c6400de

File tree

12 files changed

+97
-67
lines changed

12 files changed

+97
-67
lines changed

.github/workflows/test.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Test
2+
3+
on:
4+
push:
5+
branches: [ master ]
6+
pull_request:
7+
branches: [ master ]
8+
schedule:
9+
- cron: '0 6 * * *'
10+
11+
jobs:
12+
test:
13+
runs-on: ubuntu-latest
14+
strategy:
15+
fail-fast: false
16+
matrix:
17+
ruby-version: ['2.6', '2.7', '3.0']
18+
19+
steps:
20+
- uses: actions/checkout@v2
21+
- name: Set up Ruby
22+
uses: ruby/setup-ruby@v1
23+
with:
24+
ruby-version: ${{ matrix.ruby-version }}
25+
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
26+
- name: Run tests
27+
run: bundle exec rake

.rubocop.yml

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,33 @@ AllCops:
44
- vendor/**/*
55
Documentation:
66
Enabled: false
7-
AlignParameters:
7+
Layout/ParameterAlignment:
88
Enabled: true
9-
Encoding:
10-
Enabled: false
119
HashSyntax:
1210
Enabled: true
1311
LineLength:
1412
Enabled: false
1513
EmptyLinesAroundBlockBody:
1614
Enabled: false
15+
Style/Encoding:
16+
Enabled: false
1717
MethodLength:
1818
Max: 40
1919
NumericLiterals:
2020
MinDigits: 10
21+
Metrics/BlockLength:
22+
Max: 45 # needed for 6.1.1
2123
Metrics/CyclomaticComplexity:
2224
Max: 10
2325
Metrics/PerceivedComplexity:
2426
Max: 10
2527
Metrics/AbcSize:
26-
Max: 29
27-
Metrics/BlockLength:
28-
Max: 29
29-
AllCops:
30-
TargetRubyVersion: 2.2
28+
Max: 30
29+
# Lint/AmbiguousBlockAssociation is incompatible with RSpec
30+
# https://github.com/rubocop-hq/rubocop/issues/4222
31+
Lint/AmbiguousBlockAssociation:
32+
Enabled: false
33+
Lint/AmbiguousRegexpLiteral:
34+
Enabled: false
35+
Style/NumericPredicate:
36+
Enabled: false

Gemfile

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
1-
source 'https://rubygems.org'
1+
# frozen_string_literal: true
22

3-
gem 'highline', '~> 1.6.0'
3+
source 'https://rubygems.org'
44

5-
gem 'inspec', '~> 2'
6-
gem 'rack', '1.6.4'
5+
gem 'highline'
6+
gem 'rack'
77
gem 'rake'
8-
gem 'rubocop', '~> 0.49.0'
8+
gem 'rubocop'
99

1010
group :tools do
11-
gem 'github_changelog_generator', '~> 1.14.0'
11+
gem 'github_changelog_generator'
12+
gem 'pry-coolline'
13+
end
14+
15+
source 'https://packagecloud.io/cinc-project/stable' do
16+
gem 'chef-config'
17+
gem 'cinc-auditor-bin'
1218
end

Rakefile

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
#!/usr/bin/env rake
2-
# encoding: utf-8
1+
# frozen_string_literal: true
32

43
require 'rake/testtask'
54
require 'rubocop/rake_task'
@@ -20,23 +19,9 @@ task default: [:lint, 'test:check']
2019
namespace :test do
2120
# run inspec check to verify that the profile is properly configured
2221
task :check do
23-
dir = File.join(File.dirname(__FILE__))
24-
sh("bundle exec inspec check #{dir}")
22+
require 'inspec'
23+
puts "Checking profile with InSpec Version: #{Inspec::VERSION}"
24+
profile = Inspec::Profile.for_target('.', backend: Inspec::Backend.create(Inspec::Config.mock))
25+
pp profile.check
2526
end
2627
end
27-
28-
# Automatically generate a changelog for this project. Only loaded if
29-
# the necessary gem is installed. By default its picking up the version from
30-
# inspec.yml. You can override that behavior with `rake changelog to=1.2.0`
31-
begin
32-
require 'yaml'
33-
metadata = YAML.load_file('inspec.yml')
34-
v = ENV['to'] || metadata['version']
35-
puts "Generate changelog for version #{v}"
36-
require 'github_changelog_generator/task'
37-
GitHubChangelogGenerator::RakeTask.new :changelog do |config|
38-
config.future_release = v
39-
end
40-
rescue LoadError
41-
puts '>>>>> GitHub Changelog Generator not loaded, omitting tasks'
42-
end

Vagrantfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# encoding: utf-8
2+
# frozen_string_literal: true
23

34
# -*- mode: ruby -*-
45
# vi: set ft=ruby :

controls/container_images.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
title 'Container Images and Build File'
2424

2525
# attributes
26-
CONTAINER_USER = attribute('container_user')
26+
CONTAINER_USER = input('container_user')
2727

2828
# check if docker exists
2929
only_if('docker not found') do

controls/container_runtime.rb

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@
2323
title 'Container Runtime'
2424

2525
# attributes
26-
CONTAINER_CAPADD = attribute('container_capadd')
27-
APP_ARMOR_PROFILE = attribute('app_armor_profile')
28-
SELINUX_PROFILE = attribute('selinux_profile')
26+
CONTAINER_CAPADD = input('container_capadd')
27+
APP_ARMOR_PROFILE = input('app_armor_profile')
28+
SELINUX_PROFILE = input('selinux_profile')
2929

3030
# check if docker exists
3131
only_if('docker not found') do
@@ -153,13 +153,13 @@
153153
info['Mounts'].each do |mounts|
154154
describe mounts['Source'] do
155155
it { should_not eq '/' }
156-
it { should_not match(%r{\/boot}) }
157-
it { should_not match(%r{\/dev}) }
158-
it { should_not match(%r{\/etc}) }
159-
it { should_not match(%r{\/lib}) }
160-
it { should_not match(%r{\/proc}) }
161-
it { should_not match(%r{\/sys}) }
162-
it { should_not match(%r{\/usr}) }
156+
it { should_not match(%r{/boot}) }
157+
it { should_not match(%r{/dev}) }
158+
it { should_not match(%r{/etc}) }
159+
it { should_not match(%r{/lib}) }
160+
it { should_not match(%r{/proc}) }
161+
it { should_not match(%r{/sys}) }
162+
it { should_not match(%r{/usr}) }
163163
end
164164
end
165165
end
@@ -185,7 +185,7 @@
185185
ref 'Why you don\'t need to run SSHd in your Docker containers', url: 'https://blog.docker.com/2014/06/why-you-dont-need-to-run-sshd-in-docker/'
186186

187187
docker.containers.running?.ids.each do |id|
188-
execute_command = 'docker exec ' + id + ' ps -e'
188+
execute_command = "docker exec #{id} ps -e"
189189
describe command(execute_command) do
190190
its('stdout') { should_not match(/ssh/) }
191191
end
@@ -209,8 +209,10 @@
209209
docker.containers.running?.ids.each do |id|
210210
container_info = docker.object(id)
211211
next if container_info['NetworkSettings']['Ports'].nil?
212+
212213
container_info['NetworkSettings']['Ports'].each do |_, hosts|
213214
next if hosts.nil?
215+
214216
hosts.each do |host|
215217
describe host['HostPort'].to_i.between?(1, 1024) do
216218
it { should eq false }
@@ -341,8 +343,10 @@
341343
docker.containers.running?.ids.each do |id|
342344
container_info = docker.object(id)
343345
next if container_info['NetworkSettings']['Ports'].nil?
346+
344347
container_info['NetworkSettings']['Ports'].each do |_, hosts|
345348
next if hosts.nil?
349+
346350
hosts.each do |host|
347351
describe host['HostIp'].to_i.between?(1, 1024) do
348352
it { should_not eq '0.0.0.0' }

controls/docker_daemon_configuration.rb

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,16 @@
2323
title 'Docker Daemon Configuration'
2424

2525
# attributes
26-
DAEMON_TLSCACERT = attribute('daemon_tlscacert')
27-
DAEMON_TLSCERT = attribute('daemon_tlscert')
28-
DAEMON_TLSKEY = attribute('daemon_tlskey')
29-
AUTHORIZATION_PLUGIN = attribute('authorization_plugin')
30-
LOG_DRIVER = attribute('log_driver')
31-
LOG_OPTS = attribute('log_opts')
32-
SWARM_MODE = attribute('swarm_mode')
33-
SWARM_MAX_MANAGER_NODES = attribute('swarm_max_manager_nodes')
34-
SWARM_PORT = attribute('swarm_port')
35-
SECCOMP_DEFAULT_PROFILE = attribute('seccomp_default_profile')
26+
DAEMON_TLSCACERT = input('daemon_tlscacert')
27+
DAEMON_TLSCERT = input('daemon_tlscert')
28+
DAEMON_TLSKEY = input('daemon_tlskey')
29+
AUTHORIZATION_PLUGIN = input('authorization_plugin')
30+
LOG_DRIVER = input('log_driver')
31+
LOG_OPTS = input('log_opts')
32+
SWARM_MODE = input('swarm_mode')
33+
SWARM_MAX_MANAGER_NODES = input('swarm_max_manager_nodes')
34+
SWARM_PORT = input('swarm_port')
35+
SECCOMP_DEFAULT_PROFILE = input('seccomp_default_profile')
3636

3737
# check if docker exists
3838
only_if('docker not found') do
@@ -168,8 +168,8 @@
168168
ref 'Docker daemon deafult ulimits', url: 'https://docs.docker.com/engine/reference/commandline/daemon/#default-ulimits'
169169

170170
describe json('/etc/docker/daemon.json') do
171-
its(['default-ulimits', 'nproc']) { should eq('1024:2408') }
172-
its(['default-ulimits', 'nofile']) { should eq('100': '200') }
171+
its(%w[default-ulimits nproc]) { should eq('1024:2408') }
172+
its(%w[default-ulimits nofile]) { should eq('100': '200') }
173173
end
174174
end
175175

controls/docker_daemon_configuration_files.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@
2323
title 'Docker Daemon Configuration Files'
2424

2525
# attributes
26-
REGISTRY_CERT_PATH = attribute('registry_cert_path')
27-
REGISTRY_NAME = attribute('registry_name')
28-
REGISTRY_CA_FILE = attribute('registry_ca_file')
26+
REGISTRY_CERT_PATH = input('registry_cert_path')
27+
REGISTRY_NAME = input('registry_name')
28+
REGISTRY_CA_FILE = input('registry_ca_file')
2929

3030
# check if docker exists
3131
only_if('docker not found') do

controls/host_configuration.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@
2222

2323
title 'Host Configuration'
2424

25-
TRUSTED_USER = attribute('trusted_user')
26-
MANAGEABLE_CONTAINER_NUMBER = attribute('managable_container_number')
27-
BENCHMARK_VERSION = attribute('benchmark_version')
25+
TRUSTED_USER = input('trusted_user')
26+
MANAGEABLE_CONTAINER_NUMBER = input('managable_container_number')
27+
BENCHMARK_VERSION = input('benchmark_version')
2828

2929
# check if docker exists
3030
only_if('docker not found') do
@@ -233,7 +233,7 @@
233233

234234
only_if { os.linux? }
235235
if docker_helper.path
236-
rule = '-w ' + docker_helper.path + ' -p rwxa -k docker'
236+
rule = "-w #{docker_helper.path} -p rwxa -k docker"
237237
describe auditd do
238238
its(:lines) { should include(rule) }
239239
end
@@ -259,7 +259,7 @@
259259

260260
only_if { os.linux? }
261261
if docker_helper.socket
262-
rule = '-w ' + docker_helper.socket + ' -p rwxa -k docker'
262+
rule = "-w #{docker_helper.socket} -p rwxa -k docker"
263263
describe auditd do
264264
its(:lines) { should include(rule) }
265265
end

0 commit comments

Comments
 (0)