Skip to content

use input instead of attribute #74

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 21 commits into from
Jan 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Test

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
schedule:
- cron: '0 6 * * *'

jobs:
test:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
ruby-version: ['2.6', '2.7', '3.0']

steps:
- uses: actions/checkout@v2
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby-version }}
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
- name: Run tests
run: bundle exec rake
22 changes: 14 additions & 8 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,33 @@ AllCops:
- vendor/**/*
Documentation:
Enabled: false
AlignParameters:
Layout/ParameterAlignment:
Enabled: true
Encoding:
Enabled: false
HashSyntax:
Enabled: true
LineLength:
Enabled: false
EmptyLinesAroundBlockBody:
Enabled: false
Style/Encoding:
Enabled: false
MethodLength:
Max: 40
NumericLiterals:
MinDigits: 10
Metrics/BlockLength:
Max: 45 # needed for 6.1.1
Metrics/CyclomaticComplexity:
Max: 10
Metrics/PerceivedComplexity:
Max: 10
Metrics/AbcSize:
Max: 29
Metrics/BlockLength:
Max: 29
AllCops:
TargetRubyVersion: 2.2
Max: 30
# Lint/AmbiguousBlockAssociation is incompatible with RSpec
# https://github.com/rubocop-hq/rubocop/issues/4222
Lint/AmbiguousBlockAssociation:
Enabled: false
Lint/AmbiguousRegexpLiteral:
Enabled: false
Style/NumericPredicate:
Enabled: false
18 changes: 12 additions & 6 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
source 'https://rubygems.org'
# frozen_string_literal: true

gem 'highline', '~> 1.6.0'
source 'https://rubygems.org'

gem 'inspec', '~> 2'
gem 'rack', '1.6.4'
gem 'highline'
gem 'rack'
gem 'rake'
gem 'rubocop', '~> 0.49.0'
gem 'rubocop'

group :tools do
gem 'github_changelog_generator', '~> 1.14.0'
gem 'github_changelog_generator'
gem 'pry-coolline'
end

source 'https://packagecloud.io/cinc-project/stable' do
gem 'chef-config'
gem 'cinc-auditor-bin'
end
25 changes: 5 additions & 20 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env rake
# encoding: utf-8
# frozen_string_literal: true

require 'rake/testtask'
require 'rubocop/rake_task'
Expand All @@ -20,23 +19,9 @@ task default: [:lint, 'test:check']
namespace :test do
# run inspec check to verify that the profile is properly configured
task :check do
dir = File.join(File.dirname(__FILE__))
sh("bundle exec inspec check #{dir}")
require 'inspec'
puts "Checking profile with InSpec Version: #{Inspec::VERSION}"
profile = Inspec::Profile.for_target('.', backend: Inspec::Backend.create(Inspec::Config.mock))
pp profile.check
end
end

# Automatically generate a changelog for this project. Only loaded if
# the necessary gem is installed. By default its picking up the version from
# inspec.yml. You can override that behavior with `rake changelog to=1.2.0`
begin
require 'yaml'
metadata = YAML.load_file('inspec.yml')
v = ENV['to'] || metadata['version']
puts "Generate changelog for version #{v}"
require 'github_changelog_generator/task'
GitHubChangelogGenerator::RakeTask.new :changelog do |config|
config.future_release = v
end
rescue LoadError
puts '>>>>> GitHub Changelog Generator not loaded, omitting tasks'
end
1 change: 1 addition & 0 deletions Vagrantfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# encoding: utf-8
# frozen_string_literal: true

# -*- mode: ruby -*-
# vi: set ft=ruby :
Expand Down
2 changes: 1 addition & 1 deletion controls/container_images.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
title 'Container Images and Build File'

# attributes
CONTAINER_USER = attribute('container_user')
CONTAINER_USER = input('container_user')

# check if docker exists
only_if('docker not found') do
Expand Down
26 changes: 15 additions & 11 deletions controls/container_runtime.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
title 'Container Runtime'

# attributes
CONTAINER_CAPADD = attribute('container_capadd')
APP_ARMOR_PROFILE = attribute('app_armor_profile')
SELINUX_PROFILE = attribute('selinux_profile')
CONTAINER_CAPADD = input('container_capadd')
APP_ARMOR_PROFILE = input('app_armor_profile')
SELINUX_PROFILE = input('selinux_profile')

# check if docker exists
only_if('docker not found') do
Expand Down Expand Up @@ -153,13 +153,13 @@
info['Mounts'].each do |mounts|
describe mounts['Source'] do
it { should_not eq '/' }
it { should_not match(%r{\/boot}) }
it { should_not match(%r{\/dev}) }
it { should_not match(%r{\/etc}) }
it { should_not match(%r{\/lib}) }
it { should_not match(%r{\/proc}) }
it { should_not match(%r{\/sys}) }
it { should_not match(%r{\/usr}) }
it { should_not match(%r{/boot}) }
it { should_not match(%r{/dev}) }
it { should_not match(%r{/etc}) }
it { should_not match(%r{/lib}) }
it { should_not match(%r{/proc}) }
it { should_not match(%r{/sys}) }
it { should_not match(%r{/usr}) }
end
end
end
Expand All @@ -185,7 +185,7 @@
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/'

docker.containers.running?.ids.each do |id|
execute_command = 'docker exec ' + id + ' ps -e'
execute_command = "docker exec #{id} ps -e"
describe command(execute_command) do
its('stdout') { should_not match(/ssh/) }
end
Expand All @@ -209,8 +209,10 @@
docker.containers.running?.ids.each do |id|
container_info = docker.object(id)
next if container_info['NetworkSettings']['Ports'].nil?

container_info['NetworkSettings']['Ports'].each do |_, hosts|
next if hosts.nil?

hosts.each do |host|
describe host['HostPort'].to_i.between?(1, 1024) do
it { should eq false }
Expand Down Expand Up @@ -341,8 +343,10 @@
docker.containers.running?.ids.each do |id|
container_info = docker.object(id)
next if container_info['NetworkSettings']['Ports'].nil?

container_info['NetworkSettings']['Ports'].each do |_, hosts|
next if hosts.nil?

hosts.each do |host|
describe host['HostIp'].to_i.between?(1, 1024) do
it { should_not eq '0.0.0.0' }
Expand Down
24 changes: 12 additions & 12 deletions controls/docker_daemon_configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@
title 'Docker Daemon Configuration'

# attributes
DAEMON_TLSCACERT = attribute('daemon_tlscacert')
DAEMON_TLSCERT = attribute('daemon_tlscert')
DAEMON_TLSKEY = attribute('daemon_tlskey')
AUTHORIZATION_PLUGIN = attribute('authorization_plugin')
LOG_DRIVER = attribute('log_driver')
LOG_OPTS = attribute('log_opts')
SWARM_MODE = attribute('swarm_mode')
SWARM_MAX_MANAGER_NODES = attribute('swarm_max_manager_nodes')
SWARM_PORT = attribute('swarm_port')
SECCOMP_DEFAULT_PROFILE = attribute('seccomp_default_profile')
DAEMON_TLSCACERT = input('daemon_tlscacert')
DAEMON_TLSCERT = input('daemon_tlscert')
DAEMON_TLSKEY = input('daemon_tlskey')
AUTHORIZATION_PLUGIN = input('authorization_plugin')
LOG_DRIVER = input('log_driver')
LOG_OPTS = input('log_opts')
SWARM_MODE = input('swarm_mode')
SWARM_MAX_MANAGER_NODES = input('swarm_max_manager_nodes')
SWARM_PORT = input('swarm_port')
SECCOMP_DEFAULT_PROFILE = input('seccomp_default_profile')

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

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

Expand Down
6 changes: 3 additions & 3 deletions controls/docker_daemon_configuration_files.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
title 'Docker Daemon Configuration Files'

# attributes
REGISTRY_CERT_PATH = attribute('registry_cert_path')
REGISTRY_NAME = attribute('registry_name')
REGISTRY_CA_FILE = attribute('registry_ca_file')
REGISTRY_CERT_PATH = input('registry_cert_path')
REGISTRY_NAME = input('registry_name')
REGISTRY_CA_FILE = input('registry_ca_file')

# check if docker exists
only_if('docker not found') do
Expand Down
10 changes: 5 additions & 5 deletions controls/host_configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@

title 'Host Configuration'

TRUSTED_USER = attribute('trusted_user')
MANAGEABLE_CONTAINER_NUMBER = attribute('managable_container_number')
BENCHMARK_VERSION = attribute('benchmark_version')
TRUSTED_USER = input('trusted_user')
MANAGEABLE_CONTAINER_NUMBER = input('managable_container_number')
BENCHMARK_VERSION = input('benchmark_version')

# check if docker exists
only_if('docker not found') do
Expand Down Expand Up @@ -233,7 +233,7 @@

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

only_if { os.linux? }
if docker_helper.socket
rule = '-w ' + docker_helper.socket + ' -p rwxa -k docker'
rule = "-w #{docker_helper.socket} -p rwxa -k docker"
describe auditd do
its(:lines) { should include(rule) }
end
Expand Down
2 changes: 1 addition & 1 deletion inspec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ copyright_email: hello@dev-sec.io
license: Apache-2.0
summary: An InSpec Compliance Profile for the CIS Docker Benchmark
version: 2.1.3
inspec_version: '>= 2.3.23'
inspec_version: '>= 4.6.3'
attributes:
- name: container_user
required: false
Expand Down
1 change: 1 addition & 0 deletions libraries/docker_helper.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# encoding: utf-8
# frozen_string_literal: true

# Copyright 2016, Christoph Hartmann
#
Expand Down