diff options
Diffstat (limited to 'personal_infra/puppet/modules/proxmox')
7 files changed, 216 insertions, 0 deletions
diff --git a/personal_infra/puppet/modules/proxmox/README.md b/personal_infra/puppet/modules/proxmox/README.md new file mode 100644 index 00000000..5e5f8bc6 --- /dev/null +++ b/personal_infra/puppet/modules/proxmox/README.md @@ -0,0 +1,36 @@ +# Proxmox + +## Networking + +Configures a public Internet IP, and an internal network with forwarding for containers and virtual machines. + +Add the following to your Proxmox host Ansible variables: + +``` +network: + ip: dotted.ip.notation + netmask: 255.255.255.0 + gateway: dotted.ip.notation + proxmox: + ip: 10.3.3.1 + netmask: 255.255.255.0 + network: 10.3.3.0/24 +``` + +## Proxy + +Class `proxmox::proxy` can handle proxying internal web servers. + +``` +class {'proxmox::proxy': + mail => lookup('mail.root_mail'), + base_hostname => lookup('network.public_hostname'), +} +``` + +This uses the Apache HTTP Server and mod_md to obtain certificates. +Your hostname must be publicly accessible, because http challenges are used. + +You receive mails to restart your server when required. + +The `base_hostname` certificate is injected daily to pveproxy. diff --git a/personal_infra/puppet/modules/proxmox/manifests/freeipa.pp b/personal_infra/puppet/modules/proxmox/manifests/freeipa.pp new file mode 100644 index 00000000..f3464c78 --- /dev/null +++ b/personal_infra/puppet/modules/proxmox/manifests/freeipa.pp @@ -0,0 +1,17 @@ +class proxmox::freeipa { + class {'proxmox':} + + file {['/etc/subuid', '/etc/subgid']: + content => epp('proxmox/freeipa_subxid', {'freeipa' => lookup('freeipa')}), + } + + # TODO + service {['sssd-ssh.socket', 'sssd-pam-priv.socket', 'sssd-nss.socket', 'sssd-sudo.socket', 'sssd-pam.socket']: + ensure => stopped, + enable => mask, + } + ~> + exec {'/usr/bin/systemctl reset-failed': + refreshonly => true, + } +} diff --git a/personal_infra/puppet/modules/proxmox/manifests/init.pp b/personal_infra/puppet/modules/proxmox/manifests/init.pp new file mode 100644 index 00000000..b3297eb4 --- /dev/null +++ b/personal_infra/puppet/modules/proxmox/manifests/init.pp @@ -0,0 +1,38 @@ +class proxmox { + file {'/etc/network/interfaces': + content => epp('proxmox/interfaces', { + "network" => lookup("network"), + }), + } + ~> + exec {'/usr/sbin/ifreload -a': + refreshonly => true + } + + # to prevent Germany/Hetzner abuse complaints + service {['rpcbind.target', 'rpcbind.service', 'rpcbind.socket']: + ensure => stopped, + enable => mask, + } + + # TODO: secure this. Right now I don't use VMs, so just disable it + service {'spiceproxy': + ensure => stopped, + enable => mask, + } + + file {'/etc/logrotate.d/pve': + ensure => absent, + } + ~> + service {'logrotate':} + + file {'/etc/apt/sources.list.d/pve-enterprise.list': + ensure => absent, + } + + file {'/etc/apt/sources.list.d/pve-no-subscription.list': + content => 'deb http://download.proxmox.com/debian/pve bullseye pve-no-subscription +', + } +} diff --git a/personal_infra/puppet/modules/proxmox/manifests/proxy.pp b/personal_infra/puppet/modules/proxmox/manifests/proxy.pp new file mode 100644 index 00000000..cb3c0bd4 --- /dev/null +++ b/personal_infra/puppet/modules/proxmox/manifests/proxy.pp @@ -0,0 +1,52 @@ +class proxmox::proxy ($mail, $base_hostname) { + package {'apache2':} + -> + service {'apache2': + enable => true, + ensure => running, + require => File['/usr/local/bin/notify_md_renewal'], + } + + $apache_dep = { + require => Package['apache2'], + notify => Service['apache2'], + } + + ['md', 'ssl', 'proxy_http', 'proxy'].each |$mod| { + exec {"/usr/sbin/a2enmod $mod": + creates => "/etc/apache2/mods-enabled/$mod.load", + * => $apache_dep, + } + } + + file {'/etc/apache2/sites-enabled/test.conf': + content => @("EOT") + MDomain $base_hostname auto + MDCertificateAgreement accepted + MDContactEmail $mail + MDNotifyCmd /usr/local/bin/notify_md_renewal + + <VirtualHost *:443> + ServerName $base_hostname + SSLEngine on + </VirtualHost> + | EOT + , + * => $apache_dep + } + + file {'/usr/local/bin/notify_md_renewal': + content => @("EOT"/$) + #!/bin/sh + + systemctl restart apache2 + pvenode cert set /etc/apache2/md/domains/$base_hostname/pubcert.pem /etc/apache2/md/domains/$base_hostname/privkey.pem --force 1 --restart 1 + + for hook in /usr/local/bin/notify_md_renewal_hook_* ; do + \$hook + done + | EOT + , + mode => '0755', + } +} diff --git a/personal_infra/puppet/modules/proxmox/manifests/proxy_host.pp b/personal_infra/puppet/modules/proxmox/manifests/proxy_host.pp new file mode 100644 index 00000000..b60caf4c --- /dev/null +++ b/personal_infra/puppet/modules/proxmox/manifests/proxy_host.pp @@ -0,0 +1,53 @@ +define proxmox::proxy_host (String[1] $target, Optional[String[1]] $overwrite_rh_certs = undef) { + if $target =~ /^https:/ { + $ssl_fragment = @("EOT") + SSLProxyEngine on + SSLProxyCheckPeerName off + | EOT + } + else { + $ssl_fragment = "" + } + + file {"/etc/apache2/sites-enabled/$title.conf": + content => @("EOT") + MDomain $title + + <VirtualHost *:80> + ServerName $title + Redirect permanent / https://$title/ + </VirtualHost> + + <VirtualHost *:443> + ServerName $title + SSLEngine on + + ProxyPass "/" "$target" + ProxyPassReverse "/" "$target" + ProxyPreservehost On + $ssl_fragment + </VirtualHost> + | EOT + , + } + ~> + Service['apache2'] + + if $overwrite_rh_certs { + $pveid = lookup("hostvars.'$overwrite_rh_certs'.proxmox.id"); + + file {"/usr/local/bin/notify_md_renewal_hook_$overwrite_rh_certs": + content => @("EOT"/$) + #!/bin/sh + + cp /etc/apache2/md/domains/$title/pubcert.pem /rpool/data/subvol-$pveid-disk-0/etc/pki/tls/certs/localhost.crt + cp /etc/apache2/md/domains/$title/privkey.pem /rpool/data/subvol-$pveid-disk-0/etc/pki/tls/private/localhost.key + pct exec $pveid systemctl restart httpd + | EOT + , + mode => '0755', + } + } + + +} diff --git a/personal_infra/puppet/modules/proxmox/templates/freeipa_subxid.epp b/personal_infra/puppet/modules/proxmox/templates/freeipa_subxid.epp new file mode 100644 index 00000000..c72d1d04 --- /dev/null +++ b/personal_infra/puppet/modules/proxmox/templates/freeipa_subxid.epp @@ -0,0 +1,2 @@ +root:100000:65536 +root:<%= $freeipa['idrange_start'] %>:<%= $freeipa['idrange_size'] %> diff --git a/personal_infra/puppet/modules/proxmox/templates/interfaces.epp b/personal_infra/puppet/modules/proxmox/templates/interfaces.epp new file mode 100644 index 00000000..e0bfeceb --- /dev/null +++ b/personal_infra/puppet/modules/proxmox/templates/interfaces.epp @@ -0,0 +1,18 @@ +auto lo +iface lo inet loopback + +auto eno1 +iface eno1 inet static + address <%= $network['ip'] %> + netmask <%= $network['netmask'] %> + gateway <%= $network['gateway'] %> + +auto vmbr0 +iface vmbr0 inet static + address <%= $network['proxmox']['ip'] %> + netmask <%= $network['proxmox']['netmask'] %> + bridge_ports none + bridge_stp off + bridge_fd 0 + post-up echo 1 > /proc/sys/net/ipv4/ip_forward + post-up iptables -t nat -A POSTROUTING -s '<%= $network['proxmox']['network'] %>' -o eno1 -j MASQUERADE |
