|
2 | 2 | # frozen_string_literal: true |
3 | 3 | # |
4 | 4 | # Copyright 2016, Patrick Muench |
| 5 | +# Copyright 2017, Christoph Hartmann |
5 | 6 | # |
6 | 7 | # Licensed under the Apache License, Version 2.0 (the "License"); |
7 | 8 | # you may not use this file except in compliance with the License. |
|
59 | 60 | ) |
60 | 61 |
|
61 | 62 | SWARM_MODE = attribute( |
62 | | - 'SWARM_MODE', |
63 | | - description: 'define the swarm mode, active or inactive', |
64 | | - default: 'Swarm: inactive' |
| 63 | + 'swarm_mode', |
| 64 | + description: 'define the swarm mode, `active` or `inactive`', |
| 65 | + default: 'inactive' |
| 66 | +) |
| 67 | + |
| 68 | +SWARM_MAX_MANAGER_NODES = attribute( |
| 69 | + 'swarm_max_manager_nodes', |
| 70 | + description: 'number of manager nodes in a swarm', |
| 71 | + default: 3 |
| 72 | +) |
| 73 | + |
| 74 | +SWARM_PORT = attribute( |
| 75 | + 'swarm_port', |
| 76 | + description: 'port of the swarm node', |
| 77 | + default: 2377 |
65 | 78 | ) |
66 | 79 |
|
67 | 80 | # check if docker exists |
|
319 | 332 | tag cis: 'docker:2.15' |
320 | 333 | tag level: 2 |
321 | 334 | ref 'docker swarm init', url: 'https://docs.docker.com/engine/reference/commandline/swarm_init/' |
| 335 | + describe docker.info do |
| 336 | + its('Swarm.LocalNodeState') { should eq SWARM_MODE } |
| 337 | + end |
| 338 | +end |
| 339 | + |
| 340 | +control 'cis-docker-benchmark-2.16' do |
| 341 | + impact 1.0 |
| 342 | + title 'Control the number of manager nodes in a swarm' |
| 343 | + desc 'Ensure that the minimum number of required manager nodes is created in a swarm.' |
322 | 344 |
|
323 | | - describe command('docker info') do |
324 | | - its('stdout') { should include SWARM_MODE } |
| 345 | + tag 'daemon' |
| 346 | + tag cis: 'docker:2.16' |
| 347 | + tag level: 2 |
| 348 | + |
| 349 | + only_if { SWARM_MODE == 'active' } |
| 350 | + describe docker.info do |
| 351 | + its('Swarm.Managers') { should cmp <= SWARM_MAX_MANAGER_NODES } |
| 352 | + end |
| 353 | +end |
| 354 | + |
| 355 | +control 'cis-docker-benchmark-2.17' do |
| 356 | + impact 1.0 |
| 357 | + title 'Bind swarm services to a specific host interface' |
| 358 | + |
| 359 | + tag 'daemon' |
| 360 | + tag cis: 'docker:2.17' |
| 361 | + tag level: 2 |
| 362 | + |
| 363 | + only_if { SWARM_MODE == 'active' } |
| 364 | + describe port(SWARM_PORT) do |
| 365 | + its('addresses') { should_not include '0.0.0.0' } |
| 366 | + its('addresses') { should_not include '::' } |
| 367 | + end |
| 368 | +end |
| 369 | + |
| 370 | +control 'cis-docker-benchmark-2.18' do |
| 371 | + impact 1.0 |
| 372 | + title 'Disable Userland Proxy' |
| 373 | + |
| 374 | + tag 'daemon' |
| 375 | + tag cis: 'docker:2.18' |
| 376 | + tag level: 2 |
| 377 | + |
| 378 | + describe json('/etc/docker/daemon.json') do |
| 379 | + its(['userland-proxy']) { should eq(false) } |
| 380 | + end |
| 381 | + describe processes('dockerd').commands do |
| 382 | + it { should include 'userland-proxy=false' } |
325 | 383 | end |
326 | 384 | end |
0 commit comments