Puppet Class: profile::pki::server

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

Summary

configure a PKI sevrver

Overview

SPDX-License-Identifier: Apache-2.0

Parameters:

  • ca_key_content (String) (defaults to: lookup('profile::pki::server::ca_key_content'))

    The location of the private key as used by the secret function (Required)

  • ca_cert_content (String) (defaults to: lookup('profile::pki::server::ca_cert_content'))

    The location of the public cert as used by the file function (Required)

  • names (Array[Cfssl::Name]) (defaults to: lookup('profile::pki::server::names'))

    The certificate authority names used for intermediates

  • key_params (Cfssl::Key) (defaults to: lookup('profile::pki::server::key_params'))

    The key algorithm and size used for intermediates

  • gen_csr (Boolean) (defaults to: lookup('profile::pki::server::gen_csr'))

    if true genrate a CSR. this is only needed when bootstrapping

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

    a Hash of signing default_profiles

  • intermediates (Hash[Cfssl::Ca_name, Hash]) (defaults to: lookup('profile::pki::server::intermediates'))

    a list of intermediate CN's to create

  • vhost (String) (defaults to: lookup('profile::pki::server::vhost'))
  • db_driver (Cfssl::DB_driver) (defaults to: lookup('profile::pki::server::db_driver'))
  • db_user (String) (defaults to: lookup('profile::pki::server::db_user'))
  • db_pass (Sensitive[String[1]]) (defaults to: lookup('profile::pki::server::db_pass'))
  • db_name (String) (defaults to: lookup('profile::pki::server::db_name'))
  • db_host (Stdlib::Host) (defaults to: lookup('profile::pki::server::db_host'))
  • root_ca_profiles (Hash[String, Cfssl::Profile]) (defaults to: lookup('profile::pki::server::root_ca_profiles'))
  • auth_keys (Hash[String, Cfssl::Auth_key]) (defaults to: lookup('profile::pki::server::auth_keys'))


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
141
142
143
144
145
146
147
148
149
150
151
# File 'modules/profile/manifests/pki/server.pp', line 10

class profile::pki::server(
    String                        $vhost            = lookup('profile::pki::server::vhost'),
    String                        $ca_key_content   = lookup('profile::pki::server::ca_key_content'),
    String                        $ca_cert_content  = lookup('profile::pki::server::ca_cert_content'),
    Array[Cfssl::Name]            $names            = lookup('profile::pki::server::names'),
    Cfssl::Key                    $key_params       = lookup('profile::pki::server::key_params'),
    Boolean                       $gen_csr          = lookup('profile::pki::server::gen_csr'),
    Cfssl::DB_driver              $db_driver        = lookup('profile::pki::server::db_driver'),
    String                        $db_user          = lookup('profile::pki::server::db_user'),
    Sensitive[String[1]]          $db_pass          = lookup('profile::pki::server::db_pass'),
    String                        $db_name          = lookup('profile::pki::server::db_name'),
    Stdlib::Host                  $db_host          = lookup('profile::pki::server::db_host'),
    Hash[String, Cfssl::Profile]  $root_ca_profiles = lookup('profile::pki::server::root_ca_profiles'),
    Hash[String, Cfssl::Profile]  $default_profiles = lookup('profile::pki::server::default_profiles'),
    Hash[String, Cfssl::Auth_key] $auth_keys        = lookup('profile::pki::server::auth_keys'),
    Hash[Cfssl::Ca_name, Hash]    $intermediates    = lookup('profile::pki::server::intermediates'),
) {
    $crl_base_url = "http://${vhost}/crl"
    $ocsp_base_url = "http://${vhost}/ocsp"
    # we need to include this as we use some of the variables
    include cfssl  # lint:ignore:wmf_styleguide
    $db_conf_file = "${cfssl::conf_dir}/db.conf"
    $multirootca_service = 'cfssl-multirootca'
    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         => $facts['puppet_config']['localcacert'],
    }

    $_root_ca_profiles = $root_ca_profiles.empty? {
        true    => $default_profiles,
        default => $root_ca_profiles,
    }
    cfssl::signer {'WMF_root_CA':
        profiles         => $_root_ca_profiles,
        ca_key_content   => Sensitive(secret($ca_key_content)),
        ca_cert_content  => file($ca_cert_content),
        auth_keys        => $auth_keys,
        default_crl_url  => $crl_base_url,
        default_ocsp_url => $ocsp_base_url,
        serve_service    => $multirootca_service,
        db_conf_file     => $db_conf_file,
        manage_db        => false,
        manage_services  => false,
    }
    $signers = $intermediates.reduce({}) |$memo, $value| {

        $intermediate = $value[0]
        $config       = $value[1]
        $safe_title   = $intermediate.regsubst('\W', '_', 'G')
        $profiles     = pick($config['profiles'], $default_profiles)
        $_root_ca_profiles = $config.has_key('profiles') ? {
            true    => $config['profiles'],
            default => $default_profiles,
        }

        if 'key_content' in $config and 'cert_content' in $config {
            # Pull key material from puppet
            $ca_key_content  = Sensitive(secret($config['key_content']))
            $ca_cert_content = file($config['cert_content'])
            $ca_key_file     = "${cfssl::signer_dir}/${safe_title}/ca/${safe_title}-key.pem"
            $ca_file         = "${cfssl::signer_dir}/${safe_title}/ca/${safe_title}.pem"
        } else {
            # Generate key material on the fly
            cfssl::cert{$intermediate:
                key           => $key_params,
                names         => $names,
                signer_config => {'config_dir' => "${cfssl::signer_dir}/WMF_root_CA"},
                profile       => 'intermediate',
                require       => Cfssl::Signer['WMF_root_CA'],
                notify        => Service['cfssl-multirootca'],
            }
            $ca_key_content  = undef
            $ca_cert_content = undef
            $ca_key_file    = "${cfssl::ssl_dir}/${safe_title}/${safe_title}-key.pem"
            $ca_file        = "${cfssl::ssl_dir}/${safe_title}/${safe_title}.pem"
        }

        $crl_url = "${crl_base_url}/${safe_title}"
        $ocsp_url = "${ocsp_base_url}/${safe_title}"
        cfssl::signer {$intermediate:
            profiles         => $profiles,
            ca_key_file      => $ca_key_file,
            ca_file          => $ca_file,
            ca_key_content   => $ca_key_content,
            ca_cert_content  => $ca_cert_content,
            ca_bundle_file   => "${cfssl::signer_dir}/WMF_root_CA/ca/ca.pem",
            auth_keys        => $auth_keys,
            default_crl_url  => $crl_url,
            default_ocsp_url => $ocsp_url,
            serve_service    => $multirootca_service,
            db_conf_file     => $db_conf_file,
            manage_db        => false,
            manage_services  => false,
        }
        cfssl::ocsp{$intermediate:
            common_name      => 'pki.discovery.wmnet',
            additional_names => [$facts['fqdn']],
            listen_port      => $config['ocsp_port'],
            db_conf_file     => "${db_conf_file}.json",
            ca_file          => $ca_file,
        }
        $memo + {
            $safe_title => {
                'private'     => $ca_key_file,
                'certificate' => $ca_file,
                'config'      => "${cfssl::signer_dir}/${safe_title}/cfssl.conf",
                'dbconfig'    => $db_conf_file,
                'nets'        => $config['nets'],
            }
        }
    }
    class {'cfssl::multirootca':
        tls_cert => $facts['puppet_config']['hostcert'],
        tls_key  => $facts['puppet_config']['hostprivkey'],
        signers  => $signers,
    }

    class {'httpd':
        modules => ['proxy_http']
    }
    httpd::site{$vhost:
        ensure  => present,
        content => template('profile/pki/server/pki.discovery.wmnet.conf.erb')
    }
    ferm::service{'csr_and_ocsp_responder':
        proto  => 'tcp',
        port   => '80',
        srange => '$DOMAIN_NETWORKS',
    }
    ferm::service{'multirootca':
        proto  => 'tcp',
        port   => '8888',
        srange => '$DOMAIN_NETWORKS',
    }
}