mirror of
https://github.com/gravitl/netmaker.git
synced 2025-10-04 10:54:24 +08:00
commit
c86103e196
27 changed files with 576 additions and 57 deletions
15
README.md
15
README.md
|
@ -8,7 +8,7 @@
|
||||||
|
|
||||||
<p align="center">
|
<p align="center">
|
||||||
<a href="https://github.com/gravitl/netmaker/releases">
|
<a href="https://github.com/gravitl/netmaker/releases">
|
||||||
<img src="https://img.shields.io/badge/Version-0.9.0-informational?style=flat-square" />
|
<img src="https://img.shields.io/badge/Version-0.9.1-informational?style=flat-square" />
|
||||||
</a>
|
</a>
|
||||||
<a href="https://hub.docker.com/r/gravitl/netmaker/tags">
|
<a href="https://hub.docker.com/r/gravitl/netmaker/tags">
|
||||||
<img src="https://img.shields.io/docker/pulls/gravitl/netmaker" />
|
<img src="https://img.shields.io/docker/pulls/gravitl/netmaker" />
|
||||||
|
@ -29,9 +29,10 @@
|
||||||
|
|
||||||
# WireGuard® Automation from Homelab to Enterprise
|
# WireGuard® Automation from Homelab to Enterprise
|
||||||
- [x] Peer-to-Peer Mesh Networks
|
- [x] Peer-to-Peer Mesh Networks
|
||||||
- [x] Kubernetes, Multi-Cloud
|
- [x] Kubernetes and Multi-Cloud Enablement
|
||||||
- [x] OAuth and Private DNS
|
- [x] Remote Site Access via Gateway
|
||||||
- [x] Linux, Mac, Windows, FreeBSD, iPhone, and Android
|
- [x] OAuth and Private DNS Features
|
||||||
|
- [x] Support for Linux, Mac, Windows, FreeBSD, iPhone, and Android
|
||||||
|
|
||||||
# Get Started in 5 Minutes
|
# Get Started in 5 Minutes
|
||||||
|
|
||||||
|
@ -96,7 +97,11 @@ After installing Netmaker, check out the [Walkthrough](https://itnext.io/getting
|
||||||
|
|
||||||
- [Golang GUI](https://github.com/mattkasun/netmaker-gui)
|
- [Golang GUI](https://github.com/mattkasun/netmaker-gui)
|
||||||
|
|
||||||
- [CoreDNS Plugin](https://github.com/SekoiaLab/netmaker-coredns)
|
- [CoreDNS Plugin](https://github.com/gravitl/netmaker-coredns-plugin)
|
||||||
|
|
||||||
|
- [Multi-Cluster K8S Plugin](https://github.com/gravitl/netmak8s)
|
||||||
|
|
||||||
|
- [Terraform Provider](https://github.com/madacluster/netmaker-terraform-provider)
|
||||||
|
|
||||||
|
|
||||||
## Disclaimer
|
## Disclaimer
|
||||||
|
|
|
@ -3,7 +3,7 @@ version: "3.4"
|
||||||
services:
|
services:
|
||||||
netmaker:
|
netmaker:
|
||||||
container_name: netmaker
|
container_name: netmaker
|
||||||
image: gravitl/netmaker:v0.9.0
|
image: gravitl/netmaker:v0.9.1
|
||||||
volumes:
|
volumes:
|
||||||
- /var/run/dbus/system_bus_socket:/var/run/dbus/system_bus_socket
|
- /var/run/dbus/system_bus_socket:/var/run/dbus/system_bus_socket
|
||||||
- /run/systemd/system:/run/systemd/system
|
- /run/systemd/system:/run/systemd/system
|
||||||
|
|
|
@ -3,7 +3,7 @@ version: "3.4"
|
||||||
services:
|
services:
|
||||||
netmaker:
|
netmaker:
|
||||||
container_name: netmaker
|
container_name: netmaker
|
||||||
image: gravitl/netmaker:v0.9.0
|
image: gravitl/netmaker:v0.9.1
|
||||||
volumes:
|
volumes:
|
||||||
- dnsconfig:/root/config/dnsconfig
|
- dnsconfig:/root/config/dnsconfig
|
||||||
- /usr/bin/wg:/usr/bin/wg
|
- /usr/bin/wg:/usr/bin/wg
|
||||||
|
|
|
@ -3,7 +3,7 @@ version: "3.4"
|
||||||
services:
|
services:
|
||||||
netmaker:
|
netmaker:
|
||||||
container_name: netmaker
|
container_name: netmaker
|
||||||
image: gravitl/netmaker:v0.9.0
|
image: gravitl/netmaker:v0.9.1
|
||||||
volumes:
|
volumes:
|
||||||
- /usr/bin/wg:/usr/bin/wg
|
- /usr/bin/wg:/usr/bin/wg
|
||||||
- sqldata:/root/data
|
- sqldata:/root/data
|
||||||
|
|
|
@ -11,7 +11,7 @@ services:
|
||||||
container_name: netmaker
|
container_name: netmaker
|
||||||
depends_on:
|
depends_on:
|
||||||
- rqlite
|
- rqlite
|
||||||
image: gravitl/netmaker:v0.9.0
|
image: gravitl/netmaker:v0.9.1
|
||||||
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)
|
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.
|
- dnsconfig:/root/config/dnsconfig # Netmaker writes Corefile to this location, which gets mounted by CoreDNS for DNS configuration.
|
||||||
- /usr/bin/wg:/usr/bin/wg
|
- /usr/bin/wg:/usr/bin/wg
|
||||||
|
|
39
docker/Dockerfile-netclient-doks
Normal file
39
docker/Dockerfile-netclient-doks
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
FROM debian:buster as builder
|
||||||
|
# add glib support daemon manager
|
||||||
|
|
||||||
|
RUN apt update -y && apt install -y wget bash gcc musl-dev openssl golang git build-essential libmnl-dev iptables
|
||||||
|
|
||||||
|
RUN wget -O go.tgz https://dl.google.com/go/go1.17.1.linux-amd64.tar.gz
|
||||||
|
|
||||||
|
RUN tar -C /usr/local -xzf go.tgz
|
||||||
|
|
||||||
|
WORKDIR /usr/local/go/src
|
||||||
|
|
||||||
|
RUN chmod +x make.bash
|
||||||
|
|
||||||
|
RUN ./make.bash
|
||||||
|
|
||||||
|
ENV PATH="/usr/local/go/bin:$PATH"
|
||||||
|
|
||||||
|
ENV GOPATH=/opt/go/
|
||||||
|
|
||||||
|
ENV PATH=$PATH:$GOPATH/bin
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
COPY . .
|
||||||
|
|
||||||
|
ENV GO111MODULE=auto
|
||||||
|
|
||||||
|
RUN GOOS=linux GOARCH=amd64 CGO_ENABLED=0 /usr/local/go/bin/go build -ldflags="-w -s" -o netclient-app netclient/main.go
|
||||||
|
|
||||||
|
FROM debian:buster
|
||||||
|
|
||||||
|
WORKDIR /root/
|
||||||
|
|
||||||
|
RUN apt update -y && apt install -y bash curl wget traceroute procps dnsutils iptables openresolv iproute2
|
||||||
|
COPY --from=builder /app/netclient-app ./netclient
|
||||||
|
COPY --from=builder /app/scripts/netclient.sh .
|
||||||
|
RUN chmod 0755 netclient && chmod 0755 netclient.sh
|
||||||
|
|
||||||
|
ENTRYPOINT ["/bin/sh", "./netclient.sh"]
|
57
docker/Dockerfile-netclient-doks-uspace
Normal file
57
docker/Dockerfile-netclient-doks-uspace
Normal file
|
@ -0,0 +1,57 @@
|
||||||
|
FROM debian:buster as builder
|
||||||
|
# add glib support daemon manager
|
||||||
|
|
||||||
|
RUN apt update -y && apt install -y wget bash gcc musl-dev openssl golang git build-essential libmnl-dev iptables
|
||||||
|
|
||||||
|
RUN wget -O go.tgz https://dl.google.com/go/go1.17.1.linux-amd64.tar.gz
|
||||||
|
|
||||||
|
RUN tar -C /usr/local -xzf go.tgz
|
||||||
|
|
||||||
|
WORKDIR /usr/local/go/src
|
||||||
|
|
||||||
|
RUN chmod +x make.bash
|
||||||
|
|
||||||
|
RUN ./make.bash
|
||||||
|
|
||||||
|
ENV PATH="/usr/local/go/bin:$PATH"
|
||||||
|
|
||||||
|
ENV GOPATH=/opt/go/
|
||||||
|
|
||||||
|
ENV PATH=$PATH:$GOPATH/bin
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
COPY . .
|
||||||
|
|
||||||
|
ENV GO111MODULE=auto
|
||||||
|
|
||||||
|
RUN GOOS=linux GOARCH=amd64 CGO_ENABLED=0 /usr/local/go/bin/go build -ldflags="-w -s" -o netclient-app netclient/main.go
|
||||||
|
|
||||||
|
WORKDIR /root/
|
||||||
|
|
||||||
|
RUN git clone https://git.zx2c4.com/wireguard-go && \
|
||||||
|
cd wireguard-go && \
|
||||||
|
make && \
|
||||||
|
make install
|
||||||
|
|
||||||
|
ENV WITH_WGQUICK=yes
|
||||||
|
RUN git clone https://git.zx2c4.com/wireguard-tools && \
|
||||||
|
cd wireguard-tools && \
|
||||||
|
cd src && \
|
||||||
|
make && \
|
||||||
|
make install
|
||||||
|
|
||||||
|
|
||||||
|
FROM debian:buster
|
||||||
|
|
||||||
|
WORKDIR /root/
|
||||||
|
|
||||||
|
RUN apt update -y && apt install -y bash curl wget traceroute procps dnsutils iptables openresolv iproute2
|
||||||
|
COPY --from=builder /usr/bin/wireguard-go /usr/bin/wg* /usr/bin/
|
||||||
|
COPY --from=builder /app/netclient-app ./netclient
|
||||||
|
COPY --from=builder /app/scripts/netclient.sh .
|
||||||
|
RUN chmod 0755 netclient && chmod 0755 netclient.sh
|
||||||
|
|
||||||
|
ENV WG_QUICK_USERSPACE_IMPLEMENTATION=wireguard-go
|
||||||
|
|
||||||
|
ENTRYPOINT ["/bin/sh", "./netclient.sh"]
|
|
@ -22,7 +22,7 @@ copyright = '2021, Alex Feiszli'
|
||||||
author = 'Alex Feiszli'
|
author = 'Alex Feiszli'
|
||||||
|
|
||||||
# The full version, including alpha/beta/rc tags
|
# The full version, including alpha/beta/rc tags
|
||||||
release = '0.9.0'
|
release = '0.9.1'
|
||||||
|
|
||||||
|
|
||||||
# -- General configuration ---------------------------------------------------
|
# -- General configuration ---------------------------------------------------
|
||||||
|
|
43
kube/netclient-template-doks-uspace.yaml
Normal file
43
kube/netclient-template-doks-uspace.yaml
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: DaemonSet
|
||||||
|
metadata:
|
||||||
|
name: netclient-1
|
||||||
|
labels:
|
||||||
|
app: netclient-1
|
||||||
|
spec:
|
||||||
|
selector:
|
||||||
|
matchLabels:
|
||||||
|
app: netclient-1
|
||||||
|
template:
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
app: netclient-1
|
||||||
|
spec:
|
||||||
|
hostNetwork: true
|
||||||
|
containers:
|
||||||
|
- name: netclient-1
|
||||||
|
image: gravitl/netclient:0.9.1-doks-uspace
|
||||||
|
env:
|
||||||
|
- name: NETCLIENT_ROAMING
|
||||||
|
value: "no"
|
||||||
|
- name: NETCLIENT_PORT
|
||||||
|
value: "51821"
|
||||||
|
- name: NETCLIENT_IS_STATIC
|
||||||
|
value: "yes"
|
||||||
|
- name: NETCLIENT_ENDPOINT
|
||||||
|
valueFrom:
|
||||||
|
fieldRef:
|
||||||
|
fieldPath: status.hostIP
|
||||||
|
- name: TOKEN
|
||||||
|
value: "<token>"
|
||||||
|
volumeMounts:
|
||||||
|
- mountPath: /etc/netclient
|
||||||
|
name: etc-netclient
|
||||||
|
securityContext:
|
||||||
|
privileged: true
|
||||||
|
volumes:
|
||||||
|
- hostPath:
|
||||||
|
path: /etc/netclient
|
||||||
|
type: DirectoryOrCreate
|
||||||
|
name: etc-netclient
|
||||||
|
|
93
kube/netclient-template-doks.yaml
Normal file
93
kube/netclient-template-doks.yaml
Normal file
|
@ -0,0 +1,93 @@
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: DaemonSet
|
||||||
|
metadata:
|
||||||
|
name: netclient-1
|
||||||
|
labels:
|
||||||
|
app: netclient-1
|
||||||
|
spec:
|
||||||
|
selector:
|
||||||
|
matchLabels:
|
||||||
|
app: netclient-1
|
||||||
|
template:
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
app: netclient-1
|
||||||
|
spec:
|
||||||
|
hostNetwork: true
|
||||||
|
containers:
|
||||||
|
- name: netclient-1
|
||||||
|
image: gravitl/netclient:0.9.1-doks
|
||||||
|
env:
|
||||||
|
- name: NETCLIENT_ROAMING
|
||||||
|
value: "no"
|
||||||
|
- name: NETCLIENT_PORT
|
||||||
|
value: "51821"
|
||||||
|
- name: NETCLIENT_IS_STATIC
|
||||||
|
value: "yes"
|
||||||
|
- name: NETCLIENT_ENDPOINT
|
||||||
|
valueFrom:
|
||||||
|
fieldRef:
|
||||||
|
fieldPath: status.hostIP
|
||||||
|
- name: TOKEN
|
||||||
|
value: "<token>"
|
||||||
|
volumeMounts:
|
||||||
|
- mountPath: /etc/netclient
|
||||||
|
name: etc-netclient
|
||||||
|
- mountPath: /usr/bin/wg
|
||||||
|
name: wg
|
||||||
|
securityContext:
|
||||||
|
privileged: true
|
||||||
|
volumes:
|
||||||
|
- hostPath:
|
||||||
|
path: /etc/netclient
|
||||||
|
type: DirectoryOrCreate
|
||||||
|
name: etc-netclient
|
||||||
|
- hostPath:
|
||||||
|
path: /usr/bin/wg
|
||||||
|
type: File
|
||||||
|
name: wg
|
||||||
|
---
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: DaemonSet
|
||||||
|
metadata:
|
||||||
|
name: wireguard-controller
|
||||||
|
labels:
|
||||||
|
app: wireguard-controller
|
||||||
|
spec:
|
||||||
|
selector:
|
||||||
|
matchLabels:
|
||||||
|
app: wireguard-controller
|
||||||
|
template:
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
app: wireguard-controller
|
||||||
|
spec:
|
||||||
|
hostNetwork: true
|
||||||
|
containers:
|
||||||
|
- image: gravitl/netclient:0.9.1-doks
|
||||||
|
imagePullPolicy: IfNotPresent
|
||||||
|
name: wg-installer
|
||||||
|
command: ['bash', '-c']
|
||||||
|
args:
|
||||||
|
- while [ 1 ];
|
||||||
|
do if ! command -v wg &> /dev/null;
|
||||||
|
then echo "wireguard not installed, installing";
|
||||||
|
echo 'deb http://deb.debian.org/debian buster-backports main contrib non-free' > /etc/apt/sources.list.d/buster-backports.list;
|
||||||
|
apt update;
|
||||||
|
sudo apt -y install linux-headers-$(uname --kernel-release);
|
||||||
|
apt -y install wireguard wireguard-tools;
|
||||||
|
else echo "wireguard installed";
|
||||||
|
sleep 300;
|
||||||
|
fi;
|
||||||
|
done
|
||||||
|
securityContext:
|
||||||
|
privileged: true
|
||||||
|
volumeMounts:
|
||||||
|
- name: rootfolder
|
||||||
|
mountPath: /
|
||||||
|
volumes:
|
||||||
|
- hostPath:
|
||||||
|
path: /
|
||||||
|
type: ""
|
||||||
|
name: rootfolder
|
||||||
|
|
|
@ -136,7 +136,7 @@ func ServerJoin(network string, serverID string, privateKey string) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = initWireguard(node, privateKey, peers, hasGateway, gateways, 0)
|
err = initWireguard(node, privateKey, peers, hasGateway, gateways)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,7 +47,7 @@ func RemoveConf(iface string, printlog bool) error {
|
||||||
|
|
||||||
// Private Functions
|
// Private Functions
|
||||||
|
|
||||||
func initWireguard(node *models.Node, privkey string, peers []wgtypes.PeerConfig, hasGateway bool, gateways []string, fwmark int32) error {
|
func initWireguard(node *models.Node, privkey string, peers []wgtypes.PeerConfig, hasGateway bool, gateways []string) error {
|
||||||
|
|
||||||
key, err := wgtypes.ParseKey(privkey)
|
key, err := wgtypes.ParseKey(privkey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -85,7 +85,7 @@ func initWireguard(node *models.Node, privkey string, peers []wgtypes.PeerConfig
|
||||||
|
|
||||||
if !ncutils.IsKernel() {
|
if !ncutils.IsKernel() {
|
||||||
var newConf string
|
var newConf string
|
||||||
newConf, _ = ncutils.CreateUserSpaceConf(node.Address, key.String(), strconv.FormatInt(int64(node.ListenPort), 10), node.MTU, fwmark, node.PersistentKeepalive, peers)
|
newConf, _ = ncutils.CreateUserSpaceConf(node.Address, key.String(), strconv.FormatInt(int64(node.ListenPort), 10), node.MTU, node.PersistentKeepalive, peers)
|
||||||
confPath := ncutils.GetNetclientPathSpecific() + ifacename + ".conf"
|
confPath := ncutils.GetNetclientPathSpecific() + ifacename + ".conf"
|
||||||
Log("writing wg conf file to: "+confPath, 1)
|
Log("writing wg conf file to: "+confPath, 1)
|
||||||
err = ioutil.WriteFile(confPath, []byte(newConf), 0644)
|
err = ioutil.WriteFile(confPath, []byte(newConf), 0644)
|
||||||
|
@ -293,7 +293,7 @@ func setWGConfig(node models.Node, network string, peerupdate bool) error {
|
||||||
err = setServerPeers(iface, node.PersistentKeepalive, peers)
|
err = setServerPeers(iface, node.PersistentKeepalive, peers)
|
||||||
Log("updated peers on server "+node.Name, 2)
|
Log("updated peers on server "+node.Name, 2)
|
||||||
} else {
|
} else {
|
||||||
err = initWireguard(&node, privkey, peers, hasGateway, gateways, 0)
|
err = initWireguard(&node, privkey, peers, hasGateway, gateways)
|
||||||
Log("finished setting wg config on server "+node.Name, 3)
|
Log("finished setting wg config on server "+node.Name, 3)
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -48,6 +48,10 @@ func Join(cfg config.ClientConfig, privateKey string) error {
|
||||||
} else {
|
} else {
|
||||||
ncutils.PrintLog("success", 0)
|
ncutils.PrintLog("success", 0)
|
||||||
}
|
}
|
||||||
|
if strings.Contains(err.Error(), "ALREADY_INSTALLED") {
|
||||||
|
ncutils.PrintLog(err.Error(), 0)
|
||||||
|
err = nil
|
||||||
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
ncutils.PrintLog("joined "+cfg.Network, 1)
|
ncutils.PrintLog("joined "+cfg.Network, 1)
|
||||||
|
@ -91,7 +95,7 @@ func RunUserspaceDaemon() {
|
||||||
|
|
||||||
func CheckIn(cfg config.ClientConfig) error {
|
func CheckIn(cfg config.ClientConfig) error {
|
||||||
var err error
|
var err error
|
||||||
|
var errN error
|
||||||
if cfg.Network == "" {
|
if cfg.Network == "" {
|
||||||
ncutils.PrintLog("required, '-n', exiting", 0)
|
ncutils.PrintLog("required, '-n', exiting", 0)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
|
@ -119,10 +123,14 @@ func CheckIn(cfg config.ClientConfig) error {
|
||||||
daemon.StopWindowsDaemon()
|
daemon.StopWindowsDaemon()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
errN = err
|
||||||
err = nil
|
err = nil
|
||||||
} else {
|
} else {
|
||||||
err = functions.CheckConfig(cfg)
|
err = functions.CheckConfig(cfg)
|
||||||
}
|
}
|
||||||
|
if err == nil && errN != nil {
|
||||||
|
err = errN
|
||||||
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -31,7 +31,6 @@ type ClientConfig struct {
|
||||||
Daemon string `yaml:"daemon"`
|
Daemon string `yaml:"daemon"`
|
||||||
OperatingSystem string `yaml:"operatingsystem"`
|
OperatingSystem string `yaml:"operatingsystem"`
|
||||||
DebugJoin bool `yaml:"debugjoin"`
|
DebugJoin bool `yaml:"debugjoin"`
|
||||||
FWMark int32 `yaml:"fwmark"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ServerConfig - struct for dealing with the server information for a netclient
|
// ServerConfig - struct for dealing with the server information for a netclient
|
||||||
|
@ -342,6 +341,7 @@ func GetCLIConfig(c *cli.Context) (ClientConfig, string, error) {
|
||||||
cfg.Node.Roaming = c.String("roaming")
|
cfg.Node.Roaming = c.String("roaming")
|
||||||
cfg.Node.DNSOn = c.String("dnson")
|
cfg.Node.DNSOn = c.String("dnson")
|
||||||
cfg.Node.IsLocal = c.String("islocal")
|
cfg.Node.IsLocal = c.String("islocal")
|
||||||
|
cfg.Node.IsStatic = c.String("isstatic")
|
||||||
cfg.Node.IsDualStack = c.String("isdualstack")
|
cfg.Node.IsDualStack = c.String("isdualstack")
|
||||||
cfg.Node.PostUp = c.String("postup")
|
cfg.Node.PostUp = c.String("postup")
|
||||||
cfg.Node.PostDown = c.String("postdown")
|
cfg.Node.PostDown = c.String("postdown")
|
||||||
|
|
|
@ -6,9 +6,7 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"math/rand"
|
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"time"
|
|
||||||
|
|
||||||
nodepb "github.com/gravitl/netmaker/grpc"
|
nodepb "github.com/gravitl/netmaker/grpc"
|
||||||
"github.com/gravitl/netmaker/models"
|
"github.com/gravitl/netmaker/models"
|
||||||
|
@ -35,12 +33,6 @@ func JoinNetwork(cfg config.ClientConfig, privateKey string) error {
|
||||||
err := errors.New("ALREADY_INSTALLED. Netclient appears to already be installed for " + cfg.Network + ". To re-install, please remove by executing 'sudo netclient leave -n " + cfg.Network + "'. Then re-run the install command.")
|
err := errors.New("ALREADY_INSTALLED. Netclient appears to already be installed for " + cfg.Network + ". To re-install, please remove by executing 'sudo netclient leave -n " + cfg.Network + "'. Then re-run the install command.")
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if cfg.FWMark == 0 {
|
|
||||||
rand.Seed(time.Now().UnixNano())
|
|
||||||
var min int32 = 1000
|
|
||||||
var max int32 = 9999
|
|
||||||
cfg.FWMark = rand.Int31n(max-min) + min
|
|
||||||
}
|
|
||||||
|
|
||||||
err = config.Write(&cfg, cfg.Network)
|
err = config.Write(&cfg, cfg.Network)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -111,6 +103,7 @@ func JoinNetwork(cfg config.ClientConfig, privateKey string) error {
|
||||||
MacAddress: cfg.Node.MacAddress,
|
MacAddress: cfg.Node.MacAddress,
|
||||||
AccessKey: cfg.Server.AccessKey,
|
AccessKey: cfg.Server.AccessKey,
|
||||||
IsStatic: cfg.Node.IsStatic,
|
IsStatic: cfg.Node.IsStatic,
|
||||||
|
Roaming: cfg.Node.Roaming,
|
||||||
Network: cfg.Network,
|
Network: cfg.Network,
|
||||||
ListenPort: cfg.Node.ListenPort,
|
ListenPort: cfg.Node.ListenPort,
|
||||||
PostUp: cfg.Node.PostUp,
|
PostUp: cfg.Node.PostUp,
|
||||||
|
|
|
@ -24,7 +24,7 @@ func main() {
|
||||||
app := cli.NewApp()
|
app := cli.NewApp()
|
||||||
app.Name = "Netclient CLI"
|
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.Usage = "Netmaker's netclient agent and CLI. Used to perform interactions with Netmaker server and set local WireGuard config."
|
||||||
app.Version = "v0.9.0"
|
app.Version = "v0.9.1"
|
||||||
|
|
||||||
hostname, err := os.Hostname()
|
hostname, err := os.Hostname()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -105,6 +105,13 @@ func main() {
|
||||||
Value: "",
|
Value: "",
|
||||||
Usage: "Local address for machine. Can be used in place of Endpoint for machines on the same LAN.",
|
Usage: "Local address for machine. Can be used in place of Endpoint for machines on the same LAN.",
|
||||||
},
|
},
|
||||||
|
&cli.StringFlag{
|
||||||
|
Name: "isstatic",
|
||||||
|
Aliases: []string{"st"},
|
||||||
|
EnvVars: []string{"NETCLIENT_IS_STATIC"},
|
||||||
|
Value: "",
|
||||||
|
Usage: "Indicates if client is static by default (will not change addresses automatically).",
|
||||||
|
},
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "address",
|
Name: "address",
|
||||||
Aliases: []string{"a"},
|
Aliases: []string{"a"},
|
||||||
|
|
|
@ -410,7 +410,7 @@ func GetSystemNetworks() ([]string, error) {
|
||||||
return networks, err
|
return networks, err
|
||||||
}
|
}
|
||||||
for _, f := range files {
|
for _, f := range files {
|
||||||
if strings.Contains(f.Name(), "netconfig-") {
|
if strings.Contains(f.Name(), "netconfig-") && !strings.Contains(f.Name(), "backup") {
|
||||||
networkname := stringAfter(f.Name(), "netconfig-")
|
networkname := stringAfter(f.Name(), "netconfig-")
|
||||||
networks = append(networks, networkname)
|
networks = append(networks, networkname)
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,19 +28,15 @@ func RunCmdFormatted(command string, printerr bool) (string, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateUserSpaceConf - creates a user space WireGuard conf
|
// CreateUserSpaceConf - creates a user space WireGuard conf
|
||||||
func CreateUserSpaceConf(address string, privatekey string, listenPort string, mtu int32, fwmark int32, perskeepalive int32, peers []wgtypes.PeerConfig) (string, error) {
|
func CreateUserSpaceConf(address string, privatekey string, listenPort string, mtu int32, perskeepalive int32, peers []wgtypes.PeerConfig) (string, error) {
|
||||||
peersString, err := parsePeers(perskeepalive, peers)
|
peersString, err := parsePeers(perskeepalive, peers)
|
||||||
var listenPortString string
|
var listenPortString string
|
||||||
var fwmarkString string
|
|
||||||
if mtu <= 0 {
|
if mtu <= 0 {
|
||||||
mtu = 1280
|
mtu = 1280
|
||||||
}
|
}
|
||||||
if listenPort != "" {
|
if listenPort != "" {
|
||||||
listenPortString += "ListenPort = " + listenPort
|
listenPortString += "ListenPort = " + listenPort
|
||||||
}
|
}
|
||||||
if fwmark != 0 {
|
|
||||||
fwmarkString += "FWMark = " + strconv.Itoa(int(fwmark))
|
|
||||||
}
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
@ -49,7 +45,6 @@ Address = %s
|
||||||
PrivateKey = %s
|
PrivateKey = %s
|
||||||
MTU = %s
|
MTU = %s
|
||||||
%s
|
%s
|
||||||
%s
|
|
||||||
|
|
||||||
%s
|
%s
|
||||||
|
|
||||||
|
@ -58,7 +53,6 @@ MTU = %s
|
||||||
privatekey,
|
privatekey,
|
||||||
strconv.Itoa(int(mtu)),
|
strconv.Itoa(int(mtu)),
|
||||||
listenPortString,
|
listenPortString,
|
||||||
fwmarkString,
|
|
||||||
peersString)
|
peersString)
|
||||||
return config, nil
|
return config, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,19 +36,15 @@ func RunCmd(command string, printerr bool) (string, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateUserSpaceConf - creates a user space WireGuard conf
|
// CreateUserSpaceConf - creates a user space WireGuard conf
|
||||||
func CreateUserSpaceConf(address string, privatekey string, listenPort string, mtu int32, fwmark int32, perskeepalive int32, peers []wgtypes.PeerConfig) (string, error) {
|
func CreateUserSpaceConf(address string, privatekey string, listenPort string, mtu int32, perskeepalive int32, peers []wgtypes.PeerConfig) (string, error) {
|
||||||
peersString, err := parsePeers(perskeepalive, peers)
|
peersString, err := parsePeers(perskeepalive, peers)
|
||||||
var listenPortString string
|
var listenPortString string
|
||||||
var fwmarkString string
|
|
||||||
if mtu <= 0 {
|
if mtu <= 0 {
|
||||||
mtu = 1280
|
mtu = 1280
|
||||||
}
|
}
|
||||||
if listenPort != "" {
|
if listenPort != "" {
|
||||||
listenPortString += "ListenPort = " + listenPort
|
listenPortString += "ListenPort = " + listenPort
|
||||||
}
|
}
|
||||||
if fwmark != 0 {
|
|
||||||
fwmarkString += "FWMark = " + strconv.Itoa(int(fwmark))
|
|
||||||
}
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
@ -57,7 +53,6 @@ Address = %s
|
||||||
PrivateKey = %s
|
PrivateKey = %s
|
||||||
MTU = %s
|
MTU = %s
|
||||||
%s
|
%s
|
||||||
%s
|
|
||||||
|
|
||||||
%s
|
%s
|
||||||
|
|
||||||
|
@ -66,7 +61,6 @@ MTU = %s
|
||||||
privatekey,
|
privatekey,
|
||||||
strconv.Itoa(int(mtu)),
|
strconv.Itoa(int(mtu)),
|
||||||
listenPortString,
|
listenPortString,
|
||||||
fwmarkString,
|
|
||||||
peersString)
|
peersString)
|
||||||
return config, nil
|
return config, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,19 +28,15 @@ func RunCmdFormatted(command string, printerr bool) (string, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateUserSpaceConf - creates a user space WireGuard conf
|
// CreateUserSpaceConf - creates a user space WireGuard conf
|
||||||
func CreateUserSpaceConf(address string, privatekey string, listenPort string, mtu int32, fwmark int32, perskeepalive int32, peers []wgtypes.PeerConfig) (string, error) {
|
func CreateUserSpaceConf(address string, privatekey string, listenPort string, mtu int32, perskeepalive int32, peers []wgtypes.PeerConfig) (string, error) {
|
||||||
peersString, err := parsePeers(perskeepalive, peers)
|
peersString, err := parsePeers(perskeepalive, peers)
|
||||||
var listenPortString string
|
var listenPortString string
|
||||||
var fwmarkString string
|
|
||||||
if mtu <= 0 {
|
if mtu <= 0 {
|
||||||
mtu = 1280
|
mtu = 1280
|
||||||
}
|
}
|
||||||
if listenPort != "" {
|
if listenPort != "" {
|
||||||
listenPortString += "ListenPort = " + listenPort
|
listenPortString += "ListenPort = " + listenPort
|
||||||
}
|
}
|
||||||
if fwmark != 0 {
|
|
||||||
fwmarkString += "FWMark = " + strconv.Itoa(int(fwmark))
|
|
||||||
}
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
@ -49,7 +45,6 @@ Address = %s
|
||||||
PrivateKey = %s
|
PrivateKey = %s
|
||||||
MTU = %s
|
MTU = %s
|
||||||
%s
|
%s
|
||||||
%s
|
|
||||||
|
|
||||||
%s
|
%s
|
||||||
|
|
||||||
|
@ -58,7 +53,6 @@ MTU = %s
|
||||||
privatekey,
|
privatekey,
|
||||||
strconv.Itoa(int(mtu)),
|
strconv.Itoa(int(mtu)),
|
||||||
listenPortString,
|
listenPortString,
|
||||||
fwmarkString,
|
|
||||||
peersString)
|
peersString)
|
||||||
return config, nil
|
return config, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,7 +44,7 @@ func RunCmdFormatted(command string, printerr bool) (string, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateUserSpaceConf - creates a user space WireGuard conf
|
// CreateUserSpaceConf - creates a user space WireGuard conf
|
||||||
func CreateUserSpaceConf(address string, privatekey string, listenPort string, mtu int32, fwmark int32, perskeepalive int32, peers []wgtypes.PeerConfig) (string, error) {
|
func CreateUserSpaceConf(address string, privatekey string, listenPort string, mtu int32, perskeepalive int32, peers []wgtypes.PeerConfig) (string, error) {
|
||||||
peersString, err := parsePeers(perskeepalive, peers)
|
peersString, err := parsePeers(perskeepalive, peers)
|
||||||
var listenPortString string
|
var listenPortString string
|
||||||
if mtu <= 0 {
|
if mtu <= 0 {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||||
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
|
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
|
||||||
<assemblyIdentity
|
<assemblyIdentity
|
||||||
version="0.8.5.0"
|
version="0.9.1.0"
|
||||||
processorArchitecture="*"
|
processorArchitecture="*"
|
||||||
name="netclient.exe"
|
name="netclient.exe"
|
||||||
type="win32"
|
type="win32"
|
||||||
|
|
|
@ -29,7 +29,7 @@
|
||||||
"OriginalFilename": "",
|
"OriginalFilename": "",
|
||||||
"PrivateBuild": "",
|
"PrivateBuild": "",
|
||||||
"ProductName": "Netclient",
|
"ProductName": "Netclient",
|
||||||
"ProductVersion": "v0.9.0.0",
|
"ProductVersion": "v0.9.1.0",
|
||||||
"SpecialBuild": ""
|
"SpecialBuild": ""
|
||||||
},
|
},
|
||||||
"VarFileInfo": {
|
"VarFileInfo": {
|
||||||
|
|
|
@ -119,8 +119,6 @@ func InitWireguard(node *models.Node, privkey string, peers []wgtypes.PeerConfig
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
fwmarkint32 := modcfg.FWMark
|
|
||||||
fwmarkint := int(fwmarkint32)
|
|
||||||
nodecfg := modcfg.Node
|
nodecfg := modcfg.Node
|
||||||
servercfg := modcfg.Server
|
servercfg := modcfg.Server
|
||||||
|
|
||||||
|
@ -168,7 +166,6 @@ func InitWireguard(node *models.Node, privkey string, peers []wgtypes.PeerConfig
|
||||||
conf = wgtypes.Config{
|
conf = wgtypes.Config{
|
||||||
PrivateKey: &key,
|
PrivateKey: &key,
|
||||||
ListenPort: &nodeport,
|
ListenPort: &nodeport,
|
||||||
FirewallMark: &fwmarkint,
|
|
||||||
ReplacePeers: true,
|
ReplacePeers: true,
|
||||||
Peers: peers,
|
Peers: peers,
|
||||||
}
|
}
|
||||||
|
@ -176,9 +173,9 @@ func InitWireguard(node *models.Node, privkey string, peers []wgtypes.PeerConfig
|
||||||
if !ncutils.IsKernel() {
|
if !ncutils.IsKernel() {
|
||||||
var newConf string
|
var newConf string
|
||||||
if node.UDPHolePunch != "yes" {
|
if node.UDPHolePunch != "yes" {
|
||||||
newConf, _ = ncutils.CreateUserSpaceConf(node.Address, key.String(), strconv.FormatInt(int64(node.ListenPort), 10), node.MTU, fwmarkint32, node.PersistentKeepalive, peers)
|
newConf, _ = ncutils.CreateUserSpaceConf(node.Address, key.String(), strconv.FormatInt(int64(node.ListenPort), 10), node.MTU, node.PersistentKeepalive, peers)
|
||||||
} else {
|
} else {
|
||||||
newConf, _ = ncutils.CreateUserSpaceConf(node.Address, key.String(), "", node.MTU, fwmarkint32, node.PersistentKeepalive, peers)
|
newConf, _ = ncutils.CreateUserSpaceConf(node.Address, key.String(), "", node.MTU, node.PersistentKeepalive, peers)
|
||||||
}
|
}
|
||||||
confPath := ncutils.GetNetclientPathSpecific() + ifacename + ".conf"
|
confPath := ncutils.GetNetclientPathSpecific() + ifacename + ".conf"
|
||||||
ncutils.PrintLog("writing wg conf file to: "+confPath, 1)
|
ncutils.PrintLog("writing wg conf file to: "+confPath, 1)
|
||||||
|
@ -325,7 +322,7 @@ func SetWGConfig(network string, peerupdate bool) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if peerupdate && !ncutils.IsFreeBSD() {
|
if peerupdate && !ncutils.IsFreeBSD() && !(ncutils.IsLinux() && !ncutils.IsKernel()) {
|
||||||
var iface string
|
var iface string
|
||||||
iface = nodecfg.Interface
|
iface = nodecfg.Interface
|
||||||
if ncutils.IsMac() {
|
if ncutils.IsMac() {
|
||||||
|
|
290
scripts/install-netmaker.sh
Normal file
290
scripts/install-netmaker.sh
Normal file
|
@ -0,0 +1,290 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
cat << "EOF"
|
||||||
|
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
|
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
|
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
|
______ ______ ______ __ __ __ ______ __
|
||||||
|
/\ ___\ /\ == \ /\ __ \ /\ \ / / /\ \ /\__ _\ /\ \
|
||||||
|
\ \ \__ \ \ \ __< \ \ __ \ \ \ \'/ \ \ \ \/_/\ \/ \ \ \____
|
||||||
|
\ \_____\ \ \_\ \_\ \ \_\ \_\ \ \__| \ \_\ \ \_\ \ \_____\
|
||||||
|
\/_____/ \/_/ /_/ \/_/\/_/ \/_/ \/_/ \/_/ \/_____/
|
||||||
|
|
||||||
|
__ __ ______ ______ __ __ ______ __ __ ______ ______
|
||||||
|
/\ "-.\ \ /\ ___\ /\__ _\ /\ "-./ \ /\ __ \ /\ \/ / /\ ___\ /\ == \
|
||||||
|
\ \ \-. \ \ \ __\ \/_/\ \/ \ \ \-./\ \ \ \ __ \ \ \ _"-. \ \ __\ \ \ __<
|
||||||
|
\ \_\\"\_\ \ \_____\ \ \_\ \ \_\ \ \_\ \ \_\ \_\ \ \_\ \_\ \ \_____\ \ \_\ \_\
|
||||||
|
\/_/ \/_/ \/_____/ \/_/ \/_/ \/_/ \/_/\/_/ \/_/\/_/ \/_____/ \/_/ /_/
|
||||||
|
|
||||||
|
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
|
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
|
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
|
EOF
|
||||||
|
|
||||||
|
NETMAKER_BASE_DOMAIN=nm.$(curl -s ifconfig.me | tr . -).nip.io
|
||||||
|
COREDNS_IP=$(ip route get 1 | sed -n 's/^.*src \([0-9.]*\) .*$/\1/p')
|
||||||
|
SERVER_PUBLIC_IP=$(curl -s ifconfig.me)
|
||||||
|
MASTER_KEY=$(tr -dc A-Za-z0-9 </dev/urandom | head -c 30 ; echo '')
|
||||||
|
EMAIL="fake@email.com"
|
||||||
|
|
||||||
|
echo "Default Base Domain: $NETMAKER_BASE_DOMAIN"
|
||||||
|
echo "To Override, add a Wildcard (*.netmaker.example.com) DNS record pointing to $SERVER_PUBLIC_IP"
|
||||||
|
echo "Or, add three DNS records pointing to $SERVER_PUBLIC_IP for the following (Replacing 'netmaker.example.com' with the domain of your choice):"
|
||||||
|
echo " dashboard.netmaker.example.com"
|
||||||
|
echo " api.netmaker.example.com"
|
||||||
|
echo " grpc.netmaker.example.com"
|
||||||
|
echo "-----------------------------------------------------"
|
||||||
|
read -p "Domain (Hit 'enter' to use $NETMAKER_BASE_DOMAIN): " domain
|
||||||
|
read -p "Contact Email: " email
|
||||||
|
|
||||||
|
if [ -n "$domain" ]; then
|
||||||
|
NETMAKER_BASE_DOMAIN=$domain
|
||||||
|
fi
|
||||||
|
if [ -n "$email" ]; then
|
||||||
|
EMAIL=$email
|
||||||
|
fi
|
||||||
|
|
||||||
|
while true; do
|
||||||
|
read -p "Configure a default network automatically (y/n)? " yn
|
||||||
|
case $yn in
|
||||||
|
[Yy]* ) MESH_SETUP="true"; break;;
|
||||||
|
[Nn]* ) MESH_SETUP="false"; break;;
|
||||||
|
* ) echo "Please answer yes or no.";;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
while true; do
|
||||||
|
read -p "Configure a VPN gateway automatically (y/n)? " yn
|
||||||
|
case $yn in
|
||||||
|
[Yy]* ) VPN_SETUP="true"; break;;
|
||||||
|
[Nn]* ) VPN_SETUP="false"; break;;
|
||||||
|
* ) echo "Please answer yes or no.";;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
if [ "${VPN_SETUP}" == "true" ]; then
|
||||||
|
while :; do
|
||||||
|
read -ep '# of VPN clients to configure by default: ' num_clients
|
||||||
|
[[ $num_clients =~ ^[[:digit:]]+$ ]] || continue
|
||||||
|
(( ( (num_clients=(10#$num_clients)) <= 200 ) && num_clients >= 0 )) || continue
|
||||||
|
break
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -n "$num_clients" ]; then
|
||||||
|
NUM_CLIENTS=$num_clients
|
||||||
|
fi
|
||||||
|
|
||||||
|
while true; do
|
||||||
|
read -p "Override master key ($MASTER_KEY) (y/n)? " yn
|
||||||
|
case $yn in
|
||||||
|
[Yy]* ) override="true"; break;;
|
||||||
|
[Nn]* ) override="false"; break;;
|
||||||
|
* ) echo "Please answer yes or no.";;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
if [ "${override}" == "true" ]; then
|
||||||
|
while :; do
|
||||||
|
read -ep 'New Master Key: ' key
|
||||||
|
result="$(cracklib-check <<<"$key")"
|
||||||
|
okay="$(awk -F': ' '{ print $2}' <<<"$result")"
|
||||||
|
if [[ "$okay" == "OK" ]]
|
||||||
|
then
|
||||||
|
MASTER_KEY=$key
|
||||||
|
break
|
||||||
|
else
|
||||||
|
echo "Your password was rejected - $result"
|
||||||
|
echo "Try again."
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "-----------------------------------------------------------------"
|
||||||
|
echo " SETUP ARGUMENTS"
|
||||||
|
echo "-----------------------------------------------------------------"
|
||||||
|
echo " domain: $NETMAKER_BASE_DOMAIN"
|
||||||
|
echo " email: $EMAIL"
|
||||||
|
echo " coredns ip: $COREDNS_IP"
|
||||||
|
echo " public ip: $SERVER_PUBLIC_IP"
|
||||||
|
echo " master key: $MASTER_KEY"
|
||||||
|
echo " setup mesh?: $MESH_SETUP"
|
||||||
|
echo " setup vpn?: $VPN_SETUP"
|
||||||
|
if [ "${VPN_SETUP}" == "true" ]; then
|
||||||
|
echo " # clients: $NUM_CLIENTS"
|
||||||
|
fi
|
||||||
|
|
||||||
|
while true; do
|
||||||
|
read -p "Does everything look right (y/n)? " yn
|
||||||
|
case $yn in
|
||||||
|
[Yy]* ) override="true"; break;;
|
||||||
|
[Nn]* ) echo "exiting..."; exit;;
|
||||||
|
* ) echo "Please answer yes or no.";;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
|
||||||
|
echo "Beginning installation in 5 seconds..."
|
||||||
|
|
||||||
|
sleep 5
|
||||||
|
|
||||||
|
|
||||||
|
echo "Setting Caddyfile..."
|
||||||
|
|
||||||
|
sed -i "s/NETMAKER_BASE_DOMAIN/$NETMAKER_BASE_DOMAIN/g" /root/Caddyfile
|
||||||
|
sed -i "s/YOUR_EMAIL/$EMAIL/g" /root/Caddyfile
|
||||||
|
|
||||||
|
echo "Setting docker-compose..."
|
||||||
|
|
||||||
|
sed -i "s/NETMAKER_BASE_DOMAIN/$NETMAKER_BASE_DOMAIN/g" /root/docker-compose.yml
|
||||||
|
sed -i "s/SERVER_PUBLIC_IP/$SERVER_PUBLIC_IP/g" /root/docker-compose.yml
|
||||||
|
sed -i "s/COREDNS_IP/$COREDNS_IP/g" /root/docker-compose.yml
|
||||||
|
sed -i "s/REPLACE_MASTER_KEY/$MASTER_KEY/g" /root/docker-compose.yml
|
||||||
|
|
||||||
|
echo "Starting containers..."
|
||||||
|
|
||||||
|
docker-compose -f /root/docker-compose.yml up -d
|
||||||
|
|
||||||
|
sleep 2
|
||||||
|
|
||||||
|
setup_mesh() {
|
||||||
|
echo "Creating default network (10.101.0.0/16)..."
|
||||||
|
|
||||||
|
curl -s -o /dev/null -d '{"addressrange":"10.101.0.0/16","netid":"default"}' -H "Authorization: Bearer $MASTER_KEY" -H 'Content-Type: application/json' localhost:8081/api/networks
|
||||||
|
|
||||||
|
sleep 2
|
||||||
|
|
||||||
|
echo "Creating default key..."
|
||||||
|
|
||||||
|
curlresponse=$(curl -s -d '{"uses":99999,"name":"defaultkey"}' -H "Authorization: Bearer $MASTER_KEY" -H 'Content-Type: application/json' localhost:8081/api/networks/default/keys)
|
||||||
|
ACCESS_TOKEN=$(jq -r '.accessstring' <<< ${curlresponse})
|
||||||
|
|
||||||
|
sleep 2
|
||||||
|
|
||||||
|
echo "Configuring Netmaker server as ingress gateway..."
|
||||||
|
|
||||||
|
curlresponse=$(curl -s -H "Authorization: Bearer $MASTER_KEY" -H 'Content-Type: application/json' localhost:8081/api/nodes/default)
|
||||||
|
SERVER_ID=$(jq -r '.[0].macaddress' <<< ${curlresponse})
|
||||||
|
|
||||||
|
curl -o /dev/null -s -X POST -H "Authorization: Bearer $MASTER_KEY" -H 'Content-Type: application/json' localhost:8081/api/nodes/default/$SERVER_ID/createingress
|
||||||
|
|
||||||
|
VPN_ACCESS_TOKEN=$ACCESS_TOKEN
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
mesh_connect_logs() {
|
||||||
|
sleep 5
|
||||||
|
echo "-----------------------------------------------------------------"
|
||||||
|
echo "-----------------------------------------------------------------"
|
||||||
|
echo "DEFAULT NETWORK CLIENT INSTALL INSTRUCTIONS:"
|
||||||
|
echo "-----------------------------------------------------------------"
|
||||||
|
echo "-----------------------------------------------------------------"
|
||||||
|
sleep 5
|
||||||
|
echo "For Linux and Mac clients, install with the following command:"
|
||||||
|
echo "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -"
|
||||||
|
echo "curl -sfL https://raw.githubusercontent.com/gravitl/netmaker/develop/scripts/netclient-install.sh | sudo KEY=$VPN_ACCESS_TOKEN sh -"
|
||||||
|
sleep 5
|
||||||
|
echo "-----------------------------------------------------------------"
|
||||||
|
echo "-----------------------------------------------------------------"
|
||||||
|
echo "For Windows clients, perform the following from powershell, as administrator:"
|
||||||
|
echo "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -"
|
||||||
|
echo "1. Make sure WireGuardNT is installed - https://download.wireguard.com/windows-client/wireguard-installer.exe"
|
||||||
|
echo "2. Download netclient.exe - wget https://github.com/gravitl/netmaker/releases/download/latest/netclient.exe"
|
||||||
|
echo "3. Install Netclient - powershell.exe .\\netclient.exe join -t $VPN_ACCESS_TOKEN"
|
||||||
|
echo "4. Whitelist C:\ProgramData\Netclient in Windows Defender"
|
||||||
|
sleep 5
|
||||||
|
echo "-----------------------------------------------------------------"
|
||||||
|
echo "-----------------------------------------------------------------"
|
||||||
|
echo "For Android and iOS clients, perform the following steps:"
|
||||||
|
echo "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -"
|
||||||
|
echo "1. Log into UI at dashboard.$NETMAKER_BASE_DOMAIN"
|
||||||
|
echo "2. Navigate to \"EXTERNAL CLIENTS\" tab"
|
||||||
|
echo "3. Select the gateway and create clients"
|
||||||
|
echo "4. Scan the QR Code from WireGuard app in iOS or Android"
|
||||||
|
echo "-----------------------------------------------------------------"
|
||||||
|
echo "-----------------------------------------------------------------"
|
||||||
|
sleep 5
|
||||||
|
}
|
||||||
|
|
||||||
|
setup_vpn() {
|
||||||
|
echo "Creating vpn network (10.201.0.0/16)..."
|
||||||
|
|
||||||
|
curl -s -o /dev/null -d '{"addressrange":"10.201.0.0/16","netid":"vpn","defaultextclientdns":"8.8.8.8"}' -H "Authorization: Bearer $MASTER_KEY" -H 'Content-Type: application/json' localhost:8081/api/networks
|
||||||
|
|
||||||
|
sleep 2
|
||||||
|
|
||||||
|
echo "Configuring Netmaker server as vpn inlet..."
|
||||||
|
|
||||||
|
curlresponse=$(curl -s -H "Authorization: Bearer $MASTER_KEY" -H 'Content-Type: application/json' localhost:8081/api/nodes/vpn)
|
||||||
|
SERVER_ID=$(jq -r '.[0].macaddress' <<< ${curlresponse})
|
||||||
|
|
||||||
|
curl -s -o /dev/null -X POST -H "Authorization: Bearer $MASTER_KEY" -H 'Content-Type: application/json' localhost:8081/api/nodes/vpn/$SERVER_ID/createingress
|
||||||
|
|
||||||
|
echo "Waiting 10 seconds for server to apply configuration..."
|
||||||
|
|
||||||
|
sleep 10
|
||||||
|
|
||||||
|
echo "Configuring Netmaker server VPN gateway..."
|
||||||
|
|
||||||
|
[ -z "$GATEWAY_IFACE" ] && GATEWAY_IFACE=$(ip -4 route ls | grep default | grep -Po '(?<=dev )(\S+)' | grep -v default)
|
||||||
|
|
||||||
|
curlresponse=$(curl -s -H "Authorization: Bearer $MASTER_KEY" -H 'Content-Type: application/json' localhost:8081/api/nodes/vpn)
|
||||||
|
SERVER_ID=$(jq -r '.[0].macaddress' <<< ${curlresponse})
|
||||||
|
|
||||||
|
EGRESS_JSON=$( jq -n \
|
||||||
|
--arg gw "$GATEWAY_IFACE" \
|
||||||
|
'{ranges: ["0.0.0.0/0"], interface: $gw}' )
|
||||||
|
|
||||||
|
curl -s -o /dev/null -X POST -d "$EGRESS_JSON" -H "Authorization: Bearer $MASTER_KEY" -H 'Content-Type: application/json' localhost:8081/api/nodes/vpn/$SERVER_ID/creategateway
|
||||||
|
|
||||||
|
echo "Creating client configs..."
|
||||||
|
|
||||||
|
for ((a=1; a <= $NUM_CLIENTS; a++))
|
||||||
|
do
|
||||||
|
CLIENT_JSON=$( jq -n \
|
||||||
|
--arg clientid "vpnclient-$a" \
|
||||||
|
'{clientid: $clientid}' )
|
||||||
|
|
||||||
|
curl -s -o /dev/null -d "$CLIENT_JSON" -H "Authorization: Bearer $MASTER_KEY" -H 'Content-Type: application/json' localhost:8081/api/extclients/vpn/$SERVER_ID
|
||||||
|
done
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
vpn_connect_logs() {
|
||||||
|
sleep 5
|
||||||
|
echo "-----------------------------------------------------------------"
|
||||||
|
echo "-----------------------------------------------------------------"
|
||||||
|
echo "VPN GATEWAY CLIENT INSTALL INSTRUCTIONS:"
|
||||||
|
echo "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -"
|
||||||
|
echo "1. log into dashboard.$NETMAKER_BASE_DOMAIN"
|
||||||
|
echo "2. Navigate to \"EXTERNAL CLIENTS\" tab"
|
||||||
|
echo "3. Download or scan a client config (vpnclient-x) to the appropriate device"
|
||||||
|
echo "4. Follow the steps for your system to configure WireGuard on the appropriate device"
|
||||||
|
echo "5. Create and delete clients as necessary. Changes to netmaker server settings require regenerating ext clients."
|
||||||
|
echo "-----------------------------------------------------------------"
|
||||||
|
echo "-----------------------------------------------------------------"
|
||||||
|
sleep 5
|
||||||
|
}
|
||||||
|
|
||||||
|
if [ "${MESH_SETUP}" != "false" ]; then
|
||||||
|
setup_mesh
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "${VPN_SETUP}" == "true" ]; then
|
||||||
|
setup_vpn
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "${MESH_SETUP}" != "false" ]; then
|
||||||
|
mesh_connect_logs
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "${VPN_SETUP}" == "true" ]; then
|
||||||
|
vpn_connect_logs
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Netmaker setup is now complete. You are ready to begin using Netmaker."
|
||||||
|
echo "Visit dashboard.$NETMAKER_BASE_DOMAIN to log in"
|
||||||
|
|
||||||
|
cp -f /etc/skel/.bashrc /root/.bashrc
|
|
@ -1,4 +1,5 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
echo "[netclient] joining network"
|
echo "[netclient] joining network"
|
||||||
|
|
||||||
if [ -z "${SLEEP}" ]; then
|
if [ -z "${SLEEP}" ]; then
|
||||||
|
@ -11,12 +12,16 @@ if [ "$TOKEN" != "" ]; then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
/root/netclient join $TOKEN_CMD -daemon off -dnson no
|
/root/netclient join $TOKEN_CMD -daemon off -dnson no
|
||||||
|
if [ $? -ne 0 ]; then { echo "Failed to join, quitting." ; exit 1; } fi
|
||||||
|
|
||||||
echo "[netclient] Starting netclient checkin"
|
echo "[netclient] Starting netclient checkin"
|
||||||
# loop and call checkin -n all
|
# loop and call checkin -n all
|
||||||
|
FAILCOUNT=0
|
||||||
while [ 1 ]; do
|
while [ 1 ]; do
|
||||||
# add logs to netclient.logs
|
# add logs to netclient.logs
|
||||||
/root/netclient checkin -n all
|
/root/netclient checkin -n all
|
||||||
|
if [ $? -ne 0 ]; then FAILCOUNT=$((FAILCOUNT+1)) ; else FAILCOUNT=0; fi
|
||||||
|
if [ $FAILCOUNT -gt 2 ]; then { echo "Failing checkins frequently, restarting." ; exit 1; } fi
|
||||||
sleep $SLEEP
|
sleep $SLEEP
|
||||||
done
|
done
|
||||||
echo "[netclient] exiting"
|
echo "[netclient] exiting"
|
||||||
|
|
|
@ -109,7 +109,7 @@ func GetAPIConnString() string {
|
||||||
|
|
||||||
// GetVersion - version of netmaker
|
// GetVersion - version of netmaker
|
||||||
func GetVersion() string {
|
func GetVersion() string {
|
||||||
version := "0.9.0"
|
version := "0.9.1"
|
||||||
if config.Config.Server.Version != "" {
|
if config.Config.Server.Version != "" {
|
||||||
version = config.Config.Server.Version
|
version = config.Config.Server.Version
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue