Skip to content

Commit cbb3183

Browse files
Deric Miguelamlodzianowskigagarin-dev
committed
lint rubocop offences
* Disables Lint/AmbiguousRegexpLiteral Inspec Style Guide suggests avoiding in matchers - https://docs.chef.io/inspec/style/#avoid-unnecessary-parentheses-in-matchers Examples in the documentation - https://docs.chef.io/inspec/matchers/#match - https://docs.chef.io/inspec/dsl_inspec/#test-if-mysql-passwords-are-in-env - https://docs.chef.io/inspec/dsl_inspec/#interactive-debugging-with-pry * Other whitespace fixes on-behalf-of: @Logicworks <dmiguel@logicworks.net> Co-authored-by: amlodzianowski <adrianmlodzianowski@gmail.com> Co-authored-by: gagarin-dev <37323962+gagarin-dev@users.noreply.github.com> Signed-off-by: Deric Miguel <dmiguel@logicworks.net> Signed-off-by: Dan Rosenbloom <drosenbloom@logicworks.net> Signed-off-by: amlodzianowski <amlodzianowski@logicworks.net> Signed-off-by: gagarin-dev <ygagarin@logicworks.net>
1 parent a57e08b commit cbb3183

11 files changed

+72
-77
lines changed

.rubocop.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ Documentation:
33
Enabled: false
44
Layout/ParameterAlignment:
55
Enabled: true
6+
Lint/AmbiguousRegexpLiteral:
7+
Enabled: false
68
HashSyntax:
79
Enabled: true
810
LineLength:

controls/1_1_filesystem_configuration.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -373,9 +373,10 @@
373373
describe mount('/dev/shm') do
374374
its('options') { should include 'noexec' }
375375
end
376-
only_if('/dev/shm is mounted') {
376+
377+
only_if('/dev/shm is mounted') do
377378
mount('/dev/shm').mounted?
378-
}
379+
end
379380
end
380381

381382
control 'cis-dil-benchmark-1.1.18' do

controls/3_2_network_parameters_host_and_router.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,4 +163,4 @@
163163
its(:value) { should eq 0 }
164164
end
165165
end
166-
end
166+
end

controls/3_3_tcp_wrappers.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@
116116
it { should exist }
117117
it { should be_file }
118118

119-
its('owner') { should cmp'root' }
119+
its('owner') { should cmp 'root' }
120120
its('group') { should cmp 'root' }
121121

122122
its('mode') { should cmp '0644' }

controls/3_5_firewall_configuration.rb

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -153,28 +153,27 @@
153153
describe.one do
154154
rules.each do |rule|
155155
describe rule do
156-
it { should match(/(?=.*-A INPUT)(?=.*-i lo)(?=.*-j ACCEPT)/) }
156+
it { should match /(?=.*-A INPUT)(?=.*-i lo)(?=.*-j ACCEPT)/ }
157157
end
158158
end
159159
end
160160

161161
describe.one do
162162
rules.each do |rule|
163163
describe rule do
164-
it { should match(/(?=.*-A OUTPUT)(?=.*-o lo)(?=.*-j ACCEPT)/) }
164+
it { should match /(?=.*-A OUTPUT)(?=.*-o lo)(?=.*-j ACCEPT)/ }
165165
end
166166
end
167167
end
168168

169169
describe.one do
170170
rules.each do |rule|
171171
describe rule do
172-
it { should match(/(?=.*-A INPUT)(?=.*-s 127\.0\.0\.0\/8)(?=.*-j DROP)/) }
172+
it { should match %r{(?=.*-A INPUT)(?=.*-s 127\.0\.0\.0/8)(?=.*-j DROP)} }
173173
end
174174
end
175175
end
176176

177-
178177
end
179178

180179
control 'cis-dil-benchmark-3.5.2.3' do
@@ -191,15 +190,15 @@
191190
describe.one do
192191
rules.each do |rule|
193192
describe rule do
194-
it { should match(/(?=.*-A OUTPUT)(?=.*-p #{proto})(?=.*-m state --state NEW,ESTABLISHED)(?=.*-j ACCEPT)/) }
193+
it { should match /(?=.*-A OUTPUT)(?=.*-p #{proto})(?=.*-m state --state NEW,ESTABLISHED)(?=.*-j ACCEPT)/ }
195194
end
196195
end
197196
end
198197

199198
describe.one do
200199
rules.each do |rule|
201200
describe rule do
202-
it { should match(/(?=.*-A INPUT)(?=.*-p #{proto})(?=.*-m state --state ESTABLISHED)(?=.*-j ACCEPT)/) }
201+
it { should match /(?=.*-A INPUT)(?=.*-p #{proto})(?=.*-m state --state ESTABLISHED)(?=.*-j ACCEPT)/ }
203202
end
204203
end
205204
end
@@ -233,4 +232,4 @@
233232
describe package('iptables') do
234233
it { should be_installed }
235234
end
236-
end
235+
end

controls/4_2_configure_logging.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,20 +101,18 @@
101101
end
102102
end
103103

104-
105104
# Check the new RainerScript format in addtion to the 'legacy' rsyslog syntax
106105
# which is documented as 'obsolete'
107106
# ref: https://www.rsyslog.com/doc/v8-stable/configuration/modules/omfile.html#filecreatemode
108107
new_rsyslog_conf = command('grep -orE \'FileCreateMode="[0-7]{4}"\' /etc/rsyslog.*').stdout
109-
new_rsyslog_conf.each_line do | result |
108+
new_rsyslog_conf.each_line do |result|
110109
filename = result.split(':')[0]
111110
describe file(filename) do
112111
its('content') { should match(/FileCreateMode="0[0-6][0-4]0"/) }
113112
end
114113
end
115114
end
116115

117-
118116
control 'cis-dil-benchmark-4.2.1.5' do
119117
title 'Ensure rsyslog is configured to send logs to a remote log host'
120118
desc '

controls/5_1_configure_cron.rb

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
title 'Ensure cron daemon is enabled'
2222
desc '
2323
The cron daemon is used to execute batch jobs on the system.
24-
24+
2525
Rationale:
2626
2727
While there may not be user jobs that need to be run on the system, the system does have maintenance jobs that may include
@@ -47,9 +47,9 @@
4747
desc '
4848
The /etc/crontab file is used by cron to control its own jobs. The commands in this item make sure that root
4949
is the user and group owner of the file and that only the owner can access the file.
50-
50+
5151
Rationale:
52-
52+
5353
This file contains information on what system jobs are run by cron. Write access to these files could provide
5454
unprivileged users with the ability to elevate their privileges. Read access to these files could provide user
5555
with the ability to gain insight on system jobs that run on the system and could provide them a way to gain
@@ -80,9 +80,9 @@
8080
directory cannot be manipulated by the crontab command, but are instead edited by system administrators
8181
using a text editor. The commands below restrict read/write and search access to user and group root,
8282
preventing regular users from accessing this directory.
83-
83+
8484
Rationale:
85-
85+
8686
Granting write access to this directory for non-privileged users could provide them the means
8787
for gaining unauthorized elevated privileges. Granting read access to this directory could give
8888
an unprivileged user insight in how to gain elevated privileges or circumvent auditing controls.
@@ -112,9 +112,9 @@
112112
The files in this directory cannot be manipulated by the crontab command, but are instead edited
113113
by system administrators using a text editor. The commands below restrict read/write and search
114114
access to user and group root, preventing regular users from accessing this directory.
115-
115+
116116
Rationale:
117-
117+
118118
Granting write access to this directory for non-privileged users could provide them the means for gaining
119119
unauthorized elevated privileges. Granting read access to this directory could give an unprivileged user
120120
insight in how to gain elevated privileges or circumvent auditing controls.
@@ -144,9 +144,9 @@
144144
in this directory cannot be manipulated by the crontab command, but are instead edited by system
145145
administrators using a text editor. The commands below restrict read/write and search access to user
146146
and group root, preventing regular users from accessing this directory.
147-
147+
148148
Rationale:
149-
149+
150150
Granting write access to this directory for non-privileged users could provide them the means for gaining
151151
unauthorized elevated privileges. Granting read access to this directory could give an unprivileged user
152152
insight in how to gain elevated privileges or circumvent auditing controls.
@@ -176,9 +176,9 @@
176176
in this directory cannot be manipulated by the crontab command, but are instead edited by system
177177
administrators using a text editor. The commands below restrict read/write and search access to user and
178178
group root, preventing regular users from accessing this directory.
179-
179+
180180
Rationale:
181-
181+
182182
Granting write access to this directory for non-privileged users could provide them the means for gaining
183183
unauthorized elevated privileges. Granting read access to this directory could give an unprivileged user
184184
insight in how to gain elevated privileges or circumvent auditing controls.
@@ -209,9 +209,9 @@
209209
The files in this directory cannot be manipulated by the crontab command, but are instead edited by system
210210
administrators using a text editor. The commands below restrict read/write and search access to user and group
211211
root, preventing regular users from accessing this directory.
212-
212+
213213
Rationale:
214-
214+
215215
Granting write access to this directory for non-privileged users could provide them the means for gaining unauthorized
216216
elevated privileges. Granting read access to this directory could give an unprivileged user insight in how to gain
217217
elevated privileges or circumvent auditing controls.
@@ -240,14 +240,14 @@
240240
Configure /etc/cron.allow and /etc/at.allow to allow specific users to use these services.
241241
If /etc/cron.allow or /etc/at.allow do not exist, then /etc/at.deny and /etc/cron.deny are checked.
242242
Any user not specifically defined in those files is allowed to use at and cron. By removing the files,
243-
only users in /etc/cron.allow and /etc/at.allow are allowed to use at and cron.
244-
243+
only users in /etc/cron.allow and /etc/at.allow are allowed to use at and cron.
244+
245245
Note that even though a given user is not listed in cron.allow, cron jobs can still be run as that user.
246246
The cron.allow file only controls administrative access to the crontab command for scheduling and modifying
247247
cron jobs.
248-
248+
249249
Rationale:
250-
250+
251251
On many systems, only the system administrator is authorized to schedule cron jobs. Using the cron.allow file
252252
to control who can run cron jobs enforces this policy. It is easier to manage an allow list than a deny list.
253253
In a deny list, you could potentially add a user ID to the system and forget to add it to the deny files.

controls/5_2_ssh_server_configuration.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@
184184
control 'cis-dil-benchmark-5.2.8' do
185185
title 'Ensure SSH IgnoreRhosts is enabled (Scored)'
186186
desc '
187-
The IgnoreRhosts parameter specifies that .rhosts and .shosts files will not be used in RhostsRSAAuthentication or
187+
The IgnoreRhosts parameter specifies that .rhosts and .shosts files will not be used in RhostsRSAAuthentication or
188188
HostbasedAuthentication.
189189
190190
Rationale: Setting this parameter forces users to enter a password when authenticating with ssh.
@@ -297,7 +297,7 @@
297297
its('Ciphers') { should_not be_nil }
298298
end
299299

300-
WEAK_CIPHERS = [
300+
weak_ciphers = [
301301
'3des-cbc',
302302
'aes128-cbc',
303303
'aes192-cbc',
@@ -312,7 +312,7 @@
312312

313313
if sshd_config.Ciphers
314314
describe sshd_config.Ciphers.split(',').each do
315-
it { should_not be_in WEAK_CIPHERS }
315+
it { should_not be_in weak_ciphers }
316316
end
317317
end
318318
end
@@ -336,7 +336,7 @@
336336
its('MACs') { should_not be_nil }
337337
end
338338

339-
ALLOWED_MACS = [
339+
allowed_macs = [
340340
'hmac-sha2-512-etm@openssh.com',
341341
'hmac-sha2-256-etm@openssh.com',
342342
'hmac-sha2-512',
@@ -346,7 +346,7 @@
346346
if sshd_config.MACs
347347
sshd_config.MACs.split(',').each do |m|
348348
describe m do
349-
it { should be_in ALLOWED_MACS }
349+
it { should be_in allowed_macs }
350350
end
351351
end
352352
end
@@ -369,7 +369,7 @@
369369
its('KexAlgorithms') { should_not be_nil }
370370
end
371371

372-
ALLOWED_KEX_ALGORITHMS = [
372+
allowed_kex_algorithms = [
373373
'curve25519-sha256',
374374
'curve25519-sha256@libssh.org',
375375
'ecdh-sha2-nistp256',
@@ -384,7 +384,7 @@
384384
if sshd_config.KexAlgorithms
385385
sshd_config.KexAlgorithms.split(',').each do |m|
386386
describe m do
387-
it { should be_in ALLOWED_KEX_ALGORITHMS }
387+
it { should be_in allowed_kex_algorithms }
388388
end
389389
end
390390
end

controls/5_3_configure_pam.rb

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,17 @@
3333
* ucredit=-1 - provide at least one uppercase character
3434
* ocredit=-1 - provide at least one special character
3535
* lcredit=-1 - provide at least one lowercase character
36-
36+
3737
The pam_pwquality.so module functions similarly but the minlen, dcredit,
3838
ucredit , ocredit , and lcredit parameters are stored in the
3939
/etc/security/pwquality.conf file. The settings shown above are one possible
4040
policy. Alter these values to conform to your own organization`s password
4141
policies.
42-
42+
4343
Rationale: Strong passwords protect systems from being hacked through brute
4444
force methods.
4545
'
46-
46+
4747
impact 1.0
4848

4949
tag cis: 'distribution-independent-linux:5.3.1'
@@ -102,11 +102,11 @@
102102
users. Check the documentation for each secondary program for instructions
103103
on how to configure them to work with PAM.
104104
Set the lockout number to the policy in effect at your site.
105-
105+
106106
Rationale: Locking out user IDs after n unsuccessful consecutive login
107107
attempts mitigates brute force password attacks against your systems.
108108
'
109-
109+
110110
impact 0.0
111111

112112
tag cis: 'distribution-independent-linux:5.3.2'
@@ -122,12 +122,12 @@
122122
desc '
123123
The /etc/security/opasswd file stores the users` old passwords and can be
124124
checked to ensure that users are not recycling recent passwords.
125-
125+
126126
Rationale: Forcing users not to reuse their past 5 passwords make it less
127127
likely that an attacker will be able to guess the password. Note that these
128128
change only apply to accounts configured on the local system.
129129
'
130-
130+
131131
impact 0.0
132132

133133
tag cis: 'distribution-independent-linux:5.3.3'
@@ -152,13 +152,13 @@
152152
The commands below change password encryption from md5 to sha512 (a much
153153
stronger hashing algorithm). All existing accounts will need to perform
154154
a password change to upgrade the stored hashes to the new algorithm.
155-
155+
156156
Rationale: The SHA-512 algorithm provides much stronger hashing than MD5,
157157
thus providing additional protection to the system by increasing the level
158158
of effort for an attacker to successfully determine passwords. Note that
159159
these change only apply to accounts configured on the local system.
160160
'
161-
161+
162162
impact 0.0
163163

164164
tag cis: 'distribution-independent-linux:5.3.4'

controls/5_4_user_accounts_and_environments.rb

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
passwd_files = ['/etc/passwd']
2626
passwd_files << '/usr/share/baselayout/passwd' if file('/etc/nsswitch.conf').content =~ /^passwd:\s+(\S+\s+)*usrfiles/
2727

28-
shell_config_files = %w(bash.bashrc profile bashrc).map {|f| "/etc/#{f}"}.select {|f| file(f).file?}
28+
shell_config_files = %w(bash.bashrc profile bashrc).map { |f| "/etc/#{f}" }.select { |f| file(f).file? }
2929

3030
control 'cis-dil-benchmark-5.4.1.1' do
3131
title 'Ensure password expiration is 365 days or less'
@@ -189,11 +189,6 @@
189189
shell_config_files.each do |f|
190190
describe file(f) do
191191
its('content') { should_not match(/^\s*umask [0-7](0[1-7]|[1-7][1-6])\s*(?:#.*)?$/) }
192-
end
193-
end
194-
195-
shell_config_files.each do |f|
196-
describe file(f) do
197192
its('content') { should match(/^\s*umask [0-7][2367]7\s*(?:#.*)?$/) }
198193
end
199194
end

0 commit comments

Comments
 (0)