Puppet Class: profile::toolforge::k8s::haproxy

Defined in:
modules/profile/manifests/toolforge/k8s/haproxy.pp

Overview

Parameters:

  • web_backend_conn_limit (Integer) (defaults to: lookup('profile::toolforge::k8s::haproxy::web_backend_conn_limit', {default_value => 2000})) —

    Maximum concurrent connections per single backend server

  • web_tool_connection_limit (Integer) (defaults to: lookup('profile::toolforge::k8s::haproxy::web_tool_connection_limit', {default_value => 250})) —

    Maximum number of in-flight requests a single tool can have

  • rate_limit_requests (Integer) (defaults to: lookup('profile::toolforge::k8s::haproxy::rate_limit_requests', {default_value => 50})) —

    Number of average requests per second a single IP address can perform

  • rate_limit_burst_time (Integer) (defaults to: lookup('profile::toolforge::k8s::haproxy::rate_limit_burst_time', {default_value => 5})) —

    Number of seconds over which the per-IP rate limit is counted

  • disabled_hosts (Array[Stdlib::Fqdn]) (defaults to: lookup('profile::toolforge::k8s::haproxy::disabled_hosts', {default_value => []})) —

    Hostnames that should return a generic 403 error instead of handling actual requests

  • gateway_nodes (Array[Stdlib::Fqdn, 1]) (defaults to: lookup('profile::toolforge::k8s::gateway_nodes', {default_value => []}))
  • gateway_backend_port (Stdlib::Port) (defaults to: lookup('profile::toolforge::k8s::gateway_backend_port', {default_value => 30000}))
  • gateway_healthz_port (Stdlib::Port) (defaults to: lookup('profile::toolforge::k8s::gateway_healthz_port', {default_value => 30021}))
  • control_nodes (Array[Stdlib::Fqdn]) (defaults to: lookup('profile::toolforge::k8s::control_nodes', {default_value => ['localhost']}))
  • api_port (Stdlib::Port) (defaults to: lookup('profile::toolforge::k8s::apiserver_port', {default_value => 6443}))
  • api_gateway_port (Stdlib::Port) (defaults to: lookup('profile::toolforge::k8s::haproxy::api_gateway_port', {default_value => 30003}))
  • infra_tracing_loki_gateway_port (Stdlib::Port) (defaults to: lookup('profile::toolforge::k8s::haproxy::infra_tracing_loki_gateway_port', {default_value => 30004}))
  • keepalived_vips (Array[Stdlib::Host]) (defaults to: lookup('profile::toolforge::k8s::haproxy::keepalived_vips', {default_value => []}))
  • keepalived_peers (Array[Stdlib::Fqdn]) (defaults to: lookup('profile::toolforge::k8s::haproxy::keepalived_peers', {default_value => ['localhost']}))
  • keepalived_password (String) (defaults to: lookup('profile::toolforge::k8s::haproxy::keepalived_password', {default_value => 'notarealpassword'}))
  • web_domain (Stdlib::Fqdn) (defaults to: lookup('profile::toolforge::web_domain', {default_value => 'toolforge.org'}))
  • global_connection_limit (Integer) (defaults to: lookup('profile::toolforge::k8s::haproxy::global_connection_limit', {default_value => 98304}))
  • frontend_conn_limit (Integer) (defaults to: lookup('profile::toolforge::k8s::haproxy::frontend_conn_limit', {default_value => 65536}))
  • http_redirect_conn_limit (Integer) (defaults to: lookup('profile::toolforge::k8s::haproxy::http_redirect_conn_limit', {default_value => 4096}))
  • web_client_timeout (Integer) (defaults to: lookup('profile::toolforge::k8s::haproxy::web_client_timeout', {default_value => 90}))
  • acme_certname (String[1]) (defaults to: lookup('profile::toolforge::k8s::haproxy::acme_certname', {default_value => 'toolforge'}))
  • static_domain (Stdlib::Fqdn) (defaults to: lookup('profile::toolforge::static::static_domain', {default_value => 'tools-static.wmflabs.org'}))
  • blocked_user_agent_regex (Optional[String[1]]) (defaults to: lookup('dynamicproxy::blocked_user_agent_regex', {default_value => undef}))
  • banned_ips (Array[Stdlib::IP::Address]) (defaults to: lookup('dynamicproxy::banned_ips', {default_value => []}))
  • blocked_referer_regex (Optional[String[1]]) (defaults to: lookup('dynamicproxy::blocked_referer_regex', {default_value => undef}))
  • prometheus_nodes (Array[Stdlib::Fqdn]) (defaults to: lookup('prometheus_nodes'))


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

class profile::toolforge::k8s::haproxy (
    Array[Stdlib::Fqdn, 1]     $gateway_nodes                   = lookup('profile::toolforge::k8s::gateway_nodes',                            {default_value => []}),
    Stdlib::Port               $gateway_backend_port            = lookup('profile::toolforge::k8s::gateway_backend_port',                     {default_value => 30000}),
    Stdlib::Port               $gateway_healthz_port            = lookup('profile::toolforge::k8s::gateway_healthz_port',                     {default_value => 30021}),
    Array[Stdlib::Fqdn]        $control_nodes                   = lookup('profile::toolforge::k8s::control_nodes',                            {default_value => ['localhost']}),
    Stdlib::Port               $api_port                        = lookup('profile::toolforge::k8s::apiserver_port',                           {default_value => 6443}),
    Stdlib::Port               $api_gateway_port                = lookup('profile::toolforge::k8s::haproxy::api_gateway_port',                {default_value => 30003}),
    Stdlib::Port               $infra_tracing_loki_gateway_port = lookup('profile::toolforge::k8s::haproxy::infra_tracing_loki_gateway_port', {default_value => 30004}),
    Array[Stdlib::Host]        $keepalived_vips                 = lookup('profile::toolforge::k8s::haproxy::keepalived_vips',                 {default_value => []}),
    Array[Stdlib::Fqdn]        $keepalived_peers                = lookup('profile::toolforge::k8s::haproxy::keepalived_peers',                {default_value => ['localhost']}),
    String                     $keepalived_password             = lookup('profile::toolforge::k8s::haproxy::keepalived_password',             {default_value => 'notarealpassword'}),
    Stdlib::Fqdn               $web_domain                      = lookup('profile::toolforge::web_domain',                                    {default_value => 'toolforge.org'}),
    Integer                    $global_connection_limit         = lookup('profile::toolforge::k8s::haproxy::global_connection_limit',         {default_value => 98304}),
    Integer                    $frontend_conn_limit             = lookup('profile::toolforge::k8s::haproxy::frontend_conn_limit',             {default_value => 65536}),
    Integer                    $http_redirect_conn_limit        = lookup('profile::toolforge::k8s::haproxy::http_redirect_conn_limit',        {default_value => 4096}),
    Integer                    $web_backend_conn_limit          = lookup('profile::toolforge::k8s::haproxy::web_backend_conn_limit',          {default_value => 2000}),
    Integer                    $web_tool_connection_limit       = lookup('profile::toolforge::k8s::haproxy::web_tool_connection_limit',       {default_value => 250}),
    Integer                    $rate_limit_requests             = lookup('profile::toolforge::k8s::haproxy::rate_limit_requests',             {default_value => 50}),
    Integer                    $rate_limit_burst_time           = lookup('profile::toolforge::k8s::haproxy::rate_limit_burst_time',           {default_value => 5}),
    Integer                    $web_client_timeout              = lookup('profile::toolforge::k8s::haproxy::web_client_timeout',              {default_value => 90}),
    Array[Stdlib::Fqdn]        $disabled_hosts                  = lookup('profile::toolforge::k8s::haproxy::disabled_hosts',                  {default_value => []}),
    String[1]                  $acme_certname                   = lookup('profile::toolforge::k8s::haproxy::acme_certname',                   {default_value => 'toolforge'}),
    Stdlib::Fqdn               $static_domain                   = lookup('profile::toolforge::static::static_domain',                   {default_value => 'tools-static.wmflabs.org'}),
    Optional[String[1]]        $blocked_user_agent_regex        = lookup('dynamicproxy::blocked_user_agent_regex',                      {default_value => undef}),
    Array[Stdlib::IP::Address] $banned_ips                      = lookup('dynamicproxy::banned_ips',                                    {default_value => []}),
    Optional[String[1]]        $blocked_referer_regex           = lookup('dynamicproxy::blocked_referer_regex',                         {default_value => undef}),
    Array[Stdlib::Fqdn]        $prometheus_nodes                = lookup('prometheus_nodes'),
) {
    class { 'haproxy':
        config_content   => template('profile/toolforge/k8s/haproxy/haproxy.cfg.erb'),
        logging          => true,
        logrotate_config => 'puppet:///modules/profile/toolforge/k8s/haproxy/haproxy.logrotate',
        # No Icinga support here
        monitor          => false,
    }
    systemd::override { 'haproxy-toolforge':
        unit    => 'haproxy',
        source  => 'puppet:///modules/profile/toolforge/k8s/haproxy/haproxy.override.service',
        restart => true,
    }

    include profile::haproxy::resolver

    file { '/etc/haproxy/banned-ips.txt':
        ensure  => file,
        content => "${banned_ips.join("\n")}\n",
        notify  => Service['haproxy'],
    }

    acme_chief::cert { $acme_certname:
        puppet_svc => 'haproxy',
    }

    $prometheus_ips = $prometheus_nodes.wmflib::hosts2ips()
    haproxy::site { 'stats':
        content => template('profile/toolforge/k8s/haproxy/stats.cfg.erb'),
    }

    haproxy::site { 'k8s-api-servers':
        content => template('profile/toolforge/k8s/haproxy/k8s-api-servers.cfg.erb'),
    }

    haproxy::site { 'k8s-ingress':
        content => template('profile/toolforge/k8s/haproxy/k8s-ingress.cfg.erb'),
    }

    haproxy::site { 'k8s-ingress-api-gateway':
        content => template('profile/toolforge/k8s/haproxy/k8s-ingress-api-gateway.cfg.erb'),
    }

    haproxy::site { 'k8s-ingress-infra-tracing-loki-gateway':
        content => template('profile/toolforge/k8s/haproxy/k8s-ingress-infra-tracing-loki-gateway.cfg.erb'),
    }

    if !$keepalived_vips.empty() and $facts['networking']['fqdn'] in $keepalived_peers {
        class { 'keepalived::failover':
            auth_pass => $keepalived_password,
            peers     => delete($keepalived_peers, $facts['networking']['fqdn']),
            vips      => wmflib::hosts2ips($keepalived_vips),
        }
    }

    prometheus::blackbox::check::http {
        default:
            port                => 443,
            prometheus_instance => 'tools',
            team                => 'wmcs',
            severity            => 'warning',
            probe_runbook       => 'https://wikitech.wikimedia.org/wiki/Portal:Toolforge/Admin/Runbooks/k8s-haproxy';

        # well-known-to-exist web service
        "admin.${web_domain}":
            path               => '/healthz',
            body_regex_matches => ['OK'];

        # monitor the 404 handler
        # creation on this tool has been blocked by the title blacklist
        "this-tool-does-not-exist.${web_domain}":
            timeout            => '15s',
            body_regex_matches => ['The URL you have requested'],
            status_matches     => [404];

        "api.svc.${web_domain}":
            path               => '/healthz',
            body_regex_matches => ['ok'],
            # making it explicit
            status_matches     => [200];

        "infra-tracing-loki.svc.${::wmcs_project}.${::wmcs_deployment}.wikimedia.cloud":
            path               => '/',
            port               => 30004,
            force_tls          => true,
            insecure_tls       => true,
            body_regex_matches => ['OK'],
            # making it explicit
            status_matches     => [200];
    }

    file { '/etc/haproxy/errors':
        ensure => directory,
    }

    file { '/etc/haproxy/errors/robots.txt':
        ensure => file,
        source => 'puppet:///modules/profile/toolforge/k8s/haproxy/ingress/robots.txt',
    }
    file { '/etc/haproxy/errors/favicon.ico':
        ensure => file,
        source => 'puppet:///modules/profile/toolforge/favicon.ico',
    }

    mediawiki::errorpage {
        default:
            favicon     => "https://${static_domain}/admin/errors/favicon.ico",
            pagetitle   => 'Wikimedia Toolforge Error',
            logo_src    => "https://${static_domain}/admin/errors/toolforge-logo.svg",
            logo_width  => 120,
            logo_height => 120,
            logo_alt    => 'Wikimedia Toolforge',
            logo_link   => 'https://wikitech.wikimedia.org/wiki/Portal:Toolforge',
            footer      => "<p>${facts['networking']['fqdn']}</p>",
            owner       => 'www-data',
            group       => 'www-data',
            mode        => '0444',
            notify      => Service['haproxy'];

        '/etc/haproxy/errors/banned.html':
            content => '<p>You have been banned from accessing Toolforge. Please see <a href="https://wikitech.wikimedia.org/wiki/Help:Toolforge/Banned">Help:Toolforge/Banned</a> for more information on why and on how to resolve this.</p>';
        '/etc/haproxy/errors/disabled.html':
            content => '<p>Access to this tool has been temporarily disabled. Please try again later.</p>';
        '/etc/haproxy/errors/errorpage.html':
            content => '<p>Our servers are currently experiencing a technical problem. This is probably temporary and should be fixed soon. Please try again later.</p>';
        '/etc/haproxy/errors/overloaded.html':
            content => @(EOF)
                <p>The tool you are trying to access is currently receiving more traffic than it can handle. Please try again later.</p>
                <p>If this issue persists, you may wish to notify the tool's maintainers about the error.</p>
                <h2>If you maintain this tool</h2>
                <p>Please see <a href="https://wikitech.wikimedia.org/wiki/Help:Toolforge/Web#%22receiving_more_traffic_than_it_can_handle%22">our documentation</a> for help fixing this issue.</p>
            | EOF
            ;
        '/etc/haproxy/errors/ratelimit.html':
            content => '<p>You are trying to access this service too fast.</p>';
    }
}