cdn-ops/global/overlay/etc/puppet/modules/cdn/manifests/cache.pp

243 lines
7.4 KiB
ObjectPascal
Raw Normal View History

2024-10-10 13:22:11 +00:00
# Configure a SUNET CDN CA server
2024-10-10 13:28:23 +00:00
class cdn::cache(
2024-10-10 13:27:06 +00:00
Hash[String, Integer] $customers = {
2024-10-10 13:22:11 +00:00
customer1 => 1000000000,
2024-10-31 11:56:33 +00:00
},
String $sunet_cdnp_version = '0.0.1',
2024-10-10 13:22:11 +00:00
)
{
include sunet::packages::certbot
include cdn::ca_trust
$cache_secrets = lookup({ 'name' => 'cdn::cache-secrets', 'default_value' => undef })
file { '/opt/sunet-cdn':
ensure => directory,
owner => 'root',
group => 'root',
mode => '0755',
}
file { '/opt/sunet-cdn/customers':
ensure => directory,
owner => 'root',
group => 'root',
mode => '0755',
}
file { '/opt/sunet-cdn/conf':
ensure => directory,
owner => 'root',
group => 'root',
mode => '0755',
}
file { '/opt/sunet-cdn/conf/varnish-slash-seccomp.json':
2024-10-10 13:22:11 +00:00
ensure => file,
owner => 'root',
group => 'root',
mode => '0644',
content => template('cdn/cache/varnish-slash-seccomp.json.erb'),
}
file { '/etc/systemd/network/10-cdn-dummy.netdev':
ensure => file,
owner => 'root',
group => 'root',
mode => '0644',
content => template('cdn/cache/10-cdn-dummy.netdev.erb'),
}
file { '/etc/systemd/network/10-cdn-dummy.network':
2024-10-11 16:52:53 +00:00
ensure => file,
owner => 'root',
group => 'root',
mode => '0644',
content => template('cdn/cache/10-cdn-dummy.network.erb'),
2024-10-11 16:52:53 +00:00
}
file { '/etc/systemd/network/10-cdn-ipip.netdev':
ensure => file,
owner => 'root',
group => 'root',
mode => '0644',
content => template('cdn/cache/10-cdn-ipip.netdev.erb'),
}
file { '/etc/systemd/network/10-cdn-ipip.network':
ensure => file,
owner => 'root',
group => 'root',
mode => '0644',
content => template('cdn/cache/10-cdn-ipip.network.erb'),
}
2024-10-11 20:10:50 +00:00
file { '/etc/systemd/network/10-cdn-ip6tunl.netdev.erb':
ensure => file,
owner => 'root',
group => 'root',
mode => '0644',
content => template('cdn/cache/10-cdn-ip6tunl.netdev.erb'),
}
file { '/etc/systemd/network/10-cdn-ip6tunl.network.erb':
ensure => file,
owner => 'root',
group => 'root',
mode => '0644',
content => template('cdn/cache/10-cdn-ip6tunl.network.erb'),
}
# Reload the network config if it has changed
exec { 'networkctl reload':
2024-10-11 20:12:05 +00:00
subscribe => [File['/etc/systemd/network/10-cdn-dummy.network'], File['/etc/systemd/network/10-cdn-ipip.network']],
refreshonly => true,
}
$sysctl_file = '/etc/sysctl.d/99-cdn-cache.conf'
file { $sysctl_file:
ensure => file,
owner => 'root',
group => 'root',
mode => '0644',
content => template('cdn/cache/sysctl.erb'),
}
# Load the sysctl file if it has changed
exec { "sysctl -p ${sysctl_file}":
subscribe => File[$sysctl_file],
refreshonly => true,
}
2024-10-29 13:21:34 +00:00
# Allow IPv4 tunnel packets arriving from l4lb nodes
sunet::nftables::rule { 'sunet_cdn_tunnel4':
rule => 'add rule inet filter input ip saddr { 130.242.64.233, 130.242.64.235 } ip protocol ipencap counter accept comment "sunet-cdn-tunnel4"'
}
2024-10-29 13:21:34 +00:00
# Allow IPv6 tunnel packets arriving from l4lb nodes
2024-10-29 13:23:34 +00:00
sunet::nftables::rule { 'sunet_cdn_tunnel6':
2024-10-29 13:21:34 +00:00
rule => 'add rule inet filter input ip6 saddr { 2001:6b0:2006:74::1, 2001:6b0:2006:75::1 } ip6 nexthdr ipv6 counter accept comment "sunet-cdn-tunnel6"'
}
# Allow decapsulated tunnel packets targeting the service IP range to reach
# local service ports
2024-10-13 12:31:23 +00:00
sunet::nftables::rule { 'sunet_cdn_service4':
2024-10-13 12:32:42 +00:00
rule => 'add rule inet filter input meta iifname tunl0 ip daddr 188.240.152.0/24 tcp dport { 80, 443 } counter accept comment "sunet-cdn-service4"'
}
2024-10-30 08:25:12 +00:00
sunet::nftables::rule { 'sunet_cdn_service6':
rule => 'add rule inet filter input meta iifname ip6tnl0 ip6 daddr 2001:6b0:2100::/48 tcp dport { 80, 443 } counter accept comment "sunet-cdn-service6"'
}
$sunet_cdnp_dir = '/var/lib/sunet-cdnp'
$sunet_cdnp_file = "sunet-cdnp_${sunet_cdnp_version}_linux_${facts[os][architecture]}.tar.gz"
$sunet_cdnp_url = "https://github.com/SUNET/sunet-cdnp/releases/download/v${sunet_cdnp_version}/${sunet_cdnp_file}"
# Create directory for managing CDP purger
file { $sunet_cdnp_dir:
ensure => directory,
owner => 'root',
group => 'root',
mode => '0755',
}
exec { "curl -LO ${sunet_cdnp_url}":
creates => "${sunet_cdnp_dir}/${sunet_cdnp_file}",
2024-10-31 14:30:36 +00:00
cwd => $sunet_cdnp_dir,
notify => Exec["tar -xzf ${sunet_cdnp_file} sunet-cdnp"],
}
exec { "tar -xzf ${sunet_cdnp_file} sunet-cdnp":
2024-10-31 14:30:36 +00:00
cwd => $sunet_cdnp_dir,
refreshonly => true,
}
file { '/usr/local/bin/sunet-cdnp':
ensure => link,
target => "${sunet_cdnp_dir}/sunet-cdnp",
2024-10-31 11:55:07 +00:00
}
2024-10-10 13:22:11 +00:00
if $cache_secrets {
2024-10-10 13:29:50 +00:00
$customers.each |String $customer, Integer $customer_uid| {
2024-10-10 13:22:11 +00:00
if $cache_secrets['customers'][$customer] {
2024-10-11 09:46:06 +00:00
file { "/opt/sunet-cdn/customers/${customer}":
2024-10-10 13:22:11 +00:00
ensure => directory,
owner => $customer_uid,
group => $customer_uid,
mode => '0750',
}
2024-10-11 09:46:06 +00:00
file { "/opt/sunet-cdn/customers/${customer}/conf":
2024-10-10 13:31:54 +00:00
ensure => directory,
owner => $customer_uid,
group => $customer_uid,
mode => '0750',
}
2024-10-11 09:46:06 +00:00
file { "/opt/sunet-cdn/customers/${customer}/shared":
2024-10-10 13:22:11 +00:00
ensure => directory,
owner => $customer_uid,
group => $customer_uid,
mode => '0750',
}
2024-10-11 09:46:06 +00:00
file { "/opt/sunet-cdn/customers/${customer}/cache":
2024-10-10 13:22:11 +00:00
ensure => directory,
owner => $customer_uid,
group => $customer_uid,
mode => '0750',
}
2024-10-11 09:46:06 +00:00
file { "/opt/sunet-cdn/customers/${customer}/certs-private":
2024-10-11 09:38:58 +00:00
ensure => directory,
owner => $customer_uid,
group => $customer_uid,
mode => '0750',
}
2024-10-11 09:46:06 +00:00
$combined_pem = "/opt/sunet-cdn/customers/${customer}/certs-private/combined.pem"
2024-10-11 09:38:58 +00:00
concat { $combined_pem:
ensure => present,
owner => $customer_uid,
group => $customer_uid,
mode => '0640',
2024-10-11 09:38:58 +00:00
}
2024-10-11 09:47:44 +00:00
concat::fragment { "${customer}-fullchain-${cache_secrets['customers'][$customer]['host']}":
2024-10-11 09:46:06 +00:00
target => $combined_pem,
2024-10-11 09:51:36 +00:00
source => "/etc/letsencrypt/live/${cache_secrets['customers'][$customer]['host']}/fullchain.pem",
order => '01',
2024-10-11 09:38:58 +00:00
}
2024-10-11 09:47:44 +00:00
concat::fragment { "${customer}-privkey-${cache_secrets['customers'][$customer]['host']}":
2024-10-11 09:46:06 +00:00
target => $combined_pem,
2024-10-11 09:51:36 +00:00
source => "/etc/letsencrypt/live/${cache_secrets['customers'][$customer]['host']}/privkey.pem",
order => '02',
2024-10-11 09:38:58 +00:00
}
2024-10-11 09:46:06 +00:00
file { "/opt/sunet-cdn/customers/${customer}/conf/haproxy.cfg":
2024-10-10 13:22:11 +00:00
ensure => file,
owner => $customer_uid,
group => $customer_uid,
mode => '0440',
content => template('cdn/cache/haproxy.cfg.erb'),
}
2024-10-11 09:46:06 +00:00
file { "/opt/sunet-cdn/customers/${customer}/conf/varnish.vcl":
2024-10-10 18:39:35 +00:00
ensure => file,
owner => $customer_uid,
group => $customer_uid,
mode => '0440',
content => template('cdn/cache/varnish.vcl.erb'),
}
2024-10-11 09:46:06 +00:00
sunet::docker_compose { "sunet-cdn-cache-${customer}":
2024-10-10 13:22:11 +00:00
content => template('cdn/cache/docker-compose.yml.erb'),
2024-10-11 09:46:06 +00:00
service_name => "cdn-cache-${customer}",
compose_dir => "/opt/sunet-cdn/compose/${customer}",
2024-10-10 13:22:11 +00:00
compose_filename => 'docker-compose.yml',
2024-10-11 09:46:06 +00:00
description => "SUNET CDN CA ${customer}",
2024-10-10 13:22:11 +00:00
}
}
}
}
}