项目作者: jwhited

项目描述 :
A CoreDNS plugin that provides WireGuard peer information via DNS-SD semantics
高级语言: Go
项目地址: git://github.com/jwhited/wgsd.git
创建时间: 2020-05-09T23:24:24Z
项目社区:https://github.com/jwhited/wgsd

开源协议:Apache License 2.0

下载


wgsd

wgsd is a CoreDNS plugin that serves WireGuard® peer information via DNS-SD (RFC6763) semantics. This enables use cases such as:

  • Building a mesh of WireGuard peers from a central registry
  • Dynamic discovery of WireGuard Endpoint addressing (both IP address and port number)
  • NAT-to-NAT WireGuard connectivity where UDP hole punching is supported.

See this blog post for a deep dive on the underlying techniques and development thought.

Installation

Binary releases are available here.

There are two packages per GOOS/GOARCH for each release:

  • wgsd-coredns - CoreDNS server with all the “internal” plugins + wgsd
  • wgsd-client - A sample client

Building from source

External CoreDNS plugins can be enabled in one of two ways:

  1. Build with compile-time configuration file
  2. Build with external golang source code

For method #2 you can simply go build the contents of cmd/coredns. The resulting binary is CoreDNS server with all the “internal” plugins + wgsd.

  1. % go build
  2. % ./coredns -plugins | grep wgsd
  3. dns.wgsd

A basic client is available under cmd/wgsd-client.

Configuration Syntax

  1. wgsd ZONE DEVICE
  • ZONE is the zone name wgsd should be authoritative for, e.g. example.com.
  • DEVICE is the name of the WireGuard interface, e.g. wg0
  1. wgsd ZONE DEVICE {
  2. self [ ENDPOINT ] [ ALLOWED-IPS ... ]
  3. }
  • Supplying the self option enables serving data about the local WireGuard device in addition to its peers. The optional ENDPOINT argument enables setting a custom endpoint in ip:port form. If ENDPOINT is omitted wgsd will default to the local IP address for the DNS query and ListenPort of the WireGuard device. This can be useful if your host is behind NAT. The optional, variadic ALLOWED-IPS argument sets allowed-ips to be served for the local WireGuard device.

Querying

Following RFC6763 this plugin provides a listing of peers via PTR records at the namespace _wireguard._udp.<zone>. The target for the PTR records is of the format <base32PubKey>._wireguard._udp.<zone>. This same format is used for the accompanying SRV, A/AAAA, and TXT records. When querying the SRV record for a peer, the target A/AAAA & TXT records will be included in the “additional” section of the response. TXT records include Base64 public key and allowed IPs. Public keys are represented in Base32 rather than Base64 in record names as they are treated as case-insensitive by the DNS.

Example

This configuration:

  1. $ cat Corefile
  2. .:5353 {
  3. wgsd example.com. wg0 {
  4. self 192.0.2.1:51820 10.0.0.254/32
  5. }
  6. }

With the following WireGuard peers:

  1. $ sudo wg show
  2. interface: wg0
  3. public key: JeZlz14G8tg1Bqh6apteFCwVhNhpexJ19FDPfuxQtUY=
  4. private key: (hidden)
  5. listening port: 51820
  6. peer: xScVkH3fUGUv4RrJFfmcqm8rs3SEHr41km6+yffAHw4=
  7. endpoint: 203.0.113.1:7777
  8. allowed ips: 10.0.0.1/32
  9. latest handshake: 14 hours, 24 minutes, 40 seconds ago
  10. transfer: 840.64 KiB received, 85.54 KiB sent
  11. peer: syKB97XhGnvC+kynh2KqQJPXoOoOpx/HmpMRTc+r4js=
  12. endpoint: 198.51.100.1:8888
  13. allowed ips: 10.0.0.2/32
  14. latest handshake: 4 days, 15 hours, 8 minutes, 12 seconds ago
  15. transfer: 1.38 MiB received, 139.42 KiB sent

Will respond with:

  1. $ dig @127.0.0.1 -p 5353 _wireguard._udp.example.com. PTR +noall +answer +additional
  2. _wireguard._udp.example.com. 0 IN PTR yutrled535igkl7bdlerl6m4vjxsxm3uqqpl4nmsn27mt56ad4ha====._wireguard._udp.example.com.
  3. _wireguard._udp.example.com. 0 IN PTR wmrid55v4enhxqx2jstyoyvkicj5pihkb2tr7r42smiu3t5l4i5q====._wireguard._udp.example.com.
  4. _wireguard._udp.example.com. 0 IN PTR extglt26a3znqnigvb5gvg26cqwblbgynf5re5pukdhx53cqwvda====._wireguard._udp.example.com.
  5. $
  6. $ dig @127.0.0.1 -p 5353 yutrled535igkl7bdlerl6m4vjxsxm3uqqpl4nmsn27mt56ad4ha====._wireguard._udp.example.com. SRV +noall +answer +additional
  7. yutrled535igkl7bdlerl6m4vjxsxm3uqqpl4nmsn27mt56ad4ha====._wireguard._udp.example.com. 0 IN SRV 0 0 7777 yutrled535igkl7bdlerl6m4vjxsxm3uqqpl4nmsn27mt56ad4ha====._wireguard._udp.example.com.
  8. yutrled535igkl7bdlerl6m4vjxsxm3uqqpl4nmsn27mt56ad4ha====._wireguard._udp.example.com. 0 IN A 203.0.113.1
  9. yutrled535igkl7bdlerl6m4vjxsxm3uqqpl4nmsn27mt56ad4ha====._wireguard._udp.example.com. 0 IN TXT "txtvers=1" "pub=xScVkH3fUGUv4RrJFfmcqm8rs3SEHr41km6+yffAHw4=" "allowed=10.0.0.1/32"
  10. $
  11. $ dig @127.0.0.1 -p 5353 wmrid55v4enhxqx2jstyoyvkicj5pihkb2tr7r42smiu3t5l4i5q====._wireguard._udp.example.com. SRV +noall +answer +additional
  12. wmrid55v4enhxqx2jstyoyvkicj5pihkb2tr7r42smiu3t5l4i5q====._wireguard._udp.example.com. 0 IN SRV 0 0 8888 wmrid55v4enhxqx2jstyoyvkicj5pihkb2tr7r42smiu3t5l4i5q====._wireguard._udp.example.com.
  13. wmrid55v4enhxqx2jstyoyvkicj5pihkb2tr7r42smiu3t5l4i5q====._wireguard._udp.example.com. 0 IN A 198.51.100.1
  14. wmrid55v4enhxqx2jstyoyvkicj5pihkb2tr7r42smiu3t5l4i5q====._wireguard._udp.example.com. 0 IN TXT "txtvers=1" "pub=syKB97XhGnvC+kynh2KqQJPXoOoOpx/HmpMRTc+r4js=" "allowed=10.0.0.2/32"
  15. $
  16. $ dig @127.0.0.1 -p 5353 extglt26a3znqnigvb5gvg26cqwblbgynf5re5pukdhx53cqwvda====._wireguard._udp.example.com. SRV +noall +answer +additional
  17. extglt26a3znqnigvb5gvg26cqwblbgynf5re5pukdhx53cqwvda====._wireguard._udp.example.com. 0 IN SRV 0 0 51820 extglt26a3znqnigvb5gvg26cqwblbgynf5re5pukdhx53cqwvda====._wireguard._udp.example.com.
  18. extglt26a3znqnigvb5gvg26cqwblbgynf5re5pukdhx53cqwvda====._wireguard._udp.example.com. 0 IN A 192.0.2.1
  19. extglt26a3znqnigvb5gvg26cqwblbgynf5re5pukdhx53cqwvda====._wireguard._udp.example.com. 0 IN TXT "txtvers=1" "pub=JeZlz14G8tg1Bqh6apteFCwVhNhpexJ19FDPfuxQtUY=" "allowed=10.0.0.254/32"

Converting public keys to Base64 with coreutils:

  1. $ echo yutrled535igkl7bdlerl6m4vjxsxm3uqqpl4nmsn27mt56ad4ha==== | tr '[:lower:]' '[:upper:]' | base32 -d | base64
  2. xScVkH3fUGUv4RrJFfmcqm8rs3SEHr41km6+yffAHw4=
  3. $ echo wmrid55v4enhxqx2jstyoyvkicj5pihkb2tr7r42smiu3t5l4i5q==== | tr '[:lower:]' '[:upper:]' | base32 -d | base64
  4. syKB97XhGnvC+kynh2KqQJPXoOoOpx/HmpMRTc+r4js=
  5. $ echo extglt26a3znqnigvb5gvg26cqwblbgynf5re5pukdhx53cqwvda==== | tr '[:lower:]' '[:upper:]' | base32 -d | base64
  6. JeZlz14G8tg1Bqh6apteFCwVhNhpexJ19FDPfuxQtUY=

TODOs

  • unit tests
  • SOA record support
  • CI & release binaries

WireGuard is a registered trademark of Jason A. Donenfeld.