Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement mtu param to configure MTUBytes #23

Merged
merged 1 commit into from
Aug 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 34 additions & 5 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,33 +72,38 @@ Default value: ``true``

### <a name="wireguardinterface"></a>`wireguard::interface`

manages a wireguard setup
}

* **See also**
* https://www.freedesktop.org/software/systemd/man/systemd.netdev.html#%5BWireGuardPeer%5D%20Section%20Options

#### Examples

#####
##### Peer with one node and setup dualstack firewall rules

```puppet
Peer with one node and setup dualstack firewall rules
wireguard::interface {'as2273':
source_addresses => ['2003:4f8:c17:4cf::1', '149.9.255.4'],
public_key => 'BcxLll1BVxGQ5DeijroesjroiesjrjvX+EBhS4vcDn0R0=',
endpoint => 'wg.example.com:53668',
addresses => [{'Address' => '192.168.123.6/30',},{'Address' => 'fe80::beef:1/64'},],
}
```

Peer with one node and setup dualstack firewall rules with peers in a different layer2
##### Peer with one node and setup dualstack firewall rules with peers in a different layer2

```puppet
wireguard::interface {'as2273':
source_addresses => ['2003:4f8:c17:4cf::1', '149.9.255.4'],
public_key => 'BcxLll1BVxGQ5DeijroesjroiesjrjvX+EBhS4vcDn0R0=',
endpoint => 'wg.example.com:53668',
addresses => [{'Address' => '192.168.218.87/32', 'Peer' => '172.20.53.97/32'}, {'Address' => 'fe80::ade1/64',},],
}
```

##### Create a passive wireguard interface that listens for incoming connections. Useful when the other side has a dynamic IP / is behind NAT

Create a passive wireguard interface that listens for incoming connections. Useful when the other side has a dynamic IP / is behind NAT
```puppet
wireguard::interface {'as2273':
source_addresses => ['2003:4f8:c17:4cf::1', '149.9.255.4'],
public_key => 'BcxLll1BVxGQ5DeijroesjroiesjrjvX+EBhS4vcDn0R0=',
Expand All @@ -107,6 +112,21 @@ wireguard::interface {'as2273':
}
```

##### create a wireguard interface behind a DSL line with changing IP with lowered MTU

```puppet
wireguard::interface {'as3668-2':
source_addresses => ['144.76.249.220', '2a01:4f8:171:1152::12'],
public_key => 'Tci/bHoPCjTpYv8bw17xQ7P4OdqzGpEN+NDueNjUvBA=',
endpoint => 'router02.bastelfreak.org:1338',
dport => 1338,
input_interface => $facts['networking']['primary'],
addresses => [{'Address' => '169.254.0.10/32', 'Peer' =>'169.254.0.9/32'},{'Address' => 'fe80::beef:f/64'},],
destination_addresses => [],
persistent_keepalive => 5,
mtu => 1412,
```

#### Parameters

The following parameters are available in the `wireguard::interface` defined type:
Expand All @@ -122,6 +142,7 @@ The following parameters are available in the `wireguard::interface` defined typ
* [`addresses`](#addresses)
* [`persistent_keepalive`](#persistent_keepalive)
* [`description`](#description)
* [`mtu`](#mtu)

##### <a name="interface"></a>`interface`

Expand Down Expand Up @@ -209,3 +230,11 @@ an optional string that will be added to the wireguard network interface

Default value: ``undef``

##### <a name="mtu"></a>`mtu`

Data type: `Optional[Integer[1280, 9000]]`

configure the MTU (maximum transision unit) for the wireguard tunnel. By default linux will figure this out. You might need to lower it if you're connection through a DSL line. MTU needs to be equal on both tunnel endpoints

Default value: ``undef``

30 changes: 24 additions & 6 deletions manifests/interface.pp
Original file line number Diff line number Diff line change
Expand Up @@ -12,35 +12,49 @@
# @param addresses different addresses for the systemd-networkd configuration
# @param persistent_keepalive is set to 1 or greater, that's the interval in seconds wireguard sends a keepalive to the other peer(s). Useful if the sender is behind a NAT gateway or has a dynamic ip address
# @param description an optional string that will be added to the wireguard network interface
# @param mtu configure the MTU (maximum transision unit) for the wireguard tunnel. By default linux will figure this out. You might need to lower it if you're connection through a DSL line. MTU needs to be equal on both tunnel endpoints
#
# @author Tim Meusel <[email protected]>
#
# @see https://www.freedesktop.org/software/systemd/man/systemd.netdev.html#%5BWireGuardPeer%5D%20Section%20Options
#
# @example
# Peer with one node and setup dualstack firewall rules
# @example Peer with one node and setup dualstack firewall rules
# wireguard::interface {'as2273':
# source_addresses => ['2003:4f8:c17:4cf::1', '149.9.255.4'],
# public_key => 'BcxLll1BVxGQ5DeijroesjroiesjrjvX+EBhS4vcDn0R0=',
# endpoint => 'wg.example.com:53668',
# addresses => [{'Address' => '192.168.123.6/30',},{'Address' => 'fe80::beef:1/64'},],
# }
#
# Peer with one node and setup dualstack firewall rules with peers in a different layer2
# @example Peer with one node and setup dualstack firewall rules with peers in a different layer2
# wireguard::interface {'as2273':
# source_addresses => ['2003:4f8:c17:4cf::1', '149.9.255.4'],
# public_key => 'BcxLll1BVxGQ5DeijroesjroiesjrjvX+EBhS4vcDn0R0=',
# endpoint => 'wg.example.com:53668',
# addresses => [{'Address' => '192.168.218.87/32', 'Peer' => '172.20.53.97/32'}, {'Address' => 'fe80::ade1/64',},],
# }
#
# Create a passive wireguard interface that listens for incoming connections. Useful when the other side has a dynamic IP / is behind NAT
# @example Create a passive wireguard interface that listens for incoming connections. Useful when the other side has a dynamic IP / is behind NAT
# wireguard::interface {'as2273':
# source_addresses => ['2003:4f8:c17:4cf::1', '149.9.255.4'],
# public_key => 'BcxLll1BVxGQ5DeijroesjroiesjrjvX+EBhS4vcDn0R0=',
# dport => 53668,
# addresses => [{'Address' => '192.168.218.87/32', 'Peer' => '172.20.53.97/32'}, {'Address' => 'fe80::ade1/64',},],
# }
#
# @example create a wireguard interface behind a DSL line with changing IP with lowered MTU
# wireguard::interface {'as3668-2':
# source_addresses => ['144.76.249.220', '2a01:4f8:171:1152::12'],
# public_key => 'Tci/bHoPCjTpYv8bw17xQ7P4OdqzGpEN+NDueNjUvBA=',
# endpoint => 'router02.bastelfreak.org:1338',
# dport => 1338,
# input_interface => $facts['networking']['primary'],
# addresses => [{'Address' => '169.254.0.10/32', 'Peer' =>'169.254.0.9/32'},{'Address' => 'fe80::beef:f/64'},],
# destination_addresses => [],
# persistent_keepalive => 5,
# mtu => 1412,
# }
#
define wireguard::interface (
String[1] $public_key,
Optional[String[1]] $endpoint = undef,
Expand All @@ -53,6 +67,7 @@
Array[Stdlib::IP::Address] $source_addresses = [],
Array[Hash[String,Variant[Stdlib::IP::Address::V4::CIDR,Stdlib::IP::Address::V6::CIDR]]] $addresses = [],
Optional[String[1]] $description = undef,
Optional[Integer[1280, 9000]] $mtu = undef,
) {
require wireguard

Expand Down Expand Up @@ -94,7 +109,7 @@
}
# lint:ignore:strict_indent
$netdev_config = @(EOT)
<%- | $interface, $dport, $public_key, $endpoint, $description | -%>
<%- | $interface, $dport, $public_key, $endpoint, $description, $mtu | -%>
# THIS FILE IS MANAGED BY PUPPET
# based on https://dn42.dev/howto/wireguard
[NetDev]
Expand All @@ -103,6 +118,9 @@
<% if $description { -%>
Description=<%= $description %>
<%} -%>
<% if $mtu { -%>
MTUBytes=<%= $mtu %>
<%} -%>

[WireGuard]
PrivateKeyFile=/etc/wireguard/<%= $interface %>
Expand All @@ -119,7 +137,7 @@
AllowedIPs=0.0.0.0/0
| EOT
systemd::network { "${interface}.netdev":
content => inline_epp($netdev_config, { 'interface' => $interface, 'dport' => $dport, 'public_key' => $public_key, 'endpoint' => $endpoint, 'description' => $description }),
content => inline_epp($netdev_config, { 'interface' => $interface, 'dport' => $dport, 'public_key' => $public_key, 'endpoint' => $endpoint, 'description' => $description, 'mtu' => $mtu }),
restart_service => true,
owner => 'root',
group => 'systemd-network',
Expand Down
47 changes: 47 additions & 0 deletions spec/defines/interface_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
it { is_expected.to contain_file("/etc/systemd/network/#{title}.netdev").with_content(%r{Endpoint=#{params[:endpoint]}}) }
it { is_expected.to contain_file("/etc/systemd/network/#{title}.network").without_content(%r{Address}) }
it { is_expected.to contain_file("/etc/systemd/network/#{title}.network").without_content(%r{Description}) }
it { is_expected.to contain_file("/etc/systemd/network/#{title}.network").without_content(%r{MTUBytes}) }
it { is_expected.not_to contain_ferm__rule("allow_wg_#{title}") }
end
context 'with required params and with firewall rules' do
Expand Down Expand Up @@ -135,6 +136,52 @@ class {"systemd":
it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_file("/etc/systemd/network/#{title}.netdev").with_content(%r{Description=bla}) }
end
context 'with MTU' do
let :params do
{
public_key: 'blabla==',
endpoint: 'wireguard.example.com:1234',
manage_firewall: false,
mtu: 9000,
# we need to set destination_addresses to overwrite the default
# that would configure IPv4+IPv6, but GHA doesn't provide IPv6 for us
destination_addresses: [facts[:networking]['ip'],],
}
end

it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_file("/etc/systemd/network/#{title}.netdev").with_content(%r{MTUBytes=9000}) }
end
context 'with too high MTU' do
let :params do
{
public_key: 'blabla==',
endpoint: 'wireguard.example.com:1234',
manage_firewall: false,
mtu: 9001,
# we need to set destination_addresses to overwrite the default
# that would configure IPv4+IPv6, but GHA doesn't provide IPv6 for us
destination_addresses: [facts[:networking]['ip'],],
}
end

it { is_expected.not_to compile.with_all_deps }
end
context 'with MTU as string' do
let :params do
{
public_key: 'blabla==',
endpoint: 'wireguard.example.com:1234',
manage_firewall: false,
mtu: '9000',
# we need to set destination_addresses to overwrite the default
# that would configure IPv4+IPv6, but GHA doesn't provide IPv6 for us
destination_addresses: [facts[:networking]['ip'],],
}
end

it { is_expected.not_to compile.with_all_deps }
end
end
end
end