Puppet Class: apache::mod::security

Inherits:
::apache::params
Defined in:
manifests/mod/security.pp

Summary

Installs and configures `mod_security`.

Overview

Parameters:

  • version (Any) (defaults to: $::apache::params::modsec_version)

    Manage mod_security or mod_security2

  • logroot (Any) (defaults to: $::apache::params::logroot)

    Configures the location of audit and debug logs.

  • crs_package (Any) (defaults to: $::apache::params::modsec_crs_package)

    Name of package that installs CRS rules.

  • activated_rules (Any) (defaults to: $::apache::params::modsec_default_rules)

    An array of rules from the modsec_crs_path or absolute to activate via symlinks.

  • modsec_dir (Any) (defaults to: $::apache::params::modsec_dir)

    Defines the path where Puppet installs the modsec configuration and activated rules links.

  • modsec_secruleengine (Any) (defaults to: $::apache::params::modsec_secruleengine)

    Configures the rules engine.

  • audit_log_relevant_status (Any) (defaults to: '^(?:5|4(?!04))')

    Configures which response status code is to be considered relevant for the purpose of audit logging.

  • audit_log_parts (Any) (defaults to: $::apache::params::modsec_audit_log_parts)

    Defines which parts of each transaction are going to be recorded in the audit log. Each part is assigned a single letter; when a letter appears in the list then the equivalent part will be recorded.

  • audit_log_type (Any) (defaults to: $::apache::params::modsec_audit_log_type)

    Defines the type of audit logging mechanism to be used.

  • audit_log_storage_dir (Any) (defaults to: undef)

    Defines the directory where concurrent audit log entries are to be stored. This directive is only needed when concurrent audit logging is used.

  • secpcrematchlimit (Any) (defaults to: $::apache::params::secpcrematchlimit)

    Sets the match limit in the PCRE library.

  • secpcrematchlimitrecursion (Any) (defaults to: $::apache::params::secpcrematchlimitrecursion)

    Sets the match limit recursion in the PCRE library.

  • allowed_methods (Any) (defaults to: 'GET HEAD POST OPTIONS')

    A space-separated list of allowed HTTP methods.

  • content_types (Any) (defaults to: 'application/x-www-form-urlencoded|multipart/form-data|text/xml|application/xml|application/x-amf')

    A list of one or more allowed MIME types.

  • restricted_extensions (Any) (defaults to: '.asa/ .asax/ .ascx/ .axd/ .backup/ .bak/ .bat/ .cdx/ .cer/ .cfg/ .cmd/ .com/ .config/ .conf/ .cs/ .csproj/ .csr/ .dat/ .db/ .dbf/ .dll/ .dos/ .htr/ .htw/ .ida/ .idc/ .idq/ .inc/ .ini/ .key/ .licx/ .lnk/ .log/ .mdb/ .old/ .pass/ .pdb/ .pol/ .printer/ .pwd/ .resources/ .resx/ .sql/ .sys/ .vb/ .vbs/ .vbproj/ .vsdisco/ .webinfo/ .xsd/ .xsx/')

    A space-sparated list of prohibited file extensions.

  • restricted_headers (Any) (defaults to: '/Proxy-Connection/ /Lock-Token/ /Content-Range/ /Translate/ /via/ /if/')

    A list of restricted headers separated by slashes and spaces.

  • secdefaultaction (Any) (defaults to: 'deny')

    Defines the default list of actions, which will be inherited by the rules in the same configuration context.

  • anomaly_score_blocking (Any) (defaults to: 'off')

    Activates or deactivates the Collaborative Detection Blocking of the OWASP ModSecurity Core Rule Set.

  • inbound_anomaly_threshold (Any) (defaults to: '5')

    Sets the scoring threshold level of the inbound blocking rules for the Collaborative Detection Mode in the OWASP ModSecurity Core Rule Set.

  • outbound_anomaly_threshold (Any) (defaults to: '4')

    Sets the scoring threshold level of the outbound blocking rules for the Collaborative Detection Mode in the OWASP ModSecurity Core Rule Set.

  • critical_anomaly_score (Any) (defaults to: '5')

    Sets the Anomaly Score for rules assigned with a critical severity.

  • error_anomaly_score (Any) (defaults to: '4')

    Sets the Anomaly Score for rules assigned with a error severity.

  • warning_anomaly_score (Any) (defaults to: '3')

    Sets the Anomaly Score for rules assigned with a warning severity.

  • notice_anomaly_score (Any) (defaults to: '2')

    Sets the Anomaly Score for rules assigned with a notice severity.

  • secrequestmaxnumargs (Any) (defaults to: '255')

    Sets the maximum number of arguments in the request.

  • secrequestbodylimit (Any) (defaults to: '13107200')

    Sets the maximum request body size ModSecurity will accept for buffering.

  • secrequestbodynofileslimit (Any) (defaults to: '131072')

    Configures the maximum request body size ModSecurity will accept for buffering, excluding the size of any files being transported in the request.

  • secrequestbodyinmemorylimit (Any) (defaults to: '131072')

    Configures the maximum request body size that ModSecurity will store in memory.

  • manage_security_crs (Any) (defaults to: true)

    Toggles whether to manage ModSecurity Core Rule Set

See Also:



96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
# File 'manifests/mod/security.pp', line 96

class apache::mod::security (
  $logroot                    = $::apache::params::logroot,
  $version                     = $::apache::params::modsec_version,
  $crs_package                 = $::apache::params::modsec_crs_package,
  $activated_rules             = $::apache::params::modsec_default_rules,
  $modsec_dir                  = $::apache::params::modsec_dir,
  $modsec_secruleengine        = $::apache::params::modsec_secruleengine,
  $audit_log_relevant_status   = '^(?:5|4(?!04))',
  $audit_log_parts             = $::apache::params::modsec_audit_log_parts,
  $audit_log_type              = $::apache::params::modsec_audit_log_type,
  $audit_log_storage_dir       = undef,
  $secpcrematchlimit           = $::apache::params::secpcrematchlimit,
  $secpcrematchlimitrecursion  = $::apache::params::secpcrematchlimitrecursion,
  $allowed_methods             = 'GET HEAD POST OPTIONS',
  $content_types               = 'application/x-www-form-urlencoded|multipart/form-data|text/xml|application/xml|application/x-amf',
  $restricted_extensions       = '.asa/ .asax/ .ascx/ .axd/ .backup/ .bak/ .bat/ .cdx/ .cer/ .cfg/ .cmd/ .com/ .config/ .conf/ .cs/ .csproj/ .csr/ .dat/ .db/ .dbf/ .dll/ .dos/ .htr/ .htw/ .ida/ .idc/ .idq/ .inc/ .ini/ .key/ .licx/ .lnk/ .log/ .mdb/ .old/ .pass/ .pdb/ .pol/ .printer/ .pwd/ .resources/ .resx/ .sql/ .sys/ .vb/ .vbs/ .vbproj/ .vsdisco/ .webinfo/ .xsd/ .xsx/',
  $restricted_headers          = '/Proxy-Connection/ /Lock-Token/ /Content-Range/ /Translate/ /via/ /if/',
  $secdefaultaction            = 'deny',
  $anomaly_score_blocking      = 'off',
  $inbound_anomaly_threshold   = '5',
  $outbound_anomaly_threshold  = '4',
  $critical_anomaly_score      = '5',
  $error_anomaly_score         = '4',
  $warning_anomaly_score       = '3',
  $notice_anomaly_score        = '2',
  $secrequestmaxnumargs        = '255',
  $secrequestbodylimit         = '13107200',
  $secrequestbodynofileslimit  = '131072',
  $secrequestbodyinmemorylimit = '131072',
  $manage_security_crs         = true,
) inherits ::apache::params {
  include ::apache

  $_secdefaultaction = $secdefaultaction ? {
    /log/   => $secdefaultaction, # it has log or nolog,auditlog or log,noauditlog
    default => "${secdefaultaction},log",
  }

  if $::osfamily == 'FreeBSD' {
    fail('FreeBSD is not currently supported')
  }

  if ($::osfamily == 'Suse' and $::operatingsystemrelease < '11') {
    fail('SLES 10 is not currently supported.')
  }

  case $version {
    1: {
      $mod_name = 'security'
      $mod_conf_name = 'security.conf'
    }
    2: {
      $mod_name = 'security2'
      $mod_conf_name = 'security2.conf'
    }
    default: {
      fail('Unsuported version for mod security')
    }
  }
  ::apache::mod { $mod_name:
    id  => 'security2_module',
    lib => 'mod_security2.so',
  }


  ::apache::mod { 'unique_id_module':
    id  => 'unique_id_module',
    lib => 'mod_unique_id.so',
  }

  if $crs_package  {
    package { $crs_package:
      ensure => 'installed',
      before => [
        File[$::apache::confd_dir],
        File[$modsec_dir],
      ],
    }
  }

  # Template uses:
  # - logroot
  # - $modsec_dir
  # - $audit_log_parts
  # - $audit_log_type
  # - $audit_log_storage_dir
  # - secpcrematchlimit
  # - secpcrematchlimitrecursion
  # - secrequestbodylimit
  # - secrequestbodynofileslimit
  # - secrequestbodyinmemorylimit
  file { 'security.conf':
    ensure  => file,
    content => template('apache/mod/security.conf.erb'),
    mode    => $::apache::file_mode,
    path    => "${::apache::mod_dir}/${mod_conf_name}",
    owner   => $::apache::params::user,
    group   => $::apache::params::group,
    require => Exec["mkdir ${::apache::mod_dir}"],
    before  => File[$::apache::mod_dir],
    notify  => Class['apache::service'],
  }

  file { $modsec_dir:
    ensure  => directory,
    owner   => 'root',
    group   => 'root',
    mode    => '0755',
    purge   => true,
    force   => true,
    recurse => true,
    require => Package['httpd'],
  }

  file { "${modsec_dir}/activated_rules":
    ensure  => directory,
    owner   => $::apache::params::user,
    group   => $::apache::params::group,
    mode    => '0555',
    purge   => true,
    force   => true,
    recurse => true,
    notify  => Class['apache::service'],
  }

  if $manage_security_crs {
    # Template uses:
    # - $_secdefaultaction
    # - $critical_anomaly_score
    # - $error_anomaly_score
    # - $warning_anomaly_score
    # - $notice_anomaly_score
    # - $inbound_anomaly_threshold
    # - $outbound_anomaly_threshold
    # - $anomaly_score_blocking
    # - $allowed_methods
    # - $content_types
    # - $restricted_extensions
    # - $restricted_headers
    # - $secrequestmaxnumargs
    file { "${modsec_dir}/security_crs.conf":
      ensure  => file,
      content => template('apache/mod/security_crs.conf.erb'),
      require => File[$modsec_dir],
      notify  => Class['apache::service'],
    }

    # Debian 9 has a different rule setup
    unless $::operatingsystem == 'SLES' or ($::operatingsystem == 'Debian' and versioncmp($::operatingsystemrelease, '9') >= 0) or ($::operatingsystem == 'Ubuntu' and versioncmp($::operatingsystemrelease, '18.04') >= 0) {
      apache::security::rule_link { $activated_rules: }
    }
  }
}