Puppet Class: profile::cache::haproxy

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

Overview

SPDX-License-Identifier: Apache-2.0

Parameters:

  • 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'))
  • varnish_socket (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_benthos (Boolean) (defaults to: lookup('profile::cache::base::use_benthos', {'default_value' => false}))
  • benthos_socket (String) (defaults to: lookup('profile::cache::base::benthos_socket_address', {'default_value' => '127.0.0.1:1221'}))
  • benthos_systemd_socket (Boolean) (defaults to: lookup('profile::cache::base::benthos_systemd_socket', {'default_value' => false}))
  • benthos_udp_rbuffer_bytes (Optional[Integer[256]]) (defaults to: lookup('profile::cache::base::benthos_udp_rbuffer_bytes', {'default_value' => undef}))
  • 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}))


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
# File 'modules/profile/manifests/cache/haproxy.pp', line 2

class profile::cache::haproxy(
    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 $varnish_socket = 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_benthos = lookup('profile::cache::base::use_benthos', {'default_value'                                                          => false}),
    String $benthos_socket = lookup('profile::cache::base::benthos_socket_address', {'default_value'                                             => '127.0.0.1:1221'}),
    Boolean $benthos_systemd_socket = lookup('profile::cache::base::benthos_systemd_socket', {'default_value'                                    => false}),
    Optional[Integer[256]] $benthos_udp_rbuffer_bytes = lookup('profile::cache::base::benthos_udp_rbuffer_bytes', {'default_value'               => undef}),
    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}),
) {
    class { 'sslcert::dhparam':
    }
    if $do_ocsp {
        class { 'sslcert::ocsp::init':
        }
    }

    # 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 != 'off' {
        $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 => Haproxy::Site['tls']
            }

            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]]
    }

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

    haproxy::tls_terminator { 'tls':
        port                   => $tls_port,
        backend                => $varnish_socket,
        certificates           => $certificates,
        tls_ciphers            => $tls_ciphers,
        tls13_ciphers          => $tls13_ciphers,
        timeout                => $timeout,
        h2settings             => $h2settings,
        proxy_protocol         => $proxy_protocol,
        tls_cachesize          => $tls_cachesize,
        tls_session_lifetime   => $tls_session_lifetime,
        tls_ticket_keys_path   => $tls_ticket_keys_path,
        http_reuse             => 'always',
        vars                   => $vars,
        acls                   => $acls,
        add_headers            => $add_headers,
        del_headers            => $del_headers,
        pre_acl_actions        => $pre_acl_actions,
        post_acl_actions       => $post_acl_actions,
        prometheus_port        => $prometheus_port,
        numa_iface             => $numa_iface,
        sticktables            => $sticktables,
        haproxy_version        => $haproxy_version,
        http_redirection_port  => $http_redirection_port,
        redirection_timeout    => $redirection_timeout,
        http_disable_keepalive => $http_disable_keepalive,
        filters                => $filters,
        dedicated_hc_backend   => $dedicated_hc_backend,
        hc_sources             => $hc_sources,
        extended_logging       => $extended_logging,
    }

    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      => Haproxy::Tls_terminator['tls'],
      }
    }

    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'),
    }

    if $use_benthos and $benthos_systemd_socket {
        $benthos_socket_ensure = 'present'
    } else {
        $benthos_socket_ensure = 'absent'
    }

    # No need to set sysctl if no custom buffer size but let's be sure
    # it's cleaned up if removed.
    if ($benthos_socket_ensure == 'present') and $benthos_udp_rbuffer_bytes {
        $benthos_sysctl_ensure = 'present'
    } else {
        $benthos_sysctl_ensure = 'absent'
    }

    sysctl::parameters { 'udp rmem for benthos':
        ensure => $benthos_sysctl_ensure,
        values => {
            'net.core.rmem_max' => $benthos_udp_rbuffer_bytes,
        },
        before => Systemd::Service['benthos@haproxy_cache_systemd_socket.socket'],
    }

    systemd::service { 'benthos@haproxy_cache_systemd_socket.socket':
        ensure  => $benthos_socket_ensure,
        content => systemd_template('haproxy-benthos@.socket'),
        before  => Systemd::Override['benthos-stdin-from-socket'],
    }

    systemd::override { 'benthos-stdin-from-socket':
        ensure  => $benthos_socket_ensure,
        unit    => 'benthos@haproxy_cache_systemd_socket',
        content => "[Service]\nStandardInput=socket\nStandardOutput=journal\nStandardError=journal\n",
    }
}