Puppet Class: profile::cache::haproxy

Defined in:
modules/profile/manifests/cache/haproxy.pp

Overview

SPDX-License-Identifier: Apache-2.0

Parameters:

  • cache_cluster (String) (defaults to: lookup('cache::cluster'))
  • tls_port (Stdlib::Port) (defaults to: lookup('profile::cache::haproxy::tls_port'))
  • prometheus_port (Stdlib::Port) (defaults to: lookup('profile::cache::haproxy::prometheus_port', {'default_value' => 9422}))
  • available_unified_certificates (Hash[String, Haproxy::Tlscertificate]) (defaults to: lookup('profile::cache::haproxy::available_unified_certificates'))
  • extra_certificates (Optional[Hash[String, Haproxy::Tlscertificate]]) (defaults to: lookup('profile::cache::haproxy::extra_certificates', {'default_value' => undef}))
  • unified_certs (Optional[Array[String]]) (defaults to: lookup('profile::cache::haproxy::unified_certs', {'default_value' => undef}))
  • unified_acme_chief (Boolean) (defaults to: lookup('profile::cache::haproxy::unified_acme_chief'))
  • backend (Haproxy::Backend) (defaults to: lookup('profile::cache::haproxy::varnish_socket'))
  • tls_ciphers (String) (defaults to: lookup('profile::cache::haproxy::tls_ciphers'))
  • tls13_ciphers (String) (defaults to: lookup('profile::cache::haproxy::tls13_ciphers'))
  • tls_cachesize (Integer[0]) (defaults to: lookup('profile::cache::haproxy::tls_cachesize'))
  • tls_session_lifetime (Integer[0]) (defaults to: lookup('profile::cache::haproxy::tls_session_lifetime'))
  • timeout (Haproxy::Timeout) (defaults to: lookup('profile::cache::haproxy::timeout'))
  • h2settings (Haproxy::H2settings) (defaults to: lookup('profile::cache::haproxy::h2settings'))
  • proxy_protocol (Optional[Haproxy::Proxyprotocol]) (defaults to: lookup('profile::cache::haproxy::proxy_protocol', {'default_value' => undef}))
  • vars (Hash[String, Array[Haproxy::Var]]) (defaults to: lookup('profile::cache::haproxy::vars'))
  • acls (Hash[String, Array[Haproxy::Acl]]) (defaults to: lookup('profile::cache::haproxy::acls'))
  • add_headers (Hash[String, Array[Haproxy::Header]]) (defaults to: lookup('profile::cache::haproxy::add_headers'))
  • del_headers (Hash[String, Array[Haproxy::Header]]) (defaults to: lookup('profile::cache::haproxy::del_headers'))
  • pre_acl_actions (Optional[Hash[String, Array[Haproxy::Action]]]) (defaults to: lookup('profile::cache::haproxy::pre_acl_actions', {'default_value' => undef}))
  • post_acl_actions (Optional[Hash[String, Array[Haproxy::Action]]]) (defaults to: lookup('profile::cache::haproxy::post_acl_actions', {'default_value' => undef}))
  • sticktables (Optional[Array[Haproxy::Sticktable]]) (defaults to: lookup('profile::cache::haproxy::sticktables', {'default_value' => undef}))
  • do_ocsp (Boolean) (defaults to: lookup('profile::cache::haproxy::do_ocsp'))
  • http_disable_keepalive (Boolean) (defaults to: lookup('profile::cache::haproxy::http_disable_keepalive', {'default_value' => false}))
  • ocsp_proxy (Optional[Stdlib::HTTPUrl]) (defaults to: lookup('http_proxy', {'default_value' => undef}))
  • public_tls_unified_cert_vendor (String) (defaults to: lookup('public_tls_unified_cert_vendor'))
  • mtail_dir (Stdlib::Unixpath) (defaults to: lookup('profile::cache::haproxy::mtail_dir', {'default_value' => '/etc/haproxymtail'}))
  • mtail_port (Stdlib::Port::User) (defaults to: lookup('profile::cache::haproxy::mtail_port', {'default_value' => 3906}))
  • mtail_fifo (Stdlib::Unixpath) (defaults to: lookup('profile::cache::haproxy::mtail_fifo', {'default_value' => '/var/log/haproxy.fifo'}))
  • monitoring_enabled (Boolean) (defaults to: lookup('profile::cache::haproxy::monitoring_enabled'))
  • haproxy_version (Haproxy::Version) (defaults to: lookup('profile::cache::haproxy::version', {'default_value' => 'haproxy24'}))
  • do_systemd_hardening (Boolean) (defaults to: lookup('profile::cache::haproxy::do_systemd_hardening', {'default_value' => false}))
  • enable_coredumps (Boolean) (defaults to: lookup('profile::cache::haproxy::enable_coredumps', {'default_value' => false}))
  • http_redirection_port (Optional[Stdlib::Port]) (defaults to: lookup('profile::cache::haproxy::http_redirection_port', {'default_value' => 80}))
  • redirection_timeout (Optional[Haproxy::Timeout]) (defaults to: lookup('profile::cache::haproxy::redirection_timeout', {'default_value' => undef}))
  • filters (Optional[Array[Haproxy::Filter]]) (defaults to: lookup('profile::cache::haproxy::filters', {'default_value' => undef}))
  • dedicated_hc_backend (Boolean) (defaults to: lookup('profile::cache::haproxy::dedicated_hc_backend', {'default_value' => false}))
  • extended_logging (Boolean) (defaults to: lookup('profile::cache::haproxy::extended_logging', {'default_value' => false}))
  • use_haproxykafka (Boolean) (defaults to: lookup('profile::cache::haproxy::use_haproxykafka', {'default_value' => false}))
  • haproxykafka_socket (Stdlib::Unixpath) (defaults to: lookup('profile::cache::haproxy::haproxykafka_socket', {'default_value' => '/var/run/haproxykafka/haproxykafka.sock'}))
  • hc_sources (Optional[Array[Stdlib::IP::Address]]) (defaults to: lookup('haproxy_allowed_healthcheck_sources', {'default_value' => undef}))
  • install_haproxy26_component (Boolean) (defaults to: lookup('profile::cache::haproxy::install_haproxy26_component', {'default_value' => false}))
  • log_length (Optional[Integer]) (defaults to: lookup('profile::cache::haproxy::log_length', {'default_value' => 8192}))
  • use_etcd_req_filters (Boolean) (defaults to: lookup('profile::cache::haproxy::use_etcd_req_filters', {'default_value' => false}))
  • numa_networking (Boolean) (defaults to: lookup('profile::cache::haproxy::numa_networking', {'default_value' => true}))
  • conftool_prefix (String) (defaults to: lookup('conftool_prefix'))


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
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
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
# File 'modules/profile/manifests/cache/haproxy.pp', line 2

class profile::cache::haproxy(
    String $cache_cluster = lookup('cache::cluster'),
    Stdlib::Port $tls_port = lookup('profile::cache::haproxy::tls_port'),
    Stdlib::Port $prometheus_port = lookup('profile::cache::haproxy::prometheus_port', {'default_value'                                          => 9422}),
    Hash[String, Haproxy::Tlscertificate] $available_unified_certificates = lookup('profile::cache::haproxy::available_unified_certificates'),
    Optional[Hash[String, Haproxy::Tlscertificate]] $extra_certificates = lookup('profile::cache::haproxy::extra_certificates', {'default_value' => undef}),
    Optional[Array[String]] $unified_certs = lookup('profile::cache::haproxy::unified_certs', {'default_value'                                   => undef}),
    Boolean $unified_acme_chief = lookup('profile::cache::haproxy::unified_acme_chief'),
    Haproxy::Backend $backend = lookup('profile::cache::haproxy::varnish_socket'),
    String $tls_ciphers = lookup('profile::cache::haproxy::tls_ciphers'),
    String $tls13_ciphers = lookup('profile::cache::haproxy::tls13_ciphers'),
    Integer[0] $tls_cachesize = lookup('profile::cache::haproxy::tls_cachesize'),
    Integer[0] $tls_session_lifetime = lookup('profile::cache::haproxy::tls_session_lifetime'),
    Haproxy::Timeout $timeout = lookup('profile::cache::haproxy::timeout'),
    Haproxy::H2settings $h2settings = lookup('profile::cache::haproxy::h2settings'),
    Optional[Haproxy::Proxyprotocol] $proxy_protocol = lookup('profile::cache::haproxy::proxy_protocol', {'default_value'                        => undef}),
    Hash[String, Array[Haproxy::Var]] $vars = lookup('profile::cache::haproxy::vars'),
    Hash[String, Array[Haproxy::Acl]] $acls = lookup('profile::cache::haproxy::acls'),
    Hash[String, Array[Haproxy::Header]] $add_headers = lookup('profile::cache::haproxy::add_headers'),
    Hash[String, Array[Haproxy::Header]] $del_headers = lookup('profile::cache::haproxy::del_headers'),
    Optional[Hash[String, Array[Haproxy::Action]]] $pre_acl_actions = lookup('profile::cache::haproxy::pre_acl_actions', {'default_value'                      => undef}),
    Optional[Hash[String, Array[Haproxy::Action]]] $post_acl_actions = lookup('profile::cache::haproxy::post_acl_actions', {'default_value'                    => undef}),
    Optional[Array[Haproxy::Sticktable]] $sticktables = lookup('profile::cache::haproxy::sticktables', {'default_value'                          => undef}),
    Boolean $do_ocsp = lookup('profile::cache::haproxy::do_ocsp'),
    Boolean $http_disable_keepalive = lookup('profile::cache::haproxy::http_disable_keepalive', {'default_value'                                 => false}),
    Optional[Stdlib::HTTPUrl] $ocsp_proxy = lookup('http_proxy', {'default_value'                                                                => undef}),
    String $public_tls_unified_cert_vendor=lookup('public_tls_unified_cert_vendor'),
    Stdlib::Unixpath $mtail_dir = lookup('profile::cache::haproxy::mtail_dir', {'default_value'                                                  => '/etc/haproxymtail'}),
    Stdlib::Port::User $mtail_port = lookup('profile::cache::haproxy::mtail_port', {'default_value'                                              => 3906}),
    Stdlib::Unixpath $mtail_fifo = lookup('profile::cache::haproxy::mtail_fifo', {'default_value'                                                => '/var/log/haproxy.fifo'}),
    Boolean $monitoring_enabled = lookup('profile::cache::haproxy::monitoring_enabled'),
    Haproxy::Version $haproxy_version = lookup('profile::cache::haproxy::version', {'default_value'                                              => 'haproxy24'}),
    Boolean $do_systemd_hardening = lookup('profile::cache::haproxy::do_systemd_hardening', {'default_value'                                     => false}),
    Boolean $enable_coredumps = lookup('profile::cache::haproxy::enable_coredumps', {'default_value'                                             => false}),
    Optional[Stdlib::Port] $http_redirection_port = lookup('profile::cache::haproxy::http_redirection_port', {'default_value'                    => 80}),
    Optional[Haproxy::Timeout] $redirection_timeout = lookup('profile::cache::haproxy::redirection_timeout', {'default_value'                    => undef}),
    Optional[Array[Haproxy::Filter]] $filters = lookup('profile::cache::haproxy::filters', {'default_value'                                      => undef}),
    Boolean $dedicated_hc_backend = lookup('profile::cache::haproxy::dedicated_hc_backend', {'default_value'                                     => false}),
    Boolean $extended_logging = lookup('profile::cache::haproxy::extended_logging', {'default_value'                                             => false}),
    Boolean $use_haproxykafka = lookup('profile::cache::haproxy::use_haproxykafka', {'default_value'                                             => false}),
    Stdlib::Unixpath $haproxykafka_socket = lookup('profile::cache::haproxy::haproxykafka_socket', {'default_value'                              => '/var/run/haproxykafka/haproxykafka.sock'}),
    Optional[Array[Stdlib::IP::Address]] $hc_sources = lookup('haproxy_allowed_healthcheck_sources', {'default_value'                            => undef}),
    Boolean $install_haproxy26_component = lookup('profile::cache::haproxy::install_haproxy26_component', {'default_value'                       => false}),
    Optional[Integer] $log_length = lookup('profile::cache::haproxy::log_length', {'default_value'                                               => 8192}),
    Boolean $use_etcd_req_filters = lookup('profile::cache::haproxy::use_etcd_req_filters', {'default_value'                                     => false}),
    Boolean $numa_networking = lookup('profile::cache::haproxy::numa_networking', {'default_value'                                               => true}),
    String $conftool_prefix = lookup('conftool_prefix'),
) {
    class { 'sslcert::dhparam':
    }
    if $do_ocsp {
        class { 'sslcert::ocsp::init':
        }
    }
    if $use_etcd_req_filters {
        $site_resource = Haproxy::Confd_site['tls']
    } else {
        $site_resource = Haproxy::Site['tls']
    }
    # variable used inside HAProxy's systemd unit
    $pid = '/run/haproxy/haproxy.pid'

    # If we want to install haproxy from component/haproxy26 on bookworm, built
    # against OpenSSL 1.1.1; see T352744.
    if $install_haproxy26_component and debian::codename::eq('bookworm') {
        $component = 'component/haproxy26'
    } else {
        $component = "thirdparty/${haproxy_version}"
    }

    apt::package_from_component { 'haproxy':
        component       => $component,
        before          => Class['::haproxy'],
        priority        => 1002, # Take precedence over main
        ensure_packages => false, # this is handled by ::haproxy
    }

    # If numa_networking is turned on, use interface_primary for NUMA hinting,
    # otherwise use 'lo' for this purpose.  Assumes NUMA data has "lo" interface
    # mapped to all cpu cores in the non-NUMA case.  The numa_iface variable is
    # in turn consumed by the systemd unit and config templates.
    if $numa_networking {
        $numa_iface = $facts['interface_primary']
    } else {
        $numa_iface = 'lo'
    }

    # used on haproxy.cfg.erb
    $socket = '/run/haproxy/haproxy.sock'

    class { '::haproxy':
        config_content        => template('profile/cache/haproxy.cfg.erb'),
        systemd_content       => template('profile/cache/haproxy.service.erb'),
        logging               => false,
        monitor_check_haproxy => false,
    }

    ensure_packages('python3-pystemd')
    file { '/usr/local/sbin/haproxy-stek-manager':
        ensure => present,
        source => 'puppet:///modules/profile/cache/haproxy_stek_manager.py',
        owner  => root,
        group  => root,
        mode   => '0544',
    }

    systemd::tmpfile { 'haproxy_secrets_tmpfile':
        content => 'd /run/haproxy-secrets 0700 haproxy haproxy -',
    }

    $tls_ticket_keys_path = '/run/haproxy-secrets/stek.keys'
    systemd::timer::job { 'haproxy_stek_job':
        ensure      => present,
        description => 'HAProxy STEK manager',
        command     => "/usr/local/sbin/haproxy-stek-manager ${tls_ticket_keys_path}",
        interval    => [
            {
            'start'    => 'OnCalendar',
            'interval' => '*-*-* 00/8:00:00', # every 8 hours
            },
            {
            'start'    => 'OnBootSec',
            'interval' => '0sec',
            },
        ],
        user        => 'root',
        require     => File['/usr/local/sbin/haproxy-stek-manager'],
    }

    if !$available_unified_certificates[$public_tls_unified_cert_vendor] {
        fail('The specified TLS unified cert vendor is not available')
    }

    unless empty($unified_certs) {
        $unified_certs.each |String $cert| {
            sslcert::certificate { $cert:
                before => $site_resource,
            }

            if $do_ocsp {
                sslcert::ocsp::conf { $cert:
                    proxy  => $ocsp_proxy,
                    before => Service['haproxy'],
                }
                # HAProxy expects the prefetched OCSP response on the same path as the certificate
                file { "/etc/ssl/private/${cert}.chained.crt.key.ocsp":
                    ensure  => link,
                    target  => "/var/cache/ocsp/${cert}.ocsp",
                    require => Sslcert::Ocsp::Conf[$cert],
                }
            }
        }
        if $do_ocsp {
            sslcert::ocsp::hook { 'haproxy-ocsp':
                content => file('profile/cache/update_ocsp_haproxy_hook.sh'),
            }
        }
    }

    if $unified_acme_chief {
        acme_chief::cert { 'unified':
            puppet_svc => 'haproxy',
            key_group  => 'haproxy',
        }
    }

    if !empty($extra_certificates) {
        $extra_certificates.each |String $extra_cert_name, Hash $extra_cert| {
            acme_chief::cert { $extra_cert_name:
                puppet_svc => 'haproxy',
                key_group  => 'haproxy',
            }
        }
        $certificates = [$available_unified_certificates[$public_tls_unified_cert_vendor]] + values($extra_certificates)
    } else {
        $certificates = [$available_unified_certificates[$public_tls_unified_cert_vendor]]
    }

    ## HAProxy configuration
    file { '/etc/haproxy/tls.lua':
        ensure  => absent,
        owner   => 'haproxy',
        group   => 'haproxy',
        mode    => '0444',
        content => file('profile/cache/haproxy-tls.lua'),
    }

    $wikimedia_trust = $profile::cache::base::wikimedia_trust
    $crt_list_path = '/etc/haproxy/crt-list.cfg'
    $hc_sources_file_path = '/etc/haproxy/allowed-hc-sources.lst'

    # Build the list of certificates to be used in the tls terminator
    $ecdhe_curves = ['X25519', 'P-256']
    $alpn = ['h2', 'http/1.1']
    file { $crt_list_path:
        mode    => '0444',
        content => template('profile/cache/haproxy/crt-list.cfg.erb'),
        notify  => Service['haproxy'],
    }

    mediawiki::errorpage { '/etc/haproxy/tls-terminator-tls-plaintext-error.html':
        ensure  => ($http_redirection_port != undef).bool2str('present', 'absent'),
        content => '<p>Insecure request forbidden, use HTTPS instead. For details see <a href="https://lists.wikimedia.org/hyperkitty/list/mediawiki-api-announce@lists.wikimedia.org/message/VKQJRS36NXLIMHOWBOXJPUH35KETQCG5/">https://lists.wikimedia.org/hyperkitty/list/mediawiki-api-announce@lists.wikimedia.org/message/VKQJRS36NXLIMHOWBOXJPUH35KETQCG5/</a>.</p>',
        before  => $site_resource,
    }

    # This contains the PyBal IPs allowed to perform healthchecks
    file { $hc_sources_file_path:
        ensure  => bool2str($dedicated_hc_backend, 'present','absent'),
        mode    => '0444',
        owner   => 'root',
        group   => 'root',
        content => template('profile/cache/haproxy/allowed-hc-sources.lst.erb'),
        notify  => Service['haproxy'],
    }

    $http_reuse = 'always'
    # The haproxy site configuration
    $min_tls_version = 'TLSv1.2'
    $max_tls_version = 'TLSv1.3'
    if $use_etcd_req_filters {
        file { '/usr/local/bin/check-haproxy-map':
            ensure => present,
            owner  => 'root',
            group  => 'root',
            mode   => '0555',
            source => 'puppet:///modules/profile/cache/check-haproxy-map.sh',
        }
        file { '/etc/haproxy/ipblocks.d/':
            ensure => directory,
            owner  => 'root',
            group  => 'root',
            mode   => '0755',
        }
        ['cloud', 'abuse', 'known-clients'].each |String $scope| {
            confd::file { "/etc/haproxy/ipblocks.d/${scope}.map":
                ensure     => present,
                prefix     => $conftool_prefix,
                watch_keys => ["/request-ipblocks/${scope}"],
                content    => template('profile/cache/haproxy/ipblocks.map.tpl.erb'),
                # Please, whoever sees this in the future, don't @ me about this.
                # An haproxy map file can contain either blank lines, comments,
                # or lines with key-value pairs separated by spaces.
                # The check command is a perl one-liner that checks for these three cases.
                # If you find a nicer solution that doesn't involve writing a custom
                # parser, please fix this.
                check      => '/usr/local/bin/check-haproxy-map',
                reload     => '/usr/bin/systemctl reload haproxy.service',
                before     => Service['haproxy'],
            }
        }

        haproxy::confd_site { 'tls':
            ensure     => present,
            prefix     => $conftool_prefix,
            watch_keys => ['/request-haproxy-dsl/'],
            content    => template('profile/cache/haproxy/tls_terminator.cfg.erb'),
        }
    } else {
        haproxy::site { 'tls':
            ensure  => present,
            content => template('profile/cache/haproxy/tls_terminator.cfg.erb'),
        }
    }

    if $monitoring_enabled {
        profile::cache::haproxy::monitoring { 'haproxy_tls_monitoring':
            port         => $tls_port,
            certificates => $certificates,
            do_ocsp      => $do_ocsp,
            acme_chief   => $unified_acme_chief,
            require      => $site_resource,
        }
    }

    systemd::service { 'haproxy-mtail@tls.socket':
        content => systemd_template('haproxy-mtail@.socket'),
    }

    systemd::service { 'haproxy-mtail@tls':
        content => systemd_template('haproxy-mtail@'),
    }

    rsyslog::conf { 'haproxy@tls':
        priority => 20,
        content  => template('profile/cache/haproxy.rsyslog.conf.erb'),
    }

    mtail::program { 'cache_haproxy':
        source      => 'puppet:///modules/mtail/programs/cache_haproxy.mtail',
        destination => $mtail_dir,
        notify      => Service['haproxy-mtail@tls'],
    }

    file { '/usr/local/sbin/haproxy-restart':
        ensure  => present,
        mode    => '0555',
        owner   => 'root',
        group   => 'root',
        content => file('profile/cache/haproxy_restart.sh'),
    }
}