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
|
# File 'modules/dynamicproxy/manifests/init.pp', line 15
class dynamicproxy (
Array[String] $ssl_settings,
Hash[String, Dynamicproxy::Zone] $supported_zones,
Optional[Stdlib::Fqdn] $redis_primary,
Array[Stdlib::IP::Address] $banned_ips,
String $blocked_user_agent_regex,
String $blocked_referer_regex,
Array[Stdlib::Fqdn] $xff_fqdns,
Integer $rate_limit_requests,
Array[Stdlib::IP::Address::Nosubnet] $nameservers,
String[1] $redis_maxmemory = '512MB',
) {
$acme_certs = $supported_zones.values.map |Dynamicproxy::Zone $zone| { $zone['acmechief_cert'] }.unique
acme_chief::cert { $acme_certs:
puppet_rsc => Exec['nginx-reload'],
}
$resolver = $nameservers
.map |$ip| {
wmflib::ip_family($ip) ? {
4 => $ip,
6 => "[${ip}]",
}
}
.join(' ')
$redis_port = '6379'
if $redis_primary and !($redis_primary in [$::facts['hostname'], $::facts['fqdn']]) {
$slaveof = "${redis_primary} ${redis_port}"
} else {
$slaveof = undef
}
redis::instance { $redis_port:
settings => {
# Protected by iptables / ferm rules from elsewhere
# We need to allow this so we can replicate
bind => debian::codename::ge('bookworm').bool2str(
'* -::*', '*'
),
protected-mode => 'no',
appendonly => 'yes',
appendfilename => "${::hostname}-${redis_port}.aof",
maxmemory => $redis_maxmemory,
slaveof => $slaveof,
dir => '/var/lib/redis',
},
}
# Monitoring!
prometheus::redis_exporter { '6379': }
class { '::nginx':
variant => 'extras',
}
logrotate::conf { 'nginx':
ensure => present,
source => 'puppet:///modules/dynamicproxy/logrotate',
}
systemd::timer::job { 'dynamicproxy_logrotate':
ensure => present,
description => 'Logrotation for Dynamic Proxy',
user => 'root',
command => '/usr/sbin/logrotate /etc/logrotate.conf',
interval => {'start' => 'OnCalendar', 'interval' => '*-*-* 00/1:00:00'}
}
if debian::codename::ge('bookworm') {
package { 'lua-nginx-redis':
ensure => present,
}
$lua_path = undef
} else {
$lua_path = '/etc/nginx/lua/?.lua'
}
file { '/etc/nginx/nginx.conf':
ensure => file,
content => template('dynamicproxy/nginx.conf.erb'),
require => Package['nginx-common'],
notify => Service['nginx'],
}
file { [
'/var/www/',
'/var/www/error',
]:
ensure => directory,
owner => 'www-data',
group => 'www-data',
mode => '0444',
}
file { '/var/www/error/wmcs-logo.png':
ensure => file,
source => 'puppet:///modules/dynamicproxy/wmcs-logo.png',
owner => 'www-data',
group => 'www-data',
mode => '0444',
}
file { '/var/www/error/wmcs-logo-2x.png':
ensure => file,
source => 'puppet:///modules/dynamicproxy/wmcs-logo-2x.png',
owner => 'www-data',
group => 'www-data',
mode => '0444',
}
mediawiki::errorpage {
default:
favicon => 'https://wikitech.wikimedia.org/static/favicon/wikitech.ico',
logo_src => '/.error/wmcs-logo.png',
logo_srcset => '/.error/wmcs-logo-2x.png 2x',
logo_width => 120,
logo_height => 137,
logo_alt => 'Wikimedia Cloud Services',
logo_link => 'https://wikitech.wikimedia.org/wiki/Portal:Cloud_VPS',
footer => "<p>${::facts['networking']['fqdn']}</p>",
owner => 'www-data',
group => 'www-data',
mode => '0444';
'/var/www/error/banned.html':
doctitle => 'Forbidden',
pagetitle => '403 Forbidden',
content => '<p>You have been banned from accessing this service.</p>';
'/var/www/error/noproxy.html':
doctitle => 'Not Found',
pagetitle => '404 Not Found',
content => '<p>No proxy is configured for this host name. Please see <a href="https://wikitech.wikimedia.org/wiki/Help:Proxy">our documentation on Wikitech</a> for more information on configuring a proxy.</p>';
'/var/www/error/ratelimit.html':
doctitle => 'Too Many Requests',
pagetitle => '429 Too Many Requests',
content => '<p>You are trying to access this service too fast.</p>';
'/var/www/error/unreachable.html':
doctitle => 'Error',
pagetitle => 'Error',
content => '<p>This web service cannot be reached. Please contact a maintainer of this project.</p><p>Maintainers can find troubleshooting instructions from <a href="https://wikitech.wikimedia.org/wiki/Help:Proxy">our documentation on Wikitech</a>.</p>';
}
file { '/var/www/error/errorpage.html':
ensure => absent,
}
file { '/etc/security/limits.conf':
ensure => file,
source => 'puppet:///modules/dynamicproxy/limits.conf',
require => Package['nginx-common'],
notify => Service['nginx'],
}
$supported_zones.each |String[1] $name, Dynamicproxy::Zone $zone| {
$fqdn = $name.regsubst('(.+)\.', '\\1')
nginx::site { $fqdn:
content => template('dynamicproxy/nginx-site.conf.erb'),
require => Acme_chief::Cert[$zone['acmechief_cert']],
}
}
file { '/etc/nginx/lua':
ensure => directory,
require => Package['nginx-extras'],
}
file { '/etc/nginx/lua/domainproxy.lua':
ensure => file,
source => 'puppet:///modules/dynamicproxy/domainproxy.lua',
require => File['/etc/nginx/lua'],
notify => Service['nginx'],
}
file { '/etc/nginx/lua/resty':
ensure => absent,
recurse => true,
force => true,
purge => true,
}
if debian::codename::lt('bookworm') {
file { '/etc/nginx/lua/nginx':
ensure => directory,
require => File['/etc/nginx/lua'],
}
file { '/etc/nginx/lua/nginx/redis.lua':
ensure => file,
require => File['/etc/nginx/lua/resty'],
source => 'puppet:///modules/dynamicproxy/redis.lua',
}
}
}
|