Puppet Class: profile::pki::multirootca

Defined in:
modules/profile/manifests/pki/multirootca.pp

Overview

SPDX-License-Identifier: Apache-2.0

Parameters:

  • vhost (String) (defaults to: lookup('profile::pki::multirootca::vhost'))

    the vhost to use for the crl/ocsp responder

  • db_driver (Cfssl::DB_driver) (defaults to: lookup('profile::pki::multirootca::db_driver'))

    The db driver to use

  • db_user (String) (defaults to: lookup('profile::pki::multirootca::db_user'))

    The db user to use

  • db_pass (Sensitive[String[1]]) (defaults to: lookup('profile::pki::multirootca::db_pass'))

    The db pass to use

  • db_name (String) (defaults to: lookup('profile::pki::multirootca::db_name'))

    The db name to use

  • db_host (Stdlib::Host) (defaults to: lookup('profile::pki::multirootca::db_host'))

    The db host to use

  • root_ca_cn (Cfssl::Ca_name) (defaults to: lookup('profile::pki::multirootca::root_ca_cn'))

    The CN of the root ca used for creating the ocsp responder

  • root_ca_cert (String) (defaults to: lookup('profile::pki::multirootca::root_ca_cert'))

    The Root certificate cert

  • root_ocsp_cert (String) (defaults to: lookup('profile::pki::multirootca::root_ocsp_cert'))

    The Root CA ocsp signing certificate as a string passed to the file command

  • root_ocsp_key (String) (defaults to: lookup('profile::pki::multirootca::root_ocsp_key'))

    The Root CA ocsp signing key as a string passed to secret

  • root_ocsp_port (Stdlib::Port) (defaults to: lookup('profile::pki::multirootca::root_ocsp_port'))

    the ocsp listening port

  • client_ca_source (Stdlib::Filesource) (defaults to: lookup('profile::pki::multirootca::client_ca_source'))

    the source location of the trusted client auth CAs

  • enable_client_auth (Boolean) (defaults to: lookup('profile::pki::multirootca::enable_client_auth'))

    if true make sure connections authenticate with TLS client auth

  • enable_monitoring (Boolean) (defaults to: lookup('profile::pki::multirootca::enable_monitoring'))

    if true create icinga checks

  • maintenance_jobs (Boolean) (defaults to: lookup('profile::pki::multirootca::maintenance_jobs'))

    this parameter controls where maintenance jobs run e.g. ocsp generation cleaning expired certs

  • enable_k8s_vhost (Boolean) (defaults to: lookup('profile::pki::multirootca::enable_k8s_vhost'))

    enable the specific vhost to serve k8s

  • public_cert_base (String[1]) (defaults to: lookup('profile::pki::multirootca::public_cert_base'))

    the locations in puppet to find public certs

  • private_cert_base (String[1]) (defaults to: lookup('profile::pki::multirootca::private_cert_base'))

    the locations in the private repo to find private keys

  • prometheus_nodes (Array[Stdlib::Host]) (defaults to: lookup('profile::pki::multirootca::prometheus_nodes'))

    list of prometheus hosts

  • default_usages (Array[Cfssl::Usage]) (defaults to: lookup('profile::pki::multirootca::default_usages'))

    list of default usages

  • default_expiry (Cfssl::Expiry) (defaults to: lookup('profile::pki::multirootca::default_expiry'))

    contains the default expiry

  • default_nets (Array[Stdlib::IP::Address]) (defaults to: lookup('profile::pki::multirootca::default_nets'))

    a array of networks used by the multirootca as an ACL. Access is configured via apache so this config is not useful and should be left at the default

  • default_auth_keys (Hash[String, Cfssl::Auth_key]) (defaults to: lookup('profile::pki::multirootca::default_auth_keys'))

    a Hash of default_auth_keys

  • default_profiles (Hash[String, Cfssl::Profile]) (defaults to: lookup('profile::pki::multirootca::default_profiles'))

    a Hash of signing default_profiles

  • intermediates (Hash[Cfssl::Ca_name, Profile::Pki::Intermediate]) (defaults to: lookup('profile::pki::multirootca::intermediates'))

    a list of intermediate CN's to create

  • cfssl_httpd_cert (Boolean) (defaults to: lookup('profile::pki::multirootca::cfssl_httpd_cert'))


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
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
# File 'modules/profile/manifests/pki/multirootca.pp', line 29

class profile::pki::multirootca (
    String                        $vhost              = lookup('profile::pki::multirootca::vhost'),
    Cfssl::DB_driver              $db_driver          = lookup('profile::pki::multirootca::db_driver'),
    String                        $db_user            = lookup('profile::pki::multirootca::db_user'),
    Sensitive[String[1]]          $db_pass            = lookup('profile::pki::multirootca::db_pass'),
    String                        $db_name            = lookup('profile::pki::multirootca::db_name'),
    Stdlib::Host                  $db_host            = lookup('profile::pki::multirootca::db_host'),
    Cfssl::Ca_name                $root_ca_cn         = lookup('profile::pki::multirootca::root_ca_cn'),
    String                        $root_ca_cert       = lookup('profile::pki::multirootca::root_ca_cert'),
    String                        $root_ocsp_cert     = lookup('profile::pki::multirootca::root_ocsp_cert'),
    String                        $root_ocsp_key      = lookup('profile::pki::multirootca::root_ocsp_key'),
    Stdlib::Port                  $root_ocsp_port     = lookup('profile::pki::multirootca::root_ocsp_port'),
    Boolean                       $enable_client_auth = lookup('profile::pki::multirootca::enable_client_auth'),
    Stdlib::Filesource            $client_ca_source   = lookup('profile::pki::multirootca::client_ca_source'),
    Boolean                       $enable_monitoring  = lookup('profile::pki::multirootca::enable_monitoring'),
    Boolean                       $maintenance_jobs   = lookup('profile::pki::multirootca::maintenance_jobs'),
    Boolean                       $enable_k8s_vhost   = lookup('profile::pki::multirootca::enable_k8s_vhost'),
    Boolean                       $cfssl_httpd_cert   = lookup('profile::pki::multirootca::cfssl_httpd_cert'),
    String[1]                     $public_cert_base   = lookup('profile::pki::multirootca::public_cert_base'),
    String[1]                     $private_cert_base  = lookup('profile::pki::multirootca::private_cert_base'),
    Array[Stdlib::Host]           $prometheus_nodes   = lookup('profile::pki::multirootca::prometheus_nodes'),
    Array[Cfssl::Usage]           $default_usages     = lookup('profile::pki::multirootca::default_usages'),
    Cfssl::Expiry                 $default_expiry     = lookup('profile::pki::multirootca::default_expiry'),
    Array[Stdlib::IP::Address]    $default_nets       = lookup('profile::pki::multirootca::default_nets'),
    Hash[String, Cfssl::Auth_key] $default_auth_keys  = lookup('profile::pki::multirootca::default_auth_keys'),
    Hash[String, Cfssl::Profile]  $default_profiles   = lookup('profile::pki::multirootca::default_profiles'),
    Hash[Cfssl::Ca_name, Profile::Pki::Intermediate] $intermediates = lookup('profile::pki::multirootca::intermediates'),
) {
    # we need to include this as we use some of the variables
    include cfssl  # lint:ignore:wmf_styleguide

    $crl_base_url = "http://${vhost}/crl"
    $ocsp_base_url = "http://${vhost}/ocsp"
    $db_conf_file = "${cfssl::conf_dir}/db.conf"
    $root_ca_file = "${cfssl::ssl_dir}/${root_ca_cn.regsubst('\W', '_', 'G')}.pem"
    $multirootca_service = 'cfssl-multirootca'
    $document_root = '/srv/cfssl'
    $bundle_dir = "${document_root}/bundles"
    $crl_dir = "${document_root}/crl"
    $check_command_base = '/usr/local/sbin/cfssl-certs check -l'
    $ensure_monitoring = $enable_monitoring.bool2str('present', 'absent')

    wmflib::dir::mkdir_p($bundle_dir)
    wmflib::dir::mkdir_p($crl_dir)

    # Make the puppet CA available for download
    file {"${bundle_dir}/Puppet_Internal_CA.pem.pem":
        ensure => file,
        owner  => 'root',
        group  => 'root',
        mode   => '0444',
        source => $facts['puppet_config']['localcacert'],
    }

    cfssl::db{'multirootca-db':
        driver         => $db_driver,
        username       => $db_user,
        password       => $db_pass,
        dbname         => $db_name,
        host           => $db_host,
        conf_file      => $db_conf_file,
        notify_service => $multirootca_service,
        python_config  => true,
        ssl_ca         => '/etc/ssl/certs/wmf-ca-certificates.crt',
    }

    $root_ca_content = file($root_ca_cert)
    file {$root_ca_file:
        ensure  => file,
        owner   => root,
        group   => root,
        mode    => '0444',
        content => $root_ca_content,
    }
    # Root CA OCSP responder
    cfssl::ocsp{$root_ca_cn:
        listen_port        => $root_ocsp_port,
        db_conf_file       => $db_conf_file,
        ca_file            => $root_ca_file,
        key_content        => Sensitive(secret($root_ocsp_key)),
        cert_content       => file($root_ocsp_cert),
        ocsprefresh_update => $maintenance_jobs,
        db_driver          => $db_driver,
        require            => Service[$multirootca_service],
    }

    # Create Signers
    $signers = $intermediates.reduce({}) |$memo, $value| {
        $intermediate    = $value[0]
        $config          = $value[1]
        $safe_title      = $intermediate.regsubst('\W', '_', 'G')
        $profiles        = 'profiles' in $config ? {
            true    => $default_profiles + $config['profiles'],
            default => $default_profiles,
        }
        $auth_keys       = pick($config['auth_keys'], $default_auth_keys)
        $nets            = pick($config['nets'], $default_nets)
        $_default_usages = pick($config['default_usages'], $default_usages)
        $_default_expiry = pick($config['default_expiry'], $default_expiry)
        $ca_key_file     = "${cfssl::signer_dir}/${safe_title}/ca/${safe_title}-key.pem"
        $ca_file         = "${cfssl::signer_dir}/${safe_title}/ca/${safe_title}.pem"
        $key_content     = "${private_cert_base}/${intermediate}-key.pem"
        $cert_content    = "${public_cert_base}/${intermediate}-cert.pem"
        $int_ca_content  = file($cert_content)

        if find_file($key_content) {
            $int_ca_key_content = file($key_content)
        } else {
            $int_ca_key_content = secret($key_content)
        }

        cfssl::signer {$intermediate:
            profiles         => $profiles,
            ca_key_file      => $ca_key_file,
            ca_file          => $ca_file,
            ca_key_content   => Sensitive($int_ca_key_content),
            ca_cert_content  => $int_ca_content,
            auth_keys        => $auth_keys,
            default_crl_url  => "${crl_base_url}/${safe_title}",
            default_ocsp_url => "${ocsp_base_url}/${safe_title}",
            default_usages   => $_default_usages,
            default_expiry   => $_default_expiry,
            serve_service    => $multirootca_service,
            db_conf_file     => $db_conf_file,
            manage_db        => false,
            manage_services  => false,
        }
        cfssl::ocsp{$intermediate:
            listen_port        => $config['ocsp_port'],
            db_conf_file       => $db_conf_file,
            ca_file            => $ca_file,
            ocsprefresh_update => $maintenance_jobs,
            db_driver          => $db_driver,
        }
        profile::pki::multirootca::monitoring { $intermediate:
            ensure  => $ensure_monitoring,
            vhost   => $vhost,
            ca_file => $ca_file,
        }
        # Create a bundle file with the intermediate and root certs
        file {"${bundle_dir}/${safe_title}.pem":
            ensure  => file,
            owner   => 'root',
            group   => 'root',
            mode    => '0444',
            content => $int_ca_content,
        }
        $crl_file = "${crl_dir}/${safe_title}"
        $five_years = 157680000
        $command = @("COMMAND"/L)
        /usr/bin/cfssl gencrl - ${ca_file} ${ca_key_file} ${five_years} </dev/null |\
        /usr/bin/base64 -d > ${crl_file}
        |- COMMAND
        exec { "Generate initial CRL for ${intermediate}":
            creates => $crl_file,
            path    => ['/usr/bin'],
            command => $command,
            require => Package[$cfssl::packages],
        }
        $memo + {
            $safe_title => {
                'private'     => $ca_key_file,
                'certificate' => $ca_file,
                'config'      => "${cfssl::signer_dir}/${safe_title}/cfssl.conf",
                'dbconfig'    => $db_conf_file,
                'nets'        => $nets,
            }
        }
    }
    class {'cfssl::multirootca':
        signers             => $signers,
        enable_monitoring   => $enable_monitoring,
        monitoring_critical => $enable_monitoring,
    }
    class { 'sslcert::dhparam': }
    # CRL and OCSP responder
    class {'httpd':
        modules => ['proxy_http', 'ssl', 'headers'],
    }

    profile::auto_restarts::service { 'apache2': }

    # TODO: probably replace this with acmechief
    $ssl_settings   = ssl_ciphersuite('apache', 'strong', true)
    $client_auth_ca_file = '/etc/ssl/localcerts/multiroot_ca.pem'
    file{$client_auth_ca_file:
        ensure => file,
        owner  => 'root',
        group  => 'root',
        mode   => '0440',
        source => $client_ca_source,
        notify => Service['apache2'],
    }
    # On puppet7 we need to use cfssl to generate this certificate - T350118
    if $cfssl_httpd_cert {
        $certs = profile::pki::get_cert('puppet_rsa', 'pki.discovery.wmnet', {
            hosts           => [$facts['networking']['fqdn']],
            notify_services => [$httpd::service_name],
        })
    } else {
        $certs = {
            'cert'  => $facts['puppet_config']['hostcert'],
            'key'   => $facts['puppet_config']['hostprivkey'],
            'chain' => $facts['puppet_config']['localcacert'],
        }
    }

    httpd::site{$vhost:
        ensure  => present,
        content => template('profile/pki/multirootca/vhost.conf.erb'),
    }
    firewall::service{'csr_and_ocsp_responder':
        proto    => 'tcp',
        port     => '80',
        src_sets => ['DOMAIN_NETWORKS', 'MGMT_NETWORKS'],
    }
    firewall::service{'multirootca tls termination':
        proto    => 'tcp',
        port     => '443',
        src_sets => ['DOMAIN_NETWORKS'],
    }
    include network::constants
    $srange = ($network::constants::services_kubepods_networks +
                $network::constants::staging_kubepods_networks +
                $network::constants::mlserve_kubepods_networks +
                $network::constants::mlstage_kubepods_networks +
                $network::constants::aux_kubepods_networks +
                $network::constants::dse_kubepods_networks).join(' ')

    $k8s_vhost_ensure = $enable_k8s_vhost.bool2str('present', 'absent')
    httpd::conf {'cfssl-issuer-k8s-pods-vhost-port':
        ensure  => $k8s_vhost_ensure,
        content => 'Listen 8443',
    }
    ferm::service{'multirootca tls termination for cfssl-issuer k8s pods':
        ensure => $k8s_vhost_ensure,
        proto  => 'tcp',
        port   => '8443',
        srange => "(${srange})",
    }
    if $db_driver == 'mysql' {
        systemd::timer::job {'cfssl-gc-expired-certs':
            ensure      => $maintenance_jobs.bool2str('present', 'absent'),
            description => 'Delete expired Certificates from the cfssl DB',
            user        => 'root',
            command     => '/usr/local/sbin/cfssl-certs clean',
            interval    => {'start' => 'OnUnitInactiveSec', 'interval' => 'hourly'},
        }
    }
}