Add wireguard module managing wg-quick interfaces
ci/woodpecker/pr/ruby-validate Pipeline was successful
ci/woodpecker/pr/yamllint Pipeline was successful
ci/woodpecker/pr/puppet-lint Pipeline was successful
ci/woodpecker/pr/erb-validate Pipeline was successful
ci/woodpecker/pr/bolt-validate Pipeline was successful
ci/woodpecker/pr/epp-validate Pipeline was successful
ci/woodpecker/pr/ruby-check Pipeline was canceled
ci/woodpecker/pr/puppet-validate Pipeline was canceled
ci/woodpecker/pr/ruby-validate Pipeline was successful
ci/woodpecker/pr/yamllint Pipeline was successful
ci/woodpecker/pr/puppet-lint Pipeline was successful
ci/woodpecker/pr/erb-validate Pipeline was successful
ci/woodpecker/pr/bolt-validate Pipeline was successful
ci/woodpecker/pr/epp-validate Pipeline was successful
ci/woodpecker/pr/ruby-check Pipeline was canceled
ci/woodpecker/pr/puppet-validate Pipeline was canceled
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
# manage wireguard interfaces via wg-quick
|
||||
class wireguard (
|
||||
Boolean $manage_package = true,
|
||||
String $package_name = 'wireguard-tools',
|
||||
Hash $interfaces = {},
|
||||
) {
|
||||
|
||||
if $manage_package {
|
||||
package { $package_name:
|
||||
ensure => installed,
|
||||
before => File['/etc/wireguard'],
|
||||
}
|
||||
}
|
||||
|
||||
file { '/etc/wireguard':
|
||||
ensure => directory,
|
||||
owner => 'root',
|
||||
group => 'root',
|
||||
mode => '0700',
|
||||
}
|
||||
|
||||
$interfaces.each |String $iface, Hash $data| {
|
||||
wireguard::interface { $iface:
|
||||
* => $data,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
# manage one wg-quick interface; without private_key, the existing /etc/wireguard/<iface>.key is loaded via PostUp
|
||||
define wireguard::interface (
|
||||
Array[Stdlib::IP::Address] $addresses,
|
||||
Optional[Stdlib::Port] $listen_port = undef,
|
||||
Optional[Integer[1280, 9000]] $mtu = undef,
|
||||
Optional[Variant[String, Sensitive[String]]] $private_key = undef,
|
||||
Array[Hash] $peers = [],
|
||||
) {
|
||||
|
||||
$conf = "/etc/wireguard/${name}.conf"
|
||||
$key = $private_key ? {
|
||||
Sensitive => $private_key.unwrap,
|
||||
default => $private_key,
|
||||
}
|
||||
|
||||
file { $conf:
|
||||
ensure => file,
|
||||
owner => 'root',
|
||||
group => 'root',
|
||||
mode => '0600',
|
||||
content => Sensitive(template('wireguard/wg.conf.erb')),
|
||||
show_diff => false,
|
||||
notify => Exec["wireguard_syncconf_${name}"],
|
||||
}
|
||||
|
||||
service { "wg-quick@${name}":
|
||||
ensure => running,
|
||||
enable => true,
|
||||
require => File[$conf],
|
||||
}
|
||||
|
||||
# syncconf applies peer/key changes without bouncing the tunnel; address/mtu changes need a manual restart
|
||||
exec { "wireguard_syncconf_${name}":
|
||||
command => "/bin/bash -c 'wg syncconf ${name} <(wg-quick strip ${name})'",
|
||||
onlyif => "/usr/sbin/ip link show ${name}",
|
||||
path => ['/usr/bin', '/usr/sbin', '/bin', '/sbin'],
|
||||
refreshonly => true,
|
||||
require => Service["wg-quick@${name}"],
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
# THIS FILE IS MANAGED BY PUPPET
|
||||
[Interface]
|
||||
<% @addresses.each do |addr| -%>
|
||||
Address = <%= addr %>
|
||||
<% end -%>
|
||||
<% if @listen_port -%>
|
||||
ListenPort = <%= @listen_port %>
|
||||
<% end -%>
|
||||
<% if @mtu -%>
|
||||
MTU = <%= @mtu %>
|
||||
<% end -%>
|
||||
<% if @key -%>
|
||||
PrivateKey = <%= @key %>
|
||||
<% else -%>
|
||||
PostUp = wg set %i private-key /etc/wireguard/%i.key
|
||||
<% end -%>
|
||||
<% @peers.each do |peer| -%>
|
||||
|
||||
[Peer]
|
||||
PublicKey = <%= peer['public_key'] %>
|
||||
<% if peer['preshared_key'] -%>
|
||||
PresharedKey = <%= peer['preshared_key'].respond_to?(:unwrap) ? peer['preshared_key'].unwrap : peer['preshared_key'] %>
|
||||
<% end -%>
|
||||
AllowedIPs = <%= Array(peer['allowed_ips']).join(', ') %>
|
||||
<% if peer['endpoint'] -%>
|
||||
Endpoint = <%= peer['endpoint'] %>
|
||||
<% end -%>
|
||||
<% if peer['persistent_keepalive'] -%>
|
||||
PersistentKeepalive = <%= peer['persistent_keepalive'] %>
|
||||
<% end -%>
|
||||
<% end -%>
|
||||
Reference in New Issue
Block a user