Puppet Class: profile::puppetmaster::frontend

Defined in:
modules/profile/manifests/puppetmaster/frontend.pp

Overview

SPDX-License-Identifier: Apache-2.0

Parameters:

  • config (Hash) (defaults to: lookup('profile::puppetmaster::frontend::config'))

    addtional config to use

  • secure_private (Boolean) (defaults to: lookup('profile::puppetmaster::frontend::secure_private'))

    If false, /etc/puppet/private will be labs/private.git. Otherwise, some magic is done to have local repositories and sync between puppetmasters.

  • web_hostname (String) (defaults to: lookup('profile::puppetmaster::frontend::web_hostname'))

    hostname of the website

  • ca_server (Stdlib::Host) (defaults to: lookup('puppet_ca_server'))

    the CA server

  • ca_source (Stdlib::Filesource) (defaults to: lookup('puppet_ca_source'))

    source of the CA file

  • manage_ca_file (Boolean) (defaults to: lookup('manage_puppet_ca_file'))

    if true manage the CA file

  • prevent_cherrypicks (Boolean) (defaults to: lookup('profile::puppetmaster::frontend::prevent_cherrypicks'))

    disable cherry picks

  • monitor_signed_certs (Boolean) (defaults to: lookup('profile::puppetmaster::frontend::monitor_signed_certs'))

    if true monitor signed certs for expiry

  • extra_auth_rules (Optional[String]) (defaults to: lookup('profile::puppetmaster::frontend::extra_auth_rules'))

    Addtional auth rules

  • signed_certs_warning (Integer) (defaults to: lookup('profile::puppetmaster::frontend::signed_certs_warning'))

    Warn if agent certs are due to expire within this time

  • signed_certs_critical (Integer) (defaults to: lookup('profile::puppetmaster::frontend::signed_certs_critical'))

    Critical alert if agent certs are due to expire within this time

  • canary_hosts (Array[Stdlib::Host]) (defaults to: lookup('profile::puppetmaster::frontend::canary_hosts'))

    list of hosts used for caanary testing

  • servers (Hash[String, Puppetmaster::Backends]) (defaults to: lookup('puppetmaster::servers'))

    list of puppetmaster backend servers with wieghts

  • ssl_ca_revocation_check (Enum['chain', 'leaf', 'none']) (defaults to: lookup('profile::puppetmaster::frontend::ssl_ca_revocation_check'))

    the type of SSL revocation check to perform

  • http_proxy (Optional[Stdlib::HTTPUrl]) (defaults to: lookup('http_proxy'))

    the HTTP proxy if one is required

  • mcrouter_ca_secret (Optional[String[1]]) (defaults to: lookup('profile::puppetmaster::frontend::mcrouter_ca_secret'))

    The secret for mcrouter CA



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
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
# File 'modules/profile/manifests/puppetmaster/frontend.pp', line 20

class profile::puppetmaster::frontend(
    # Globals
    Stdlib::Host        $ca_server               = lookup('puppet_ca_server'),
    Stdlib::Filesource  $ca_source               = lookup('puppet_ca_source'),
    Boolean             $manage_ca_file          = lookup('manage_puppet_ca_file'),
    Optional[Stdlib::HTTPUrl] $http_proxy        = lookup('http_proxy'),
    # Class scope
    # TODO: we should probably configure theses in P:puppetmaster::common
    Hash[String, Puppetmaster::Backends] $servers        = lookup('puppetmaster::servers'),
    # Locals
    Hash                          $config                  = lookup('profile::puppetmaster::frontend::config'),
    Boolean                       $secure_private          = lookup('profile::puppetmaster::frontend::secure_private'),
    String                        $web_hostname            = lookup('profile::puppetmaster::frontend::web_hostname'),
    Boolean                       $prevent_cherrypicks     = lookup('profile::puppetmaster::frontend::prevent_cherrypicks'),
    Boolean                       $monitor_signed_certs    = lookup('profile::puppetmaster::frontend::monitor_signed_certs'),
    Integer                       $signed_certs_warning    = lookup('profile::puppetmaster::frontend::signed_certs_warning'),
    Integer                       $signed_certs_critical   = lookup('profile::puppetmaster::frontend::signed_certs_critical'),
    Array[Stdlib::Host]           $canary_hosts            = lookup('profile::puppetmaster::frontend::canary_hosts'),
    Enum['chain', 'leaf', 'none'] $ssl_ca_revocation_check = lookup('profile::puppetmaster::frontend::ssl_ca_revocation_check'),
    Optional[String]              $extra_auth_rules        = lookup('profile::puppetmaster::frontend::extra_auth_rules'),
    Optional[String[1]]           $mcrouter_ca_secret      = lookup('profile::puppetmaster::frontend::mcrouter_ca_secret'),
) {
    ensure_packages([
      'libapache2-mod-passenger',
      'age'  # useful file encryption tool, modern gpg replacement
    ])

    backup::set { 'var-lib-puppet-ssl': }
    backup::set { 'var-lib-puppet-volatile': }
    if $manage_ca_file {
        file{[$facts['puppet_config']['master']['localcacert'],
              "${facts['puppet_config']['master']['ssldir']}/ca/ca_crt.pem"]:
            ensure => file,
            owner  => 'puppet',
            group  => 'puppet',
            source => $ca_source,
        }
    }
    # Puppet frontends are git masters at least for their datacenter
    $ca = $ca_server == $facts['networking']['fqdn']
    $sync_ensure = $ca.bool2str('absent', 'present')

    if $ca {
        # Ensure cergen is present for managing TLS keys and
        # x509 certificates signed by the Puppet CA.
        class { 'cergen': }
        if $mcrouter_ca_secret {
            class { 'cergen::mcrouter_ca':
                ca_secret => $mcrouter_ca_secret,
            }
        }

        # Ship cassandra-ca-manager (precursor of cergen)
        class { 'cassandra::ca_manager': }

        # Ensure nagios can read the signed certs
        $signed_cert_path = "${facts['puppet_config']['master']['ssldir']}/ca/signed"
        file {$signed_cert_path:
            ensure  => directory,
            owner   => 'puppet',
            group   => 'puppet',
            mode    => '0644',
            recurse => true,
        }

        $monitor_ensure = ($monitor_signed_certs and $ca).bool2str('present', 'absent')
        nrpe::plugin { 'nrpe_check_puppetca_expired_certs':
            ensure => $monitor_ensure,
            source => 'puppet:///modules/profile/puppetmaster/nrpe_check_puppetca_expired_certs.sh',
        }

        nrpe::monitor_service {'puppetca_expired_certs':
            ensure         => $monitor_ensure,
            description    => 'Puppet CA expired certs',
            check_interval => 60,  # minutes
            timeout        => 60,  # seconds
            nrpe_command   => "/usr/local/lib/nagios/plugins/nrpe_check_puppetca_expired_certs ${signed_cert_path} ${signed_certs_warning} ${signed_certs_critical}",
            notes_url      => 'https://wikitech.wikimedia.org/wiki/Puppet#Renew_agent_certificate',
        }
    }

    class { 'httpd':
        remove_default_ports => true,
        modules              => ['proxy', 'proxy_http', 'proxy_balancer',
                                'passenger', 'rewrite', 'lbmethod_byrequests'],
    }

    class { 'puppetmaster::ca_server':
        master => $ca_server,
    }

    $common_config = {
        'ca'              => $ca,
        'ca_server'       => $ca_server,
        'stringify_facts' => false,
    }

    $base_config = merge($config, $common_config)

    class { 'profile::puppetmaster::common':
        base_config => $base_config,
    }

    class { 'puppetmaster':
        bind_address        => '*',
        server_type         => 'frontend',
        is_git_master       => true,
        hiera_config        => $profile::puppetmaster::common::hiera_config,
        config              => $profile::puppetmaster::common::config,
        secure_private      => $secure_private,
        prevent_cherrypicks => $prevent_cherrypicks,
        extra_auth_rules    => $extra_auth_rules,
        ca_server           => $ca_server,
        ssl_verify_depth    => $profile::puppetmaster::common::ssl_verify_depth,
        servers             => $servers,
        upload_facts        => $ca, # We only want to upload from one place
        http_proxy          => $http_proxy,
        netbox_hiera_enable => $profile::puppetmaster::common::netbox_hiera_enable,
        enable_merge_cli    => $profile::puppetmaster::common::enable_merge_cli,
    }

    $workers = $servers[$facts['networking']['fqdn']]
    # Main site to respond to
    puppetmaster::web_frontend { $web_hostname:
        master                  => $ca_server,
        workers                 => $workers,
        bind_address            => $puppetmaster::bind_address,
        priority                => 40,
        ssl_ca_revocation_check => $ssl_ca_revocation_check,
        canary_hosts            => $canary_hosts,
        ssl_verify_depth        => $profile::puppetmaster::common::ssl_verify_depth,
    }

    # On all the puppetmasters, we should respond
    # to the FQDN too, in case we point them explicitly
    puppetmaster::web_frontend { $facts['networking']['fqdn']:
        master                  => $ca_server,
        workers                 => $workers,
        bind_address            => $puppetmaster::bind_address,
        priority                => 50,
        ssl_ca_revocation_check => $ssl_ca_revocation_check,
        canary_hosts            => $canary_hosts,
        ssl_verify_depth        => $profile::puppetmaster::common::ssl_verify_depth,
    }

    # Run the rsync servers on all puppetmaster frontends, and activate
    # timer jobs syncing from the master
    class { 'puppetmaster::rsync':
        server      => $ca_server,
        sync_ensure => $sync_ensure,
        frontends   => keys($servers),
    }

    ferm::service { 'puppetmaster-frontend':
        srange => '$DOMAIN_NETWORKS',
        proto  => 'tcp',
        port   => 8140,
    }

    $puppetmaster_frontend_ferm = join(keys($servers), ' ')
    ferm::service { 'ssh_puppet_merge':
        proto  => 'tcp',
        port   => '22',
        srange => "(@resolve((${servers.keys.join(' ')})))",
    }

    ferm::service { 'rsync_puppet_frontends':
        proto  => 'tcp',
        port   => '873',
        srange => "(@resolve((${servers.keys.join(' ')})))",
    }
    ferm::service { 'puppetmaster-backend':
        proto  => 'tcp',
        port   => 8141,
        srange => "(@resolve((${servers.keys.join(' ')})))",
    }

    # Let's download the public cloud IP ranges, save them to etcd.
    # This will only upload to conftool on the CA puppetmaster.
    class { 'external_clouds_vendors':
        ensure      => 'present',
        user        => 'root',
        manage_user => false,
        conftool    => $ca,
        outfile     => '/var/lib/puppet/volatile/external_cloud_vendors/public_clouds.json',
        http_proxy  => $http_proxy,
    }
}