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 description attribute for network interface #18

Merged
merged 1 commit into from
Aug 14, 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
9 changes: 9 additions & 0 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ The following parameters are available in the `wireguard::interface` defined typ
* [`endpoint`](#endpoint)
* [`addresses`](#addresses)
* [`persistent_keepalive`](#persistent_keepalive)
* [`description`](#description)

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

Expand Down Expand Up @@ -191,3 +192,11 @@ is set to 1 or greater, that's the interval in seconds wireguard sends a keepali

Default value: `0`

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

Data type: `Optional[String[1]]`

an optional string that will be added to the wireguard network interface

Default value: ``undef``

9 changes: 7 additions & 2 deletions manifests/interface.pp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
# @param endpoint fqdn:port or ip:port where we connect to
# @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
#
# @author Tim Meusel <[email protected]>
#
Expand Down Expand Up @@ -51,6 +52,7 @@
Boolean $manage_firewall = true,
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,
) {
require wireguard

Expand Down Expand Up @@ -92,12 +94,15 @@
}
# lint:ignore:strict_indent
$netdev_config = @(EOT)
<%- | $interface, $dport, $public_key, $endpoint | -%>
<%- | $interface, $dport, $public_key, $endpoint, $description | -%>
# THIS FILE IS MANAGED BY PUPPET
# based on https://dn42.dev/howto/wireguard
[NetDev]
Name=<%= $interface %>
Kind=wireguard
<% if $description { -%>
Description=<%= $description %>
<%} -%>

[WireGuard]
PrivateKeyFile=/etc/wireguard/<%= $interface %>
Expand All @@ -114,7 +119,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 }),
content => inline_epp($netdev_config, { 'interface' => $interface, 'dport' => $dport, 'public_key' => $public_key, 'endpoint' => $endpoint, 'description' => $description }),
restart_service => true,
owner => 'root',
group => 'systemd-network',
Expand Down
17 changes: 17 additions & 0 deletions spec/defines/interface_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
it { is_expected.to contain_file("/etc/systemd/network/#{title}.netdev").with_content(%r{ListenPort=1234}) }
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.not_to contain_ferm__rule("allow_wg_#{title}") }
end
context 'with required params and with firewall rules' do
Expand Down Expand Up @@ -118,6 +119,22 @@ class {"systemd":
it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_ferm__rule("allow_wg_#{title}").without_daddr }
end
context 'with description' do
let :params do
{
public_key: 'blabla==',
endpoint: 'wireguard.example.com:1234',
manage_firewall: false,
description: 'bla',
# 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{Description=bla}) }
end
end
end
end