Puppet Class: stunnel::config

Inherits:
stunnel
Defined in:
manifests/config.pp

Overview

Global stunnel options

Parameters:

  • chroot (Stdlib::Absolutepath) (defaults to: '/var/stunnel')

    The location of the chroot jail, if it is not set to ‘undef` If SELinux is set to Enforced or Permissive, `$chroot` will be set to `undef`. This option only affects `stunnel::connection`.

    • Do NOT make this anything under “/var/run“

  • pki (Variant[Enum['simp'],Boolean]) (defaults to: $stunnel::pki)
    • If “simp“, include SIMP’s “pki“ module and use “pki::copy“ to manage application certs in “/etc/pki/simp_apps/stunnel/x509“

    • If “true“, do not include SIMP’s pki module, but still use “pki::copy“ to manage certs in “/etc/pki/simp_apps/stunnel/x509“

    • If “false“, do not include SIMP’s pki module and do not use “pki::copy“ to manage certs. You will need to appropriately assign a subset of:

      * app_pki_dir
      * app_pki_key
      * app_pki_cert
      * app_pki_ca_dir
      
  • app_pki_external_source (String) (defaults to: $stunnel::app_pki_external_source)
    • If pki = “simp“ or “true“, this is the directory from which certs will be copied, via “pki::copy“

    • If pki = “false“, this variable has no effect

  • app_pki_dir (Stdlib::Absolutepath) (defaults to: $stunnel::app_pki_dir)

    The source of certs in the chroot, and the basepath of “$app_pki_key“, “$app_pki_cert“, “$app_pki_ca“, “$app_pki_ca_dir“, and “$app_pki_crl“

    • NOTE: Even when using a chroot, stunnel needs the certs to reside outside of the chroot path

  • app_pki_key (Stdlib::Absolutepath) (defaults to: $stunnel::app_pki_key)

    Path and name of the private SSL key file

  • app_pki_cert (Stdlib::Absolutepath) (defaults to: $stunnel::app_pki_cert)

    Path and name of the public SSL certificate

  • app_pki_ca_dir (Stdlib::Absolutepath) (defaults to: $stunnel::app_pki_ca_dir)

    Since stunnel runs in a chroot, you need to copy the appropriate CA certificates in from an external source

    • This should be the full path to a directory containing hashed

    versions of the CA certificates

  • app_pki_crl (Optional[Stdlib::Absolutepath]) (defaults to: $stunnel::app_pki_crl)

    Since stunnel runs in a chroot, you need to copy the appropriate CRL in from an external source

  • pid (Optional[Stdlib::Absolutepath]) (defaults to: undef)

    The PID file

    • Relative to the chroot jail!

    • Let the startup script handle it by default

  • setuid (String) (defaults to: $stunnel::setuid)

    The user stunnel should run as

  • setgid (String) (defaults to: $stunnel::setgid)

    The group stunnel should run as

  • uid (Integer) (defaults to: $stunnel::uid)

    The UID of the stunnel user

  • gid (Integer) (defaults to: $stunnel::gid)

    The GID of the stunnel user

  • stunnel_debug (String) (defaults to: 'err')

    The debug level for logging

  • syslog (Boolean) (defaults to: $stunnel::syslog)

    Enable logging to syslog

  • compression (Optional[Enum['zlib','rle']]) (defaults to: undef)

    The compression type to use for this service

  • egd (Optional[String]) (defaults to: undef)

    The path to the Entropy Gathering Daemon socket used to feed the OpenSSL Random Number Generator

  • engine (String) (defaults to: 'auto')

    If “$egd“ is set, sets the Hardware Engine to be used

  • engine_ctrl (Optional[String]) (defaults to: undef)

    If “$egd“ is set, sets the Hardware Engine Control parameters

  • fips (Boolean) (defaults to: $stunnel::fips)

    Set the “fips“ global option

    • We don’t enable FIPS mode by default since we want to be able to use TLS1.2

    • NOTE: This has no effect on EL < 7 due to stunnel not accepting the fips option in that version of stunnel

  • output (Optional[Stdlib::Absolutepath]) (defaults to: undef)

    The path to a log output file to use

  • rnd_bytes (Optional[Integer]) (defaults to: undef)

    The number of bytes to read from the random seed file

  • rnd_file (Optional[Stdlib::Absolutepath]) (defaults to: undef)

    The path to the random seed data file

  • rnd_overwrite (Boolean) (defaults to: true)

    Overwrite the random seed file with new random data

  • socket_options (Array[String]) (defaults to: [])

Author:



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
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
# File 'manifests/config.pp', line 116

class stunnel::config (
  Variant[Enum['simp'],Boolean]  $pki                     = $stunnel::pki,
  Stdlib::Absolutepath           $app_pki_dir             = $stunnel::app_pki_dir,
  String                         $app_pki_external_source = $stunnel::app_pki_external_source,
  Stdlib::Absolutepath           $app_pki_key             = $stunnel::app_pki_key,
  Stdlib::Absolutepath           $app_pki_cert            = $stunnel::app_pki_cert,
  Stdlib::Absolutepath           $app_pki_ca_dir          = $stunnel::app_pki_ca_dir,
  Optional[Stdlib::Absolutepath] $app_pki_crl             = $stunnel::app_pki_crl,
  Stdlib::Absolutepath           $chroot                  = '/var/stunnel',
  Optional[Stdlib::Absolutepath] $pid                     = undef,
  String                         $setuid                  = $stunnel::setuid,
  String                         $setgid                  = $stunnel::setgid,
  Integer                        $uid                     = $stunnel::uid,
  Integer                        $gid                     = $stunnel::gid,
  String                         $stunnel_debug           = 'err',
  Optional[Enum['zlib','rle']]   $compression             = undef,
  Optional[String]               $egd                     = undef,
  String                         $engine                  = 'auto',
  Optional[String]               $engine_ctrl             = undef,
  Optional[Stdlib::Absolutepath] $output                  = undef,
  Optional[Integer]              $rnd_bytes               = undef,
  Optional[Stdlib::Absolutepath] $rnd_file                = undef,
  Boolean                        $rnd_overwrite           = true,
  Array[String]                  $socket_options          = [],
  Boolean                        $syslog                  = $stunnel::syslog,
  Boolean                        $fips                    = $stunnel::fips
) inherits stunnel {

  include 'stunnel::monolithic'

  ensure_resource('stunnel::account', $setuid,
    {
      'groupname' => $setgid,
      'uid'       => $uid,
      'gid'       => $gid
    }
  )

  if $facts['os']['selinux']['current_mode'] and $facts['os']['selinux']['current_mode'] != 'disabled' {
    $_chroot = undef
  }
  else {
    $_chroot = $chroot
  }

  if $pki {
    pki::copy { 'stunnel':
      source => $app_pki_external_source,
      pki    => $pki
    }
  }

  # $_legacy_pid is used to kill the old stunnel process set up from a previous
  #   version of this module. It should be set to $_pid, unless $_pid is unset.
  $on_systemd = 'systemd' in $facts['init_systems']

  if $pid =~ Undef {
    if $on_systemd {
      $_foreground = true
    } else {
      $_foreground = undef
    }
    $_pid        = '/var/run/stunnel/stunnel.pid'
    $_legacy_pid = '/var/run/stunnel/stunnel.pid'

  } else {
    $_pid        = $pid
    $_legacy_pid = $pid
  }

  if $_pid and !$on_systemd {
    $_stunnel_piddir = File[dirname($_pid)]
    ensure_resource('file', dirname($_pid),
      {
        'ensure'  => 'directory',
        'owner'   => $setuid,
        'group'   => $setgid,
        'mode'    => '0644',
        'seluser' => 'system_u',
        'selrole' => 'object_r',
        'seltype' => 'stunnel_var_run_t',
      }
    )
  }

  concat { '/etc/stunnel/stunnel.conf':
    owner          => 'root',
    group          => 'root',
    mode           => '0600',
    ensure_newline => true,
    warn           => true
  }

  concat::fragment { '0_stunnel_global':
    order   => 1,
    target  => '/etc/stunnel/stunnel.conf',
    content => template('stunnel/connection_conf.erb')
  }

  if $_chroot !~ Undef {
    if $_chroot in ['/',''] {
      fail("stunnel: \$chroot should not be root ('/')")
    }
    if $_chroot =~ /^\/var\/run/ {
      fail("stunnel: \$chroot cannot be under /var/run")
    }

    # The _chroot directory
    file { $_chroot:
      ensure => 'directory',
      owner  => 'root',
      group  => $setgid,
      mode   => '0770'
    }

    # The following two entries are required to be able to properly resolve
    # hosts using the _chroot directory.
    file { "${_chroot}/etc":
      ensure => 'directory',
      owner  => 'root',
      group  => 'root',
      mode   => '0755'
    }

    file { "${_chroot}/etc/resolv.conf":
      ensure => 'file',
      owner  => 'root',
      group  => 'root',
      mode   => '0644',
      source => 'file:///etc/resolv.conf'
    }

    file { "${_chroot}/etc/nsswitch.conf":
      ensure => 'file',
      owner  => 'root',
      group  => 'root',
      mode   => '0644',
      source => 'file:///etc/nsswitch.conf'
    }

    file { "${_chroot}/etc/hosts":
      ensure => 'file',
      owner  => 'root',
      group  => 'root',
      mode   => '0644',
      source => 'file:///etc/hosts'
    }

    file { "${_chroot}/var":
      ensure => 'directory',
      owner  => 'root',
      group  => 'root',
      mode   => '0644'
    }

    file { "${_chroot}/var/run":
      ensure => 'directory',
      owner  => $setuid,
      group  => $setgid,
      mode   => '0644'
    }

    file { "${_chroot}/var/run/stunnel":
      ensure => 'directory',
      owner  => $setuid,
      group  => $setgid,
      mode   => '0644'
    }

    file { "${_chroot}/etc/pki":
      ensure => 'directory',
      owner  => 'root',
      group  => $setgid,
      mode   => '0640'
    }

    file { "${_chroot}/etc/pki/cacerts":
      source  => "file://${app_pki_dir}/cacerts",
      group   => $setgid,
      mode    => '0640',
      recurse => true,
    }

    # If we're setting up PKI here, we also need to make sure the
    # correct structure is setup prior to copy or we get errors.
    if $pki {
      Pki::Copy['stunnel'] -> File["${_chroot}/etc/pki/cacerts"]
    }
  }

  # These templates need variables, that's why they are here
  if $on_systemd {
    file { '/etc/systemd/system/stunnel.service':
      ensure  => file,
      content => template('stunnel/connection_systemd.erb'),
      owner   => 'root',
      group   => 'root',
      mode    => '0644',
      notify  => Exec['stunnel daemon reload']
    }
    exec { 'stunnel daemon reload':
      command     => '/usr/bin/systemctl daemon-reload',
      refreshonly => true,
    }

  }
  else {
    if $_pid {
      # The selinux context settings are ignored if SELinux is disabled
      ensure_resource('file', dirname($_pid),
        {
          'ensure'  => 'directory',
          'owner'   => $setuid,
          'group'   => $setgid,
          'mode'    => '0644',
          'seluser' => 'system_u',
          'selrole' => 'object_r',
          'seltype' => 'stunnel_var_run_t',
        }
      )
    }

    file { '/etc/rc.d/init.d/stunnel':
      ensure  => 'present',
      owner   => 'root',
      group   => 'root',
      mode    => '0750',
      content => template('stunnel/connection_init.erb'),
    }

  }

}