puppet-lint-security-plugins 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +21 -0
  3. data/README.md +90 -0
  4. data/lib/puppet-lint-security-plugins.rb +2 -0
  5. data/lib/puppet-lint/plugins/check_class_or_define_parameter_in_exec.rb +36 -0
  6. data/lib/puppet-lint/plugins/check_security_apache_bad_cipher.rb +28 -0
  7. data/lib/puppet-lint/plugins/check_security_apache_no_ssl_vhost.rb +27 -0
  8. data/lib/puppet-lint/plugins/check_security_apt_no_key.rb +26 -0
  9. data/lib/puppet-lint/plugins/check_security_eval_in_erb.rb +21 -0
  10. data/lib/puppet-lint/plugins/check_security_file_with_setgid_permission.rb +25 -0
  11. data/lib/puppet-lint/plugins/check_security_file_with_setuid_permission.rb +25 -0
  12. data/lib/puppet-lint/plugins/check_security_file_with_world_permissions.rb +25 -0
  13. data/lib/puppet-lint/plugins/check_security_firewall_any_any_allow.rb +26 -0
  14. data/lib/puppet-lint/plugins/check_security_firewall_any_any_deny.rb +27 -0
  15. data/lib/puppet-lint/plugins/check_security_firewall_dns_used.rb +30 -0
  16. data/lib/puppet-lint/plugins/check_security_firewall_puppetmaster_any_deny.rb +33 -0
  17. data/lib/puppet-lint/plugins/check_security_package_pinned_version.rb +25 -0
  18. data/lib/puppet-lint/plugins/check_security_password_in_code.rb +31 -0
  19. data/lib/puppet-lint/plugins/check_security_password_variable_in_exec.rb +22 -0
  20. data/lib/puppet-lint/plugins/check_security_regex_unspecific.rb +23 -0
  21. data/lib/puppet-lint/plugins/check_security_service_mysql_disabled.rb +22 -0
  22. data/lib/puppet-lint/plugins/check_security_service_puppetmaster_disabled.rb +24 -0
  23. data/lib/puppet-lint/plugins/check_security_ssh_root_allowed.rb +26 -0
  24. data/lib/puppet-lint/plugins/check_security_sudo_with_world_nopasswd.rb +23 -0
  25. data/lib/puppet-lint/plugins/check_security_tidy_all_files.rb +20 -0
  26. data/lib/puppet-lint/plugins/check_security_tidy_matches_greedy.rb +27 -0
  27. data/lib/puppet-lint/plugins/check_security_tidy_recurse.rb +21 -0
  28. data/lib/puppet-lint/plugins/check_security_user_with_id_0_created.rb +28 -0
  29. data/lib/puppet-lint/security.rb +280 -0
  30. data/spec/puppet-lint/plugins/check_class_or_define_parameter_in_exec_spec.rb +85 -0
  31. data/spec/puppet-lint/plugins/check_security_apache_bad_cipher_spec.rb +49 -0
  32. data/spec/puppet-lint/plugins/check_security_apache_no_ssl_vhost_spec.rb +40 -0
  33. data/spec/puppet-lint/plugins/check_security_apt_absent_no_key_spec.rb +45 -0
  34. data/spec/puppet-lint/plugins/check_security_apt_no_key_spec.rb +38 -0
  35. data/spec/puppet-lint/plugins/check_security_dir_guid_permissions_spec.rb +49 -0
  36. data/spec/puppet-lint/plugins/check_security_dir_world_permissions_spec.rb +39 -0
  37. data/spec/puppet-lint/plugins/check_security_eval_in_erb_spec.rb +35 -0
  38. data/spec/puppet-lint/plugins/check_security_file_suid_permissions_spec.rb +48 -0
  39. data/spec/puppet-lint/plugins/check_security_file_with_setgid_permission_spec.rb +59 -0
  40. data/spec/puppet-lint/plugins/check_security_file_with_setuid_permission_spec.rb +59 -0
  41. data/spec/puppet-lint/plugins/check_security_file_with_world_permissions_spec.rb +62 -0
  42. data/spec/puppet-lint/plugins/check_security_file_world_and_guid_permissions_spec.rb +43 -0
  43. data/spec/puppet-lint/plugins/check_security_firewall_any_any_allow_spec.rb +36 -0
  44. data/spec/puppet-lint/plugins/check_security_firewall_any_any_deny_spec.rb +124 -0
  45. data/spec/puppet-lint/plugins/check_security_firewall_dns_used_spec.rb +77 -0
  46. data/spec/puppet-lint/plugins/check_security_firewall_puppetmaster_any_deny_spec.rb +60 -0
  47. data/spec/puppet-lint/plugins/check_security_package_pinned_version_spec.rb +43 -0
  48. data/spec/puppet-lint/plugins/check_security_password_in_code_spec.rb +55 -0
  49. data/spec/puppet-lint/plugins/check_security_password_variable_in_exec_spec.rb +45 -0
  50. data/spec/puppet-lint/plugins/check_security_regex_unspecific_spec.rb +40 -0
  51. data/spec/puppet-lint/plugins/check_security_service_mysql_disabled_spec.rb +54 -0
  52. data/spec/puppet-lint/plugins/check_security_service_puppetmaster_disabled_spec.rb +40 -0
  53. data/spec/puppet-lint/plugins/check_security_ssh_root_allowed_spec.rb +60 -0
  54. data/spec/puppet-lint/plugins/check_security_ssh_server_root_allowed_spec.rb +60 -0
  55. data/spec/puppet-lint/plugins/check_security_sudo_with_world_nopasswd_spec.rb +40 -0
  56. data/spec/puppet-lint/plugins/check_security_tidy_all_files_spec.rb +36 -0
  57. data/spec/puppet-lint/plugins/check_security_tidy_matches_greedy_spec.rb +37 -0
  58. data/spec/puppet-lint/plugins/check_security_tidy_recurse_spec.rb +37 -0
  59. data/spec/puppet-lint/plugins/check_security_user_with_id_0_created_spec.rb +47 -0
  60. data/spec/spec_helper.rb +5 -0
  61. metadata +232 -0
@@ -0,0 +1,85 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'security_class_or_define_parameter_in_exec' do
4
+ let(:msg) { 'Class or definded_type parameter in exec used (security!)' }
5
+
6
+ context 'with fix disabled' do
7
+ context 'code having variables in execs' do
8
+ let(:code) { "
9
+ class test ($command_var){
10
+ exec { 'exec_echo_name':
11
+ command => \"${command_var}\";
12
+ }
13
+ }
14
+ "}
15
+
16
+ it 'should detect a single problem' do
17
+ expect(problems).to have(1).problem
18
+ end
19
+
20
+ it 'should create a error' do
21
+ expect(problems).to contain_error(msg).on_line(4).in_column(18)
22
+ end
23
+ end
24
+
25
+ context 'code having variable only in exec' do
26
+ let(:code) { "
27
+ class test ($command_var){
28
+ exec { 'exec_echo_name':
29
+ command => $command_var;
30
+ }
31
+ }
32
+ "}
33
+
34
+ it 'should detect a single problem' do
35
+ expect(problems).to have(1).problem
36
+ end
37
+
38
+ it 'should create a error' do
39
+ expect(problems).to contain_error(msg).on_line(4).in_column(16)
40
+ end
41
+ end
42
+
43
+
44
+ context 'code having four variables in execs' do
45
+ let(:code) { "exec { 'exec_echo_name': command => \"/bin/echo ${name} jonoin ${name} hiohoi ${name} ihoiphoi${name}\"; }" }
46
+ it 'should detect a single problem' do
47
+ expect(problems).to have(4).problem
48
+ end
49
+
50
+ end
51
+
52
+ context 'code having no variables in exec' do
53
+ let(:code) { "
54
+ class test {
55
+
56
+ exec { 'exec_command': command => \"${command_var}\"; }
57
+
58
+ exec { 'exec_echo_name': command => \"/bin/echo hello\"; }
59
+
60
+ exec { 'killall_puppet_user':
61
+ command => \"/usr/bin/killall -9 -u puppet\",
62
+ onlyif => \"/usr/bin/pgrep -u puppet >/dev/null 2>&1\",
63
+ }
64
+
65
+ exec { 'del_puppet_user':
66
+ command => '/usr/sbin/deluser --system -q puppet && /bin/sed -i \"/puppet/d\" /var/lib/dpkg/statoverride',
67
+ onlyif => \"/bin/grep '^puppet:' /etc/passwd\",
68
+ require => Exec['killall_puppet_user'],
69
+ before => Class['http'],
70
+ }
71
+
72
+ # Notwendig, damit die ca_crl erzeugt wird. Sonst startet der Apache nicht
73
+ exec { \"/usr/bin/puppet cert list\":
74
+ creates => [\"/var/lib/puppet/ssl/ca/ca_crl.pem\"],
75
+ require => Package[\"puppetmaster\"],
76
+ }
77
+ }
78
+ " }
79
+
80
+ it 'should not detect any problems' do
81
+ expect(problems).to have(0).problems
82
+ end
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,49 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'security_apache_bad_cipher' do
4
+ let(:msg) { 'Unsecure ciphers used (security!)' }
5
+
6
+ context 'with fix disabled' do
7
+ context 'code having unsecure ciphers' do
8
+ let(:code) { "
9
+
10
+ class { 'apache::mod::ssl':
11
+ ssl_compression => false,
12
+ ssl_options => [ 'StdEnvVars' ],
13
+ ssl_cipher => 'HIGH:MEDIUM:!aNULL:!MD5',
14
+ ssl_protocol => [ 'all', '-SSLv2', '-SSLv3' ],
15
+ ssl_pass_phrase_dialog => 'builtin',
16
+ ssl_random_seed_bytes => '512',
17
+ }
18
+
19
+ " }
20
+
21
+ it 'should detect a single problem' do
22
+ expect(problems).to have(1).problem
23
+ end
24
+
25
+ it 'should create a warning' do
26
+ expect(problems).to contain_warning(msg).on_line(6).in_column(29)
27
+ end
28
+ end
29
+
30
+ context 'code having no unsecure ciphers' do
31
+ let(:code) { "
32
+ # from https://cipherli.st/
33
+ class { 'apache::mod::ssl':
34
+ ssl_compression => false,
35
+ ssl_options => [ 'StdEnvVars' ],
36
+ ssl_cipher => 'EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH:ECDHE-RSA-AES128-GCM-SHA384:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA128:DHE-RSA-AES128-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES128-GCM-SHA128:ECDHE-RSA-AES128-SHA384:ECDHE-RSA-AES128-SHA128:ECDHE-RSA-AES128-SHA:ECDHE-RSA-AES128-SHA:DHE-RSA-AES128-SHA128:DHE-RSA-AES128-SHA128:DHE-RSA-AES128-SHA:DHE-RSA-AES128-SHA:ECDHE-RSA-DES-CBC3-SHA:EDH-RSA-DES-CBC3-SHA:AES128-GCM-SHA384:AES128-GCM-SHA128:AES128-SHA128:AES128-SHA128:AES128-SHA:AES128-SHA:DES-CBC3-SHA:HIGH:!aNULL:!eNULL:!EXPORT:!DES:!MD5:!PSK:!RC4',
37
+ ssl_protocol => [ 'all', '-SSLv2', '-SSLv3' ],
38
+ ssl_pass_phrase_dialog => 'builtin',
39
+ ssl_random_seed_bytes => '512',
40
+ }
41
+ " }
42
+
43
+ it 'should not detect any problems' do
44
+ expect(problems).to have(0).problems
45
+ end
46
+ end
47
+
48
+ end
49
+ end
@@ -0,0 +1,40 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'security_apache_no_ssl_vhost' do
4
+ let(:msg) { 'Vhost without ssl detected (security!)' }
5
+
6
+ context 'with fix disabled' do
7
+ context 'code having vhost wihtout ssl' do
8
+ let(:code) { "
9
+ apache::vhost { 'fourth.example.com':
10
+ docroot => '/var/www/fourth',
11
+ }
12
+ " }
13
+
14
+ it 'should detect a single problem' do
15
+ expect(problems).to have(1).problem
16
+ end
17
+
18
+ it 'should create a warning' do
19
+ expect(problems).to contain_warning(msg).on_line(2).in_column(38)
20
+ end
21
+ end
22
+
23
+ context 'code having vhost with ssl' do
24
+ let(:code) { "
25
+ apache::vhost { 'fourth.example.com':
26
+ port => '443',
27
+ docroot => '/var/www/fourth',
28
+ ssl => true,
29
+ ssl_cert => '/etc/ssl/fourth.example.com.cert',
30
+ ssl_key => '/etc/ssl/fourth.example.com.key',
31
+ }
32
+ " }
33
+
34
+ it 'should not detect any problems' do
35
+ expect(problems).to have(0).problems
36
+ end
37
+ end
38
+
39
+ end
40
+ end
@@ -0,0 +1,45 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'security_apt_no_key' do
4
+ let(:msg) { 'APT Repository without key detected (security!)' }
5
+
6
+ context 'with fix disabled' do
7
+
8
+
9
+ context 'code having no key parameter in apt' do
10
+ let(:code) { "
11
+
12
+ apt::source {
13
+ 'apt.postgresql.org':
14
+ ensure => absent;
15
+ 'puppetlabs':
16
+ location => 'http://apt.puppetlabs.com',
17
+ repos => 'main',
18
+ }
19
+
20
+ " }
21
+
22
+ it 'should detect a single problem' do
23
+ expect(problems).to have(1).problem
24
+ end
25
+
26
+ it 'should create a error' do
27
+ expect(problems).to contain_error(msg).on_line(6).in_column(16)
28
+ end
29
+ end
30
+
31
+
32
+
33
+ context 'code deleting apt repo' do
34
+ let(:code) { "
35
+ apt::source { 'apt.postgresql.org':
36
+ ensure => absent,
37
+ }
38
+ " }
39
+
40
+ it 'should not detect any problems' do
41
+ expect(problems).to have(0).problems
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,38 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'security_apt_no_key' do
4
+ let(:msg) { 'APT Repository without key detected (security!)' }
5
+
6
+ context 'with fix disabled' do
7
+ context 'code having no key parameter in apt' do
8
+ let(:code) { "apt::source { 'puppetlabs':
9
+ location => 'http://apt.puppetlabs.com',
10
+ repos => 'main',
11
+ }
12
+ " }
13
+
14
+ it 'should detect a single problem' do
15
+ expect(problems).to have(1).problem
16
+ end
17
+
18
+ it 'should create a error' do
19
+ expect(problems).to contain_error(msg).on_line(1).in_column(28)
20
+ end
21
+ end
22
+
23
+ context 'code having key parameter in apt' do
24
+ let(:code) { "apt::source { 'puppetlabs':
25
+ location => 'http://apt.puppetlabs.com',
26
+ repos => 'main',
27
+ key => {
28
+ 'id' => '47B320EB4C7C375AA9DAE1A01054B7A24BD6EC30',
29
+ 'server' => 'pgp.mit.edu',
30
+ },
31
+ }," }
32
+
33
+ it 'should not detect any problems' do
34
+ expect(problems).to have(0).problems
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,49 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'security_file_with_setgid_permission' do
4
+
5
+ let(:msg) { 'File or directory definition with setgid to root detected (security!)'}
6
+
7
+ context 'with fix disabled' do
8
+
9
+ context 'code having directory with setgid permissions' do
10
+ let(:code) { "
11
+
12
+ file { '/usr/local/bin':
13
+ ensure => present,
14
+ mode => '2755',
15
+ owner => 'root',
16
+ group => 'root',
17
+ source => 'puppet:///modules/myscript/usr_local_bin_myscript',
18
+ }
19
+
20
+ " }
21
+
22
+ it 'should detect a single problem' do
23
+ expect(problems).to have(1).problem
24
+ end
25
+
26
+ it 'should create a warning' do
27
+ expect(problems).to contain_error(msg).on_line(5).in_column(11)
28
+ end
29
+ end
30
+
31
+ context 'code having no directory with setgid permissions' do
32
+ let(:code) { "
33
+
34
+ file { '/usr/local/bin':
35
+ ensure => present,
36
+ mode => '755',
37
+ owner => 'root',
38
+ group => 'root',
39
+ source => 'puppet:///modules/myscript/usr_local_bin_myscript',
40
+ }
41
+ " }
42
+
43
+ it 'should not detect any problems' do
44
+ expect(problems).to have(0).problems
45
+ end
46
+ end
47
+
48
+ end
49
+ end
@@ -0,0 +1,39 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'security_file_with_world_permissions' do
4
+ let(:msg) { 'File or directory definition with world permissions detected (security!)' }
5
+
6
+ context 'with fix disabled' do
7
+
8
+ context 'code having directory with world permissions' do
9
+ let(:code) { "file { '/var/log':
10
+ ensure => directory,
11
+ mode => '0777',
12
+ owner => 'root',
13
+ group => 'root',
14
+ }" }
15
+
16
+ it 'should detect a single problem' do
17
+ expect(problems).to have(1).problem
18
+ end
19
+
20
+ it 'should create a error' do
21
+ expect(problems).to contain_error(msg).on_line(3).in_column(11)
22
+ end
23
+ end
24
+
25
+ context 'code having no directory with world permissions' do
26
+ let(:code) { "file { '/var/log':
27
+ ensure => directory,
28
+ mode => '0755',
29
+ owner => 'root',
30
+ group => 'root',
31
+ }" }
32
+
33
+ it 'should not detect any problems' do
34
+ expect(problems).to have(0).problems
35
+ end
36
+ end
37
+
38
+ end
39
+ end
@@ -0,0 +1,35 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'security_eval_in_erb' do
4
+ let(:msg) { '"eval" ruby function used (security!)' }
5
+
6
+ context 'with fix disabled' do
7
+ context 'code having eval in inline_template' do
8
+ let(:code) { "
9
+ $test='p Dir.entries(\"/etc\")'
10
+ $variable = inline_template('<% eval(@test) %>')
11
+ notice($variable)
12
+ " }
13
+
14
+ it 'should detect a single problem' do
15
+ expect(problems).to have(1).problem
16
+ end
17
+
18
+ it 'should create a error' do
19
+ expect(problems).to contain_error(msg).on_line(3).in_column(29)
20
+ end
21
+ end
22
+
23
+ context 'code having no eval in inline_template' do
24
+ let(:code) { "
25
+ $variable = inline_template('<%= Dir.entries(\"/etc\") %>')
26
+ notice($variable)
27
+ " }
28
+
29
+ it 'should not detect any problems' do
30
+ expect(problems).to have(0).problems
31
+ end
32
+ end
33
+
34
+ end
35
+ end
@@ -0,0 +1,48 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'security_file_with_setuid_permission' do
4
+ let(:msg) { 'File or directory definition with setuid to root detected (security!)'}
5
+
6
+ context 'with fix disabled' do
7
+
8
+ context 'code having file with suid permissions' do
9
+ let(:code) { "
10
+
11
+ file { '/usr/local/bin/myscript':
12
+ ensure => present,
13
+ mode => '1755',
14
+ owner => 'root',
15
+ group => 'root',
16
+ source => 'puppet:///modules/myscript/usr_local_bin_myscript',
17
+ }
18
+
19
+ " }
20
+
21
+ it 'should detect a single problem' do
22
+ expect(problems).to have(1).problem
23
+ end
24
+
25
+ it 'should create a warning' do
26
+ expect(problems).to contain_error(msg).on_line(5).in_column(11)
27
+ end
28
+ end
29
+
30
+ context 'code having no file with suid permissions' do
31
+ let(:code) { "
32
+
33
+ file { '/usr/local/bin/myscript':
34
+ ensure => present,
35
+ mode => '755',
36
+ owner => 'root',
37
+ group => 'root',
38
+ source => 'puppet:///modules/myscript/usr_local_bin_myscript',
39
+ }
40
+ " }
41
+
42
+ it 'should not detect any problems' do
43
+ expect(problems).to have(0).problems
44
+ end
45
+ end
46
+
47
+ end
48
+ end
@@ -0,0 +1,59 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'security_file_with_setgid_permission' do
4
+ let(:msg) { 'File or directory definition with setgid to root detected (security!)'}
5
+
6
+ context 'with fix disabled' do
7
+ context 'code having file with setgid permissions' do
8
+ let(:code) { "
9
+
10
+ file { '/bin/bash':
11
+ mode => '2755',
12
+ owner => 'root',
13
+ group => 'root',
14
+ }
15
+
16
+ " }
17
+
18
+ it 'should detect a single problem' do
19
+ expect(problems).to have(1).problem
20
+ end
21
+
22
+ it 'should create a error' do
23
+ expect(problems).to contain_error(msg).on_line(4).in_column(11)
24
+ end
25
+ end
26
+
27
+ context 'code having no file with setgid permissions' do
28
+ let(:code) { "
29
+
30
+ file { '/bin/bash':
31
+ mode => '0755',
32
+ owner => 'root',
33
+ group => 'root',
34
+ }
35
+
36
+ file {
37
+ '/etc/icinga/commands.cfg':
38
+ content => template('icinga/etc_icinga_commands.cfg'),
39
+ notify => Exec['icinga'],
40
+ owner => 'root',
41
+ group => 'root',
42
+ mode => '0644',
43
+ require => Package['icinga'];
44
+ '/usr/local/bin/icinga2ticket.rb':
45
+ content => template('icinga/usr_local_bin_icinga2ticket.rb'),
46
+ notify => Exec['icinga'],
47
+ owner => 'nagios',
48
+ group => 'nagios',
49
+ mode => '0750';
50
+ }
51
+ " }
52
+
53
+ it 'should not detect any problems' do
54
+ expect(problems).to have(0).problems
55
+ end
56
+ end
57
+
58
+ end
59
+ end