Puppet Class: profile::ganeti
- Defined in:
- modules/profile/manifests/ganeti.pp
Overview
SPDX-License-Identifier: Apache-2.0
Class: profile::ganeti
This profile configures Ganeti's keys, RAPI users, and configures the firewall on the host.
Actions:
Requires:
Sample Usage: include profile::ganeti
Parameters
[nodes] A list of Ganeti nodes in this particular cluster.
[rapi_nodes] A list of nodes to open the RAPI port to.
[rapi_certificate] A string containing the name of the certificate to use
[rapi_ro_user] A string containing the name of the read-only user to configure in RAPI.
[rapi_ro_password] A string containing the password for the aforementioned user.
[critical_memory] Percentage of memory (0-100) which, if using over it, it will throw a critical alert due to memory pressure. It must be higher than warning memory.
[warning_memory] Percentage of memory (0-100) which, if using over it, it will throw a warning alert due to memory pressure. It must be lower than critical_memory.
[routed] If Ganeti is used in routed (L3) mode or not. See https://wikitech.wikimedia.org/wiki/Ganeti#Routed_Ganeti
[tap_ip4] Required in routed mode only, specify the public, private and/or sandbox IPv4 assigned to all the VM facing interfaces. IPv6 automatically uses the link-local address.
[v6_prefixes] Required in routed mode only, specify the public, private and/or sandbox V6 prefixes used by VMs.
[dhcp_servers] Dictionary of DHCP servers keyed by site.
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 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 |
# File 'modules/profile/manifests/ganeti.pp', line 55
class profile::ganeti (
Array[Stdlib::Fqdn] $nodes = lookup('profile::ganeti::nodes'),
Array[Stdlib::Fqdn] $rapi_nodes = lookup('profile::ganeti::rapi_nodes'),
String $rapi_certificate = lookup('profile::ganeti::rapi::certificate'),
Optional[String] $rapi_ro_user = lookup('profile::ganeti::rapi::ro_user',
{ default_value => undef }),
Optional[String] $rapi_ro_password = lookup('profile::ganeti::rapi::ro_password',
{ default_value => undef }),
Integer[0, 100] $critical_memory = lookup('profile::ganeti::critical_memory'),
Integer[0, 100] $warning_memory = lookup('profile::ganeti::warning_memory'),
Boolean $routed = lookup('profile::ganeti::routed'),
Optional[Hash[String, Stdlib::IP::Address]] $tap_ip4 = lookup('profile::ganeti::tap_ip4',
{ default_value => undef }),
Optional[Hash[String, String]] $v6_prefixes = lookup('profile::ganeti::v6_prefixes',
{ default_value => undef }),
Hash[Wmflib::Sites, Stdlib::IP::Address] $dhcp_servers = lookup('profile::installserver::dhcp::install_servers'),
Boolean $manage_known_hosts = lookup('profile::ganeti::manage_known_hosts', { default_value => false }),
Optional[String] $cfssl_label = lookup('profile::ganeti::cfssl_label', { default_value => 'discovery2026' }),
Optional[String] $cluster_ssh_key = lookup('profile::ganeti::cluster_ssh_key',
{ default_value => undef }),
Optional[Array[Stdlib::IP::Address::Nosubnet]] $neighbors_list = lookup('profile::bird::neighbors_list', {default_value => undef}),
) {
if $manage_known_hosts and $cluster_ssh_key == undef {
fail('You need to configure the cluster SSH pubkey when using the managed known_hosts')
}
class { 'ganeti': }
$ssl_paths = profile::pki::get_cert($cfssl_label, $rapi_certificate, {
'owner' => 'root',
'group' => 'gnt-admin',
'notify_services' => ['ganeti'],
'outdir' => '/etc/ganeti/ssl',
})
$rapi_ssl_key = $ssl_paths['key']
$rapi_ssl_cert = $ssl_paths['cert']
$chain_file_name = $ssl_paths['chained']
$rapi_ssl_chain = "--ssl-chain ${chain_file_name}"
# Deploy defaults (for now, configuring RAPI) and the certificates for RAPI.
# Potential fixme: We don't restart the daemon here since it's not independent
# and this file configures other aspects of Ganeti. Manually restart ganeti
# on the target hosts after changes are merged.
file { '/etc/default/ganeti':
ensure => present,
mode => '0644',
content => template('ganeti/etc_default_ganeti.erb')
}
class { 'ganeti::prometheus':
rapi_endpoint => $rapi_certificate,
rapi_ro_user => $rapi_ro_user,
rapi_ro_password => $rapi_ro_password,
}
# Ganeti needs intracluster SSH root access
# DSS+RSA keys in here, but note that DSS is deprecated
ssh::userkey { 'root-ganeti':
ensure => present,
user => 'root',
skey => 'ganeti',
source => 'puppet:///modules/profile/ganeti/ganeti.pub',
}
# The RSA private key
file { '/root/.ssh/id_rsa':
ensure => present,
owner => 'root',
group => 'root',
mode => '0400',
content => secret('ganeti/id_rsa'),
show_diff => false,
}
# This is here for completeness
file { '/root/.ssh/id_rsa.pub':
ensure => present,
owner => 'root',
group => 'root',
mode => '0400',
source => 'puppet:///modules/profile/ganeti/id_rsa.pub',
}
motd::script { 'ganeti-master-motd':
ensure => present,
source => 'puppet:///modules/profile/ganeti/motd',
}
if defined('$rapi_ro_user') and defined('$rapi_ro_password') {
# Authentication for RAPI (for now just a single read-only user)
$ro_password_hash = md5("${rapi_ro_user}:Ganeti Remote API:${rapi_ro_password}")
$real_content = "${rapi_ro_user} {HA1}${ro_password_hash} read\n"
} else {
# Provide a blank authentication file for the RAPI server (no users will be defined, thus denying all)
$real_content = ''
}
file { '/var/lib/ganeti/rapi':
ensure => directory,
owner => 'gnt-rapi',
group => 'gnt-masterd',
mode => '0750',
}
file { '/var/lib/ganeti/rapi/users':
ensure => present,
owner => 'gnt-rapi',
group => 'gnt-masterd',
mode => '0640',
content => $real_content,
require => Class['ganeti'],
}
# Allow SSH between ganeti cluster members
firewall::service { 'ganeti_ssh_cluster':
proto => 'tcp',
port => 22,
srange => $nodes,
}
# RAPI is the API of ganeti
firewall::service { 'ganeti_rapi_cluster':
proto => 'tcp',
port => 5080,
srange => $nodes + $rapi_nodes,
}
# Ganeti noded is responsible for all cluster/node actions
firewall::service { 'ganeti_noded_cluster':
proto => 'tcp',
port => 1811,
srange => $nodes,
}
# Ganeti confd provides a HA and fast way to query cluster configuration
firewall::service { 'ganeti_confd_cluster':
proto => 'udp',
port => 1814,
srange => $nodes,
}
# Ganeti mond is the monitoring daemon. Data is available via port 1815
firewall::service { 'ganeti_mond_cluster':
proto => 'tcp',
port => 1815,
srange => $nodes,
}
# DRBD is used for HA of disk images. Port range for ganeti is 11000-14999
firewall::service { 'ganeti_drbd':
proto => 'tcp',
port_range => [11000,14999],
srange => $nodes,
}
# Migration is done over TCP port
firewall::service { 'ganeti_migration':
proto => 'tcp',
port => 8102,
srange => $nodes,
}
file { '/usr/local/sbin/ganeti_rebalance':
ensure => present,
mode => '0755',
owner => 'root',
group => 'root',
source => 'puppet:///modules/profile/ganeti/ganeti_rebalance.sh',
}
# If ganeti_cluster fact is not defined, the node has not been added to a
# cluster yet, so don't monitor
if $facts['ganeti_cluster'] {
# Service monitoring
nrpe::monitor_service{ 'ganeti-noded':
description => 'ganeti-noded running',
nrpe_command => '/usr/lib/nagios/plugins/check_procs -w 1:2 -c 1:2 -u root -C ganeti-noded',
notes_url => 'https://wikitech.wikimedia.org/wiki/Ganeti',
migration_task => 'T357099',
}
prometheus::blackbox::check::tcp { 'ganeti-noded':
port => 1811,
ip_families => ['ip4',],
probe_runbook => 'https://wikitech.wikimedia.org/wiki/Ganeti',
}
nrpe::monitor_service{ 'ganeti-confd':
description => 'ganeti-confd running',
nrpe_command => '/usr/lib/nagios/plugins/check_procs -w 1:1 -c 1:1 -u gnt-confd -C ganeti-confd',
notes_url => 'https://wikitech.wikimedia.org/wiki/Ganeti',
migration_task => 'T357099',
}
# Memory monitoring
ensure_packages( 'monitoring-plugins-contrib' ) # for pmp-check-unix-memory
if $facts['ganeti_master'] == $facts['fqdn'] {
nrpe::monitor_service { "https-gnt-rapi-${::site}":
description => "HTTPS Ganeti RAPI ${::site}",
nrpe_command => "/usr/lib/nagios/plugins/check_http -H ${facts['ganeti_cluster']} -p 5080 -S -e 401",
notes_url => 'https://www.mediawiki.org/wiki/Ganeti#RAPI_daemon',
migration_task => 'T350694',
}
nrpe::monitor_service{ 'ganeti-wconfd':
description => 'ganeti-wconfd running',
nrpe_command => '/usr/lib/nagios/plugins/check_procs -w 1:1 -c 1:1 -u gnt-masterd -C ganeti-wconfd',
notes_url => 'https://wikitech.wikimedia.org/wiki/Ganeti',
migration_task => 'T357099',
}
}
if $manage_known_hosts {
$known_hosts = ganeti::known_hosts($facts['ganeti_cluster'])
file { '/var/lib/ganeti/known_hosts':
ensure => present,
mode => '0644',
owner => 'gnt-masterd',
group => 'gnt-masterd',
content => sprintf('%s%s', $known_hosts , $cluster_ssh_key),
}
}
# Run a montly rebalancing for all nodegroups
# Note: We only run this on the first Wednesday of the month
# This should only be run on the master and absented from all other
# nodes
$hbal_presence = $facts['ganeti_master'] ? {
$facts['fqdn'] => absent,
default => absent,
}
systemd::timer::job { 'monthly_ganeti_rebalance':
ensure => $hbal_presence,
description => 'Run a monthly rebalance of Ganeti instances',
command => '/usr/local/sbin/ganeti_rebalance',
user => 'root',
interval => [{
'start' => 'OnCalendar',
'interval' => 'Wed *-*-01,02,03,04,05,06,07 11:47:00',
}
]
}
}
if $routed {
if $tap_ip4 == undef or $v6_prefixes == undef {
fail('In routed mode, `profile::ganeti::tap_ip4` and `profile::ganeti::v6_prefixes` must be defined.')
}
ensure_packages('dnsmasq')
file { '/etc/dnsmasq.conf':
content => template('profile/ganeti/dnsmasq.conf.erb'),
notify => Exec['dnsmasq-restart'],
require => Package['dnsmasq'],
validate_cmd => '/usr/sbin/dnsmasq --test --conf-file=%',
}
exec { 'dnsmasq-restart':
command => '/usr/sbin/dnsmasq --test && /bin/systemctl restart dnsmasq',
refreshonly => true,
require => Package['dnsmasq'],
}
nftables::file { 'ganeti-forward-chain':
order => 101,
content => file('profile/ganeti/ganeti-forward.nft'),
}
nftables::rules { 'ganeti_vms_in':
desc => 'Traffic from the VMs towards the hypervisor (and not through)',
chain => 'input',
prio => 10,
rules => ['tcp dport { 179 } iifname "tap*" accept', # BGP
'udp dport { 67 } iifname "tap*" accept', # DHCP request
],
}
nftables::rules { 'ganeti_vms_notrack':
desc => 'Perform FIB lookup and do not track if dest IP is not a local on on the host',
chain => 'prerouting',
prio => 10,
rules => ["iifname { ${$facts['interface_primary']}, tap* } fib daddr type != local notrack"],
}
# Below is an adaptation of homer-public:policies/common-sandbox.yaml
nftables::rules { 'ganeti_vms_forward':
desc => 'Traffic from the VMs through the hypervisor', # mostly to restrict sandbox traffic
chain => 'forward',
prio => 10,
rules => [# Forward external trafic TO VMs
"iifname ${$facts['interface_primary']} accept",
# Forward the below FROM all VMs (including sandbox)
'ip protocol icmp accept',
'meta l4proto ipv6-icmp accept',
'meta l4proto { tcp, udp } th dport 53 accept',
# Replies to monitoring http probes through install host web-proxy
'ip daddr @INSTALL_HOSTS_ipv4 tcp sport 80 tcp dport gt 1023 tcp dport != 8080 accept',
'ip6 daddr @INSTALL_HOSTS_ipv6 tcp sport 80 tcp dport gt 1023 tcp dport != 8080 accept',
# Block from Sandbox VMs to WMF internal ranges
'ip saddr @SANDBOX_NETWORKS_ipv4 ip daddr @INTERNAL_ipv4 iifname "tap*" drop',
'ip6 saddr @SANDBOX_NETWORKS_ipv6 ip6 daddr @INTERNAL_ipv6 iifname "tap*" drop',
'ip saddr @SANDBOX_NETWORKS_ipv4 ip daddr @PRODUCTION_NETWORKS_ipv4 iifname "tap*" drop',
'ip6 saddr @SANDBOX_NETWORKS_ipv6 ip6 daddr @PRODUCTION_NETWORKS_ipv6 iifname "tap*" drop',
# Forward all remaining traffic FROM VMs
'iifname "tap*" accept'
],
}
# TODO: cleaniup. Leftover from v6_prefixes, not in use.
#'eqiad' => {'private' => '2620:0:861:140', 'public' => '2620:0:861:5', 'sandbox' => '2620:0:861:202'},}
# Override the Package provided net-common script
file { '/usr/lib/ganeti/3.0/usr/lib/ganeti/net-common':
ensure => present,
owner => 'root',
group => 'root',
mode => '0755',
content => template('profile/ganeti/net-common.erb'),
}
sysctl::parameters { 'primary-nic-ip-forward':
values => {
'net.ipv4.ip_forward' => 1,
"net.ipv4.conf.${$facts['interface_primary']}.ip_forward" => 1,
"net.ipv6.conf.${$facts['interface_primary']}.accept_ra" => 2,
"net.ipv6.conf.${$facts['interface_primary']}.forwarding" => 1,
'net.ipv6.conf.all.forwarding' => 1,
},
}
sysctl::parameters { 'disable-v4-redirects':
values => {
'net.ipv4.conf.all.send_redirects' => 0,
'net.ipv4.conf.default.send_redirects' => 0,
},
}
# Unlike the legacy bridged mode routed packets are processed by hypervisor
# local firewall, so we need to not re-mark DSCP in packets from VMs
nftables::rules { 'trust-vm-dscp':
desc => 'Skip DSCP marking rules in postrouting for packets from VMs',
chain => 'postrouting',
prio => 5,
rules => ['iifname "tap*" return'],
}
class { 'bird':
neighbors => $neighbors_list,
bfd => false,
do_ipv6 => true,
multihop => false,
config_template => 'bird/bird_ganeti.conf.erb',
}
} else {
if debian::codename::ge('bookworm') {
ensure_packages('bridge-utils')
}
}
}
|