Skip to content

Commit b171fd2

Browse files
committed
Merge pull request #1 from dev-sec/chris-rock/attributes
determine attribute values at the beginning
2 parents b870183 + 6abe5e5 commit b171fd2

3 files changed

Lines changed: 49 additions & 14 deletions

File tree

controls/docker_host_os_level1.rb

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,14 @@
2020

2121
title 'CIS Docker Benchmark - Level 1 - Linux Host OS'
2222

23+
# attributes
24+
attrs = {}
25+
# define trusted user to control Docker daemon. cis-docker-benchmark-1.6
26+
attrs['TRUSTED_USER'] = ENV['TRUSTED_USER'] || 'vagrant'
27+
# keep number of containers on a host to a manageable total. cis-docker-benchmark-6.5
28+
attrs['MANAGEABLE_CONTAINER_NUMBER'] = ENV['MANAGEABLE_CONTAINER_NUMBER'] || 25
29+
30+
# check if docker exists
2331
only_if do
2432
command('docker').exist?
2533
end
@@ -99,7 +107,7 @@
99107
end
100108

101109
describe etc_group.where(group_name: 'docker') do
102-
its('users') { should include ENV['TRUSTED_USER'] || 'vagrant' }
110+
its('users') { should include attrs['TRUSTED_USER'] }
103111
end
104112
end
105113

@@ -245,6 +253,6 @@
245253
diff = total_on_host - total_running
246254

247255
describe diff do
248-
it { should be <= (ENV['MANAGEABLE_CONTAINER_NUMBER'] || 25) }
256+
it { should be <= (attrs['MANAGEABLE_CONTAINER_NUMBER']) }
249257
end
250258
end

controls/docker_level1.rb

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,20 @@
2020

2121
title 'CIS Docker Benchmark - Level 1 - Docker'
2222

23+
# attributes
24+
attrs = {}
25+
# directory contains various Docker registry directories. cis-docker-benchmark-3.7
26+
attrs['REGISTRY_CERT_PATH'] = ENV['REGISTRY_CERT_PATH'] || '/etc/docker/certs.d'
27+
# directory contain certificate certain Docker registry. cis-docker-benchmark-3.7
28+
attrs['REGISTRY_NAME'] = ENV['REGISTRY_NAME'] || '/etc/docker/certs.d/registry_hostname:port'
29+
# certificate file for a certain Docker registry certificate files. cis-docker-benchmark-3.7 and cis-docker-benchmark-3.8
30+
attrs['REGISTRY_CA_FILE'] = ENV['REGISTRY_CA_FILE'] || '/etc/docker/certs.d/registry_hostname:port/ca.crt'
31+
# define user within containers. cis-docker-benchmark-4.1
32+
attrs['CONTAINER_USER'] = ENV['CONTAINER_USER'] || 'ubuntu'
33+
# define needed capabilities for containers. example: `CONTAINER_CAPADD="NET_ADMIN,SYS_ADMIN"` cis-docker-benchmark-5.3
34+
attrs['CONTAINER_CAPADD'] = ENV['CONTAINER_CAPADD'].nil? ? ENV['CONTAINER_CAPADD'] : ENV['CONTAINER_CAPADD'].split(',')
35+
36+
# check if docker exists
2337
only_if do
2438
command('docker').exist?
2539
end
@@ -236,21 +250,21 @@
236250
ref 'https://docs.docker.com/engine/security/certificates/'
237251
ref 'docs.docker.com/reference/commandline/cli/#insecure-registries'
238252

239-
describe file(ENV['REGISTRY_CERT_PATH'] || '/etc/docker/certs.d') do
253+
describe file(attrs['REGISTRY_CERT_PATH']) do
240254
it { should exist }
241255
it { should be_directory }
242256
it { should be_owned_by 'root' }
243257
it { should be_grouped_into 'root' }
244258
end
245259

246-
describe file(ENV['REGISTRY_NAME'] || '/etc/docker/certs.d/registry_hostname:port') do
260+
describe file(attrs['REGISTRY_NAME']) do
247261
it { should exist }
248262
it { should be_directory }
249263
it { should be_owned_by 'root' }
250264
it { should be_grouped_into 'root' }
251265
end
252266

253-
describe file(ENV['REGISTRY_CA_FILE'] || '/etc/docker/certs.d/registry_hostname:port/ca.crt') do
267+
describe file(attrs['REGISTRY_CA_FILE']) do
254268
it { should exist }
255269
it { should be_file }
256270
it { should be_owned_by 'root' }
@@ -265,7 +279,7 @@
265279
ref 'https://docs.docker.com/engine/security/certificates/'
266280
ref 'docs.docker.com/reference/commandline/cli/#insecure-registries'
267281

268-
describe file(ENV['REGISTRY_CA_FILE'] || '/etc/docker/certs.d/registry_hostname:port/ca.crt') do
282+
describe file(attrs['REGISTRY_CA_FILE']) do
269283
it { should exist }
270284
it { should be_file }
271285
it { should be_readable }
@@ -493,7 +507,7 @@
493507
raw = command("docker inspect #{id}").stdout
494508
info = json('').parse(raw)
495509
describe info[0] do
496-
its(%w(Config User)) { should eq ENV['CONTAINER_USER'] || 'ubuntu' }
510+
its(%w(Config User)) { should eq attrs['CONTAINER_USER'] }
497511
its(%w(Config User)) { should_not eq nil }
498512
end
499513
end
@@ -543,8 +557,7 @@
543557
describe info[0] do
544558
its(%w(HostConfig CapDrop)) { should include(/all/) }
545559
its(%w(HostConfig CapDrop)) { should_not eq nil }
546-
# its(%w(HostConfig CapAdd)) { should eq ENV['CONTAINER_CAPADD']&.split(',') }
547-
its(%w(HostConfig CapAdd)) { should eq ENV['CONTAINER_CAPADD'].nil? ? ENV['CONTAINER_CAPADD'] : ENV['CONTAINER_CAPADD'].split(',') }
560+
its(%w(HostConfig CapAdd)) { should eq attrs['CONTAINER_CAPADD'] }
548561
end
549562
end
550563
end

controls/docker_level2.rb

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,20 @@
2020

2121
title 'CIS Docker Benchmark - Level 2 - Docker'
2222

23+
# attributes
24+
attrs = {}
25+
# define authorization plugin to manage access to Docker daemon. cis-docker-benchmark-2.11
26+
attrs['AUTHORIZATION_PLUGIN'] = [ENV['AUTHORIZATION_PLUGIN'] || 'authz-broker']
27+
# define preferable way to store logs. cis-docker-benchmark-2.12
28+
attrs['LOG_DRIVER'] = ENV['LOG_DRIVER'] || 'syslog'
29+
# define Docker daemon log-opts. cis-docker-benchmark-2.12
30+
attrs['LOG_OPTS'] = ENV['LOG_OPTS'] || /syslog-address/
31+
# define apparmor profile for Docker containers. cis-docker-benchmark-5.1
32+
attrs['APP_ARMOR_PROFILE'] = ENV['APP_ARMOR_PROFILE'] || 'docker-default'
33+
# define SELinux profile for Docker containers. cis-docker-benchmark-5.2
34+
attrs['SELINUX_PROFILE'] = ENV['SELINUX_PROFILE'] || /label\:level\:s0-s0\:c1023/
35+
36+
# check if docker exists
2337
only_if do
2438
command('docker').exist?
2539
end
@@ -73,7 +87,7 @@
7387
its(['authorization-plugins']) { should_not be_empty }
7488
end
7589
describe json('/etc/docker/daemon.json') do
76-
its(['authorization-plugins']) { should eq([ENV['AUTHORIZATION_PLUGIN'] || 'authz-broker']) }
90+
its(['authorization-plugins']) { should eq(attrs['AUTHORIZATION_PLUGIN']) }
7791
end
7892
end
7993

@@ -88,10 +102,10 @@
88102
its(['log-driver']) { should_not be_empty }
89103
end
90104
describe json('/etc/docker/daemon.json') do
91-
its(['log-driver']) { should eq(ENV['LOG_DRIVER'] || 'syslog') }
105+
its(['log-driver']) { should eq(attrs['LOG_DRIVER']) }
92106
end
93107
describe json('/etc/docker/daemon.json') do
94-
its(['log-opts']) { should include(ENV['LOG_OPTS'] || /syslog-address/) }
108+
its(['log-opts']) { should include(attrs['LOG_OPTS']) }
95109
end
96110
end
97111

@@ -136,7 +150,7 @@
136150
raw = command("docker inspect #{id}").stdout
137151
info = json('').parse(raw)
138152
describe info[0] do
139-
its(['AppArmorProfile']) { should include(ENV['APP_ARMOR_PROFILE'] || 'docker-default') }
153+
its(['AppArmorProfile']) { should include(attrs['APP_ARMOR_PROFILE']) }
140154
its(['AppArmorProfile']) { should_not eq nil }
141155
end
142156
end
@@ -163,7 +177,7 @@
163177
info = json('').parse(raw)
164178
describe info[0] do
165179
its(%w(HostConfig SecurityOpt)) { should_not eq nil }
166-
its(%w(HostConfig SecurityOpt)) { should include(ENV['SELINUX_PROFILE'] || /label\:level\:s0-s0\:c1023/) }
180+
its(%w(HostConfig SecurityOpt)) { should include(attrs['SELINUX_PROFILE']) }
167181
end
168182
end
169183
end

0 commit comments

Comments
 (0)