From 9068792e614bd8907612210bd6e4abf75bafb0c3 Mon Sep 17 00:00:00 2001 From: Matthew R Kasun Date: Thu, 30 Dec 2021 06:45:45 -0500 Subject: [PATCH 01/35] update join command to use wg.conf file in all cases. --- netclient/ncutils/netclientutils_linux.go | 4 +- netclient/wireguard/common.go | 204 ++++++---------------- 2 files changed, 58 insertions(+), 150 deletions(-) diff --git a/netclient/ncutils/netclientutils_linux.go b/netclient/ncutils/netclientutils_linux.go index 4b2f3204..f1147295 100644 --- a/netclient/ncutils/netclientutils_linux.go +++ b/netclient/ncutils/netclientutils_linux.go @@ -34,7 +34,7 @@ func GetEmbedded() error { } // CreateUserSpaceConf - creates a user space WireGuard conf -func CreateUserSpaceConf(address string, privatekey string, listenPort string, mtu int32, perskeepalive int32, peers []wgtypes.PeerConfig) (string, error) { +func CreateUserSpaceConf(address string, privatekey string, listenPort string, mtu int32, dns string, perskeepalive int32, peers []wgtypes.PeerConfig) (string, error) { peersString, err := parsePeers(perskeepalive, peers) var listenPortString string if mtu <= 0 { @@ -48,6 +48,7 @@ func CreateUserSpaceConf(address string, privatekey string, listenPort string, m } config := fmt.Sprintf(`[Interface] Address = %s +DNS = %s PrivateKey = %s MTU = %s %s @@ -56,6 +57,7 @@ MTU = %s `, address+"/32", + dns, privatekey, strconv.Itoa(int(mtu)), listenPortString, diff --git a/netclient/wireguard/common.go b/netclient/wireguard/common.go index 9b28d908..53787881 100644 --- a/netclient/wireguard/common.go +++ b/netclient/wireguard/common.go @@ -2,11 +2,8 @@ package wireguard import ( "errors" - "fmt" "io/ioutil" "log" - "os" - "os/exec" "runtime" "strconv" "strings" @@ -140,165 +137,74 @@ func InitWireguard(node *models.Node, privkey string, peers []wgtypes.PeerConfig } nameserver := servercfg.CoreDNSAddr - network := node.Network - if nodecfg.Network != "" { - network = nodecfg.Network - } else if node.Network != "" { - network = node.Network - } - - if ncutils.IsKernel() { - setKernelDevice(ifacename, node.Address) - } - - nodeport := int(node.ListenPort) - conf := wgtypes.Config{} - if nodecfg.UDPHolePunch == "yes" && - nodecfg.IsServer == "no" && - nodecfg.IsIngressGateway != "yes" && - nodecfg.IsStatic != "yes" { - conf = wgtypes.Config{ - PrivateKey: &key, - ReplacePeers: true, - Peers: peers, - } + var newConf string + if node.UDPHolePunch != "yes" { + newConf, _ = ncutils.CreateUserSpaceConf(node.Address, key.String(), strconv.FormatInt(int64(node.ListenPort), 10), node.MTU, nameserver, node.PersistentKeepalive, peers) } else { - conf = wgtypes.Config{ - PrivateKey: &key, - ListenPort: &nodeport, - ReplacePeers: true, - Peers: peers, - } + newConf, _ = ncutils.CreateUserSpaceConf(node.Address, key.String(), "", node.MTU, nameserver, node.PersistentKeepalive, peers) } - if !ncutils.IsKernel() { - var newConf string - if node.UDPHolePunch != "yes" { - newConf, _ = ncutils.CreateUserSpaceConf(node.Address, key.String(), strconv.FormatInt(int64(node.ListenPort), 10), node.MTU, node.PersistentKeepalive, peers) - } else { - newConf, _ = ncutils.CreateUserSpaceConf(node.Address, key.String(), "", node.MTU, node.PersistentKeepalive, peers) - } - confPath := ncutils.GetNetclientPathSpecific() + ifacename + ".conf" - ncutils.PrintLog("writing wg conf file to: "+confPath, 1) - err = ioutil.WriteFile(confPath, []byte(newConf), 0644) + confPath := ncutils.GetNetclientPathSpecific() + ifacename + ".conf" + ncutils.PrintLog("writing wg conf file to: "+confPath, 1) + err = ioutil.WriteFile(confPath, []byte(newConf), 0644) + if err != nil { + ncutils.PrintLog("error writing wg conf file to "+confPath+": "+err.Error(), 1) + return err + } + if ncutils.IsWindows() { + wgConfPath := ncutils.GetWGPathSpecific() + ifacename + ".conf" + err = ioutil.WriteFile(wgConfPath, []byte(newConf), 0644) if err != nil { - ncutils.PrintLog("error writing wg conf file to "+confPath+": "+err.Error(), 1) + ncutils.PrintLog("error writing wg conf file to "+wgConfPath+": "+err.Error(), 1) return err } - if ncutils.IsWindows() { - wgConfPath := ncutils.GetWGPathSpecific() + ifacename + ".conf" - err = ioutil.WriteFile(wgConfPath, []byte(newConf), 0644) + confPath = wgConfPath + } + // spin up userspace / windows interface + apply the conf file + var deviceiface string + if ncutils.IsMac() { + deviceiface, err = local.GetMacIface(node.Address) + if err != nil || deviceiface == "" { + deviceiface = ifacename + } + } + if syncconf { + log.Println("syncing conf") + err = SyncWGQuickConf(ifacename, confPath) + } else { + d, _ := wgclient.Device(deviceiface) + for d != nil && d.Name == deviceiface { + _ = RemoveConf(ifacename, false) // remove interface first + time.Sleep(time.Second >> 2) + d, _ = wgclient.Device(deviceiface) + } + if !ncutils.IsWindows() { + err = ApplyConf(confPath) if err != nil { - ncutils.PrintLog("error writing wg conf file to "+wgConfPath+": "+err.Error(), 1) + ncutils.PrintLog("failed to create wireguard interface", 1) return err } - confPath = wgConfPath - } - // spin up userspace / windows interface + apply the conf file - var deviceiface string - if ncutils.IsMac() { - deviceiface, err = local.GetMacIface(node.Address) - if err != nil || deviceiface == "" { - deviceiface = ifacename - } - } - if syncconf { - log.Println("syncing conf") - err = SyncWGQuickConf(ifacename, confPath) } else { - d, _ := wgclient.Device(deviceiface) - for d != nil && d.Name == deviceiface { - _ = RemoveConf(ifacename, false) // remove interface first - time.Sleep(time.Second >> 2) - d, _ = wgclient.Device(deviceiface) - } - if !ncutils.IsWindows() { + var output string + starttime := time.Now() + RemoveConf(ifacename, false) + time.Sleep(time.Second >> 2) + ncutils.PrintLog("waiting for interface...", 1) + for !strings.Contains(output, ifacename) && !(time.Now().After(starttime.Add(time.Duration(10) * time.Second))) { + output, _ = ncutils.RunCmd("wg", false) err = ApplyConf(confPath) - if err != nil { - ncutils.PrintLog("failed to create wireguard interface", 1) - return err - } - } else { - var output string - starttime := time.Now() - RemoveConf(ifacename, false) - time.Sleep(time.Second >> 2) - ncutils.PrintLog("waiting for interface...", 1) - for !strings.Contains(output, ifacename) && !(time.Now().After(starttime.Add(time.Duration(10) * time.Second))) { - output, _ = ncutils.RunCmd("wg", false) - err = ApplyConf(confPath) - time.Sleep(time.Second) - } - if !strings.Contains(output, ifacename) { - return errors.New("could not create wg interface for " + ifacename) - } - ip, mask, err := ncutils.GetNetworkIPMask(nodecfg.NetworkSettings.AddressRange) - if err != nil { - log.Println(err.Error()) - return err - } - ncutils.RunCmd("route add "+ip+" mask "+mask+" "+node.Address, true) - time.Sleep(time.Second >> 2) - ncutils.RunCmd("route change "+ip+" mask "+mask+" "+node.Address, true) + time.Sleep(time.Second) } - } - } else { - ipExec, err := exec.LookPath("ip") - if err != nil { - return err - } - - _, err = wgclient.Device(ifacename) - if err != nil { - if os.IsNotExist(err) { - fmt.Println("Device does not exist: ") - fmt.Println(err) - } else { - log.Fatalf("Unknown config error: %v", err) + if !strings.Contains(output, ifacename) { + return errors.New("could not create wg interface for " + ifacename) } - } - - err = wgclient.ConfigureDevice(ifacename, conf) - if err != nil { - if os.IsNotExist(err) { - fmt.Println("Device does not exist: ") - fmt.Println(err) - } else { - fmt.Printf("This is inconvenient: %v", err) + ip, mask, err := ncutils.GetNetworkIPMask(nodecfg.NetworkSettings.AddressRange) + if err != nil { + log.Println(err.Error()) + return err } - } - - //=========DNS Setup==========\\ - if nodecfg.DNSOn == "yes" { - _ = local.UpdateDNS(ifacename, network, nameserver) - } - //=========End DNS Setup=======\\ - if _, err := ncutils.RunCmd(ipExec+" link set down dev "+ifacename, false); err != nil { - ncutils.Log("attempted to remove interface before editing") - return err - } - - if nodecfg.PostDown != "" { - runcmds := strings.Split(nodecfg.PostDown, "; ") - _ = ncutils.RunCmds(runcmds, true) - } - // set MTU of node interface - if _, err := ncutils.RunCmd(ipExec+" link set mtu "+strconv.Itoa(int(nodecfg.MTU))+" up dev "+ifacename, true); err != nil { - ncutils.Log("failed to create interface with mtu " + ifacename) - return err - } - - if nodecfg.PostUp != "" { - runcmds := strings.Split(nodecfg.PostUp, "; ") - _ = ncutils.RunCmds(runcmds, true) - } - if hasGateway { - for _, gateway := range gateways { - _, _ = ncutils.RunCmd(ipExec+" -4 route add "+gateway+" dev "+ifacename, true) - } - } - if node.Address6 != "" && node.IsDualStack == "yes" { - log.Println("[netclient] adding address: "+node.Address6, 1) - _, _ = ncutils.RunCmd(ipExec+" address add dev "+ifacename+" "+node.Address6+"/64", true) + ncutils.RunCmd("route add "+ip+" mask "+mask+" "+node.Address, true) + time.Sleep(time.Second >> 2) + ncutils.RunCmd("route change "+ip+" mask "+mask+" "+node.Address, true) } } From 4ef0b164d7caf547634e77ffa2ab1798253e8b51 Mon Sep 17 00:00:00 2001 From: Matthew R Kasun Date: Thu, 30 Dec 2021 07:11:01 -0500 Subject: [PATCH 02/35] use wireguard.conf files for all --- netclient/functions/common.go | 41 ++++------------------------------- 1 file changed, 4 insertions(+), 37 deletions(-) diff --git a/netclient/functions/common.go b/netclient/functions/common.go index a5c60696..dd5bf2df 100644 --- a/netclient/functions/common.go +++ b/netclient/functions/common.go @@ -8,8 +8,6 @@ import ( "log" "net" "os" - "os/exec" - "strings" nodepb "github.com/gravitl/netmaker/grpc" "github.com/gravitl/netmaker/models" @@ -244,22 +242,7 @@ func RemoveLocalInstance(cfg *config.ClientConfig, networkName string) error { // DeleteInterface - delete an interface of a network func DeleteInterface(ifacename string, postdown string) error { - var err error - if !ncutils.IsKernel() { - err = wireguard.RemoveConf(ifacename, true) - } else { - ipExec, errN := exec.LookPath("ip") - err = errN - if err != nil { - ncutils.PrintLog(err.Error(), 1) - } - _, err = ncutils.RunCmd(ipExec+" link del "+ifacename, false) - if postdown != "" { - runcmds := strings.Split(postdown, "; ") - err = ncutils.RunCmds(runcmds, true) - } - } - return err + return wireguard.RemoveConf(ifacename, true) } // WipeLocal - wipes local instance @@ -271,27 +254,11 @@ func WipeLocal(network string) error { nodecfg := cfg.Node ifacename := nodecfg.Interface if ifacename != "" { - if !ncutils.IsKernel() { - if err = wireguard.RemoveConf(ifacename, true); err == nil { - ncutils.PrintLog("removed WireGuard interface: "+ifacename, 1) - } - } else { - ipExec, err := exec.LookPath("ip") - if err != nil { - return err - } - out, err := ncutils.RunCmd(ipExec+" link del "+ifacename, false) - dontprint := strings.Contains(out, "does not exist") || strings.Contains(out, "Cannot find device") - if err != nil && !dontprint { - ncutils.PrintLog("error running command: "+ipExec+" link del "+ifacename, 1) - ncutils.PrintLog(out, 1) - } - if nodecfg.PostDown != "" { - runcmds := strings.Split(nodecfg.PostDown, "; ") - _ = ncutils.RunCmds(runcmds, false) - } + if err = wireguard.RemoveConf(ifacename, true); err == nil { + ncutils.PrintLog("removed WireGuard interface: "+ifacename, 1) } } + home := ncutils.GetNetclientPathSpecific() if ncutils.FileExists(home + "netconfig-" + network) { _ = os.Remove(home + "netconfig-" + network) From 45464c00f5265cdf55cb2b2fd1728980cf36bdb2 Mon Sep 17 00:00:00 2001 From: Matthew R Kasun Date: Fri, 31 Dec 2021 16:04:25 +0000 Subject: [PATCH 03/35] use dns entry in wireguard config file; checkin temporarily disabled til figure issue with dns on checkin --- netclient/command/commands.go | 2 ++ netclient/functions/join.go | 4 ++-- netclient/ncutils/netclientutils_linux.go | 1 + netclient/wireguard/common.go | 5 ++++- 4 files changed, 9 insertions(+), 3 deletions(-) diff --git a/netclient/command/commands.go b/netclient/command/commands.go index e4a3aeec..baa07a3c 100644 --- a/netclient/command/commands.go +++ b/netclient/command/commands.go @@ -99,6 +99,8 @@ func RunUserspaceDaemon() { } func CheckIn(cfg config.ClientConfig) error { + log.Println("checkin --- diabled for now") + return nil var err error var errN error if cfg.Network == "" { diff --git a/netclient/functions/join.go b/netclient/functions/join.go index 905f08d7..20769d67 100644 --- a/netclient/functions/join.go +++ b/netclient/functions/join.go @@ -83,9 +83,9 @@ func JoinNetwork(cfg config.ClientConfig, privateKey string) error { } } if ncutils.IsLinux() { - _, err := exec.LookPath("resolvectl") + _, err := exec.LookPath("resolveconf") if err != nil { - ncutils.PrintLog("resolvectl not present", 2) + ncutils.PrintLog("resolveconf not present", 2) ncutils.PrintLog("unable to configure DNS automatically, disabling automated DNS management", 2) cfg.Node.DNSOn = "no" } diff --git a/netclient/ncutils/netclientutils_linux.go b/netclient/ncutils/netclientutils_linux.go index f1147295..123ec7c2 100644 --- a/netclient/ncutils/netclientutils_linux.go +++ b/netclient/ncutils/netclientutils_linux.go @@ -35,6 +35,7 @@ func GetEmbedded() error { // CreateUserSpaceConf - creates a user space WireGuard conf func CreateUserSpaceConf(address string, privatekey string, listenPort string, mtu int32, dns string, perskeepalive int32, peers []wgtypes.PeerConfig) (string, error) { + log.Println("---------- dns passed to create conf ", dns) peersString, err := parsePeers(perskeepalive, peers) var listenPortString string if mtu <= 0 { diff --git a/netclient/wireguard/common.go b/netclient/wireguard/common.go index 53787881..f256de81 100644 --- a/netclient/wireguard/common.go +++ b/netclient/wireguard/common.go @@ -136,7 +136,10 @@ func InitWireguard(node *models.Node, privkey string, peers []wgtypes.PeerConfig log.Fatal("no address to configure") } - nameserver := servercfg.CoreDNSAddr + var nameserver string + if node.DNSOn == "yes" { + nameserver = servercfg.CoreDNSAddr + } var newConf string if node.UDPHolePunch != "yes" { newConf, _ = ncutils.CreateUserSpaceConf(node.Address, key.String(), strconv.FormatInt(int64(node.ListenPort), 10), node.MTU, nameserver, node.PersistentKeepalive, peers) From 6056d711a6b42e4296ab64d35b98de96424f5da0 Mon Sep 17 00:00:00 2001 From: Matthew R Kasun Date: Fri, 31 Dec 2021 22:45:50 +0000 Subject: [PATCH 04/35] fix dns issues on checkin when resolvconf not installed --- netclient/command/commands.go | 4 ++-- netclient/functions/checkin.go | 8 ++++---- netclient/wireguard/common.go | 9 ++++++++- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/netclient/command/commands.go b/netclient/command/commands.go index baa07a3c..3f2090f6 100644 --- a/netclient/command/commands.go +++ b/netclient/command/commands.go @@ -99,8 +99,8 @@ func RunUserspaceDaemon() { } func CheckIn(cfg config.ClientConfig) error { - log.Println("checkin --- diabled for now") - return nil + //log.Println("checkin --- diabled for now") + //return nil var err error var errN error if cfg.Network == "" { diff --git a/netclient/functions/checkin.go b/netclient/functions/checkin.go index 3bd11859..0b6c61b2 100644 --- a/netclient/functions/checkin.go +++ b/netclient/functions/checkin.go @@ -156,7 +156,7 @@ func Pull(network string, manual bool) (*models.Node, error) { } node := cfg.Node - servercfg := cfg.Server + //servercfg := cfg.Server if cfg.Node.IPForwarding == "yes" && !ncutils.IsWindows() { if err = local.SetIPForwarding(); err != nil { @@ -241,9 +241,9 @@ func Pull(network string, manual bool) (*models.Node, error) { } } } - if ncutils.IsLinux() { - setDNS(&resNode, servercfg, &cfg.Node) - } + //if ncutils.IsLinux() { + // setDNS(&resNode, servercfg, &cfg.Node) + //} var bkupErr = config.SaveBackup(network) if bkupErr != nil { ncutils.Log("unable to update backup file") diff --git a/netclient/wireguard/common.go b/netclient/wireguard/common.go index f256de81..6df8dde3 100644 --- a/netclient/wireguard/common.go +++ b/netclient/wireguard/common.go @@ -4,6 +4,7 @@ import ( "errors" "io/ioutil" "log" + "os/exec" "runtime" "strconv" "strings" @@ -135,8 +136,14 @@ func InitWireguard(node *models.Node, privkey string, peers []wgtypes.PeerConfig if node.Address == "" { log.Fatal("no address to configure") } - var nameserver string + if ncutils.IsLinux() { + if _, err := exec.LookPath("resolvconf"); err != nil { + ncutils.PrintLog("resolvconf not present", 2) + ncutils.PrintLog("unable to configure DNS automatically, disabling automated DNS management", 2) + node.DNSOn = "no" + } + } if node.DNSOn == "yes" { nameserver = servercfg.CoreDNSAddr } From 314fc3057ef56a52f986bfe494871d487e017541 Mon Sep 17 00:00:00 2001 From: Matthew R Kasun Date: Sat, 1 Jan 2022 08:39:07 -0500 Subject: [PATCH 05/35] add resolvconf as dependency in nm-quick.sh --- scripts/nm-quick.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/nm-quick.sh b/scripts/nm-quick.sh index 507e6258..6e253a09 100755 --- a/scripts/nm-quick.sh +++ b/scripts/nm-quick.sh @@ -50,7 +50,7 @@ elif [ -f /etc/fedora-release ]; then dnf update fi -dependencies=("docker.io" "docker-compose" "wireguard" "jq") +dependencies=("docker.io" "docker-compose" "wireguard" "jq" "resolvconf") From 5448042b9aa8bb339b23558b4f2e2fbd9e8f07f6 Mon Sep 17 00:00:00 2001 From: 0xdcarns Date: Sun, 2 Jan 2022 10:30:07 -0500 Subject: [PATCH 06/35] logs, unused funcs, cleanup --- netclient/cli_options/cmds.go | 4 +-- netclient/command/commands.go | 22 +++++------- netclient/functions/checkin.go | 17 ++++----- netclient/functions/common.go | 43 ++++++++++------------- netclient/local/local.go | 2 +- netclient/ncutils/netclientutils_linux.go | 10 +++--- netclient/server/grpc.go | 5 ++- netclient/wireguard/common.go | 5 ++- netclient/wireguard/kernel.go | 21 ----------- 9 files changed, 50 insertions(+), 79 deletions(-) delete mode 100644 netclient/wireguard/kernel.go diff --git a/netclient/cli_options/cmds.go b/netclient/cli_options/cmds.go index 2349e528..a43a88c3 100644 --- a/netclient/cli_options/cmds.go +++ b/netclient/cli_options/cmds.go @@ -21,11 +21,11 @@ func GetCommands(cliFlags []cli.Flag) []*cli.Command { return err } if cfg.Network == "all" { - err = errors.New("No network provided.") + err = errors.New("no network provided") return err } if cfg.Server.GRPCAddress == "" { - err = errors.New("No server address provided.") + err = errors.New("no server address provided") return err } err = command.Join(cfg, pvtKey) diff --git a/netclient/command/commands.go b/netclient/command/commands.go index 3f2090f6..940eb67b 100644 --- a/netclient/command/commands.go +++ b/netclient/command/commands.go @@ -7,22 +7,13 @@ import ( "strings" "time" - nodepb "github.com/gravitl/netmaker/grpc" "github.com/gravitl/netmaker/netclient/config" "github.com/gravitl/netmaker/netclient/daemon" "github.com/gravitl/netmaker/netclient/functions" "github.com/gravitl/netmaker/netclient/ncutils" - "golang.zx2c4.com/wireguard/wgctrl" -) - -var ( - wgclient *wgctrl.Client -) - -var ( - wcclient nodepb.NodeServiceClient ) +// Join - join command to run from cli func Join(cfg config.ClientConfig, privateKey string) error { var err error @@ -83,6 +74,7 @@ func getWindowsInterval() int { return interval } +// RunUserspaceDaemon - runs continual checkins func RunUserspaceDaemon() { cfg := config.ClientConfig{ @@ -91,13 +83,12 @@ func RunUserspaceDaemon() { interval := getWindowsInterval() dur := time.Duration(interval) * time.Second for { - if err := CheckIn(cfg); err != nil { - // pass - } + CheckIn(cfg) time.Sleep(dur) } } +// CheckIn - runs checkin command from cli func CheckIn(cfg config.ClientConfig) error { //log.Println("checkin --- diabled for now") //return nil @@ -141,6 +132,7 @@ func CheckIn(cfg config.ClientConfig) error { return err } +// Leave - runs the leave command from cli func Leave(cfg config.ClientConfig) error { err := functions.LeaveNetwork(cfg.Network) if err != nil { @@ -151,6 +143,7 @@ func Leave(cfg config.ClientConfig) error { return err } +// Push - runs push command func Push(cfg config.ClientConfig) error { var err error if cfg.Network == "all" || ncutils.IsWindows() { @@ -177,6 +170,7 @@ func Push(cfg config.ClientConfig) error { return err } +// Pull - runs pull command from cli func Pull(cfg config.ClientConfig) error { var err error if cfg.Network == "all" { @@ -203,11 +197,13 @@ func Pull(cfg config.ClientConfig) error { return err } +// List - runs list command from cli func List(cfg config.ClientConfig) error { err := functions.List(cfg.Network) return err } +// Uninstall - runs uninstall command from cli func Uninstall() error { ncutils.PrintLog("uninstalling netclient", 0) err := functions.Uninstall() diff --git a/netclient/functions/checkin.go b/netclient/functions/checkin.go index 0b6c61b2..185be82e 100644 --- a/netclient/functions/checkin.go +++ b/netclient/functions/checkin.go @@ -82,14 +82,15 @@ func checkIP(node *models.Node, servercfg config.ServerConfig, cliconf config.Cl return ipchange && err == nil } -func setDNS(node *models.Node, servercfg config.ServerConfig, nodecfg *models.Node) { - if nodecfg.DNSOn == "yes" { - ifacename := node.Interface - nameserver := servercfg.CoreDNSAddr - network := node.Network - local.UpdateDNS(ifacename, network, nameserver) - } -} +// DEPRECATED +// func setDNS(node *models.Node, servercfg config.ServerConfig, nodecfg *models.Node) { +// if nodecfg.DNSOn == "yes" { +// ifacename := node.Interface +// nameserver := servercfg.CoreDNSAddr +// network := node.Network +// local.UpdateDNS(ifacename, network, nameserver) +// } +// } func checkNodeActions(node *models.Node, networkName string, servercfg config.ServerConfig, localNode *models.Node, cfg *config.ClientConfig) string { if (node.Action == models.NODE_UPDATE_KEY || localNode.Action == models.NODE_UPDATE_KEY) && diff --git a/netclient/functions/common.go b/netclient/functions/common.go index dd5bf2df..385af71b 100644 --- a/netclient/functions/common.go +++ b/netclient/functions/common.go @@ -1,8 +1,6 @@ package functions import ( - "context" - "encoding/json" "errors" "fmt" "log" @@ -21,10 +19,6 @@ import ( "google.golang.org/grpc/metadata" ) -var ( - wcclient nodepb.NodeServiceClient -) - // ListPorts - lists ports of WireGuard devices func ListPorts() error { wgclient, err := wgctrl.New() @@ -101,30 +95,31 @@ func getPrivateAddrBackup() (string, error) { } } if !found { - err := errors.New("Local Address Not Found.") + err := errors.New("local ip address not found") return "", err } return local, err } -func needInterfaceUpdate(ctx context.Context, mac string, network string, iface string) (bool, string, error) { - var header metadata.MD - req := &nodepb.Object{ - Data: mac + "###" + network, - Type: nodepb.STRING_TYPE, - } - readres, err := wcclient.ReadNode(ctx, req, grpc.Header(&header)) - if err != nil { - return false, "", err - } - var resNode models.Node - if err := json.Unmarshal([]byte(readres.Data), &resNode); err != nil { - return false, iface, err - } - oldiface := resNode.Interface +// DEPRECATED +// func needInterfaceUpdate(ctx context.Context, mac string, network string, iface string) (bool, string, error) { +// var header metadata.MD +// req := &nodepb.Object{ +// Data: mac + "###" + network, +// Type: nodepb.STRING_TYPE, +// } +// readres, err := wcclient.ReadNode(ctx, req, grpc.Header(&header)) +// if err != nil { +// return false, "", err +// } +// var resNode models.Node +// if err := json.Unmarshal([]byte(readres.Data), &resNode); err != nil { +// return false, iface, err +// } +// oldiface := resNode.Interface - return iface != oldiface, oldiface, err -} +// return iface != oldiface, oldiface, err +// } // GetNode - gets node locally func GetNode(network string) models.Node { diff --git a/netclient/local/local.go b/netclient/local/local.go index 12518766..e4679f8a 100644 --- a/netclient/local/local.go +++ b/netclient/local/local.go @@ -25,7 +25,7 @@ func SetIPForwarding() error { case "darwin": err = SetIPForwardingMac() default: - err = errors.New("This OS is not supported") + err = errors.New("this OS is not currently supported") } return err } diff --git a/netclient/ncutils/netclientutils_linux.go b/netclient/ncutils/netclientutils_linux.go index 123ec7c2..ae40c292 100644 --- a/netclient/ncutils/netclientutils_linux.go +++ b/netclient/ncutils/netclientutils_linux.go @@ -2,7 +2,6 @@ package ncutils import ( "fmt" - "log" "os/exec" "strconv" "strings" @@ -17,8 +16,8 @@ func RunCmd(command string, printerr bool) (string, error) { cmd.Wait() out, err := cmd.CombinedOutput() if err != nil && printerr { - log.Println("error running command:", command) - log.Println(strings.TrimSuffix(string(out), "\n")) + Log(fmt.Sprintf("error running command: %s", command)) + Log(strings.TrimSuffix(string(out), "\n")) } return string(out), err } @@ -33,9 +32,8 @@ func GetEmbedded() error { return nil } -// CreateUserSpaceConf - creates a user space WireGuard conf -func CreateUserSpaceConf(address string, privatekey string, listenPort string, mtu int32, dns string, perskeepalive int32, peers []wgtypes.PeerConfig) (string, error) { - log.Println("---------- dns passed to create conf ", dns) +// CreateWireGuardConf - creates a user space WireGuard conf +func CreateWireGuardConf(address string, privatekey string, listenPort string, mtu int32, dns string, perskeepalive int32, peers []wgtypes.PeerConfig) (string, error) { peersString, err := parsePeers(perskeepalive, peers) var listenPortString string if mtu <= 0 { diff --git a/netclient/server/grpc.go b/netclient/server/grpc.go index 60019341..5bb1c213 100644 --- a/netclient/server/grpc.go +++ b/netclient/server/grpc.go @@ -50,6 +50,9 @@ func CheckIn(network string) (*models.Node, error) { // == run client action == var header metadata.MD ctx, err := auth.SetJWT(wcclient, network) + if err != nil { + return nil, err + } nodeData, err := json.Marshal(&node) if err != nil { return nil, err @@ -123,7 +126,7 @@ func GetPeers(macaddress string, network string, server string, dualstack bool, } keepalive := nodecfg.PersistentKeepalive - keepalivedur, err := time.ParseDuration(strconv.FormatInt(int64(keepalive), 10) + "s") + keepalivedur, _ := time.ParseDuration(strconv.FormatInt(int64(keepalive), 10) + "s") keepaliveserver, err := time.ParseDuration(strconv.FormatInt(int64(5), 10) + "s") if err != nil { log.Fatalf("Issue with format of keepalive value. Please update netconfig: %v", err) diff --git a/netclient/wireguard/common.go b/netclient/wireguard/common.go index 6df8dde3..53613790 100644 --- a/netclient/wireguard/common.go +++ b/netclient/wireguard/common.go @@ -149,9 +149,9 @@ func InitWireguard(node *models.Node, privkey string, peers []wgtypes.PeerConfig } var newConf string if node.UDPHolePunch != "yes" { - newConf, _ = ncutils.CreateUserSpaceConf(node.Address, key.String(), strconv.FormatInt(int64(node.ListenPort), 10), node.MTU, nameserver, node.PersistentKeepalive, peers) + newConf, _ = ncutils.CreateWireGuardConf(node.Address, key.String(), strconv.FormatInt(int64(node.ListenPort), 10), node.MTU, nameserver, node.PersistentKeepalive, peers) } else { - newConf, _ = ncutils.CreateUserSpaceConf(node.Address, key.String(), "", node.MTU, nameserver, node.PersistentKeepalive, peers) + newConf, _ = ncutils.CreateWireGuardConf(node.Address, key.String(), "", node.MTU, nameserver, node.PersistentKeepalive, peers) } confPath := ncutils.GetNetclientPathSpecific() + ifacename + ".conf" ncutils.PrintLog("writing wg conf file to: "+confPath, 1) @@ -178,7 +178,6 @@ func InitWireguard(node *models.Node, privkey string, peers []wgtypes.PeerConfig } } if syncconf { - log.Println("syncing conf") err = SyncWGQuickConf(ifacename, confPath) } else { d, _ := wgclient.Device(deviceiface) diff --git a/netclient/wireguard/kernel.go b/netclient/wireguard/kernel.go deleted file mode 100644 index d2466142..00000000 --- a/netclient/wireguard/kernel.go +++ /dev/null @@ -1,21 +0,0 @@ -package wireguard - -import ( - "os/exec" - - "github.com/gravitl/netmaker/netclient/ncutils" - //homedir "github.com/mitchellh/go-homedir" -) - -func setKernelDevice(ifacename string, address string) error { - ipExec, err := exec.LookPath("ip") - if err != nil { - return err - } - - _, _ = ncutils.RunCmd("ip link delete dev "+ifacename, false) - _, _ = ncutils.RunCmd(ipExec+" link add dev "+ifacename+" type wireguard", true) - _, _ = ncutils.RunCmd(ipExec+" address add dev "+ifacename+" "+address+"/24", true) - - return nil -} From 83fce6226ab0053a2e1e8de63a4dc4fa24072b52 Mon Sep 17 00:00:00 2001 From: 0xdcarns Date: Sun, 2 Jan 2022 10:51:22 -0500 Subject: [PATCH 07/35] added DNS call to server --- logic/wireguard.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/logic/wireguard.go b/logic/wireguard.go index eff360c6..2090ec18 100644 --- a/logic/wireguard.go +++ b/logic/wireguard.go @@ -13,6 +13,7 @@ import ( "github.com/gravitl/netmaker/logger" "github.com/gravitl/netmaker/models" "github.com/gravitl/netmaker/netclient/ncutils" + "github.com/gravitl/netmaker/servercfg" "golang.zx2c4.com/wireguard/wgctrl" "golang.zx2c4.com/wireguard/wgctrl/wgtypes" ) @@ -86,7 +87,7 @@ func initWireguard(node *models.Node, privkey string, peers []wgtypes.PeerConfig if !ncutils.IsKernel() { var newConf string - newConf, _ = ncutils.CreateUserSpaceConf(node.Address, key.String(), strconv.FormatInt(int64(node.ListenPort), 10), node.MTU, node.PersistentKeepalive, peers) + newConf, _ = ncutils.CreateWireGuardConf(node.Address, key.String(), strconv.FormatInt(int64(node.ListenPort), 10), node.MTU, servercfg.GetCoreDNSAddr(), node.PersistentKeepalive, peers) confPath := ncutils.GetNetclientPathSpecific() + ifacename + ".conf" logger.Log(1, "writing wg conf file to:", confPath) err = ioutil.WriteFile(confPath, []byte(newConf), 0644) From 8a4dce7bec96d9fb6558bb61aa6dfb1b3a77b958 Mon Sep 17 00:00:00 2001 From: 0xdcarns Date: Tue, 28 Dec 2021 11:23:38 -0500 Subject: [PATCH 08/35] fixed user deletion --- .gitignore | 1 + controllers/user.go | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 995aa2bc..defe793f 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,4 @@ netclient/netclient32 netclient/netclient.exe config/dnsconfig/ data/ +.vscode/ diff --git a/controllers/user.go b/controllers/user.go index f08328c7..c9e387e3 100644 --- a/controllers/user.go +++ b/controllers/user.go @@ -23,7 +23,7 @@ func userHandlers(r *mux.Router) { r.HandleFunc("/api/users/networks/{username}", securityCheck(true, http.HandlerFunc(updateUserNetworks))).Methods("PUT") r.HandleFunc("/api/users/{username}/adm", securityCheck(true, http.HandlerFunc(updateUserAdm))).Methods("PUT") r.HandleFunc("/api/users/{username}", securityCheck(true, http.HandlerFunc(createUser))).Methods("POST") - r.HandleFunc("/api/users/{username}", securityCheck(false, continueIfUserMatch(http.HandlerFunc(deleteUser)))).Methods("DELETE") + r.HandleFunc("/api/users/{username}", securityCheck(true, http.HandlerFunc(deleteUser))).Methods("DELETE") r.HandleFunc("/api/users/{username}", securityCheck(false, continueIfUserMatch(http.HandlerFunc(getUser)))).Methods("GET") r.HandleFunc("/api/users", securityCheck(true, http.HandlerFunc(getUsers))).Methods("GET") r.HandleFunc("/api/oauth/login", auth.HandleAuthLogin).Methods("GET") From d45d41769d4b61f89094d762c8afcb148da361ea Mon Sep 17 00:00:00 2001 From: 0xdcarns Date: Tue, 28 Dec 2021 12:07:50 -0500 Subject: [PATCH 09/35] changed log --- main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.go b/main.go index 384302d7..c908c5bb 100644 --- a/main.go +++ b/main.go @@ -43,7 +43,7 @@ func initialize() { // Client Mode Prereq Check var authProvider = auth.InitializeAuthProvider() if authProvider != "" { - logger.Log(0, "OAuth provider, ", authProvider, ", initialized") + logger.Log(0, "OAuth provider,", authProvider+",", "initialized") } else { logger.Log(0, "no OAuth provider found or not configured, continuing without OAuth") } From 76a75fb984089fcb1e6e850cd2a7091d9613f364 Mon Sep 17 00:00:00 2001 From: 0xdcarns Date: Mon, 3 Jan 2022 10:01:37 -0500 Subject: [PATCH 10/35] go mod tidy and conver azure tenant to env/conf var --- auth/azure-ad.go | 3 +-- config/config.go | 1 + go.mod | 1 + servercfg/serverconf.go | 11 +++++++++++ 4 files changed, 14 insertions(+), 2 deletions(-) diff --git a/auth/azure-ad.go b/auth/azure-ad.go index 8ad9a8e3..ffe1a173 100644 --- a/auth/azure-ad.go +++ b/auth/azure-ad.go @@ -5,7 +5,6 @@ import ( "fmt" "io/ioutil" "net/http" - "os" "github.com/gravitl/netmaker/logger" "github.com/gravitl/netmaker/logic" @@ -36,7 +35,7 @@ func initAzureAD(redirectURL string, clientID string, clientSecret string) { ClientID: clientID, ClientSecret: clientSecret, Scopes: []string{"User.Read"}, - Endpoint: microsoft.AzureADEndpoint(os.Getenv("AZURE_TENANT")), + Endpoint: microsoft.AzureADEndpoint(servercfg.GetAzureTenant()), } } diff --git a/config/config.go b/config/config.go index c3b2fbd5..95756c9c 100644 --- a/config/config.go +++ b/config/config.go @@ -68,6 +68,7 @@ type ServerConfig struct { ClientSecret string `yaml:"clientsecret"` FrontendURL string `yaml:"frontendurl"` DisplayKeys string `yaml:"displaykeys"` + AzureTenant string `yaml:"azuretenant"` } // Generic SQL Config diff --git a/go.mod b/go.mod index 4c86fb3f..8e1900fe 100644 --- a/go.mod +++ b/go.mod @@ -31,6 +31,7 @@ require ( require ( cloud.google.com/go v0.34.0 // indirect github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d // indirect + github.com/davecgh/go-spew v1.1.1 // indirect github.com/felixge/httpsnoop v1.0.1 // indirect github.com/go-playground/locales v0.14.0 // indirect github.com/go-playground/universal-translator v0.18.0 // indirect diff --git a/servercfg/serverconf.go b/servercfg/serverconf.go index fb7a67cb..7c1ebd74 100644 --- a/servercfg/serverconf.go +++ b/servercfg/serverconf.go @@ -502,6 +502,17 @@ func GetAuthProviderInfo() []string { return []string{"", "", ""} } +// GetAzureTenant - retrieve the azure tenant ID from env variable or config file +func GetAzureTenant() string { + var azureTenant = "" + if os.Getenv("AZURE_TENANT") != "" { + azureTenant = os.Getenv("AZURE_TENANT") + } else if config.Config.Server.AzureTenant != "" { + azureTenant = config.Config.Server.AzureTenant + } + return azureTenant +} + // GetMacAddr - get's mac address func getMacAddr() string { ifas, err := net.Interfaces() From b28927805362de136ebb0aa260246ccbedd67ef2 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 3 Jan 2022 15:08:19 +0000 Subject: [PATCH 11/35] Bump github.com/go-playground/validator/v10 from 10.9.0 to 10.10.0 Bumps [github.com/go-playground/validator/v10](https://github.com/go-playground/validator) from 10.9.0 to 10.10.0. - [Release notes](https://github.com/go-playground/validator/releases) - [Commits](https://github.com/go-playground/validator/compare/v10.9.0...v10.10.0) --- updated-dependencies: - dependency-name: github.com/go-playground/validator/v10 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 8e1900fe..8b1dddc6 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/gravitl/netmaker go 1.17 require ( - github.com/go-playground/validator/v10 v10.9.0 + github.com/go-playground/validator/v10 v10.10.0 github.com/golang-jwt/jwt/v4 v4.2.0 github.com/golang/protobuf v1.5.2 // indirect github.com/gorilla/handlers v1.5.1 diff --git a/go.sum b/go.sum index 867461fc..013f8596 100644 --- a/go.sum +++ b/go.sum @@ -40,8 +40,8 @@ github.com/go-playground/locales v0.14.0 h1:u50s323jtVGugKlcYeyzC0etD1HifMjqmJqb github.com/go-playground/locales v0.14.0/go.mod h1:sawfccIbzZTqEDETgFXqTho0QybSa7l++s0DH+LDiLs= github.com/go-playground/universal-translator v0.18.0 h1:82dyy6p4OuJq4/CByFNOn/jYrnRPArHwAcmLoJZxyho= github.com/go-playground/universal-translator v0.18.0/go.mod h1:UvRDBj+xPUEGrFYl+lu/H90nyDXpg0fqeB/AQUGNTVA= -github.com/go-playground/validator/v10 v10.9.0 h1:NgTtmN58D0m8+UuxtYmGztBJB7VnPgjj221I1QHci2A= -github.com/go-playground/validator/v10 v10.9.0/go.mod h1:74x4gJWsvQexRdW8Pn3dXSGrTK4nAUsbPlLADvpJkos= +github.com/go-playground/validator/v10 v10.10.0 h1:I7mrTYv78z8k8VXa/qJlOlEXn/nBh+BF8dHX5nt/dr0= +github.com/go-playground/validator/v10 v10.10.0/go.mod h1:74x4gJWsvQexRdW8Pn3dXSGrTK4nAUsbPlLADvpJkos= github.com/golang-jwt/jwt/v4 v4.2.0 h1:besgBTC8w8HjP6NzQdxwKH9Z5oQMZ24ThTrHp3cZ8eU= github.com/golang-jwt/jwt/v4 v4.2.0/go.mod h1:/xlHOz8bRuivTWchD4jCa+NbatV+wEUSzwAxVc6locg= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= From 8c70a699d27ef135205d9882ec050f73babbffdd Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 3 Jan 2022 15:08:51 +0000 Subject: [PATCH 12/35] Bump google.golang.org/grpc from 1.42.0 to 1.43.0 Bumps [google.golang.org/grpc](https://github.com/grpc/grpc-go) from 1.42.0 to 1.43.0. - [Release notes](https://github.com/grpc/grpc-go/releases) - [Commits](https://github.com/grpc/grpc-go/compare/v1.42.0...v1.43.0) --- updated-dependencies: - dependency-name: google.golang.org/grpc dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 8e1900fe..eb1744a9 100644 --- a/go.mod +++ b/go.mod @@ -23,7 +23,7 @@ require ( golang.zx2c4.com/wireguard v0.0.0-20210805125648-3957e9b9dd19 // indirect golang.zx2c4.com/wireguard/wgctrl v0.0.0-20210913210325-91d1988e44de google.golang.org/genproto v0.0.0-20210201151548-94839c025ad4 // indirect - google.golang.org/grpc v1.42.0 + google.golang.org/grpc v1.43.0 google.golang.org/protobuf v1.27.1 gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b ) diff --git a/go.sum b/go.sum index 867461fc..e1c085d3 100644 --- a/go.sum +++ b/go.sum @@ -258,8 +258,8 @@ google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQ google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= google.golang.org/grpc v1.33.1/go.mod h1:fr5YgcSWrqhRRxogOsw7RzIpsmvOZ6IcH4kBYTpR3n0= google.golang.org/grpc v1.36.0/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU= -google.golang.org/grpc v1.42.0 h1:XT2/MFpuPFsEX2fWh3YQtHkZ+WYZFQRfaUgLZYj/p6A= -google.golang.org/grpc v1.42.0/go.mod h1:k+4IHHFw41K8+bbowsex27ge2rCb65oeWqe4jJ590SU= +google.golang.org/grpc v1.43.0 h1:Eeu7bZtDZ2DpRCsLhUlcrLnvYaMK1Gz86a+hMVvELmM= +google.golang.org/grpc v1.43.0/go.mod h1:k+4IHHFw41K8+bbowsex27ge2rCb65oeWqe4jJ590SU= google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= From 4606ec4afe0d29c7efdae30a39a92847d30678a7 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 3 Jan 2022 15:09:10 +0000 Subject: [PATCH 13/35] Bump github.com/mattn/go-sqlite3 from 1.14.9 to 1.14.10 Bumps [github.com/mattn/go-sqlite3](https://github.com/mattn/go-sqlite3) from 1.14.9 to 1.14.10. - [Release notes](https://github.com/mattn/go-sqlite3/releases) - [Commits](https://github.com/mattn/go-sqlite3/compare/v1.14.9...v1.14.10) --- updated-dependencies: - dependency-name: github.com/mattn/go-sqlite3 dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 8e1900fe..299b57d5 100644 --- a/go.mod +++ b/go.mod @@ -9,7 +9,7 @@ require ( github.com/gorilla/handlers v1.5.1 github.com/gorilla/mux v1.8.0 github.com/lib/pq v1.10.4 - github.com/mattn/go-sqlite3 v1.14.9 + github.com/mattn/go-sqlite3 v1.14.10 github.com/rqlite/gorqlite v0.0.0-20210514125552-08ff1e76b22f github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e github.com/stretchr/testify v1.7.0 diff --git a/go.sum b/go.sum index 867461fc..7285101e 100644 --- a/go.sum +++ b/go.sum @@ -100,8 +100,8 @@ github.com/leodido/go-urn v1.2.1/go.mod h1:zt4jvISO2HfUBqxjfIshjdMTYS56ZS/qv49ic github.com/lib/pq v1.10.4 h1:SO9z7FRPzA03QhHKJrH5BXA6HU1rS4V2nIVrrNC1iYk= github.com/lib/pq v1.10.4/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o= github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= -github.com/mattn/go-sqlite3 v1.14.9 h1:10HX2Td0ocZpYEjhilsuo6WWtUqttj2Kb0KtD86/KYA= -github.com/mattn/go-sqlite3 v1.14.9/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU= +github.com/mattn/go-sqlite3 v1.14.10 h1:MLn+5bFRlWMGoSRmJour3CL1w/qL96mvipqpwQW/Sfk= +github.com/mattn/go-sqlite3 v1.14.10/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU= github.com/mdlayher/ethtool v0.0.0-20210210192532-2b88debcdd43 h1:WgyLFv10Ov49JAQI/ZLUkCZ7VJS3r74hwFIGXJsgZlY= github.com/mdlayher/ethtool v0.0.0-20210210192532-2b88debcdd43/go.mod h1:+t7E0lkKfbBsebllff1xdTmyJt8lH37niI6kwFk9OTo= github.com/mdlayher/genetlink v1.0.0 h1:OoHN1OdyEIkScEmRgxLEe2M9U8ClMytqA5niynLtfj0= From dcaba24b1113ce3232d32c6d7983306da10039a8 Mon Sep 17 00:00:00 2001 From: 0xdcarns Date: Mon, 3 Jan 2022 11:30:02 -0500 Subject: [PATCH 14/35] added egress relayed addrs to relayed nodes --- config/config.go | 14 +++++------ logic/util.go | 63 +++++++++++++++++++++++++++++++++++++----------- 2 files changed, 56 insertions(+), 21 deletions(-) diff --git a/config/config.go b/config/config.go index 95756c9c..044d1a88 100644 --- a/config/config.go +++ b/config/config.go @@ -12,7 +12,7 @@ import ( "gopkg.in/yaml.v3" ) -//setting dev by default +// setting dev by default func getEnv() string { env := os.Getenv("NETMAKER_ENV") @@ -27,13 +27,13 @@ func getEnv() string { // Config : application config stored as global variable var Config *EnvironmentConfig -// EnvironmentConfig : +// EnvironmentConfig - environment conf struct type EnvironmentConfig struct { Server ServerConfig `yaml:"server"` SQL SQLConfig `yaml:"sql"` } -// ServerConfig : +// ServerConfig - server conf struct type ServerConfig struct { CoreDNSAddr string `yaml:"corednsaddr"` APIConnString string `yaml:"apiconn"` @@ -58,8 +58,8 @@ type ServerConfig struct { Version string `yaml:"version"` SQLConn string `yaml:"sqlconn"` Platform string `yaml:"platform"` - Database string `yaml:database` - CheckinInterval string `yaml:checkininterval` + Database string `yaml:"database"` + CheckinInterval string `yaml:"checkininterval"` DefaultNodeLimit int32 `yaml:"defaultnodelimit"` Verbosity int32 `yaml:"verbosity"` ServerCheckinInterval int64 `yaml:"servercheckininterval"` @@ -71,7 +71,7 @@ type ServerConfig struct { AzureTenant string `yaml:"azuretenant"` } -// Generic SQL Config +// SQLConfig - Generic SQL Config type SQLConfig struct { Host string `yaml:"host"` Port int32 `yaml:"port"` @@ -81,7 +81,7 @@ type SQLConfig struct { SSLMode string `yaml:"sslmode"` } -//reading in the env file +// reading in the env file func readConfig() *EnvironmentConfig { file := fmt.Sprintf("config/environments/%s.yaml", getEnv()) f, err := os.Open(file) diff --git a/logic/util.go b/logic/util.go index d7ce5534..d89b0daa 100644 --- a/logic/util.go +++ b/logic/util.go @@ -184,26 +184,18 @@ func GetNode(macaddress string, network string) (models.Node, error) { // GetNodePeers - fetches peers for a given node func GetNodePeers(networkName string, excludeRelayed bool) ([]models.Node, error) { var peers []models.Node - collection, err := database.FetchRecords(database.NODES_TABLE_NAME) + var networkNodes, egressNetworkNodes, err = getNetworkEgressAndNodes(networkName) if err != nil { - if database.IsEmptyRecord(err) { - return peers, nil - } - logger.Log(2, err.Error()) - return nil, err + return peers, nil } + udppeers, errN := database.GetPeers(networkName) if errN != nil { logger.Log(2, errN.Error()) } - for _, value := range collection { - var node = &models.Node{} + + for _, node := range networkNodes { var peer = models.Node{} - err := json.Unmarshal([]byte(value), node) - if err != nil { - logger.Log(2, err.Error()) - continue - } if node.IsEgressGateway == "yes" { // handle egress stuff peer.EgressGatewayRanges = node.EgressGatewayRanges peer.IsEgressGateway = node.IsEgressGateway @@ -211,7 +203,7 @@ func GetNodePeers(networkName string, excludeRelayed bool) ([]models.Node, error allow := node.IsRelayed != "yes" || !excludeRelayed if node.Network == networkName && node.IsPending != "yes" && allow { - peer = setPeerInfo(node) + peer = setPeerInfo(&node) if node.UDPHolePunch == "yes" && errN == nil && CheckEndpoint(udppeers[node.PublicKey]) { endpointstring := udppeers[node.PublicKey] endpointarr := strings.Split(endpointstring, ":") @@ -230,6 +222,11 @@ func GetNodePeers(networkName string, excludeRelayed bool) ([]models.Node, error } else { peer.AllowedIPs = append(peer.AllowedIPs, node.RelayAddrs...) } + for _, egressNode := range egressNetworkNodes { + if egressNode.IsRelayed == "yes" && StringSliceContains(node.RelayAddrs, egressNode.Address) { + peer.AllowedIPs = append(peer.AllowedIPs, egressNode.EgressGatewayRanges...) + } + } } peers = append(peers, peer) } @@ -286,6 +283,34 @@ func RandomString(length int) string { // == Private Methods == +func getNetworkEgressAndNodes(networkName string) ([]models.Node, []models.Node, error) { + var networkNodes, egressNetworkNodes []models.Node + collection, err := database.FetchRecords(database.NODES_TABLE_NAME) + if err != nil { + if database.IsEmptyRecord(err) { + return networkNodes, egressNetworkNodes, nil + } + logger.Log(2, err.Error()) + return nil, nil, err + } + + for _, value := range collection { + var node = models.Node{} + err := json.Unmarshal([]byte(value), &node) + if err != nil { + logger.Log(2, err.Error()) + continue + } + if node.Network == networkName { + networkNodes = append(networkNodes, node) + if node.IsEgressGateway == "yes" { + egressNetworkNodes = append(egressNetworkNodes, node) + } + } + } + return networkNodes, egressNetworkNodes, nil +} + func setPeerInfo(node *models.Node) models.Node { var peer models.Node peer.RelayAddrs = node.RelayAddrs @@ -326,3 +351,13 @@ func setIPForwardingLinux() error { } return nil } + +// StringSliceContains - sees if a string slice contains a string element +func StringSliceContains(slice []string, item string) bool { + for _, s := range slice { + if s == item { + return true + } + } + return false +} From 4ca0e856bc689003c3ecc6ce24a4ecb0fdcb23a1 Mon Sep 17 00:00:00 2001 From: 0xdcarns Date: Mon, 3 Jan 2022 19:09:19 -0500 Subject: [PATCH 15/35] added post commands for wg quick --- logic/wireguard.go | 2 +- netclient/ncutils/netclientutils_linux.go | 29 ++++++++++++++++------- netclient/wireguard/common.go | 6 ++--- netclient/wireguard/unix.go | 3 ++- 4 files changed, 27 insertions(+), 13 deletions(-) diff --git a/logic/wireguard.go b/logic/wireguard.go index 2090ec18..3eff6b80 100644 --- a/logic/wireguard.go +++ b/logic/wireguard.go @@ -87,7 +87,7 @@ func initWireguard(node *models.Node, privkey string, peers []wgtypes.PeerConfig if !ncutils.IsKernel() { var newConf string - newConf, _ = ncutils.CreateWireGuardConf(node.Address, key.String(), strconv.FormatInt(int64(node.ListenPort), 10), node.MTU, servercfg.GetCoreDNSAddr(), node.PersistentKeepalive, peers) + newConf, _ = ncutils.CreateWireGuardConf(node, key.String(), strconv.FormatInt(int64(node.ListenPort), 10), servercfg.GetCoreDNSAddr(), peers) confPath := ncutils.GetNetclientPathSpecific() + ifacename + ".conf" logger.Log(1, "writing wg conf file to:", confPath) err = ioutil.WriteFile(confPath, []byte(newConf), 0644) diff --git a/netclient/ncutils/netclientutils_linux.go b/netclient/ncutils/netclientutils_linux.go index ae40c292..bc4c399e 100644 --- a/netclient/ncutils/netclientutils_linux.go +++ b/netclient/ncutils/netclientutils_linux.go @@ -6,6 +6,7 @@ import ( "strconv" "strings" + "github.com/gravitl/netmaker/models" "golang.zx2c4.com/wireguard/wgctrl/wgtypes" ) @@ -33,15 +34,23 @@ func GetEmbedded() error { } // CreateWireGuardConf - creates a user space WireGuard conf -func CreateWireGuardConf(address string, privatekey string, listenPort string, mtu int32, dns string, perskeepalive int32, peers []wgtypes.PeerConfig) (string, error) { - peersString, err := parsePeers(perskeepalive, peers) - var listenPortString string - if mtu <= 0 { - mtu = 1280 +func CreateWireGuardConf(node *models.Node, privatekey string, listenPort string, dns string, peers []wgtypes.PeerConfig) (string, error) { + peersString, err := parsePeers(node.PersistentKeepalive, peers) + var listenPortString, postDownString, postUpString string + if node.MTU <= 0 { + node.MTU = 1280 } + if node.PostDown != "" { + postDownString = fmt.Sprintf("PostDown = %s", node.PostDown) + } + if node.PostUp != "" { + postUpString = fmt.Sprintf("PostUp = %s", node.PostUp) + } + if listenPort != "" { - listenPortString += "ListenPort = " + listenPort + listenPortString = fmt.Sprintf("ListenPort = %s", listenPort) } + if err != nil { return "", err } @@ -51,14 +60,18 @@ DNS = %s PrivateKey = %s MTU = %s %s +%s +%s %s `, - address+"/32", + node.Address+"/32", dns, privatekey, - strconv.Itoa(int(mtu)), + strconv.Itoa(int(node.MTU)), + postDownString, + postUpString, listenPortString, peersString) return config, nil diff --git a/netclient/wireguard/common.go b/netclient/wireguard/common.go index 53613790..f65016dd 100644 --- a/netclient/wireguard/common.go +++ b/netclient/wireguard/common.go @@ -149,9 +149,9 @@ func InitWireguard(node *models.Node, privkey string, peers []wgtypes.PeerConfig } var newConf string if node.UDPHolePunch != "yes" { - newConf, _ = ncutils.CreateWireGuardConf(node.Address, key.String(), strconv.FormatInt(int64(node.ListenPort), 10), node.MTU, nameserver, node.PersistentKeepalive, peers) + newConf, _ = ncutils.CreateWireGuardConf(node, key.String(), strconv.FormatInt(int64(node.ListenPort), 10), nameserver, peers) } else { - newConf, _ = ncutils.CreateWireGuardConf(node.Address, key.String(), "", node.MTU, nameserver, node.PersistentKeepalive, peers) + newConf, _ = ncutils.CreateWireGuardConf(node, key.String(), "", nameserver, peers) } confPath := ncutils.GetNetclientPathSpecific() + ifacename + ".conf" ncutils.PrintLog("writing wg conf file to: "+confPath, 1) @@ -182,7 +182,7 @@ func InitWireguard(node *models.Node, privkey string, peers []wgtypes.PeerConfig } else { d, _ := wgclient.Device(deviceiface) for d != nil && d.Name == deviceiface { - _ = RemoveConf(ifacename, false) // remove interface first + RemoveConf(ifacename, false) // remove interface first time.Sleep(time.Second >> 2) d, _ = wgclient.Device(deviceiface) } diff --git a/netclient/wireguard/unix.go b/netclient/wireguard/unix.go index 8b557d0a..6e9e52af 100644 --- a/netclient/wireguard/unix.go +++ b/netclient/wireguard/unix.go @@ -1,6 +1,7 @@ package wireguard import ( + "fmt" "io/ioutil" "log" "os" @@ -86,7 +87,7 @@ func SyncWGQuickConf(iface string, confPath string) error { // RemoveWGQuickConf - calls wg-quick down func RemoveWGQuickConf(confPath string, printlog bool) error { - _, err := ncutils.RunCmd("wg-quick down "+confPath, printlog) + _, err := ncutils.RunCmd(fmt.Sprintf("wg-quick down %s", confPath), printlog) return err } From bfcf9ecdc393aeefcb8ddae712f2049a59097bdb Mon Sep 17 00:00:00 2001 From: 0xdcarns Date: Tue, 4 Jan 2022 10:00:59 -0500 Subject: [PATCH 16/35] refactored ncutils x-platform --- netclient/ncutils/netclientutils_darwin.go | 15 ++++++++------- netclient/ncutils/netclientutils_freebsd.go | 18 ++++++++++-------- netclient/ncutils/netclientutils_windows.go | 15 ++++++++------- 3 files changed, 26 insertions(+), 22 deletions(-) diff --git a/netclient/ncutils/netclientutils_darwin.go b/netclient/ncutils/netclientutils_darwin.go index 79fc85d7..a073f989 100644 --- a/netclient/ncutils/netclientutils_darwin.go +++ b/netclient/ncutils/netclientutils_darwin.go @@ -7,6 +7,7 @@ import ( "strconv" "strings" + "github.com/gravitl/netmaker/models" "golang.zx2c4.com/wireguard/wgctrl/wgtypes" ) @@ -33,12 +34,12 @@ func GetEmbedded() error { return nil } -// CreateUserSpaceConf - creates a user space WireGuard conf -func CreateUserSpaceConf(address string, privatekey string, listenPort string, mtu int32, perskeepalive int32, peers []wgtypes.PeerConfig) (string, error) { - peersString, err := parsePeers(perskeepalive, peers) +// CreateWireGuardConf - creates a WireGuard conf string +func CreateWireGuardConf(node *models.Node, privatekey string, listenPort string, dns string, peers []wgtypes.PeerConfig) (string, error) { + peersString, err := parsePeers(node.PersistentKeepalive, peers) var listenPortString string - if mtu <= 0 { - mtu = 1280 + if node.MTU <= 0 { + node.MTU = 1280 } if listenPort != "" { listenPortString += "ListenPort = " + listenPort @@ -55,9 +56,9 @@ MTU = %s %s `, - address+"/32", + node.Address+"/32", privatekey, - strconv.Itoa(int(mtu)), + strconv.Itoa(int(node.MTU)), listenPortString, peersString) return config, nil diff --git a/netclient/ncutils/netclientutils_freebsd.go b/netclient/ncutils/netclientutils_freebsd.go index 19d3aa19..bbacdc6c 100644 --- a/netclient/ncutils/netclientutils_freebsd.go +++ b/netclient/ncutils/netclientutils_freebsd.go @@ -3,13 +3,15 @@ package ncutils import ( "context" "fmt" - "golang.zx2c4.com/wireguard/wgctrl/wgtypes" "log" "os/exec" "strconv" "strings" "syscall" "time" + + "github.com/gravitl/netmaker/models" + "golang.zx2c4.com/wireguard/wgctrl/wgtypes" ) // RunCmdFormatted - run a command formatted for freebsd @@ -41,12 +43,12 @@ func RunCmd(command string, printerr bool) (string, error) { return string(out), err } -// CreateUserSpaceConf - creates a user space WireGuard conf -func CreateUserSpaceConf(address string, privatekey string, listenPort string, mtu int32, perskeepalive int32, peers []wgtypes.PeerConfig) (string, error) { - peersString, err := parsePeers(perskeepalive, peers) +// CreateWireGuardConf - creates a WireGuard conf string +func CreateWireGuardConf(node *models.Node, privatekey string, listenPort string, dns string, peers []wgtypes.PeerConfig) (string, error) { + peersString, err := parsePeers(node.PersistentKeepalive, peers) var listenPortString string - if mtu <= 0 { - mtu = 1280 + if node.MTU <= 0 { + node.MTU = 1280 } if listenPort != "" { listenPortString += "ListenPort = " + listenPort @@ -63,9 +65,9 @@ MTU = %s %s `, - address+"/32", + node.Address+"/32", privatekey, - strconv.Itoa(int(mtu)), + strconv.Itoa(int(node.MTU)), listenPortString, peersString) return config, nil diff --git a/netclient/ncutils/netclientutils_windows.go b/netclient/ncutils/netclientutils_windows.go index 45974297..5acf73a7 100644 --- a/netclient/ncutils/netclientutils_windows.go +++ b/netclient/ncutils/netclientutils_windows.go @@ -10,6 +10,7 @@ import ( "strings" "syscall" + "github.com/gravitl/netmaker/models" "golang.zx2c4.com/wireguard/wgctrl/wgtypes" ) @@ -47,12 +48,12 @@ func RunCmdFormatted(command string, printerr bool) (string, error) { return string(out), err } -// CreateUserSpaceConf - creates a user space WireGuard conf -func CreateUserSpaceConf(address string, privatekey string, listenPort string, mtu int32, perskeepalive int32, peers []wgtypes.PeerConfig) (string, error) { - peersString, err := parsePeers(perskeepalive, peers) +// CreateWireGuardConf - creates a WireGuard conf string +func CreateWireGuardConf(node *models.Node, privatekey string, listenPort string, dns string, peers []wgtypes.PeerConfig) (string, error) { + peersString, err := parsePeers(node.PersistentKeepalive, peers) var listenPortString string - if mtu <= 0 { - mtu = 1280 + if node.MTU <= 0 { + node.MTU = 1280 } if listenPort != "" { listenPortString += "ListenPort = " + listenPort @@ -69,9 +70,9 @@ MTU = %s %s `, - address+"/32", + node.Address+"/32", privatekey, - strconv.Itoa(int(mtu)), + strconv.Itoa(int(node.MTU)), listenPortString, peersString) return config, nil From af08abe925bbb94203adf6e0537a40b0b7aa5628 Mon Sep 17 00:00:00 2001 From: 0xdcarns Date: Tue, 4 Jan 2022 13:13:12 -0500 Subject: [PATCH 17/35] log fix --- netclient/command/commands.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/netclient/command/commands.go b/netclient/command/commands.go index 940eb67b..49e075a2 100644 --- a/netclient/command/commands.go +++ b/netclient/command/commands.go @@ -205,7 +205,8 @@ func List(cfg config.ClientConfig) error { // Uninstall - runs uninstall command from cli func Uninstall() error { - ncutils.PrintLog("uninstalling netclient", 0) + ncutils.PrintLog("uninstalling netclient...", 0) err := functions.Uninstall() + ncutils.PrintLog("uninstalled netclient", 0) return err } From 1c9cb819dc6441a1a39ce6a8bb615797667c0e38 Mon Sep 17 00:00:00 2001 From: afeiszli Date: Tue, 4 Jan 2022 13:45:18 -0500 Subject: [PATCH 18/35] adding egress to relay --- logic/util.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/logic/util.go b/logic/util.go index d89b0daa..213f0c13 100644 --- a/logic/util.go +++ b/logic/util.go @@ -249,6 +249,14 @@ func GetPeersList(networkName string, excludeRelayed bool, relayedNodeAddr strin network, err := GetNetwork(networkName) if err == nil { peerNode.AllowedIPs = append(peerNode.AllowedIPs, network.AddressRange) + var _, egressNetworkNodes, err = getNetworkEgressAndNodes(networkName) + if err == nil { + for _, egress := range egressNetworkNodes { + if egress.Address != peerNode.Address { + peerNode.AllowedIPs = append(peerNode.AllowedIPs, egress.EgressGatewayRanges...) + } + } + } } else { peerNode.AllowedIPs = append(peerNode.AllowedIPs, peerNode.RelayAddrs...) } From 1081e63cc106e9a6adae0f3ba272a082087b303e Mon Sep 17 00:00:00 2001 From: afeiszli Date: Tue, 4 Jan 2022 13:54:03 -0500 Subject: [PATCH 19/35] fixing egress on relay --- logic/util.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/logic/util.go b/logic/util.go index 213f0c13..989bff4e 100644 --- a/logic/util.go +++ b/logic/util.go @@ -252,7 +252,7 @@ func GetPeersList(networkName string, excludeRelayed bool, relayedNodeAddr strin var _, egressNetworkNodes, err = getNetworkEgressAndNodes(networkName) if err == nil { for _, egress := range egressNetworkNodes { - if egress.Address != peerNode.Address { + if egress.Address != relayedNodeAddr { peerNode.AllowedIPs = append(peerNode.AllowedIPs, egress.EgressGatewayRanges...) } } From 12e718f00852900531921b7ec63ccd63dccb0646 Mon Sep 17 00:00:00 2001 From: 0xdcarns Date: Wed, 5 Jan 2022 13:13:03 -0500 Subject: [PATCH 20/35] updated version, made RCE optional --- config/config.go | 1 + controllers/node.go | 6 ++++++ controllers/node_grpc.go | 7 +++++++ netclient/main.go | 2 +- servercfg/serverconf.go | 12 +++++++++++- 5 files changed, 26 insertions(+), 2 deletions(-) diff --git a/config/config.go b/config/config.go index 044d1a88..fc1bcbf2 100644 --- a/config/config.go +++ b/config/config.go @@ -69,6 +69,7 @@ type ServerConfig struct { FrontendURL string `yaml:"frontendurl"` DisplayKeys string `yaml:"displaykeys"` AzureTenant string `yaml:"azuretenant"` + RCE string `yaml:"rce"` } // SQLConfig - Generic SQL Config diff --git a/controllers/node.go b/controllers/node.go index 12727f1e..605ceec3 100644 --- a/controllers/node.go +++ b/controllers/node.go @@ -524,6 +524,12 @@ func updateNode(w http.ResponseWriter, r *http.Request) { } } } + + if !servercfg.GetRce() { + newNode.PostDown = node.PostDown + newNode.PostUp = node.PostUp + } + err = logic.UpdateNode(&node, &newNode) if err != nil { returnErrorResponse(w, r, formatError(err, "internal")) diff --git a/controllers/node_grpc.go b/controllers/node_grpc.go index 8e9cd71f..633cb369 100644 --- a/controllers/node_grpc.go +++ b/controllers/node_grpc.go @@ -10,6 +10,7 @@ import ( "github.com/gravitl/netmaker/logger" "github.com/gravitl/netmaker/logic" "github.com/gravitl/netmaker/models" + "github.com/gravitl/netmaker/servercfg" ) // NodeServiceServer - represents the service server for gRPC @@ -107,6 +108,12 @@ func (s *NodeServiceServer) UpdateNode(ctx context.Context, req *nodepb.Object) if err != nil { return nil, err } + + if !servercfg.GetRce() { + newnode.PostDown = node.PostDown + newnode.PostUp = node.PostUp + } + err = logic.UpdateNode(&node, &newnode) if err != nil { return nil, err diff --git a/netclient/main.go b/netclient/main.go index 8030569e..1c6c1ff9 100644 --- a/netclient/main.go +++ b/netclient/main.go @@ -18,7 +18,7 @@ func main() { app := cli.NewApp() app.Name = "Netclient CLI" app.Usage = "Netmaker's netclient agent and CLI. Used to perform interactions with Netmaker server and set local WireGuard config." - app.Version = "v0.9.2" + app.Version = "v0.9.3" cliFlags := cli_options.GetFlags(ncutils.GetHostname()) app.Commands = cli_options.GetCommands(cliFlags[:]) diff --git a/servercfg/serverconf.go b/servercfg/serverconf.go index 7c1ebd74..a7ef3bf1 100644 --- a/servercfg/serverconf.go +++ b/servercfg/serverconf.go @@ -80,6 +80,11 @@ func GetServerConfig() config.ServerConfig { cfg.ClientID = authInfo[1] cfg.ClientSecret = authInfo[2] cfg.FrontendURL = GetFrontendURL() + if GetRce() { + cfg.RCE = "on" + } else { + cfg.RCE = "off" + } return cfg } @@ -108,7 +113,7 @@ func GetAPIConnString() string { // GetVersion - version of netmaker func GetVersion() string { - version := "0.9.2" + version := "0.9.3" if config.Config.Server.Version != "" { version = config.Config.Server.Version } @@ -528,3 +533,8 @@ func getMacAddr() string { } return as[0] } + +// GetRce - sees if Rce is enabled, off by default +func GetRce() bool { + return os.Getenv("RCE") == "on" || config.Config.Server.RCE == "on" +} From 4ca537ee0686b66dcfbc498da97dc95170a7a0c7 Mon Sep 17 00:00:00 2001 From: sgmoore Date: Wed, 5 Jan 2022 10:27:25 -0800 Subject: [PATCH 21/35] Minor typo Spelling fix at line 50. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a4e448f0..886d45c2 100644 --- a/README.md +++ b/README.md @@ -47,7 +47,7 @@ -Upon completion, the logs will display the instructions to connect various devices. These can also be retrived from the UI under "Access Keys." +Upon completion, the logs will display the instructions to connect various devices. These can also be retrieved from the UI under "Access Keys." After installing Netmaker, check out the [Walkthrough](https://itnext.io/getting-started-with-netmaker-a-wireguard-virtual-networking-platform-3d563fbd87f0) and [Getting Started](https://netmaker.readthedocs.io/en/master/getting-started.html) guides to learn more about configuring networks. Or, check out some of our other [Tutorials](https://gravitl.com/resources) for different use cases, including Kubernetes. From 85ef232b3a0b27e91ebb5dd8bb108cdb41f42d99 Mon Sep 17 00:00:00 2001 From: sgmoore Date: Wed, 5 Jan 2022 10:34:17 -0800 Subject: [PATCH 22/35] Minor typo Spelling fix at line 15. --- docs/api.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/api.rst b/docs/api.rst index 4231815e..f219890d 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -12,7 +12,7 @@ Authentication ============== API calls must be authenticated via a header of the format `-H "Authorization: Bearer "` There are two methods to obtain YOUR_SECRET_KEY: 1. Using the masterkey. By default, this value is "secret key," but you should change this on your instance and keep it secure. This value can be set via env var at startup or in a config file (config/environments/< env >.yaml). See the [general usage](./USAGE.md) documentation for more details. -2. Using a JWT recieved for a node. This can be retrieved by calling the `/api/nodes//authenticate` endpoint, as documented below. +2. Using a JWT received for a node. This can be retrieved by calling the `/api/nodes//authenticate` endpoint, as documented below. Format of Calls for Curl From c40ab517378d40f065702832c7cc9e5c9d441662 Mon Sep 17 00:00:00 2001 From: 0xdcarns Date: Wed, 5 Jan 2022 13:41:11 -0500 Subject: [PATCH 23/35] disabled updating default post cmds if RCE disabled --- controllers/network.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/controllers/network.go b/controllers/network.go index 44630b4b..840c06c7 100644 --- a/controllers/network.go +++ b/controllers/network.go @@ -68,7 +68,7 @@ func getNetworks(w http.ResponseWriter, r *http.Request) { json.NewEncoder(w).Encode(allnetworks) } -//Simple get network function +// Simple get network function func getNetwork(w http.ResponseWriter, r *http.Request) { // set header. w.Header().Set("Content-Type", "application/json") @@ -101,7 +101,7 @@ func keyUpdate(w http.ResponseWriter, r *http.Request) { json.NewEncoder(w).Encode(network) } -//Update a network +// Update a network func updateNetwork(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "application/json") var params = mux.Vars(r) @@ -119,6 +119,11 @@ func updateNetwork(w http.ResponseWriter, r *http.Request) { return } + if !servercfg.GetRce() { + newNetwork.DefaultPostDown = network.DefaultPostDown + newNetwork.DefaultPostUp = network.DefaultPostUp + } + rangeupdate, localrangeupdate, err := logic.UpdateNetwork(&network, &newNetwork) if err != nil { returnErrorResponse(w, r, formatError(err, "badrequest")) From 2d8df05067af807f869d206ce2671ed7a17f2272 Mon Sep 17 00:00:00 2001 From: sgmoore Date: Wed, 5 Jan 2022 10:47:17 -0800 Subject: [PATCH 24/35] Minor typos Spelling fixes at lines 24, 50, 156 --- docs/architecture.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/architecture.rst b/docs/architecture.rst index e760597a..34292cef 100644 --- a/docs/architecture.rst +++ b/docs/architecture.rst @@ -21,7 +21,7 @@ WireGuard WireGuard is a relatively new but very important technology which was recently added to the Linux kernel. WireGuard creates very fast but simple encrypted tunnels between devices. From the `WireGuard `_ website, "it might be regarded as the most secure, easiest to use, and simplest VPN solution in the industry." -Previous solutions like OpenVPN and IPSec are considerably more heavy and complex, while being less performant. All existing VPN tunnelling solutions will cause a significant increase in your network latency. WireGuard is the first to achieve near over-the-line network speeds, meaning you see no signigifant performance impact. With the release of WireGuard, there is little reason to use any other existing tunnel encryption technology. +Previous solutions like OpenVPN and IPSec are considerably more heavy and complex, while being less performant. All existing VPN tunneling solutions will cause a significant increase in your network latency. WireGuard is the first to achieve near over-the-line network speeds, meaning you see no significant performance impact. With the release of WireGuard, there is little reason to use any other existing tunnel encryption technology. Mesh Network ------------- @@ -56,7 +56,7 @@ Netmaker does a lot of work to set configurations for you, so that you don't hav Node ------ -A machine in a Netmaker network, which is managed by the Netclient, is referred to as a Node, as you will see in the UI. A Node can be a VM, a bare metal server, a desktop computer, an IoT device, or any other number of internet-connected machines on which the netclient is installed. A node is simply an endpoint in the network, which can send traffic to all the other nodes, and recieve traffic from all of the other nodes. +A machine in a Netmaker network, which is managed by the Netclient, is referred to as a Node, as you will see in the UI. A Node can be a VM, a bare metal server, a desktop computer, an IoT device, or any other number of internet-connected machines on which the netclient is installed. A node is simply an endpoint in the network, which can send traffic to all the other nodes, and receive traffic from all of the other nodes. SystemD ------- @@ -153,7 +153,7 @@ Below is a high level, step-by-step overview of the flow of communications withi 9. Netmaker server verifies information and creates the node, setting default values for any missing information. 10. Timestamp is set for the network (see #16). 11. Netmaker returns settings as response to netclient. Some settings may be added or modified based on the network. -12. Netclient recieves response. If successful, it takes any additional info returned from Netmaker and configures the local system/WireGuard +12. Netclient receives response. If successful, it takes any additional info returned from Netmaker and configures the local system/WireGuard 13. Netclient sends another request to Netmaker's GRPC server, this time to retrieve the peers list (all other clients in the network). 14. Netmaker sends back peers list, including current known configurations of all nodes in network. 15. Netclient configures WireGuard with this information. At this point, the node is fully configured as a part of the network and should be able to reach the other nodes via private address. From 9ded75d741bd0a7598bda8c33a291e38e735e711 Mon Sep 17 00:00:00 2001 From: 0xdcarns Date: Wed, 5 Jan 2022 14:14:32 -0500 Subject: [PATCH 25/35] fixed setting default node postdown --- logic/nodes.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/logic/nodes.go b/logic/nodes.go index bd16ab60..c2e804b1 100644 --- a/logic/nodes.go +++ b/logic/nodes.go @@ -253,6 +253,10 @@ func SetNodeDefaults(node *models.Node) { postup := parentNetwork.DefaultPostUp node.PostUp = postup } + if node.PostDown == "" { + postdown := parentNetwork.DefaultPostDown + node.PostDown = postdown + } if node.IsStatic == "" { node.IsStatic = "no" } From f43e5d9afff421976a7c4608ba8d6421735b63f5 Mon Sep 17 00:00:00 2001 From: 0xdcarns Date: Wed, 5 Jan 2022 15:17:28 -0500 Subject: [PATCH 26/35] change resolve to resolv --- netclient/functions/join.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/netclient/functions/join.go b/netclient/functions/join.go index 20769d67..f8a8ba8f 100644 --- a/netclient/functions/join.go +++ b/netclient/functions/join.go @@ -83,9 +83,9 @@ func JoinNetwork(cfg config.ClientConfig, privateKey string) error { } } if ncutils.IsLinux() { - _, err := exec.LookPath("resolveconf") + _, err := exec.LookPath("resolvconf") if err != nil { - ncutils.PrintLog("resolveconf not present", 2) + ncutils.PrintLog("resolvconf not present", 2) ncutils.PrintLog("unable to configure DNS automatically, disabling automated DNS management", 2) cfg.Node.DNSOn = "no" } From a6429c883c476299a6a641bb7456b1423e3001fa Mon Sep 17 00:00:00 2001 From: Matthew R Kasun Date: Thu, 6 Jan 2022 09:08:03 -0500 Subject: [PATCH 27/35] remove DNS from wireguard conf and revert to setting DNS with resolvectl --- netclient/ncutils/netclientutils_linux.go | 4 +--- netclient/wireguard/common.go | 20 +++++--------------- 2 files changed, 6 insertions(+), 18 deletions(-) diff --git a/netclient/ncutils/netclientutils_linux.go b/netclient/ncutils/netclientutils_linux.go index bc4c399e..e4cbb1c7 100644 --- a/netclient/ncutils/netclientutils_linux.go +++ b/netclient/ncutils/netclientutils_linux.go @@ -34,7 +34,7 @@ func GetEmbedded() error { } // CreateWireGuardConf - creates a user space WireGuard conf -func CreateWireGuardConf(node *models.Node, privatekey string, listenPort string, dns string, peers []wgtypes.PeerConfig) (string, error) { +func CreateWireGuardConf(node *models.Node, privatekey string, listenPort string, peers []wgtypes.PeerConfig) (string, error) { peersString, err := parsePeers(node.PersistentKeepalive, peers) var listenPortString, postDownString, postUpString string if node.MTU <= 0 { @@ -56,7 +56,6 @@ func CreateWireGuardConf(node *models.Node, privatekey string, listenPort string } config := fmt.Sprintf(`[Interface] Address = %s -DNS = %s PrivateKey = %s MTU = %s %s @@ -67,7 +66,6 @@ MTU = %s `, node.Address+"/32", - dns, privatekey, strconv.Itoa(int(node.MTU)), postDownString, diff --git a/netclient/wireguard/common.go b/netclient/wireguard/common.go index f65016dd..828c1dab 100644 --- a/netclient/wireguard/common.go +++ b/netclient/wireguard/common.go @@ -4,7 +4,6 @@ import ( "errors" "io/ioutil" "log" - "os/exec" "runtime" "strconv" "strings" @@ -119,7 +118,6 @@ func InitWireguard(node *models.Node, privkey string, peers []wgtypes.PeerConfig return err } nodecfg := modcfg.Node - servercfg := modcfg.Server if err != nil { log.Fatalf("failed to open client: %v", err) @@ -136,22 +134,11 @@ func InitWireguard(node *models.Node, privkey string, peers []wgtypes.PeerConfig if node.Address == "" { log.Fatal("no address to configure") } - var nameserver string - if ncutils.IsLinux() { - if _, err := exec.LookPath("resolvconf"); err != nil { - ncutils.PrintLog("resolvconf not present", 2) - ncutils.PrintLog("unable to configure DNS automatically, disabling automated DNS management", 2) - node.DNSOn = "no" - } - } - if node.DNSOn == "yes" { - nameserver = servercfg.CoreDNSAddr - } var newConf string if node.UDPHolePunch != "yes" { - newConf, _ = ncutils.CreateWireGuardConf(node, key.String(), strconv.FormatInt(int64(node.ListenPort), 10), nameserver, peers) + newConf, _ = ncutils.CreateWireGuardConf(node, key.String(), strconv.FormatInt(int64(node.ListenPort), 10), peers) } else { - newConf, _ = ncutils.CreateWireGuardConf(node, key.String(), "", nameserver, peers) + newConf, _ = ncutils.CreateWireGuardConf(node, key.String(), "", peers) } confPath := ncutils.GetNetclientPathSpecific() + ifacename + ".conf" ncutils.PrintLog("writing wg conf file to: "+confPath, 1) @@ -260,6 +247,9 @@ func SetWGConfig(network string, peerupdate bool) error { } else { err = InitWireguard(&nodecfg, privkey, peers, hasGateway, gateways, false) } + if nodecfg.DNSOn == "yes" { + _ = local.UpdateDNS(nodecfg.Interface, nodecfg.Network, servercfg.CoreDNSAddr) + } return err } From 781de684a09f10a1bfd151536db2ce9369ad825a Mon Sep 17 00:00:00 2001 From: Matthew R Kasun Date: Thu, 6 Jan 2022 09:13:49 -0500 Subject: [PATCH 28/35] remove nameserver from call to CreateWireGuardConf --- logic/wireguard.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/logic/wireguard.go b/logic/wireguard.go index 3eff6b80..0d0f8d4e 100644 --- a/logic/wireguard.go +++ b/logic/wireguard.go @@ -13,7 +13,6 @@ import ( "github.com/gravitl/netmaker/logger" "github.com/gravitl/netmaker/models" "github.com/gravitl/netmaker/netclient/ncutils" - "github.com/gravitl/netmaker/servercfg" "golang.zx2c4.com/wireguard/wgctrl" "golang.zx2c4.com/wireguard/wgctrl/wgtypes" ) @@ -87,7 +86,7 @@ func initWireguard(node *models.Node, privkey string, peers []wgtypes.PeerConfig if !ncutils.IsKernel() { var newConf string - newConf, _ = ncutils.CreateWireGuardConf(node, key.String(), strconv.FormatInt(int64(node.ListenPort), 10), servercfg.GetCoreDNSAddr(), peers) + newConf, _ = ncutils.CreateWireGuardConf(node, key.String(), strconv.FormatInt(int64(node.ListenPort), 10), peers) confPath := ncutils.GetNetclientPathSpecific() + ifacename + ".conf" logger.Log(1, "writing wg conf file to:", confPath) err = ioutil.WriteFile(confPath, []byte(newConf), 0644) From f989bd86b57d837a839985e165ddcf2d51e51154 Mon Sep 17 00:00:00 2001 From: Lam Tran Date: Thu, 6 Jan 2022 22:57:05 +0700 Subject: [PATCH 29/35] Gracefully shutdown in HTTP and gRPC apps --- .idea/.gitignore | 8 ++++++++ .idea/modules.xml | 8 ++++++++ .idea/netmaker.iml | 9 +++++++++ .idea/vcs.xml | 6 ++++++ controllers/controller.go | 7 +++---- main.go | 12 +++++------- 6 files changed, 39 insertions(+), 11 deletions(-) create mode 100644 .idea/.gitignore create mode 100644 .idea/modules.xml create mode 100644 .idea/netmaker.iml create mode 100644 .idea/vcs.xml diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 00000000..13566b81 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 00000000..0ddbe09c --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/netmaker.iml b/.idea/netmaker.iml new file mode 100644 index 00000000..5e764c4f --- /dev/null +++ b/.idea/netmaker.iml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 00000000..94a25f7f --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/controllers/controller.go b/controllers/controller.go index 4129afa3..008d517f 100644 --- a/controllers/controller.go +++ b/controllers/controller.go @@ -52,20 +52,19 @@ func HandleRESTRequests(wg *sync.WaitGroup) { } }() logger.Log(0, "REST Server successfully started on port ", port, " (REST)") - c := make(chan os.Signal) // Relay os.Interrupt to our channel (os.Interrupt = CTRL+C) // Ignore other incoming signals - signal.Notify(c, os.Interrupt) + ctx, stop := signal.NotifyContext(context.TODO(), os.Interrupt) + defer stop() // Block main routine until a signal is received // As long as user doesn't press CTRL+C a message is not passed and our main routine keeps running - <-c + <-ctx.Done() // After receiving CTRL+C Properly stop the server logger.Log(0, "Stopping the REST server...") srv.Shutdown(context.TODO()) logger.Log(0, "REST Server closed.") logger.DumpFile(fmt.Sprintf("data/netmaker.log.%s", time.Now().Format(logger.TimeFormatDay))) - } diff --git a/main.go b/main.go index c908c5bb..fd9aad97 100644 --- a/main.go +++ b/main.go @@ -1,6 +1,7 @@ package main import ( + "context" "fmt" "net" "os" @@ -157,21 +158,18 @@ func runGRPC(wg *sync.WaitGroup) { }() logger.Log(0, "Agent Server successfully started on port ", grpcport, "(gRPC)") - // Right way to stop the server using a SHUTDOWN HOOK - // Create a channel to receive OS signals - c := make(chan os.Signal, 1) - // Relay os.Interrupt to our channel (os.Interrupt = CTRL+C) // Ignore other incoming signals - signal.Notify(c, os.Interrupt) + ctx, stop := signal.NotifyContext(context.TODO(), os.Interrupt) + defer stop() // Block main routine until a signal is received // As long as user doesn't press CTRL+C a message is not passed and our main routine keeps running - <-c + <-ctx.Done() // After receiving CTRL+C Properly stop the server logger.Log(0, "Stopping the Agent server...") - s.Stop() + s.GracefulStop() listener.Close() logger.Log(0, "Agent server closed..") logger.Log(0, "Closed DB connection.") From 9ae2995e0e4958efca2967cacf10967988ed4365 Mon Sep 17 00:00:00 2001 From: Lam Tran Date: Thu, 6 Jan 2022 23:01:18 +0700 Subject: [PATCH 30/35] Update .gitignore --- .gitignore | 1 + .idea/.gitignore | 8 -------- .idea/modules.xml | 8 -------- .idea/netmaker.iml | 9 --------- .idea/vcs.xml | 6 ------ 5 files changed, 1 insertion(+), 31 deletions(-) delete mode 100644 .idea/.gitignore delete mode 100644 .idea/modules.xml delete mode 100644 .idea/netmaker.iml delete mode 100644 .idea/vcs.xml diff --git a/.gitignore b/.gitignore index defe793f..3f09bc2e 100644 --- a/.gitignore +++ b/.gitignore @@ -16,3 +16,4 @@ netclient/netclient.exe config/dnsconfig/ data/ .vscode/ +.idea/ diff --git a/.idea/.gitignore b/.idea/.gitignore deleted file mode 100644 index 13566b81..00000000 --- a/.idea/.gitignore +++ /dev/null @@ -1,8 +0,0 @@ -# Default ignored files -/shelf/ -/workspace.xml -# Editor-based HTTP Client requests -/httpRequests/ -# Datasource local storage ignored files -/dataSources/ -/dataSources.local.xml diff --git a/.idea/modules.xml b/.idea/modules.xml deleted file mode 100644 index 0ddbe09c..00000000 --- a/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/.idea/netmaker.iml b/.idea/netmaker.iml deleted file mode 100644 index 5e764c4f..00000000 --- a/.idea/netmaker.iml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index 94a25f7f..00000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file From 6e614bdd3de7f07cc43e297ea57dfe7572e2b54c Mon Sep 17 00:00:00 2001 From: 0xdcarns Date: Thu, 6 Jan 2022 11:39:35 -0500 Subject: [PATCH 31/35] updated compose versions --- netclient/versioninfo.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/netclient/versioninfo.json b/netclient/versioninfo.json index 9af03281..344adbc0 100644 --- a/netclient/versioninfo.json +++ b/netclient/versioninfo.json @@ -29,7 +29,7 @@ "OriginalFilename": "", "PrivateBuild": "", "ProductName": "Netclient", - "ProductVersion": "v0.9.2.0", + "ProductVersion": "v0.9.3.0", "SpecialBuild": "" }, "VarFileInfo": { From 43b9e73eaa11c1c4aa3921186e36e59b02569094 Mon Sep 17 00:00:00 2001 From: 0xdcarns Date: Thu, 6 Jan 2022 15:05:38 -0500 Subject: [PATCH 32/35] updated ioutil refs and composes --- .github/workflows/buildandrelease.yml | 2 +- .github/workflows/test-artifacts.yml | 4 ++++ .github/workflows/test.yml | 4 ++++ auth/azure-ad.go | 4 ++-- auth/github.go | 4 ++-- auth/google.go | 4 ++-- compose/docker-compose.caddy.yml | 4 ++-- compose/docker-compose.contained.yml | 4 ++-- compose/docker-compose.nodns.yml | 4 ++-- compose/docker-compose.reference.yml | 4 ++-- compose/docker-compose.yml | 4 ++-- controllers/dns_test.go | 5 ++--- logger/logger.go | 3 +-- logic/dns.go | 3 +-- logic/wireguard.go | 5 ++--- netclient/auth/auth.go | 12 ++++++------ netclient/config/config.go | 9 ++++----- netclient/daemon/macos.go | 3 +-- netclient/daemon/systemd.go | 5 ++--- netclient/daemon/windows.go | 3 +-- netclient/local/dns.go | 3 +-- netclient/ncutils/netclientutils.go | 5 ++--- netclient/ncwindows/windows.go | 5 ++--- netclient/wireguard/common.go | 6 +++--- netclient/wireguard/unix.go | 7 +++---- servercfg/serverconf.go | 4 ++-- 26 files changed, 58 insertions(+), 62 deletions(-) diff --git a/.github/workflows/buildandrelease.yml b/.github/workflows/buildandrelease.yml index 2fe5ffe0..3bc5fe94 100644 --- a/.github/workflows/buildandrelease.yml +++ b/.github/workflows/buildandrelease.yml @@ -29,7 +29,7 @@ jobs: - name: Setup go uses: actions/setup-go@v2 with: - go-version: 1.16 + go-version: 1.17 - name: Build run: | diff --git a/.github/workflows/test-artifacts.yml b/.github/workflows/test-artifacts.yml index fa60d107..e2145b3e 100644 --- a/.github/workflows/test-artifacts.yml +++ b/.github/workflows/test-artifacts.yml @@ -12,6 +12,10 @@ jobs: steps: - name: Checkout uses: actions/checkout@v2 + - name: Setup Go + uses: actions/setup-go@v2 + with: + go-version: 1.17 - name: Set up QEMU uses: docker/setup-qemu-action@v1 - name: Set up Docker Buildx diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index bc3c0509..4679086d 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -11,6 +11,10 @@ jobs: steps: - name: Checkout uses: actions/checkout@v2 + - name: Setup Go + uses: actions/setup-go@v2 + with: + go-version: 1.17 - name: run tests run: | go test -p 1 ./... -v diff --git a/auth/azure-ad.go b/auth/azure-ad.go index ffe1a173..8f6f32b6 100644 --- a/auth/azure-ad.go +++ b/auth/azure-ad.go @@ -3,7 +3,7 @@ package auth import ( "encoding/json" "fmt" - "io/ioutil" + "io" "net/http" "github.com/gravitl/netmaker/logger" @@ -109,7 +109,7 @@ func getAzureUserInfo(state string, code string) (*azureOauthUser, error) { return nil, fmt.Errorf("failed getting user info: %s", err.Error()) } defer response.Body.Close() - contents, err := ioutil.ReadAll(response.Body) + contents, err := io.ReadAll(response.Body) if err != nil { return nil, fmt.Errorf("failed reading response body: %s", err.Error()) } diff --git a/auth/github.go b/auth/github.go index aa06f791..9e45c869 100644 --- a/auth/github.go +++ b/auth/github.go @@ -3,7 +3,7 @@ package auth import ( "encoding/json" "fmt" - "io/ioutil" + "io" "net/http" "github.com/gravitl/netmaker/logger" @@ -113,7 +113,7 @@ func getGithubUserInfo(state string, code string) (*githubOauthUser, error) { return nil, fmt.Errorf("failed getting user info: %s", err.Error()) } defer response.Body.Close() - contents, err := ioutil.ReadAll(response.Body) + contents, err := io.ReadAll(response.Body) if err != nil { return nil, fmt.Errorf("failed reading response body: %s", err.Error()) } diff --git a/auth/google.go b/auth/google.go index 7ba92d40..59ba75ff 100644 --- a/auth/google.go +++ b/auth/google.go @@ -3,7 +3,7 @@ package auth import ( "encoding/json" "fmt" - "io/ioutil" + "io" "net/http" "github.com/gravitl/netmaker/logger" @@ -104,7 +104,7 @@ func getGoogleUserInfo(state string, code string) (*googleOauthUser, error) { return nil, fmt.Errorf("failed getting user info: %s", err.Error()) } defer response.Body.Close() - contents, err := ioutil.ReadAll(response.Body) + contents, err := io.ReadAll(response.Body) if err != nil { return nil, fmt.Errorf("failed reading response body: %s", err.Error()) } diff --git a/compose/docker-compose.caddy.yml b/compose/docker-compose.caddy.yml index 02975c96..1fcb9445 100644 --- a/compose/docker-compose.caddy.yml +++ b/compose/docker-compose.caddy.yml @@ -3,7 +3,7 @@ version: "3.4" services: netmaker: container_name: netmaker - image: gravitl/netmaker:v0.9.2 + image: gravitl/netmaker:v0.9.3 volumes: - /var/run/dbus/system_bus_socket:/var/run/dbus/system_bus_socket - /run/systemd/system:/run/systemd/system @@ -40,7 +40,7 @@ services: container_name: netmaker-ui depends_on: - netmaker - image: gravitl/netmaker-ui:v0.9.2 + image: gravitl/netmaker-ui:v0.9.3 links: - "netmaker:api" ports: diff --git a/compose/docker-compose.contained.yml b/compose/docker-compose.contained.yml index aa3ea175..5d36e2c4 100644 --- a/compose/docker-compose.contained.yml +++ b/compose/docker-compose.contained.yml @@ -3,7 +3,7 @@ version: "3.4" services: netmaker: container_name: netmaker - image: gravitl/netmaker:v0.9.2 + image: gravitl/netmaker:v0.9.3 volumes: - dnsconfig:/root/config/dnsconfig - /usr/bin/wg:/usr/bin/wg @@ -38,7 +38,7 @@ services: container_name: netmaker-ui depends_on: - netmaker - image: gravitl/netmaker-ui:v0.9.2 + image: gravitl/netmaker-ui:v0.9.3 links: - "netmaker:api" ports: diff --git a/compose/docker-compose.nodns.yml b/compose/docker-compose.nodns.yml index 64d925f1..bde0977f 100644 --- a/compose/docker-compose.nodns.yml +++ b/compose/docker-compose.nodns.yml @@ -3,7 +3,7 @@ version: "3.4" services: netmaker: container_name: netmaker - image: gravitl/netmaker:v0.9.2 + image: gravitl/netmaker:v0.9.3 volumes: - /usr/bin/wg:/usr/bin/wg - sqldata:/root/data @@ -36,7 +36,7 @@ services: container_name: netmaker-ui depends_on: - netmaker - image: gravitl/netmaker-ui:v0.9.2 + image: gravitl/netmaker-ui:v0.9.3 links: - "netmaker:api" ports: diff --git a/compose/docker-compose.reference.yml b/compose/docker-compose.reference.yml index 9eb19540..b6ecfa41 100644 --- a/compose/docker-compose.reference.yml +++ b/compose/docker-compose.reference.yml @@ -11,7 +11,7 @@ services: container_name: netmaker depends_on: - rqlite - image: gravitl/netmaker:v0.9.2 + image: gravitl/netmaker:v0.9.3 volumes: # Volume mounts necessary for CLIENT_MODE to control wireguard networking on host (except dnsconfig, which is where dns config files are stored for use by CoreDNS) - dnsconfig:/root/config/dnsconfig # Netmaker writes Corefile to this location, which gets mounted by CoreDNS for DNS configuration. - /usr/bin/wg:/usr/bin/wg @@ -41,7 +41,7 @@ services: container_name: netmaker-ui depends_on: - netmaker - image: gravitl/netmaker-ui:v0.9.2 + image: gravitl/netmaker-ui:v0.9.3 links: - "netmaker:api" ports: diff --git a/compose/docker-compose.yml b/compose/docker-compose.yml index db4e3b25..047a7671 100644 --- a/compose/docker-compose.yml +++ b/compose/docker-compose.yml @@ -3,7 +3,7 @@ version: "3.4" services: netmaker: container_name: netmaker - image: gravitl/netmaker:v0.9.0 + image: gravitl/netmaker:v0.9.3 volumes: - /var/run/dbus/system_bus_socket:/var/run/dbus/system_bus_socket - /run/systemd/system:/run/systemd/system @@ -40,7 +40,7 @@ services: container_name: netmaker-ui depends_on: - netmaker - image: gravitl/netmaker-ui:v0.9.2 + image: gravitl/netmaker-ui:v0.9.3 links: - "netmaker:api" ports: diff --git a/controllers/dns_test.go b/controllers/dns_test.go index 47070a9a..4ad16244 100644 --- a/controllers/dns_test.go +++ b/controllers/dns_test.go @@ -1,7 +1,6 @@ package controller import ( - "io/ioutil" "os" "testing" @@ -200,7 +199,7 @@ func TestSetDNS(t *testing.T) { info, err := os.Stat("./config/dnsconfig/netmaker.hosts") assert.Nil(t, err) assert.False(t, info.IsDir()) - content, err := ioutil.ReadFile("./config/dnsconfig/netmaker.hosts") + content, err := os.ReadFile("./config/dnsconfig/netmaker.hosts") assert.Nil(t, err) assert.Contains(t, string(content), "testnode.skynet") }) @@ -212,7 +211,7 @@ func TestSetDNS(t *testing.T) { info, err := os.Stat("./config/dnsconfig/netmaker.hosts") assert.Nil(t, err) assert.False(t, info.IsDir()) - content, err := ioutil.ReadFile("./config/dnsconfig/netmaker.hosts") + content, err := os.ReadFile("./config/dnsconfig/netmaker.hosts") assert.Nil(t, err) assert.Contains(t, string(content), "newhost.skynet") }) diff --git a/logger/logger.go b/logger/logger.go index 67c7e0ff..6ffd6ad0 100644 --- a/logger/logger.go +++ b/logger/logger.go @@ -2,7 +2,6 @@ package logger import ( "fmt" - "io/ioutil" "os" "sort" "strconv" @@ -90,7 +89,7 @@ func DumpFile(filePath string) { // Retrieve - retrieves logs from given file func Retrieve(filePath string) string { - contents, err := ioutil.ReadFile(filePath) + contents, err := os.ReadFile(filePath) if err != nil { panic(err) } diff --git a/logic/dns.go b/logic/dns.go index 29cb196d..7d9f9a48 100644 --- a/logic/dns.go +++ b/logic/dns.go @@ -2,7 +2,6 @@ package logic import ( "encoding/json" - "io/ioutil" "os" "github.com/go-playground/validator/v10" @@ -135,7 +134,7 @@ func SetCorefile(domains string) error { ` corebytes := []byte(corefile) - err = ioutil.WriteFile(dir+"/config/dnsconfig/Corefile", corebytes, 0644) + err = os.WriteFile(dir+"/config/dnsconfig/Corefile", corebytes, 0644) if err != nil { return err } diff --git a/logic/wireguard.go b/logic/wireguard.go index 0d0f8d4e..c8b53a54 100644 --- a/logic/wireguard.go +++ b/logic/wireguard.go @@ -3,7 +3,6 @@ package logic import ( "errors" "fmt" - "io/ioutil" "os" "os/exec" "strconv" @@ -89,7 +88,7 @@ func initWireguard(node *models.Node, privkey string, peers []wgtypes.PeerConfig newConf, _ = ncutils.CreateWireGuardConf(node, key.String(), strconv.FormatInt(int64(node.ListenPort), 10), peers) confPath := ncutils.GetNetclientPathSpecific() + ifacename + ".conf" logger.Log(1, "writing wg conf file to:", confPath) - err = ioutil.WriteFile(confPath, []byte(newConf), 0644) + err = os.WriteFile(confPath, []byte(newConf), 0644) if err != nil { logger.Log(1, "error writing wg conf file to", confPath, ":", err.Error()) return err @@ -97,7 +96,7 @@ func initWireguard(node *models.Node, privkey string, peers []wgtypes.PeerConfig if ncutils.IsWindows() { wgConfPath := ncutils.GetWGPathSpecific() + ifacename + ".conf" logger.Log(1, "writing wg conf file to:", confPath) - err = ioutil.WriteFile(wgConfPath, []byte(newConf), 0644) + err = os.WriteFile(wgConfPath, []byte(newConf), 0644) if err != nil { logger.Log(1, "error writing wg conf file to", wgConfPath, ":", err.Error()) return err diff --git a/netclient/auth/auth.go b/netclient/auth/auth.go index a20a575a..fdfedb78 100644 --- a/netclient/auth/auth.go +++ b/netclient/auth/auth.go @@ -3,6 +3,7 @@ package auth import ( "encoding/json" "fmt" + "os" "github.com/gravitl/netmaker/models" "github.com/gravitl/netmaker/netclient/config" @@ -10,7 +11,6 @@ import ( // "os" "context" - "io/ioutil" nodepb "github.com/gravitl/netmaker/grpc" "google.golang.org/grpc/codes" @@ -21,13 +21,13 @@ import ( // SetJWT func will used to create the JWT while signing in and signing out func SetJWT(client nodepb.NodeServiceClient, network string) (context.Context, error) { home := ncutils.GetNetclientPathSpecific() - tokentext, err := ioutil.ReadFile(home + "nettoken-" + network) + tokentext, err := os.ReadFile(home + "nettoken-" + network) if err != nil { err = AutoLogin(client, network) if err != nil { return nil, status.Errorf(codes.Unauthenticated, fmt.Sprintf("Something went wrong with Auto Login: %v", err)) } - tokentext, err = ioutil.ReadFile(home + "nettoken-" + network) + tokentext, err = os.ReadFile(home + "nettoken-" + network) if err != nil { return nil, status.Errorf(codes.Unauthenticated, fmt.Sprintf("Something went wrong: %v", err)) } @@ -71,7 +71,7 @@ func AutoLogin(client nodepb.NodeServiceClient, network string) error { return err } tokenstring := []byte(res.Data) - err = ioutil.WriteFile(home+"nettoken-"+network, tokenstring, 0644) + err = os.WriteFile(home+"nettoken-"+network, tokenstring, 0644) if err != nil { return err } @@ -81,13 +81,13 @@ func AutoLogin(client nodepb.NodeServiceClient, network string) error { // StoreSecret - stores auth secret locally func StoreSecret(key string, network string) error { d1 := []byte(key) - err := ioutil.WriteFile(ncutils.GetNetclientPathSpecific()+"secret-"+network, d1, 0644) + err := os.WriteFile(ncutils.GetNetclientPathSpecific()+"secret-"+network, d1, 0644) return err } // RetrieveSecret - fetches secret locally func RetrieveSecret(network string) (string, error) { - dat, err := ioutil.ReadFile(ncutils.GetNetclientPathSpecific() + "secret-" + network) + dat, err := os.ReadFile(ncutils.GetNetclientPathSpecific() + "secret-" + network) return string(dat), err } diff --git a/netclient/config/config.go b/netclient/config/config.go index 91b8b8c0..c343ccb5 100644 --- a/netclient/config/config.go +++ b/netclient/config/config.go @@ -6,7 +6,6 @@ import ( "encoding/json" "errors" "fmt" - "io/ioutil" "log" "os" @@ -133,12 +132,12 @@ func SaveBackup(network string) error { var configPath = ncutils.GetNetclientPathSpecific() + "netconfig-" + network var backupPath = ncutils.GetNetclientPathSpecific() + "backup.netconfig-" + network if FileExists(configPath) { - input, err := ioutil.ReadFile(configPath) + input, err := os.ReadFile(configPath) if err != nil { ncutils.Log("failed to read " + configPath + " to make a backup") return err } - if err = ioutil.WriteFile(backupPath, input, 0644); err != nil { + if err = os.WriteFile(backupPath, input, 0644); err != nil { ncutils.Log("failed to copy backup to " + backupPath) return err } @@ -151,12 +150,12 @@ func ReplaceWithBackup(network string) error { var backupPath = ncutils.GetNetclientPathSpecific() + "backup.netconfig-" + network var configPath = ncutils.GetNetclientPathSpecific() + "netconfig-" + network if FileExists(backupPath) { - input, err := ioutil.ReadFile(backupPath) + input, err := os.ReadFile(backupPath) if err != nil { ncutils.Log("failed to read file " + backupPath + " to backup network: " + network) return err } - if err = ioutil.WriteFile(configPath, input, 0644); err != nil { + if err = os.WriteFile(configPath, input, 0644); err != nil { ncutils.Log("failed backup " + backupPath + " to " + configPath) return err } diff --git a/netclient/daemon/macos.go b/netclient/daemon/macos.go index c00a618e..4fe21ff1 100644 --- a/netclient/daemon/macos.go +++ b/netclient/daemon/macos.go @@ -2,7 +2,6 @@ package daemon import ( "fmt" - "io/ioutil" "log" "os" "path/filepath" @@ -64,7 +63,7 @@ func CreateMacService(servicename string, interval string) error { daemonbytes := []byte(daemonstring) if !ncutils.FileExists("/Library/LaunchDaemons/com.gravitl.netclient.plist") { - err = ioutil.WriteFile("/Library/LaunchDaemons/com.gravitl.netclient.plist", daemonbytes, 0644) + err = os.WriteFile("/Library/LaunchDaemons/com.gravitl.netclient.plist", daemonbytes, 0644) } return err } diff --git a/netclient/daemon/systemd.go b/netclient/daemon/systemd.go index 3bbcb4ce..015f4626 100644 --- a/netclient/daemon/systemd.go +++ b/netclient/daemon/systemd.go @@ -3,7 +3,6 @@ package daemon import ( //"github.com/davecgh/go-spew/spew" - "io/ioutil" "log" "os" "path/filepath" @@ -75,7 +74,7 @@ WantedBy=timers.target timerbytes := []byte(systemtimer) if !ncutils.FileExists("/etc/systemd/system/netclient.service") { - err = ioutil.WriteFile("/etc/systemd/system/netclient.service", servicebytes, 0644) + err = os.WriteFile("/etc/systemd/system/netclient.service", servicebytes, 0644) if err != nil { log.Println(err) return err @@ -83,7 +82,7 @@ WantedBy=timers.target } if !ncutils.FileExists("/etc/systemd/system/netclient.timer") { - err = ioutil.WriteFile("/etc/systemd/system/netclient.timer", timerbytes, 0644) + err = os.WriteFile("/etc/systemd/system/netclient.timer", timerbytes, 0644) if err != nil { log.Println(err) return err diff --git a/netclient/daemon/windows.go b/netclient/daemon/windows.go index 9855f54a..aa613d24 100644 --- a/netclient/daemon/windows.go +++ b/netclient/daemon/windows.go @@ -2,7 +2,6 @@ package daemon import ( "fmt" - "io/ioutil" "log" "os" "strings" @@ -57,7 +56,7 @@ func writeServiceConfig() error { `, strings.Replace(ncutils.GetNetclientPathSpecific()+"netclient.exe", `\\`, `\`, -1)) if !ncutils.FileExists(serviceConfigPath) { - err := ioutil.WriteFile(serviceConfigPath, []byte(scriptString), 0644) + err := os.WriteFile(serviceConfigPath, []byte(scriptString), 0644) if err != nil { return err } diff --git a/netclient/local/dns.go b/netclient/local/dns.go index 60999b11..fe9cf1c7 100644 --- a/netclient/local/dns.go +++ b/netclient/local/dns.go @@ -1,7 +1,6 @@ package local import ( - "io/ioutil" "os" "strings" @@ -14,7 +13,7 @@ import ( // SetDNS - sets the DNS of a local machine func SetDNS(nameserver string) error { - bytes, err := ioutil.ReadFile("/etc/resolv.conf") + bytes, err := os.ReadFile("/etc/resolv.conf") if err != nil { return err } diff --git a/netclient/ncutils/netclientutils.go b/netclient/ncutils/netclientutils.go index b9e79f89..ae20367c 100644 --- a/netclient/ncutils/netclientutils.go +++ b/netclient/ncutils/netclientutils.go @@ -5,7 +5,6 @@ import ( "errors" "fmt" "io" - "io/ioutil" "log" "math/rand" "net" @@ -132,7 +131,7 @@ func GetPublicIP() (string, error) { } defer resp.Body.Close() if resp.StatusCode == http.StatusOK { - bodyBytes, err := ioutil.ReadAll(resp.Body) + bodyBytes, err := io.ReadAll(resp.Body) if err != nil { continue } @@ -409,7 +408,7 @@ func PrintLog(message string, loglevel int) { // GetSystemNetworks - get networks locally func GetSystemNetworks() ([]string, error) { var networks []string - files, err := ioutil.ReadDir(GetNetclientPathSpecific()) + files, err := os.ReadDir(GetNetclientPathSpecific()) if err != nil { return networks, err } diff --git a/netclient/ncwindows/windows.go b/netclient/ncwindows/windows.go index a9b8782d..288a7244 100644 --- a/netclient/ncwindows/windows.go +++ b/netclient/ncwindows/windows.go @@ -1,7 +1,6 @@ package ncwindows import ( - "io/ioutil" "log" "os" @@ -24,12 +23,12 @@ func InitWindows() { if os.IsNotExist(dataNetclientErr) { // check and see if netclient.exe is in appdata if currentNetclientErr == nil { // copy it if it exists locally - input, err := ioutil.ReadFile(wdPath + "\\netclient.exe") + input, err := os.ReadFile(wdPath + "\\netclient.exe") if err != nil { log.Println("failed to find netclient.exe") return } - if err = ioutil.WriteFile(ncutils.GetNetclientPathSpecific()+"netclient.exe", input, 0644); err != nil { + if err = os.WriteFile(ncutils.GetNetclientPathSpecific()+"netclient.exe", input, 0644); err != nil { log.Println("failed to copy netclient.exe to", ncutils.GetNetclientPath()) return } diff --git a/netclient/wireguard/common.go b/netclient/wireguard/common.go index 828c1dab..e264cab6 100644 --- a/netclient/wireguard/common.go +++ b/netclient/wireguard/common.go @@ -2,8 +2,8 @@ package wireguard import ( "errors" - "io/ioutil" "log" + "os" "runtime" "strconv" "strings" @@ -142,14 +142,14 @@ func InitWireguard(node *models.Node, privkey string, peers []wgtypes.PeerConfig } confPath := ncutils.GetNetclientPathSpecific() + ifacename + ".conf" ncutils.PrintLog("writing wg conf file to: "+confPath, 1) - err = ioutil.WriteFile(confPath, []byte(newConf), 0644) + err = os.WriteFile(confPath, []byte(newConf), 0644) if err != nil { ncutils.PrintLog("error writing wg conf file to "+confPath+": "+err.Error(), 1) return err } if ncutils.IsWindows() { wgConfPath := ncutils.GetWGPathSpecific() + ifacename + ".conf" - err = ioutil.WriteFile(wgConfPath, []byte(newConf), 0644) + err = os.WriteFile(wgConfPath, []byte(newConf), 0644) if err != nil { ncutils.PrintLog("error writing wg conf file to "+wgConfPath+": "+err.Error(), 1) return err diff --git a/netclient/wireguard/unix.go b/netclient/wireguard/unix.go index 6e9e52af..254f6482 100644 --- a/netclient/wireguard/unix.go +++ b/netclient/wireguard/unix.go @@ -2,7 +2,6 @@ package wireguard import ( "fmt" - "io/ioutil" "log" "os" "regexp" @@ -68,7 +67,7 @@ func SyncWGQuickConf(iface string, confPath string) error { } regex := regexp.MustCompile(".*Warning.*\n") conf := regex.ReplaceAllString(confRaw, "") - err = ioutil.WriteFile(tmpConf, []byte(conf), 0644) + err = os.WriteFile(tmpConf, []byte(conf), 0644) if err != nil { return err } @@ -95,12 +94,12 @@ func RemoveWGQuickConf(confPath string, printlog bool) error { func StorePrivKey(key string, network string) error { var err error d1 := []byte(key) - err = ioutil.WriteFile(ncutils.GetNetclientPathSpecific()+"wgkey-"+network, d1, 0644) + err = os.WriteFile(ncutils.GetNetclientPathSpecific()+"wgkey-"+network, d1, 0644) return err } // RetrievePrivKey - reads wg priv key from local disk func RetrievePrivKey(network string) (string, error) { - dat, err := ioutil.ReadFile(ncutils.GetNetclientPathSpecific() + "wgkey-" + network) + dat, err := os.ReadFile(ncutils.GetNetclientPathSpecific() + "wgkey-" + network) return string(dat), err } diff --git a/servercfg/serverconf.go b/servercfg/serverconf.go index a7ef3bf1..d15af77a 100644 --- a/servercfg/serverconf.go +++ b/servercfg/serverconf.go @@ -2,7 +2,7 @@ package servercfg import ( "errors" - "io/ioutil" + "io" "net" "net/http" "os" @@ -417,7 +417,7 @@ func GetPublicIP() (string, error) { } defer resp.Body.Close() if resp.StatusCode == http.StatusOK { - bodyBytes, err := ioutil.ReadAll(resp.Body) + bodyBytes, err := io.ReadAll(resp.Body) if err != nil { continue } From ff9e76340573c647eb6dd03b6a70d7087eec1dd3 Mon Sep 17 00:00:00 2001 From: 0xdcarns Date: Thu, 6 Jan 2022 15:14:13 -0500 Subject: [PATCH 33/35] version updates --- README.md | 2 +- netclient/netclient.exe.manifest.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 886d45c2..04f7d0ee 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@

- + diff --git a/netclient/netclient.exe.manifest.xml b/netclient/netclient.exe.manifest.xml index a7cb64c0..cbb731fd 100644 --- a/netclient/netclient.exe.manifest.xml +++ b/netclient/netclient.exe.manifest.xml @@ -1,7 +1,7 @@ Date: Thu, 6 Jan 2022 15:18:18 -0500 Subject: [PATCH 34/35] update build&release workflow for freebsd and macOs --- .github/workflows/buildandrelease.yml | 68 ++++++++++++++++++++++++++- 1 file changed, 67 insertions(+), 1 deletion(-) diff --git a/.github/workflows/buildandrelease.yml b/.github/workflows/buildandrelease.yml index 3bc5fe94..67891994 100644 --- a/.github/workflows/buildandrelease.yml +++ b/.github/workflows/buildandrelease.yml @@ -40,7 +40,13 @@ jobs: env GOOS=linux GOARCH=arm GOARM=7 go build -o build/netclient-arm7/netclient main.go env GOOS=linux GOARCH=arm64 go build -o build/netclient-arm64/netclient main.go env GOOS=linux GOARCH=mipsle go build -ldflags "-s -w" -o build/netclient-mipsle/netclient main.go && upx build/netclient-mipsle/netclient - + env CGO_ENABLED=0 GOOS=freebsd GOARCH=amd64 go build -o build/netclient-freebsd/netclient main.go + env CGO_ENABLED=0 GOOS=freebsd GOARCH=arm GOARM=5 go build -o build/netclient-freebsd-arm5/netclient main.go + env CGO_ENABLED=0 GOOS=freebsd GOARCH=arm GOARM=6 go build -o build/netclient-freebsd-arm6/netclient main.go + env CGO_ENABLED=0 GOOS=freebsd GOARCH=arm GOARM=7 go build -o build/netclient-freebsd-arm7/netclient main.go + env CGO_ENABLED=0 GOOS=freebsd GOARCH=arm64 go build -o build/netclient-freebsd-arm64/netclient main.go + env CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -o build/netclient-darwin/netclient main.go + - name: Upload x86 to Release uses: svenstaro/upload-release-action@v2 with: @@ -100,3 +106,63 @@ jobs: overwrite: true prerelease: true asset_name: netclient-mipsle + + - name: Upload freebsd to Release + uses: svenstaro/upload-release-action@v2 + with: + repo_token: ${{ secrets.GITHUB_TOKEN }} + file: netclient/build/netclient-freebsd/netclient + tag: ${{ env.NETMAKER_VERSION }} + overwrite: true + prerelease: true + asset_name: netclient-freebsd + + - name: Upload freebsd-arm5 to Release + uses: svenstaro/upload-release-action@v2 + with: + repo_token: ${{ secrets.GITHUB_TOKEN }} + file: netclient/build/netclient-freebsd-arm5/netclient + tag: ${{ env.NETMAKER_VERSION }} + overwrite: true + prerelease: true + asset_name: netclient-freebsd-arm5 + + - name: Upload freebsd-arm6 to Release + uses: svenstaro/upload-release-action@v2 + with: + repo_token: ${{ secrets.GITHUB_TOKEN }} + file: netclient/build/netclient-freebsd-arm6/netclient + tag: ${{ env.NETMAKER_VERSION }} + overwrite: true + prerelease: true + asset_name: netclient-freebsd-arm6 + + - name: Upload freebsd-arm7 to Release + uses: svenstaro/upload-release-action@v2 + with: + repo_token: ${{ secrets.GITHUB_TOKEN }} + file: netclient/build/netclient-freebsd-arm7/netclient + tag: ${{ env.NETMAKER_VERSION }} + overwrite: true + prerelease: true + asset_name: netclient-freebsd-arm7 + + - name: Upload freebsd-arm64 to Release + uses: svenstaro/upload-release-action@v2 + with: + repo_token: ${{ secrets.GITHUB_TOKEN }} + file: netclient/build/netclient-freebsd-arm64/netclient + tag: ${{ env.NETMAKER_VERSION }} + overwrite: true + prerelease: true + asset_name: netclient-freebsd-arm64 + + - name: Upload darwin to Release + uses: svenstaro/upload-release-action@v2 + with: + repo_token: ${{ secrets.GITHUB_TOKEN }} + file: netclient/build/netclient-darwin/netclient + tag: ${{ env.NETMAKER_VERSION }} + overwrite: true + prerelease: true + asset_name: netclient-darwin From afe94a4ea9a34b03d0c5b4646fd41132b0ee3407 Mon Sep 17 00:00:00 2001 From: Matthew R Kasun Date: Thu, 6 Jan 2022 15:32:19 -0500 Subject: [PATCH 35/35] change to trigger on publish/release vice publish/create --- .github/workflows/buildandrelease.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/buildandrelease.yml b/.github/workflows/buildandrelease.yml index 67891994..36f4e301 100644 --- a/.github/workflows/buildandrelease.yml +++ b/.github/workflows/buildandrelease.yml @@ -7,7 +7,7 @@ on: description: 'Netmaker version' required: false release: - types: [created] + types: [published] jobs: build: