|
37 | 37 | postgres_config_file = "#{config_path}/postgresql.conf" |
38 | 38 | psql_command = "sudo -u postgres -i PGPASSWORD='#{ENV['PGPASSWORD']}' psql" |
39 | 39 |
|
40 | | - |
41 | 40 | describe command('sudo -i psql -V') do |
42 | 41 | its(:stdout) { should_not match(/RC/) } |
43 | 42 | its(:stdout) { should_not match(/DEVEL/) } |
44 | 43 | its(:stdout) { should_not match(/BETA/) } |
45 | 44 | end |
46 | 45 |
|
47 | | - |
48 | 46 | describe command("ps aux | grep #{task_name} | grep -v grep | wc -l") do |
49 | 47 | its(:stdout) { should match(/^1/) } |
50 | 48 | end |
51 | 49 |
|
52 | 50 | describe 'Checking Postgres-databases for risky entries' do |
53 | 51 |
|
54 | | - |
55 | 52 | describe command("#{psql_command} -d postgres -c \"SELECT count (*) FROM pg_language WHERE lanpltrusted = 'f' AND lanname!='internal' AND lanname!='c';\" | tail -n3 | head -n1 | tr -d ' '") do |
56 | 53 | its(:stdout) { should match(/^0/) } |
57 | 54 | end |
58 | 55 |
|
59 | | - |
60 | 56 | describe command("#{psql_command} -d postgres -c \"SELECT * FROM pg_shadow WHERE passwd IS NULL;\" | tail -n2 | head -n1 | cut -d '(' -f2 | cut -d ' ' -f1") do |
61 | 57 | its(:stdout) { should match(/^0/) } |
62 | 58 | end |
63 | 59 |
|
64 | | - |
65 | 60 | describe command("#{psql_command} -d psql -d postgres -c \"SELECT passwd FROM pg_shadow;\" | tail -n+3 | head -n-2 | grep -v \"md5\" -c") do |
66 | 61 | its(:stdout) { should match(/^0/) } |
67 | 62 | end |
68 | 63 |
|
69 | | - |
70 | 64 | describe command("#{psql_command} -d postgres -c \"SELECT rolname,rolsuper,rolcreaterole,rolcreatedb FROM pg_roles WHERE rolsuper IS TRUE OR rolcreaterole IS TRUE or rolcreatedb IS TRUE;\" | tail -n+3 | head -n-2 | wc -l") do |
71 | 65 | its(:stdout) { should match(/^1/) } |
72 | 66 | end |
73 | 67 |
|
74 | | - |
75 | 68 | describe command("#{psql_command} -d postgres -c \"\\dp pg_catalog.pg_authid\" | grep pg_catalog | wc -l") do |
76 | 69 | its(:stdout) { should match(/^1/) } |
77 | 70 | end |
78 | | - |
79 | 71 | end |
80 | 72 |
|
81 | | - |
82 | 73 | describe 'Postgres FS-permissions' do |
83 | | - |
84 | 74 | describe command("sudo find #{postgres_home} -user #{user_name} -group #{user_name} -perm /go=rwx | wc -l") do |
85 | 75 | its(:stdout) { should match(/^0/) } |
86 | 76 | end |
87 | | - |
88 | 77 | end |
89 | 78 |
|
90 | 79 | describe 'Parsing configfiles' do |
91 | 80 |
|
92 | | - |
93 | 81 | describe file(postgres_config_file) do |
94 | 82 | its(:content) { should match_key_value('ssl', 'off') } |
95 | | - end |
96 | | - |
97 | | - |
98 | | - describe file(postgres_config_file) do |
99 | 83 | its(:content) { should match_key_value('ssl_ciphers', "'ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH'") } |
100 | | - end |
101 | | - |
102 | | - |
103 | | - describe file(postgres_config_file) do |
104 | 84 | its(:content) { should match_key_value('password_encryption', 'on') } |
105 | 85 | end |
106 | 86 |
|
107 | | - |
108 | 87 | describe 'require MD5 for ALL users, peers in pg_hba.conf' do |
109 | | - |
110 | 88 | describe file(hba_config_file) do |
111 | 89 | its(:content) { should match(/local\s.*?all\s.*?all\s.*?md5/) } |
112 | | - end |
113 | | - |
114 | | - describe file(hba_config_file) do |
115 | 90 | its(:content) { should match(%r{/host\s.*?all\s.*?all\s.*?127.0.0.1\/32\s.*?md5/}) } |
116 | | - end |
117 | | - |
118 | | - describe file(hba_config_file) do |
119 | 91 | its(:content) { should match(%r{/host\s.*?all\s.*?all\s.*?::1\/128\s.*?md5/}) } |
120 | 92 | end |
121 | 93 |
|
122 | | - |
123 | 94 | # We accept one peer and one ident for now (chef automation) |
124 | | - |
125 | 95 | describe command("sudo -i cat #{hba_config_file} | egrep 'peer|ident' | wc -l") do |
126 | 96 | its(:stdout) { should match(/^[2|1]/) } |
127 | 97 | end |
128 | 98 |
|
129 | 99 | describe command("sudo -i cat #{hba_config_file} | egrep 'trust|password|crypt' | wc -l") do |
130 | 100 | its(:stdout) { should match(/^0/) } |
131 | 101 | end |
132 | | - |
133 | 102 | end |
134 | 103 |
|
135 | | - |
136 | 104 | describe 'System Monitoring' do |
137 | | - |
138 | 105 | describe file(postgres_config_file) do |
139 | 106 | its(:content) { should match_key_value('logging_collector', 'on') } |
140 | 107 | its(:content) { should match(/log_directory\s.*?pg_log/) } # match pg_log and 'pg_log' |
|
144 | 111 | its(:content) { should match_key_value('log_hostname', 'on') } |
145 | 112 | its(:content) { should match_key_value('log_line_prefix', "'%t %u %d %h'") } |
146 | 113 | end |
147 | | - |
148 | 114 | end |
149 | | - |
150 | 115 | end |
0 commit comments