|
20 | 20 |
|
21 | 21 | title 'CIS Docker Benchmark - Level 1 - Docker' |
22 | 22 |
|
| 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 |
23 | 37 | only_if do |
24 | 38 | command('docker').exist? |
25 | 39 | end |
|
236 | 250 | ref 'https://docs.docker.com/engine/security/certificates/' |
237 | 251 | ref 'docs.docker.com/reference/commandline/cli/#insecure-registries' |
238 | 252 |
|
239 | | - describe file(ENV['REGISTRY_CERT_PATH'] || '/etc/docker/certs.d') do |
| 253 | + describe file(attrs['REGISTRY_CERT_PATH']) do |
240 | 254 | it { should exist } |
241 | 255 | it { should be_directory } |
242 | 256 | it { should be_owned_by 'root' } |
243 | 257 | it { should be_grouped_into 'root' } |
244 | 258 | end |
245 | 259 |
|
246 | | - describe file(ENV['REGISTRY_NAME'] || '/etc/docker/certs.d/registry_hostname:port') do |
| 260 | + describe file(attrs['REGISTRY_NAME']) do |
247 | 261 | it { should exist } |
248 | 262 | it { should be_directory } |
249 | 263 | it { should be_owned_by 'root' } |
250 | 264 | it { should be_grouped_into 'root' } |
251 | 265 | end |
252 | 266 |
|
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 |
254 | 268 | it { should exist } |
255 | 269 | it { should be_file } |
256 | 270 | it { should be_owned_by 'root' } |
|
265 | 279 | ref 'https://docs.docker.com/engine/security/certificates/' |
266 | 280 | ref 'docs.docker.com/reference/commandline/cli/#insecure-registries' |
267 | 281 |
|
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 |
269 | 283 | it { should exist } |
270 | 284 | it { should be_file } |
271 | 285 | it { should be_readable } |
|
493 | 507 | raw = command("docker inspect #{id}").stdout |
494 | 508 | info = json('').parse(raw) |
495 | 509 | 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'] } |
497 | 511 | its(%w(Config User)) { should_not eq nil } |
498 | 512 | end |
499 | 513 | end |
|
543 | 557 | describe info[0] do |
544 | 558 | its(%w(HostConfig CapDrop)) { should include(/all/) } |
545 | 559 | 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'] } |
548 | 561 | end |
549 | 562 | end |
550 | 563 | end |
|
0 commit comments