-
-
Notifications
You must be signed in to change notification settings - Fork 23
Exported peers #82
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
Open
brunoleon
wants to merge
12
commits into
voxpupuli:master
Choose a base branch
from
brunoleon:exported_peers
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Exported peers #82
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
5c65ea4
Add support for peers using exported ressources
brunoleon bbb00c3
Add service management for wg-quick
brunoleon baaaf40
Add dependency to concat
brunoleon a49e9d2
Add docstrings
brunoleon dc0ba16
Update REFERENCE.md
brunoleon a5bd8b7
Check if wireguard_pubkeys fact is present
brunoleon c705d2a
Set String minimal length to [1]
brunoleon 17d5d61
Do not use Optional on Array type
brunoleon 3d941f1
fix typo
brunoleon 73b03e1
fix indentation
brunoleon d86a24b
Update REFERENCE.md
brunoleon 32e8dd0
Update $fqdn fact syntax
brunoleon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,6 +24,7 @@ | |
| # @param postup_cmds is an array of commands which should run as preup command (only supported by wgquick) | ||
| # @param predown_cmds is an array of commands which should run as preup command (only supported by wgquick) | ||
| # @param postdown_cmds is an array of commands which should run as preup command (only supported by wgquick) | ||
| # @param allowed_ips different addresses that should be routed to this peer | ||
| # | ||
| # @author Tim Meusel <[email protected]> | ||
| # @author Sebastian Rakel <[email protected]> | ||
|
|
@@ -105,6 +106,7 @@ | |
| Boolean $manage_firewall = true, | ||
| Array[Stdlib::IP::Address] $source_addresses = [], | ||
| Array[Hash[String,Variant[Stdlib::IP::Address::V4,Stdlib::IP::Address::V6]]] $addresses = [], | ||
| Array[Variant[Stdlib::IP::Address::V4,Stdlib::IP::Address::V6]] $allowed_ips = [], | ||
| Optional[String[1]] $description = undef, | ||
| Optional[Integer[1200, 9000]] $mtu = undef, | ||
| Optional[String[1]] $public_key = undef, | ||
|
|
@@ -243,4 +245,22 @@ | |
| fail("provider ${provider} not supported") | ||
| } | ||
| } | ||
| if 'wireguard_pubkeys' in $facts { | ||
| if $interface in $facts['wireguard_pubkeys'] { | ||
| $peer_params = { | ||
| 'description' => $description, | ||
| 'public_key' => $facts['wireguard_pubkeys'][$interface], | ||
| 'endpoint' => "${facts['networking']['fqdn']}:${dport}", | ||
| 'allowed_ips' => $allowed_ips, | ||
| 'preshared_key' => $preshared_key, | ||
| 'persistent_keepalive' => $persistent_keepalive, | ||
| 'interface' => $interface, | ||
| 'tag' => "wireguard-${interface}", | ||
| } | ||
| @@wireguard::peer { "${facts['networking']['fqdn']}-${interface}-peer": | ||
| * => $peer_params, | ||
| } | ||
| } | ||
| } | ||
| Wireguard::Peer <<| tag == "wireguard-${interface}" |>> | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| # @summary define a wireguard peer | ||
| # | ||
| # @param interface the title of the defined resource, will be used for the targetted wg interface | ||
| # @param description provide some identification details about the peer | ||
| # @param public_key base64 encoded pubkey from the remote peer | ||
| # @param endpoint fqdn:port or ip:port where we connect to | ||
| # @param allowed_ips different addresses that should be routed to this peer | ||
| # @param preshared_key Define preshared key for the remote peer | ||
| # @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 | ||
| # | ||
| define wireguard::peer ( | ||
| String[1] $interface, | ||
| Optional[String[1]] $description = undef, | ||
| String[1] $public_key, | ||
| String[1] $endpoint, | ||
| Array[Variant[Stdlib::IP::Address::V4,Stdlib::IP::Address::V6]] $allowed_ips, | ||
| Optional[String[1]] $preshared_key = undef, | ||
| Integer[0,65535] $persistent_keepalive = 0, | ||
| ) { | ||
| $peer_params = { | ||
| 'description' => $description, | ||
| 'public_key' => $public_key, | ||
| 'endpoint' => $endpoint, | ||
| 'allowed_ips' => $allowed_ips, | ||
| 'preshared_key' => $preshared_key, | ||
| 'persistent_keepalive' => $persistent_keepalive, | ||
| } | ||
|
|
||
| concat::fragment { $name: | ||
| order => 20, | ||
| target => "/etc/wireguard/${interface}.conf", | ||
| content => epp("${module_name}/wireguard_peer.epp", $peer_params), | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| <%- | | ||
| String[1] $interface, | ||
| Stdlib::Port $dport, | ||
| Optional[Integer] $firewall_mark, | ||
| Array[Hash] $addresses, | ||
| Array[String[1]] $preup_cmds, | ||
| Array[String[1]] $postup_cmds, | ||
| Array[String[1]] $predown_cmds, | ||
| Array[String[1]] $postdown_cmds, | ||
| Optional[Integer[1280, 9000]] $mtu = undef, | ||
| | -%> | ||
| # THIS FILE IS MANAGED BY PUPPET | ||
| <% $addresses.each |$address| { -%> | ||
|
|
||
| [Interface] | ||
| <% $address.each |$key, $value| { -%> | ||
| <%= $key %>=<%= $value %> | ||
| <% } -%> | ||
| <% } -%> | ||
| ListenPort=<%= $dport %> | ||
| <% if $firewall_mark { -%> | ||
| FwMark=<%= $firewall_mark %> | ||
| <% } -%> | ||
| <% $preup_cmds.each |$cmd| { -%> | ||
| PreUp=<%= $cmd %> | ||
| <% } -%> | ||
| PostUp=wg set %i private-key /etc/wireguard/<%= $interface %> | ||
| <% $postup_cmds.each |$cmd| { -%> | ||
| PostUp=<%= $cmd %> | ||
| <% } -%> | ||
| <% $predown_cmds.each |$cmd| { -%> | ||
| PreDown=<%= $cmd %> | ||
| <% } -%> | ||
| <% $postdown_cmds.each |$cmd| { -%> | ||
| PostDown=<%= $cmd %> | ||
| <% } -%> | ||
| <% if $mtu { -%> | ||
| MTU=<%= $mtu %> | ||
| <% } -%> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| <%- | | ||
| Optional[String[1]] $description, | ||
| String[1] $public_key, | ||
| String[1] $endpoint, | ||
| Optional[String[1]] $preshared_key, | ||
| Optional[Integer[0,65535]] $persistent_keepalive, | ||
| Array[Variant[Stdlib::IP::Address::V4,Stdlib::IP::Address::V6]] $allowed_ips, | ||
| | -%> | ||
|
|
||
| <% if $description { -%> | ||
| # <%= $description %> | ||
| <% } -%> | ||
| [Peer] | ||
| PublicKey=<%= $public_key %> | ||
| Endpoint=<%= $endpoint %> | ||
| <% if $preshared_key { -%> | ||
| PresharedKey=<%= $preshared_key %> | ||
| <% } -%> | ||
| PersistentKeepalive=<%= pick($persistent_keepalive, 0) %> | ||
| <% pick($allowed_ips, ['fe80::/64', 'fd00::/8', '0.0.0.0/0']).each |$allowed_ip| { -%> | ||
| AllowedIPs=<%= $allowed_ip %> | ||
| <% } -%> |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a benefit for checking if
wireguard_pubkeysis in$factsand not directly usingif $interface in $facts['wireguard_pubkeys']?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wireguard_pubkeysfact is not present in facts on first run , so we cannot check is$interfaceis present in it