23

Is there an open-source tool to bulk-generate wireguard configurations without managing the wireguard installation itself?

I have an existing server set up with a special wireguard configuration that I created manually. I want to add a standard VPN server configuration to that machine without affecting the existing configuration. I've used tools for this in the past, but they all work on the premise that wireguard isn't already installed and that only said tool is used to managed the installation. I'm worried this might break my existing config, so what I want is something to automate generating keys and writing configuration files, without interacting with the existing wireguard installation. Does this exist?

all 5 comments
sorted by: hot top new old
[-] rambos@lemm.ee 2 points 3 years ago

Creating a new client should be possible without messing up existing one. There are some options for managing clients using GUI like pivpn. I personally use OMV with wireguard extension

[-] Skyline@lemmy.cafe 1 points 3 years ago

Sure, it's possible. I could do it by hand, but the more clients you want to add, the more cumbersome the process. What I'd like is a tool to automate what is mostly a templating process.

[-] aard@kyu.de 2 points 3 years ago* (last edited 3 years ago)

This should be trivially scriptable by ansible. Ideally you'd also transform your existing configuration into an ansible data structure so it can write out the complete config as that way is just more reliably - but ansible also is capable of editing stuff in place.

I'm using a structure like this:

wireguard:
  wg-mgmt:
    interface:
      address: 192.168.1.10/24
      listen_port: 34800
      private_key_file: /etc/wireguard/private.key
      passdb_entry: vpn/fi1-mgmt
    peers:
      aard_meteor:
        public_key: bmV2ZXIgZ29ubmEgZ2l2ZSB5b3UgdXAK
        allowed_ips:
          - 192.168.1.11/32
      aard_zak:
        public_key: bmV2ZXIgZ29ubmEgbGV0IHlvdSBkb3duCg==
        allowed_ips:
          - 192.168.1.12/32

To set up both server and client. I'm mostly adding other peoples systems, so I don't know the private keys, and receive the public ones from them - but if you control both it's also trivial to pull that information from the system you're generating it on, and reuse it later.

This is the template used for the wireguard configuration, this the task managing the wireguard setup.

Getting the pubkey from a private key into a variable in ansible would look something like this:

- name: dump pubkey
  shell: "wg pubkey < {{_pubkey_file}}"
  register: _wg_pubkey
  changed_when: false

- name: register pubkey
  set_fact:
    wg_pubkey: "{{_wg_pubkey.stdout}}"
  when: >
     _wg_pubkey is defined

It's then easy to dump it into a password store or something like that - if you check the repo in above links you'll see pass heavily used.

[-] dud3@feddit.de 1 points 3 years ago
this post was submitted on 04 Sep 2023
23 points (92.6% liked)

Selfhosted

62860 readers
1384 users here now

A place to share alternatives to popular online services that can be self-hosted without giving up privacy or locking you into a service you don't control.

Rules:

Detailed Rules Post

  1. Be civil.

  2. No spam.

  3. Posts are to be related to self-hosting.

  4. Don't duplicate the full text of your blog or readme if you're providing a link.

  5. Submission headline should match the article title.

  6. No trolling.

  7. Promotion posts require active participation, with an account that is at least 30 days old. F/LOSS without a paywall has exceptions, with requirements. See the rules link for details. Tags [CBH] or [AIP] are required, see the links in Rule 8 for details.

  8. AI-related discussions and AI-involved promotional posts have additional requirements for tagging, as noted in Rule 7 and the AI & Promotional Post Expanded Rules post, and find example disclosures here.

Resources:

Any issues on the community? Report it using the report flag.

Questions? DM the mods!

founded 3 years ago
MODERATORS