Skip to content

Commit 922c95e

Browse files
authored
Merge pull request #2270 from Vincevrp/crs-paranoia-level
Allow configuring CRS paranoia level
2 parents 8d37daa + c38aac1 commit 922c95e

File tree

3 files changed

+87
-14
lines changed

3 files changed

+87
-14
lines changed

manifests/mod/security.pp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,13 @@
7575
# @param notice_anomaly_score
7676
# Sets the Anomaly Score for rules assigned with a notice severity.
7777
#
78+
# @param paranoia_level
79+
# Sets the paranoia level in the OWASP ModSecurity Core Rule Set.
80+
#
81+
# @param executing_paranoia_level
82+
# Sets the executing paranoia level in the OWASP ModSecurity Core Rule Set.
83+
# The default is equal to, and cannot be lower than, $paranoia_level.
84+
#
7885
# @param secrequestmaxnumargs
7986
# Sets the maximum number of arguments in the request.
8087
#
@@ -123,6 +130,8 @@
123130
Integer $secrequestbodylimit = 13107200,
124131
Integer $secrequestbodynofileslimit = 131072,
125132
Integer $secrequestbodyinmemorylimit = 131072,
133+
Integer[1,4] $paranoia_level = 1,
134+
Integer[1,4] $executing_paranoia_level = $paranoia_level,
126135
Boolean $manage_security_crs = true,
127136
) inherits apache::params {
128137
include apache
@@ -140,6 +149,10 @@
140149
fail('SLES 10 is not currently supported.')
141150
}
142151

152+
if ($executing_paranoia_level < $paranoia_level) {
153+
fail('Executing paranoia level cannot be lower than paranoia level')
154+
}
155+
143156
case $version {
144157
1: {
145158
$mod_name = 'security'
@@ -248,6 +261,8 @@
248261
# - $notice_anomaly_score
249262
# - $inbound_anomaly_threshold
250263
# - $outbound_anomaly_threshold
264+
# - $paranoia_level
265+
# - $executing_paranoia_level
251266
# - $allowed_methods
252267
# - $content_types
253268
# - $restricted_extensions

spec/classes/mod/security_spec.rb

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,35 @@
130130
}
131131
it { is_expected.to contain_file('/etc/httpd/modsecurity.d/custom_rules/custom_01_rules.conf').with_content %r{^\s*.*"id:199999,phase:1,nolog,allow,ctl:ruleEngine=off"$} }
132132
end
133+
134+
describe 'with CRS parameters' do
135+
let :params do
136+
{
137+
paranoia_level: 1,
138+
executing_paranoia_level: 2,
139+
}
140+
end
141+
142+
it {
143+
is_expected.to contain_file('/etc/httpd/modsecurity.d/security_crs.conf').with_content \
144+
%r{^SecAction \\\n\s+\"id:900000,\\\n\s+phase:1,\\\n\s+nolog,\\\n\s+pass,\\\n\s+t:none,\\\n\s+setvar:tx.paranoia_level=1"$}
145+
is_expected.to contain_file('/etc/httpd/modsecurity.d/security_crs.conf').with_content \
146+
%r{^SecAction \\\n\s+\"id:900001,\\\n\s+phase:1,\\\n\s+nolog,\\\n\s+pass,\\\n\s+t:none,\\\n\s+setvar:tx.executing_paranoia_level=2"$}
147+
}
148+
end
149+
150+
describe 'with invalid CRS parameters' do
151+
let :params do
152+
{
153+
paranoia_level: 2,
154+
executing_paranoia_level: 1,
155+
}
156+
end
157+
158+
it {
159+
is_expected.to compile.and_raise_error(%r{Executing paranoia level cannot be lower than paranoia level})
160+
}
161+
end
133162
end
134163
when 'Debian'
135164
context 'on Debian based systems' do
@@ -259,6 +288,35 @@
259288
)
260289
}
261290
end
291+
292+
describe 'with CRS parameters' do
293+
let :params do
294+
{
295+
paranoia_level: 1,
296+
executing_paranoia_level: 1,
297+
}
298+
end
299+
300+
it {
301+
is_expected.to contain_file('/etc/modsecurity/security_crs.conf').with_content \
302+
%r{^SecAction \\\n\s+\"id:900000,\\\n\s+phase:1,\\\n\s+nolog,\\\n\s+pass,\\\n\s+t:none,\\\n\s+setvar:tx.paranoia_level=1"$}
303+
is_expected.to contain_file('/etc/modsecurity/security_crs.conf').with_content \
304+
%r{^SecAction \\\n\s+\"id:900001,\\\n\s+phase:1,\\\n\s+nolog,\\\n\s+pass,\\\n\s+t:none,\\\n\s+setvar:tx.executing_paranoia_level=1"$}
305+
}
306+
end
307+
308+
describe 'with invalid CRS parameters' do
309+
let :params do
310+
{
311+
paranoia_level: 2,
312+
executing_paranoia_level: 1,
313+
}
314+
end
315+
316+
it {
317+
is_expected.to compile.and_raise_error(%r{Executing paranoia level cannot be lower than paranoia level})
318+
}
319+
end
262320
end
263321
end
264322
end

templates/mod/security_crs.conf.erb

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -175,13 +175,13 @@ SecDefaultAction "phase:2,<%= @_secdefaultaction -%>"
175175
#
176176
# Uncomment this rule to change the default:
177177
#
178-
#SecAction \
179-
# "id:900000,\
180-
# phase:1,\
181-
# nolog,\
182-
# pass,\
183-
# t:none,\
184-
# setvar:tx.paranoia_level=1"
178+
SecAction \
179+
"id:900000,\
180+
phase:1,\
181+
nolog,\
182+
pass,\
183+
t:none,\
184+
setvar:tx.paranoia_level=<%= @paranoia_level -%>"
185185

186186

187187
# It is possible to execute rules from a higher paranoia level but not include
@@ -201,13 +201,13 @@ SecDefaultAction "phase:2,<%= @_secdefaultaction -%>"
201201
# level results in a performance impact that is equally high as setting
202202
# tx.paranoia_level to said level.
203203
#
204-
#SecAction \
205-
# "id:900001,\
206-
# phase:1,\
207-
# nolog,\
208-
# pass,\
209-
# t:none,\
210-
# setvar:tx.executing_paranoia_level=1"
204+
SecAction \
205+
"id:900001,\
206+
phase:1,\
207+
nolog,\
208+
pass,\
209+
t:none,\
210+
setvar:tx.executing_paranoia_level=<%= @executing_paranoia_level -%>"
211211

212212

213213
#

0 commit comments

Comments
 (0)