Repository navigation
Expand file tree
/
Copy pathinit.pp
More file actions
140 lines (131 loc) · 4.55 KB
/
Copy pathinit.pp
File metadata and controls
140 lines (131 loc) · 4.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
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
# @summary
# Manage SSL certs for NGINX on PE using letsencrypt
#
# @param nginx_conf_dir Stdlib::Absolutepath
# The directory containing the nginx config for the console
#
# @param letsencrypt_conf_dir Stdlib::Absolutepath
# The directory containing the letsencrypt config
#
# @param docroot Stdlib::Absolutepath
# The directory we should use as the docroot
#
# @param mode Stdlib::Filemode
# Octal value for the file permissions
#
# @param email Stdlib::Email
# Email address to use when requesting the certificates
#
# @param port Stdlib::Port
# Port to use for the nginx server
#
# @param owner String
# User running the puppet console services
#
# @param group String
# Group running the puppet console services
#
# @param manage_letsencrypt Boolean
# Should we manage the letsencrypt install?
#
# @param cert_dir Stdlib::Absolutepath
# Where are the PE console certs?
#
# @example Basic usage
# include pe_console_letsencrypt
#
class pe_console_letsencrypt (
Stdlib::Absolutepath $cert_dir = $facts['puppet_ssldir'],
Stdlib::Absolutepath $nginx_conf_dir = '/etc/puppetlabs/nginx/conf.d',
Stdlib::Absolutepath $letsencrypt_conf_dir = '/etc/letsencrypt',
Stdlib::Absolutepath $docroot = '/var/www',
Stdlib::Filemode $mode = '0640',
Stdlib::Email $email = "puppet@${facts['puppet_server']}",
Stdlib::Port $port = 80,
Boolean $manage_letsencrypt = true,
String $owner = 'pe-puppet',
String $group = 'pe-puppet',
) {
# Lookup the default redirect value
$default_redirect_enabled = lookup('puppet_enterprise::profile::console::proxy::http_redirect::enable_http_redirect',Boolean,first,true)
$hiera_cert = lookup('puppet_enterprise::profile::console::browser_ssl_cert',Variant[String,Boolean],first,false)
$hiera_key = lookup('puppet_enterprise::profile::console::browser_ssl_private_key',Variant[String,Boolean],first,false)
# Ensure that the default redirect has been disabled before we begin
# If it hasn't, we have to fail as it'll end up in a change loop
#
# This can be set in hiera or in the console
if $default_redirect_enabled == true {
fail('Could not enable pe_console_letsencrypt,
puppet_enterprise::profile::console::proxy::http_redirect::enable_http_redirect is set to true'
)
}
if $hiera_cert or $hiera_key {
fail('Existing entries exist for the browser ssl cert and private key')
}
if $manage_letsencrypt {
# Setup the letsencrypt class using the email parameter
class { 'letsencrypt':
config => {
email => $email,
},
config_dir => $letsencrypt_conf_dir,
require => File["${nginx_conf_dir}/certs.conf"],
}
}
unless defined(File[$docroot]) {
file { $docroot:
ensure => directory,
owner => $owner,
group => $group,
mode => '0755',
}
}
# Generate the certs for the puppet server
letsencrypt::certonly { $facts['puppet_server']:
domains => [$facts['puppet_server']],
manage_cron => true,
plugin => 'webroot',
webroot_paths => [$docroot],
require => File[$docroot],
}
# A custom nginx vhost to do the redirection and host the letsencrypt challange response
file { "${nginx_conf_dir}/certs.conf":
ensure => file,
owner => 'root',
group => 'root',
mode => '0644',
content => epp("${module_name}/cert_vhost.conf.epp", {'server' => $facts['networking']['fqdn'], 'port' => $port, 'docroot' => $docroot}),
notify => Exec['restart_nginx'],
}
# This is a **TINY** bit hacky, but it means we can get a new cert live in a single puppet run
exec { 'restart_nginx':
command => '/bin/systemctl restart pe-nginx',
refreshonly => true,
}
# The console cert
file { "${cert_dir}/certs/console-cert.pem":
ensure => file,
owner => $owner,
group => $group,
links => 'follow',
mode => $mode,
source => "${letsencrypt_conf_dir}/live/${facts['puppet_server']}/fullchain.pem",
backup => '.puppet_bak',
notify => Service['pe-nginx'],
require => Exec['restart_nginx'],
subscribe => Letsencrypt::Certonly[$facts['puppet_server']],
}
# The console key
file { "${cert_dir}/private_keys/console-cert.pem":
ensure => file,
owner => $owner,
group => $group,
links => 'follow',
mode => $mode,
source => "${letsencrypt_conf_dir}/live/${facts['puppet_server']}/privkey.pem",
backup => '.puppet_bak',
notify => Service['pe-nginx'],
require => Exec['restart_nginx'],
subscribe => Letsencrypt::Certonly[$facts['puppet_server']],
}
}