Mercurial > repos > other > Puppet
view modules/website/manifests/https.pp @ 149:af30a5eb468f puppet-3.6
Remove now deprecated mcrypt extension - all scripts now use openssl
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sun, 26 Mar 2017 16:53:34 +0100 |
parents | 765e72629b3e |
children | 060f81349dd6 |
line wrap: on
line source
# If the SSL cert and key are defined then the definer deals with them existing # If the SSL cert and key are not defined then we use template file paths and ensure they exist define website::https( $docroot = undef, $ip = $website::primary_ip, $ssl_cert = undef, $ssl_key = undef, $ssl_ca_chain = undef, $priority = undef, $docroot_owner = undef, $docroot_group = undef, $serveraliases = [], $ensure = 'present', $custom_fragment = '', $force_no_www = true, $force_no_index = true, $lockdown_requests = true, ) { if ! defined(Class['website']) { fail('You must include the website base class before using any website defined resources') } validate_re($ensure, '^(present|absent)$', "${ensure} is not supported for ensure. Allowed values are 'present' and 'absent'.") $shortname = domain_to_short_name($name) $logpart = $shortname $shortdomain = domain_to_short_domain($name) $custom_conf0 = 'Header always set Strict-Transport-Security "max-age=16070400; includeSubDomains" Header always set X-Xss-Protection "1; mode=block" Header always set X-Content-Type-Options "nosniff" Header always set X-Frame-Options "SAMEORIGIN"' if $force_no_index { $custom_conf1 = "$custom_conf0 Include conf.extra/no-index.conf" } else { $custom_conf1 = $custom_conf0 } if $lockdown_requests { $custom_conf2 = "$custom_conf1 Include conf.custom/filter-core.conf" } else { $custom_conf2 = $custom_conf1 } if $force_no_www { $custom_conf3 = "$custom_conf2 Include conf.extra/no-www.conf" } else { $custom_conf3 = $custom_conf2 } if $custom_fragment { $custom_conf = "$custom_conf3 #Additional custom fragment $custom_fragment" } else { $custom_conf = $custom_conf3 } if $docroot == undef { $siteroot = "${website::basedir}/${shortname}" } else { $siteroot = $docroot } # These conditionals use an ugly cludge from # http://grokbase.com/t/gg/puppet-users/147by1key3/checking-a-variable-is-not-undef#20140713grem6zqsai7qjbgkmd2f4ia3qi # because if we don't then undef gets auto-cast to the empty string and the empty string matches our special "no CA chain" case # It'd be nicer to use "=~ Undef" to check types (https://puppet-on-the-edge.blogspot.co.uk/2013/12/lets-talk-about-undef.html), # but that threw syntax errors. if $ssl_cert == undef and $ssl_ca_chain == undef and !("" in [$ssl_ca_chain]) { $sslcert = "/etc/letsencrypt/live/${::fqdn}/cert.pem" $sslkey = "/etc/letsencrypt/live/${::fqdn}/privkey.pem" } elsif $ssl_cert == undef { $sslcert = "${website::certdir}/${shortdomain}.crt" $sslkey = "${website::certdir}/${shortdomain}.key" File { mode => '0400', owner => 'root', group => 'root', } file { $sslcert: source => "puppet:///private/pki/custom/${shortdomain}.crt", before => Apache::Vhost[$name], notify => Service['httpd'], ensure => present; } file { $sslkey: source => "puppet:///private/pki/custom/${shortdomain}.key", before => Apache::Vhost[$name], notify => Service['httpd'], ensure => present; } } else { $sslcert = $ssl_cert $sslkey = $ssl_key } if $ssl_ca_chain == undef and !("" in [$ssl_ca_chain]) { $ssl_chain = $website::ca_chain } elsif $ssl_ca_chain == '' { # Special case where we're directly under the CA and don't want to unnecessarily send the CA cert $ssl_chain = undef } else { $ssl_chain = "/etc/pki/custom/$ssl_ca_chain" if ! defined(File[$ssl_chain]) { file { $ssl_chain: ensure => present, source => "puppet:///private/pki/custom/$ssl_ca_chain", notify => Service['httpd'], } } } if $docroot_owner == undef { $owner = $website::docroot_owner } else { $owner = $docroot_owner } if $docroot_group == undef { $group = $website::docroot_group } else { $group = $docroot_group } apache::vhost { $name: ip => $ip, port => '443', priority => $priority, docroot => $siteroot, docroot_owner => $owner, docroot_group => $group, custom_fragment => $custom_conf, logroot => '/var/log/apache/', access_log_file => "access_${logpart}.log", error_log_file => "error_${logpart}.log", serveraliases => $serveraliases, ssl => true, ssl_cert => $sslcert, ssl_key => $sslkey, ssl_chain => $ssl_chain, ensure => $ensure, } apache::vhost { "${name}-80": servername => $name, port => 80, docroot => $siteroot, redirect_status => 'permanent', redirect_dest => "https://$name/", serveraliases => $serveraliases, logroot => '/var/log/apache/', access_log_file => "access_${logpart}_nossl.log", error_log_file => "error_${logpart}_nossl.log", } }