Skip to content

Commit

Permalink
merge ui changes
Browse files Browse the repository at this point in the history
  • Loading branch information
aschmidt75 committed Apr 2, 2021
2 parents d9fb44c + dbb8298 commit 08ca9ec
Show file tree
Hide file tree
Showing 23 changed files with 13,036 additions and 11 deletions.
6 changes: 3 additions & 3 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
# Make sure to check the documentation at http://goreleaser.com
before:
hooks:
# You may remove this if you don't use go modules.
- go mod download
# you may remove this if you don't need go generate
- go generate ./...
builds:
- env:
- CGO_ENABLED=0
goos:
- linux
hooks:
pre: make gen web
post: rice append -v -i github.com/aschmidt75/wgmesh/meshservice --exec {{ .Path }}
archives:
- replacements:
linux: Linux
Expand Down
13 changes: 11 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@ BINARY_NAME = wgmesh
NOW = `date +"%Y-%m-%d_%H-%M-%S"`
MAIN_GO_PATH=wgmesh.go

all: clean gen lint build
all: clean gen lint build web webappend

.PHONY: build
build: gen
CGO_ENABLED=0 GOOS=linux go build -i -v -o dist/${BINARY_NAME} ${MAIN_GO_PATH}

.PHONY: web
web:
( cd web && npm install && npm run build )

.PHONY: staticcheck
staticcheck:
staticcheck ./...
Expand All @@ -24,12 +28,17 @@ lint:
gen:
(cd meshservice ; protoc --go_opt=paths=source_relative --go-grpc_opt=paths=source_relative --go_out=. --go-grpc_out=. meshservice.proto agent.proto)

.PHONY: webappend
webappend:
( cd meshservice && rice append --exec ../dist/${BINARY_NAME} )

.PHONY: release
release: gen
release: gen webappend
goreleaser --snapshot --rm-dist

.PHONY: clean
clean:
rm -rf dist/*
rm -fr web/dist
rm -f cover.out
go clean -testcache
30 changes: 26 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ Automatically build private wireguard mesh networks.
[![Go Report Card](https://goreportcard.com/badge/github.com/aschmidt75/wgmesh)](https://goreportcard.com/report/github.com/aschmidt75/wgmesh)
[![Go](https://github.com/aschmidt75/wgmesh/actions/workflows/go.yml/badge.svg)](https://github.com/aschmidt75/wgmesh/actions/workflows/go.yml)

![wgmesh Dashboard](docs/wgmesh-ui-sample.png)

## How it works

* A mesh consist of interconnected nodes. Each node has a [wireguard](https://www.wireguard.com/) interface with all other nodes registered as peers. The mesh is thus fully-connected through the wireguard-based overlay network. Each node can IP-reach all other nodes via direct host routes.
* A mesh consist of interconnected nodes. Each node has a [wireguard](https://www.wireguard.com/) interface with all other nodes registered as peers. The mesh is fully-connected through the wireguard-based overlay network. Each node can IP-reach all other nodes via direct host routes.
* At least one of the mesh nodes is a bootstrap node. Besides the wireguard peerings it runs a gRPC-based mesh endpoint, where other nodes can issue join requests.
* New nodes can enter the mesh by joining via a bootstrap node. The bootstrap node learns about the joining node and its wireguard endpoint and public key. It distributes this information to the other mesh nodes. It also fowards a list of mesh peers to the new joining node so it is able to configure its own wireguard interface.
* Existing mesh nodes learn about the new joining node from the bootstrap node and update their wireguard peer configuration accordingly.
Expand All @@ -16,10 +18,17 @@ Automatically build private wireguard mesh networks.

## Build

The default targets of `Makefile` generate protobuf and grpc parts and build the binary in `dist/`
The default targets of `Makefile` generate protobuf and grpc parts and build the binary in `dist/`. It also builds the web ui (and needs node/npm for this), and
appends the web artifacts using [go.rice](https://github.com/GeertJohan/go.rice).

```bash
$ make all
```

The binary can be built without web ui support:

```bash
$ make
$ make clean gen build
```

Additionally, goreleaser can be used to create a snapshot release for different platforms (also in `dist/`)
Expand All @@ -28,11 +37,18 @@ Additionally, goreleaser can be used to create a snapshot release for different
$ make release
```

So for a full, releaseable build one needs
* go (tested w/ version go1.15.5 darwin/amd64)
* [rice](https://github.com/GeertJohan/go.rice)
* node (tested w/ v14.16.0)
* npm (tested w/ 6.14.11)
* [goreleaser](https://github.com/goreleaser/goreleaser) (tested w/ version 0.155.0)

## Prerequisites

* Linux
* Wireguard module installed/enabled in kernel
* Works best with a non-NATed setup. It may work with a NAT, but there's no guarantee.
* Works best with a non-NATed setup. It can partially work with NAT, but there's no guarantee.

## Usage

Expand Down Expand Up @@ -106,7 +122,13 @@ xoJbYw07PMAE8B8DB |10.232.184.219 |alive |7 | _addr=, _port=54540, |
xoJbYw07PMAE80101 |10.232.1.1 |alive |38 | _addr=, _port=54540, |
```

The `ui` command start an HTTP server, serving a simple, vue-based dashboard. By default it binds
to port 9095 on the localhost interface only. It does not authenticate clients and does not (yet) support TLS.

```bash
# wgmesh ui
Serving files on 127.0.0.1:9095, press ctrl-C to exit
```

## License

Expand Down
1 change: 1 addition & 0 deletions cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ var cmds = []Runner{
NewTagsCommand(),
NewRTTCommand(),
NewInfoCommand(),
NewUICommand(),
}

// ProcessCommands takes the command line arguments and
Expand Down
1 change: 1 addition & 0 deletions cmd/help.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ func DisplayHelp(vi VersionInfo) {
fmt.Println(" info Print out information about the mesh and its nodes")
fmt.Println(" tags Set or remove tags on nodes")
fmt.Println(" rtt Query RTTs for all nodes")
fmt.Println(" ui Starts the web user interface")
fmt.Println()
}
65 changes: 65 additions & 0 deletions cmd/ui.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package cmd

import (
"flag"

meshservice "github.com/aschmidt75/wgmesh/meshservice"
log "github.com/sirupsen/logrus"
)

// UICommand struct
type UICommand struct {
CommandDefaults

fs *flag.FlagSet
agentGrpcSocket string
httpBindAddr string
httpBindPort int
}

// NewUICommand creates the UI Command structure and sets the parameters
func NewUICommand() *UICommand {
c := &UICommand{
CommandDefaults: NewCommandDefaults(),
fs: flag.NewFlagSet("ui", flag.ContinueOnError),
agentGrpcSocket: "/var/run/wgmesh.sock",
httpBindAddr: envStrWithDefault("WGMESH_HTTP_BIND_ADDR", "127.0.0.1"),
httpBindPort: envIntWithDefault("WGMESH_HTTP_BIND_PORT", 9095),
}

c.fs.StringVar(&c.agentGrpcSocket, "agent-grpc-socket", c.agentGrpcSocket, "agent socket to dial")
c.fs.StringVar(&c.httpBindAddr, "http-bind-addr", c.httpBindAddr, "HTTP bind address")
c.fs.IntVar(&c.httpBindPort, "http-bind-port", c.httpBindPort, "HTTP bind port")

c.DefaultFields(c.fs)

return c
}

// Name returns the name of the command
func (g *UICommand) Name() string {
return g.fs.Name()
}

// Init sets up the command struct from arguments
func (g *UICommand) Init(args []string) error {
err := g.fs.Parse(args)
if err != nil {
return err
}
g.ProcessDefaults()

return nil
}

// Run starts an http server to serve the user interface
func (g *UICommand) Run() error {
log.WithField("g", g).Trace(
"Running cli command",
)

uiServer := meshservice.NewUIServer(g.agentGrpcSocket, g.httpBindAddr, g.httpBindPort)
uiServer.Serve()

return nil
}
Binary file added docs/wgmesh-ui-sample.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ go 1.15
replace github.com/aschmidt75/wgmesh/cmd => ./cmd

require (
github.com/GeertJohan/go.rice v1.0.2
github.com/armon/go-metrics v0.3.6 // indirect
github.com/aschmidt75/go-wg-wrapper v0.1.1-0.20210206151906-a540c071fbf8
github.com/cristalhq/jwt/v3 v3.0.12
Expand All @@ -24,7 +25,7 @@ require (
go.opencensus.io v0.22.6
golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad // indirect
golang.org/x/lint v0.0.0-20201208152925-83fdc39ff7b5 // indirect
golang.org/x/net v0.0.0-20210119194325-5f4716e94777 // indirect
golang.org/x/net v0.0.0-20210119194325-5f4716e94777
golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c // indirect
golang.org/x/text v0.3.5 // indirect
golang.org/x/tools v0.1.0 // indirect
Expand Down
17 changes: 16 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/DataDog/datadog-go v3.2.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ=
github.com/GeertJohan/go.incremental v1.0.0 h1:7AH+pY1XUgQE4Y1HcXYaMqAI0m9yrFqo/jt0CW30vsg=
github.com/GeertJohan/go.incremental v1.0.0/go.mod h1:6fAjUhbVuX1KcMD3c8TEgVUqmo4seqhv0i0kdATSkM0=
github.com/GeertJohan/go.rice v1.0.2 h1:PtRw+Tg3oa3HYwiDBZyvOJ8LdIyf6lAovJJtr7YOAYk=
github.com/GeertJohan/go.rice v1.0.2/go.mod h1:af5vUNlDNkCjOZeSGFgIJxDje9qdjsO6hshx0gTmZt4=
github.com/akavel/rsrc v0.8.0 h1:zjWn7ukO9Kc5Q62DOJCcxGpXC18RawVtYAGdz2aLlfw=
github.com/akavel/rsrc v0.8.0/go.mod h1:uLoCtb9J+EyAqh+26kdrTgmzRBFPGOolLWKpdxkKq+c=
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
Expand Down Expand Up @@ -35,9 +41,10 @@ github.com/circonus-labs/circonusllhist v0.1.3/go.mod h1:kMXHVDlOchFAehlya5ePtbp
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk=
github.com/cristalhq/jwt v1.2.0 h1:fHmMkFJvEbS4o04aQP8BmtJg7fqkYvd7r8er3sUdS4Q=
github.com/cristalhq/jwt/v3 v3.0.12 h1:hblvQJcmcBVt0TJgaaWHwRMa/nLVG1jUnCQGlv67rxs=
github.com/cristalhq/jwt/v3 v3.0.12/go.mod h1:XOnIXst8ozq/esy5N1XOlSyQqBd+84fxJ99FK+1jgL8=
github.com/daaku/go.zipexe v1.0.0 h1:VSOgZtH418pH9L16hC/JrgSNJbbAL26pj7lmD1+CGdY=
github.com/daaku/go.zipexe v1.0.0/go.mod h1:z8IiR6TsVLEYKwXAoE/I+8ys/sDkgTzSL0CLnGVd57E=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
Expand Down Expand Up @@ -120,6 +127,8 @@ github.com/hashicorp/memberlist v0.2.2 h1:5+RffWKwqJ71YPu9mWsF7ZOscZmwfasdA8kbdC
github.com/hashicorp/memberlist v0.2.2/go.mod h1:MS2lj3INKhZjWNqd3N0m3J+Jxf3DAOnAH9VT3Sh9MUE=
github.com/hashicorp/serf v0.9.5 h1:EBWvyu9tcRszt3Bxp3KNssBMP1KuHWyO51lz9+786iM=
github.com/hashicorp/serf v0.9.5/go.mod h1:UWDWwZeL5cuWDJdl0C6wrvrUwEqtQ4ZKBKKENpqIUyk=
github.com/jessevdk/go-flags v1.4.0 h1:4IU2WS7AumrZ/40jfhf4QVDMsQwqA7VEHozFRrGARJA=
github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
github.com/josharian/native v0.0.0-20200817173448-b6b71def0850 h1:uhL5Gw7BINiiPAo24A2sxkcDI0Jt/sqp1v5xQCniEFA=
github.com/josharian/native v0.0.0-20200817173448-b6b71def0850/go.mod h1:7X/raswPFr05uY3HiLlYeyQntB6OO7E/d2Cu7qoaN2w=
github.com/jsimonetti/rtnetlink v0.0.0-20190606172950-9527aa82566a/go.mod h1:Oz+70psSo5OFh8DBl0Zv2ACw7Esh6pPUphlvZG9x7uw=
Expand Down Expand Up @@ -168,6 +177,8 @@ github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJ
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
github.com/nkovacs/streamquote v1.0.0 h1:PmVIV08Zlx2lZK5fFZlMZ04eHcDTIFJCv/5/0twVUow=
github.com/nkovacs/streamquote v1.0.0/go.mod h1:BN+NaZ2CmdKqUuTUXUEm9j95B2TRbpOWpxbJYzzgUsc=
github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc=
github.com/pascaldekloe/goe v0.1.0/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc=
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
Expand Down Expand Up @@ -203,6 +214,10 @@ github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81P
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/tv42/httpunix v0.0.0-20150427012821-b75d8614f926/go.mod h1:9ESjWnEqriFuLhtthL60Sar/7RFoluCcXsuvEwTV5KM=
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
github.com/valyala/fasttemplate v1.0.1 h1:tY9CJiPnMXf1ERmG2EyK7gNUd+c6RKGD0IfU8WdUSz8=
github.com/valyala/fasttemplate v1.0.1/go.mod h1:UQGH1tvbgY+Nz5t2n7tXsz52dQxojPUpymEIMZ47gx8=
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
go.opencensus.io v0.22.6 h1:BdkrbWrzDlV9dnbzoP7sfN+dHheJ4J9JOaYxcUDL+ok=
go.opencensus.io v0.22.6/go.mod h1:XItmlyltB5F7CS4xOC1DcqMoFqwtC6OG2xF7mCv7P7E=
Expand Down
Loading

0 comments on commit 08ca9ec

Please sign in to comment.