|
22 | 22 | title 'CIS Docker Benchmark - Level 1 - Docker' |
23 | 23 |
|
24 | 24 | # attributes |
25 | | -attrs = {} |
26 | | -# directory contains various Docker registry directories. cis-docker-benchmark-3.7 |
27 | | -attrs['REGISTRY_CERT_PATH'] = ENV['REGISTRY_CERT_PATH'] || '/etc/docker/certs.d' |
28 | | -# directory contain certificate certain Docker registry. cis-docker-benchmark-3.7 |
29 | | -attrs['REGISTRY_NAME'] = ENV['REGISTRY_NAME'] || '/etc/docker/certs.d/registry_hostname:port' |
30 | | -# certificate file for a certain Docker registry certificate files. cis-docker-benchmark-3.7 and cis-docker-benchmark-3.8 |
31 | | -attrs['REGISTRY_CA_FILE'] = ENV['REGISTRY_CA_FILE'] || '/etc/docker/certs.d/registry_hostname:port/ca.crt' |
32 | | -# define user within containers. cis-docker-benchmark-4.1 |
33 | | -attrs['CONTAINER_USER'] = ENV['CONTAINER_USER'] || 'ubuntu' |
34 | | -# define needed capabilities for containers. example: `CONTAINER_CAPADD="NET_ADMIN,SYS_ADMIN"` cis-docker-benchmark-5.3 |
35 | | -attrs['CONTAINER_CAPADD'] = ENV['CONTAINER_CAPADD'].nil? ? ENV['CONTAINER_CAPADD'] : ENV['CONTAINER_CAPADD'].split(',') |
| 25 | +REGISTRY_CERT_PATH = attribute( |
| 26 | + 'registry_cert_path', |
| 27 | + description: 'directory contains various Docker registry directories. cis-docker-benchmark-3.7', |
| 28 | + default: '/etc/docker/certs.d' |
| 29 | +) |
| 30 | + |
| 31 | +REGISTRY_NAME = attribute( |
| 32 | + 'registry_name', |
| 33 | + description: 'directory contain certificate certain Docker registry. cis-docker-benchmark-3.7', |
| 34 | + default: '/etc/docker/certs.d/registry_hostname:port' |
| 35 | +) |
| 36 | + |
| 37 | +REGISTRY_CA_FILE = attribute( |
| 38 | + 'registry_ca_file', |
| 39 | + description: 'certificate file for a certain Docker registry certificate files. cis-docker-benchmark-3.7 and cis-docker-benchmark-3.8', |
| 40 | + default: '/etc/docker/certs.d/registry_hostname:port/ca.crt' |
| 41 | +) |
| 42 | + |
| 43 | +CONTAINER_USER = attribute( |
| 44 | + 'container_user', |
| 45 | + description: 'define user within containers. cis-docker-benchmark-4.1', |
| 46 | + default: 'ubuntu' |
| 47 | +) |
| 48 | + |
| 49 | +CONTAINER_CAPADD = attribute( |
| 50 | + 'container_capadd', |
| 51 | + description: 'define needed capabilities for containers.' |
| 52 | +) |
36 | 53 |
|
37 | 54 | # check if docker exists |
38 | 55 | only_if do |
|
251 | 268 | ref 'https://docs.docker.com/engine/security/certificates/' |
252 | 269 | ref 'docs.docker.com/reference/commandline/cli/#insecure-registries' |
253 | 270 |
|
254 | | - describe file(attrs['REGISTRY_CERT_PATH']) do |
| 271 | + describe file(REGISTRY_CERT_PATH) do |
255 | 272 | it { should exist } |
256 | 273 | it { should be_directory } |
257 | 274 | it { should be_owned_by 'root' } |
258 | 275 | it { should be_grouped_into 'root' } |
259 | 276 | end |
260 | 277 |
|
261 | | - describe file(attrs['REGISTRY_NAME']) do |
| 278 | + describe file(REGISTRY_NAME) do |
262 | 279 | it { should exist } |
263 | 280 | it { should be_directory } |
264 | 281 | it { should be_owned_by 'root' } |
265 | 282 | it { should be_grouped_into 'root' } |
266 | 283 | end |
267 | 284 |
|
268 | | - describe file(attrs['REGISTRY_CA_FILE']) do |
| 285 | + describe file(REGISTRY_CA_FILE) do |
269 | 286 | it { should exist } |
270 | 287 | it { should be_file } |
271 | 288 | it { should be_owned_by 'root' } |
|
280 | 297 | ref 'https://docs.docker.com/engine/security/certificates/' |
281 | 298 | ref 'docs.docker.com/reference/commandline/cli/#insecure-registries' |
282 | 299 |
|
283 | | - describe file(attrs['REGISTRY_CA_FILE']) do |
| 300 | + describe file(REGISTRY_CA_FILE) do |
284 | 301 | it { should exist } |
285 | 302 | it { should be_file } |
286 | 303 | it { should be_readable } |
|
505 | 522 |
|
506 | 523 | docker.ps.each do |id| |
507 | 524 | describe docker.inspect(id) do |
508 | | - its(%w(Config User)) { should eq attrs['CONTAINER_USER'] } |
| 525 | + its(%w(Config User)) { should eq CONTAINER_USER } |
509 | 526 | its(%w(Config User)) { should_not eq nil } |
510 | 527 | end |
511 | 528 | end |
|
552 | 569 | describe docker.inspect(id) do |
553 | 570 | its(%w(HostConfig CapDrop)) { should include(/all/) } |
554 | 571 | its(%w(HostConfig CapDrop)) { should_not eq nil } |
555 | | - its(%w(HostConfig CapAdd)) { should eq attrs['CONTAINER_CAPADD'] } |
| 572 | + its(%w(HostConfig CapAdd)) { should eq CONTAINER_CAPADD } |
556 | 573 | end |
557 | 574 | end |
558 | 575 | end |
|
601 | 618 | ref 'https://blog.docker.com/2014/06/why-you-dont-need-to-run-sshd-in-docker/' |
602 | 619 |
|
603 | 620 | docker.ps.each do |id| |
604 | | - execute_command = 'docker exec ' << id << ' ps -e' |
| 621 | + execute_command = 'docker exec ' + id + ' ps -e' |
605 | 622 | describe command(execute_command) do |
606 | 623 | its('stdout') { should_not match(/ssh/) } |
607 | 624 | end |
|
0 commit comments