Git Product home page Git Product logo

puppet-wireguard's Introduction

puppet-wireguard

Build Status Release Puppet Forge Puppet Forge - downloads Puppet Forge - endorsement Puppet Forge - scores puppetmodule.info docs AGPL v3 License

Puppet module to configure wireguard through systemd-networkd configs

Setup

The module can create firewall rules with voxpupuli/nftables. This is enabled by default but can be disabled by setting the manage_firewall parameter to false in the wireguard::interface defined resource. You need to have the nftables class in your catalog to use the feature (Version 3.6.0 or newer).

Version 3 and older of the module use voxpupuli/ferm to manage firewall rules

This module can use systemd-networkd or wg-quick to configure tunnels. For the former, you need to have a systemd-networkd service resource in your catalog. We recommend voxpupuli/systemd with manage_networkd set to true. You do not need to configure your entire network with systemd-networkd, only the tunnels. That said, wg-quick might be better a better match if you do not want to touch systemd.

Furthermore, this module assumes that you've a dualstack machine. Your IPv4 and IPv6 addresses will be automatically set to the destination_addresses array from the wireguard::interface defined resource. If you don't have dualstack you need to overwrite the parameter.

There is a structured fact called wireguard_pubkeys which is a hash with each filename without the .pub and the content (the public key):

# facter -p wireguard_pubkeys
{
  as1234 => "40mH10BbolserhidsruhieudrstlJBB7fxvoPlU=",
  as5678 => "Tci/bHoPColserjfoisehrjioesurrhGpEN+NDueNjUvBA=",
  asblub => "M7lTopd2koserhioesrhiouwerhpcvqSWEviI=",
  notebook => "sK9Ld+p1eH4id+BAuM6lserheoishriouwKhgwFf/HRw=",
  lan => "dIXj6QcWGBWTzq0pwoerjow4eroiwe4jr4CGkXUID3J8rO2k="
}

Example configurations

configure a tunnel with the name as9876.

  • listen for incoming traffic on port 9876
  • create a ferm rule to allow traffic on the global IPv4/IPv6 addresses
  • configure the provided public key from the peer
  • assign a IPv4 and IPv6 prefix on the tunnel interface
wireguard::interface {'as9876':
  source_addresses => ['2003:4e0:c17:5d::1', '195.37.53.176'],
  public_key       => 'BcxLll1BVxGkehriuehrFvjvX+EBhS4vcDn0R0=',
  endpoint         => 'wireguard.example.com:53668',
  addresses        => [{'Address' => '192.168.123.6/30',},{'Address' => 'fe80::beef:1/64'},],
}

configure a tunnel with the name as1234

  • listen on port 9876
  • don't create firewall rules
  • assign a IPv4 and IPv6 prefix on the tunnel interface
    • use /32 for the IPv4 address and add a peer route
wireguard::interface {'as1234':
  manage_firewall => false,
  public_key      => 'B1xSG/XTJRLd+GrWDsB06BqnIq8Xud93YVh/LYYYtUY=',
  endpoint        => 'wireguard.example.com:53668',
  addresses       => [{'Address' => '192.168.218.87/32', 'Peer' => '172.20.53.97/32'}, {'Address' => 'fe80::ade1/64',},],
}

More examples are available in the REFERENCE.md file.

Parameter reference

All parameters are documented with puppet-strings. You can view the markdown-rendered result at REFERENCE.md.

Tests

This module has several unit tests and linters configured. You can execute them by running:

bundle exec rake test

Detailed instructions are in the CONTRIBUTING.md file.

Contributions

Contribution is fairly easy:

  • Fork the module into your namespace
  • Create a new branch
  • Commit your bugfix or enhancement
  • Write a test for it (maybe start with the test first)
  • Create a pull request

Detailed instructions are in the CONTRIBUTING.md file.

License and Author

This module was originally written by Tim Meusel. It's licensed with AGPL version 3.

puppet-wireguard's People

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

puppet-wireguard's Issues

Persistent keepalive setting not configured on simple interface with systemd-networkd provider

Affected Puppet, Ruby, OS and module versions/distributions

  • Puppet: 5.5
  • Ruby: 2.5
  • Distribution: Debian
  • Module version: 2.2.0

How to reproduce (e.g Puppet code you use)

wireguard::interface {
    'wg0':
      manage_firewall      => false,
      endpoint             => '10.0.0.1:51820',
      dport                => 51820,
      addresses            => [{'Address' => '192.168.0.1/24'},],
      persistent_keepalive => 25,
      public_key           => '<key>';
}

What are you seeing

Persistent keepalive set to 0 on the interface.

What behaviour did you expect instead

Persistent keepalive configured to 25 seconds on the interface.

Output log

[NetDev]
Name=wg0
Kind=wireguard

[WireGuard]
PrivateKeyFile=/etc/wireguard/wg0
ListenPort=51820

[WireGuardPeer]
PublicKey=<key>
Endpoint=10.0.0.1:51820
PersistentKeepalive=0
AllowedIPs=fe80::/64
AllowedIPs=fd00::/8
AllowedIPs=0.0.0.0/0

Any additional information you'd like to impart

Support newer module dependency versions

Affected Puppet, Ruby, OS and module versions/distributions

  • Puppet: 7.23.0
  • Ruby: 3.1.2p20
  • Distribution: all
  • Module version: 3.0.0

How to reproduce (e.g Puppet code you use)

Read the website

What are you seeing

Dependencies for:

  • puppetlabs-stdlib < 9.0.0
  • puppet-systemd < 5.0.0

What behaviour did you expect instead

Dependencies for

  • puppetlabs-stdlib <= 9.2.0
  • puppet-systemd <= 5.2.0

Output log

Any additional information you'd like to impart

Setting wireguard::interaces causes a dependency cycle

Affected Puppet, Ruby, OS and module versions/distributions

  • Puppet: 7.16.0
  • Ruby: 2.7.6
  • Distribution: any
  • Module version: 1.1.1-rc0

How to reproduce (e.g Puppet code you use)

Set wireguard::interfaces in Hiera and include wireguard.

What are you seeing

Error: Found 1 dependency cycle:
(Exec[generate public key wg0] => Wireguard::Interface[wg0] => Class[Wireguard] => Wireguard::Interface[wg0] => Exec[generate public key wg0])\nTry the '--graph' option and opening the resulting '.dot' file in OmniGraffle or GraphViz
Error: Failed to apply catalog: One or more resource dependency cycles detected in graph

What behaviour did you expect instead

Clean Puppet run

Any additional information you'd like to impart

The problem is a require instead of an include in the wireguard::interface defined type. PR incoming.

The group (in the /etc/wireguard/ permissions) should not be hard coded.

Affected Puppet, Ruby, OS and module versions/distributions

  • Puppet: all
  • Ruby: all
  • Distribution: Gentoo
  • Module version: 4.0.0

How to reproduce (e.g Puppet code you use)

  • Use the role on a system without systemd

What are you seeing

Error: /Stage[main]/Wireguard/File[/etc/wireguard]/group: change from 'root' to 'systemd-network' failed: Could not find group systemd-network

What behaviour did you expect instead

It would be better if the group was not hardcoded.

Output log

Error: /Stage[main]/Wireguard/File[/etc/wireguard]/group: change from 'root' to 'systemd-network' failed: Could not find group systemd-network

v0.8.2 release summary

the V0.8.1 release had an issue in the Rakefile which prevented the release. V0.8.2 fixes only this and is otherwise identical to the v0.8.1 release.

dport should be 51820 by default

Currently, dport are the last digits of the title by default. This configuration is quite opinionated and not something a user would expect. It should default to the standard WireGuard port, 51820.

Note: This would be a major version change.

Please add support for Table= option in wg-quick

I would like to turn off routing table modification by wg-quick - this can be done by entering Table=off in the configuration file (it also supports other options than off).

From man wg-quick:

       •      Table — Controls the routing table to which routes are added. There are two special values: `off' disables the creation of routes altogether, and `auto' (the default) adds routes to the default table and enables special handling  of
              default routes.

Currently this is not configurable in the Puppet module. I am allowing all IPs over the tunnel but do not want wireguard to enter any default routes over it.

The systemd provider equivalent would, I believe, be RouteTable=off under [WireGuardPeer] in the netdev file.

Support newer module dependency versions

Affected Puppet, Ruby, OS and module versions/distributions

  • Puppet: v7.28.0
  • Ruby: ruby 2.7.8p225
  • Distribution: all
  • Module version: 4.0.1

How to reproduce (e.g Puppet code you use)

Trying to add module with puppet module install puppet/wireguard

What are you seeing

Error: Could not install module 'puppet-wireguard' (v4.0.1)
  The requested version cannot satisfy one or more of the following installed modules:
    puppet-systemd, installed: 6.3.0, expected: >= 3.0.0 < 6.0.0

What behaviour did you expect instead

Successful installation of the module with puppet-systemd version 6.3.0

Output log

Any additional information you'd like to impart

Publish 0.6.0 as 0.6.1

the 0.6.0 release wasn't successful because the CI pipeline failed. 0.6.1 contains the same Puppet code + a fixed Gemfile

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.