mirror of
https://github.com/gravitl/netmaker.git
synced 2024-11-10 17:48:25 +08:00
fixed readme, composes, netclient push/pull
This commit is contained in:
parent
0ffb590b99
commit
963a3d1b92
17 changed files with 190 additions and 63 deletions
13
README.md
13
README.md
|
@ -8,12 +8,11 @@
|
|||
|
||||
## Documentation
|
||||
|
||||
### Netmaker's documentation can be found on ReadTheDocs and on Netmaker.org.
|
||||
|
||||
- netmaker.readthedocs.io
|
||||
- docs.netmaker.org
|
||||
|
||||
Below is a quick summary of Netmaker. For information about installing and using Netmaker, please visit the documentation sites.
|
||||
### Netmaker's documentation can be found at:
|
||||
### docs.netmaker.org
|
||||
### netmaker.readthedocs.io
|
||||
|
||||
For information about installing and using Netmaker, including the [quick start guide](https://docs.netmaker.org/quick-start.html), please visit one of the above documentation sites, or read on for a short description of Netmaker.
|
||||
|
||||
## What is Netmaker?
|
||||
Netmaker is a platform for creating and managing networks that are:
|
||||
|
@ -25,7 +24,7 @@ Netmaker is a platform for creating and managing networks that are:
|
|||
- Zero-Trust
|
||||
- WireGuard-based
|
||||
|
||||
Netmaker manages networks between computers that span data centers, clouds, and edge devices. Networking can be a challenge, so Netmaker is designed to allow developers, devops engineers, SRE's, and more to manage virtual networks with as little pain as possible. You create a network with a few clicks, and add machines to that network with a single command.
|
||||
Netmaker manages networks between computers that span data centers, clouds, and edge devices. Networking between environments can be a challenge, so Netmaker is designed to allow developers, DevOps engineers, SRE's, and more to manage virtual networks with as little pain as possible. You create a network with a few clicks, and add machines to that network with a single command.
|
||||
|
||||
## Why Netmaker?
|
||||
1. Create a flat, secure network between multiple/hybrid cloud environments
|
||||
|
|
|
@ -17,10 +17,10 @@ services:
|
|||
MONGO_INITDB_ROOT_PASSWORD: mongopass
|
||||
netmaker-ui:
|
||||
container_name: netmaker-ui
|
||||
image: gravitl/netmaker-ui:v0.3
|
||||
image: gravitl/netmaker-ui:v0.5
|
||||
ports:
|
||||
- "80:80"
|
||||
environment:
|
||||
BACKEND_URL: "http://3.236.111.47:8081"
|
||||
BACKEND_URL: "http://HOST_IP:8081"
|
||||
volumes:
|
||||
mongovol: {}
|
||||
|
|
|
@ -22,16 +22,17 @@ services:
|
|||
- "50051:50051"
|
||||
depends_on:
|
||||
- mongodb
|
||||
image: gravitl/netmaker:v0.3
|
||||
image: gravitl/netmaker:v0.5
|
||||
restart: always
|
||||
environment:
|
||||
SERVER_HOST: "HOST_IP"
|
||||
CLIENT_MODE: "off"
|
||||
SERVER_GRPC_WIREGUARD: "off"
|
||||
netmaker-ui:
|
||||
container_name: netmaker-ui
|
||||
depends_on:
|
||||
- netmaker
|
||||
image: gravitl/netmaker-ui:v0.3
|
||||
image: gravitl/netmaker-ui:v0.5
|
||||
links:
|
||||
- "netmaker:api"
|
||||
ports:
|
||||
|
|
|
@ -20,7 +20,7 @@ services:
|
|||
container_name: netmaker
|
||||
depends_on:
|
||||
- mongodb
|
||||
image: gravitl/netmaker:v0.3
|
||||
image: gravitl/netmaker:v0.5
|
||||
volumes:
|
||||
- ./:/local
|
||||
- /etc/netclient:/etc/netclient
|
||||
|
@ -41,7 +41,7 @@ services:
|
|||
container_name: netmaker-ui
|
||||
depends_on:
|
||||
- netmaker
|
||||
image: gravitl/netmaker-ui:v0.3
|
||||
image: gravitl/netmaker-ui:v0.5
|
||||
links:
|
||||
- "netmaker:api"
|
||||
ports:
|
||||
|
|
|
@ -50,6 +50,13 @@ services:
|
|||
MONGO_HOST: "127.0.0.1" # Address of MongoDB. Change if necessary.
|
||||
MONGO_PORT: "27017" # Port of MongoDB. Change if necessary.
|
||||
MONGO_OPTS: "/?authSource=admin" # Opts to enable admin login for Mongo.
|
||||
SERVER_GRPC_WIREGUARD: "on" # Whether to run GRPC over a WireGuard network. On by default. Secures server comms. Switch to "off" to turn off.
|
||||
SERVER_GRPC_WG_INTERFACE: "nm-grpc-wg" # Interface to use for GRPC WireGuard network if enabled
|
||||
SERVER_GRPC_WG_ADDRESS: "10.101.0.1" # Private Address to use for GRPC WireGuard network if enabled
|
||||
SERVER_GRPC_WG_ADDRESS_RANGE: "10.101.0.0/16" # Private Address range to use for GRPC WireGard clients if enabled
|
||||
SERVER_GRPC_WG_PORT: "50555" # Port to use for GRPC WireGuard if enabled
|
||||
SERVER_GRPC_WG_PUBKEY: "SERVER_GRPC_WG_PUBKEY" # PublicKey for GRPC WireGuard interface. Generated if blank.
|
||||
SERVER_GRPC_WG_PRIVKEY: "SERVER_GRPC_WG_PRIVKEY" # PrivateKey for GRPC WireGuard interface. Generated if blank.
|
||||
netmaker-ui: # The Netmaker UI Component
|
||||
container_name: netmaker-ui
|
||||
depends_on:
|
||||
|
|
|
@ -19,7 +19,7 @@ services:
|
|||
container_name: netmaker
|
||||
depends_on:
|
||||
- mongodb
|
||||
image: gravitl/netmaker:v0.3
|
||||
image: gravitl/netmaker:v0.5
|
||||
ports:
|
||||
- "8081:8081"
|
||||
- "50051:50051"
|
||||
|
|
|
@ -28,6 +28,7 @@ services:
|
|||
SERVER_HOST: "HOST_IP"
|
||||
DNS_MODE: "off"
|
||||
CLIENT_MODE: "off"
|
||||
SERVER_GRPC_WIREGUARD: "off"
|
||||
netmaker-ui:
|
||||
container_name: netmaker-ui
|
||||
depends_on:
|
||||
|
|
|
@ -17,7 +17,7 @@ services:
|
|||
container_name: netmaker
|
||||
depends_on:
|
||||
- mongodb
|
||||
image: gravitl/netmaker:v0.3
|
||||
image: gravitl/netmaker:v0.5
|
||||
volumes:
|
||||
- ./:/local
|
||||
- /etc/netclient:/etc/netclient
|
||||
|
@ -33,18 +33,18 @@ services:
|
|||
restart: always
|
||||
network_mode: host
|
||||
environment:
|
||||
SERVER_HOST: "HOST_IP"
|
||||
SERVER_HOST: "3.235.190.90"
|
||||
netmaker-ui:
|
||||
container_name: netmaker-ui
|
||||
depends_on:
|
||||
- netmaker
|
||||
image: gravitl/netmaker-ui:v0.3
|
||||
image: gravitl/netmaker-ui:v0.5
|
||||
links:
|
||||
- "netmaker:api"
|
||||
ports:
|
||||
- "80:80"
|
||||
environment:
|
||||
BACKEND_URL: "http://HOST_IP:8081"
|
||||
BACKEND_URL: "http://3.235.190.90:8081"
|
||||
coredns:
|
||||
depends_on:
|
||||
- netmaker
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
default comms skynet poopynet poopynet2 newnet {
|
||||
default comms {
|
||||
reload 15s
|
||||
hosts /root/dnsconfig/netmaker.hosts {
|
||||
fallthrough
|
||||
|
|
|
@ -1,2 +1 @@
|
|||
190.123.112.1 somenode.skynet
|
||||
1.2.3.4 doopy.skynet
|
||||
10.10.10.1 nethub.default
|
||||
|
|
|
@ -369,24 +369,39 @@ func updateExtClient(w http.ResponseWriter, r *http.Request) {
|
|||
returnErrorResponse(w, r, formatError(err, "internal"))
|
||||
return
|
||||
}
|
||||
success, err := DeleteExtClient(params["network"], params["clientid"])
|
||||
if err != nil {
|
||||
returnErrorResponse(w, r, formatError(err, "internal"))
|
||||
return
|
||||
} else if !success {
|
||||
returnErrorResponse(w, r, formatError(err, "internal"))
|
||||
return
|
||||
}
|
||||
|
||||
oldExtClient.ClientID = newExtClient.ClientID
|
||||
CreateExtClient(oldExtClient)
|
||||
newclient, err := UpdateExtClient(newExtClient.ClientID, params["network"], oldExtClient)
|
||||
if err != nil {
|
||||
returnErrorResponse(w, r, formatError(err, "internal"))
|
||||
return
|
||||
}
|
||||
|
||||
w.WriteHeader(http.StatusOK)
|
||||
json.NewEncoder(w).Encode(oldExtClient)
|
||||
json.NewEncoder(w).Encode(newclient)
|
||||
}
|
||||
|
||||
func UpdateExtClient(newclientid string, network string, client models.ExtClient) (models.ExtClient, error) {
|
||||
|
||||
//collection := mongoconn.ConnectDB()
|
||||
collection := mongoconn.Client.Database("netmaker").Collection("extclients")
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||
|
||||
// Create filter
|
||||
filter := bson.M{"clientid": client.ClientID, "network": network}
|
||||
|
||||
// prepare update model.
|
||||
update := bson.D{
|
||||
{"$set", bson.D{
|
||||
{"clientid", newclientid},
|
||||
}},
|
||||
}
|
||||
var clientupdate models.ExtClient
|
||||
|
||||
err := collection.FindOneAndUpdate(ctx, filter, update).Decode(&clientupdate)
|
||||
|
||||
defer cancel()
|
||||
|
||||
return clientupdate, err
|
||||
}
|
||||
|
||||
func DeleteExtClient(network string, clientid string) (bool, error) {
|
||||
|
|
|
@ -116,7 +116,6 @@ func updateIntClient(w http.ResponseWriter, r *http.Request) {
|
|||
json.NewEncoder(w).Encode(client)
|
||||
}
|
||||
|
||||
|
||||
func RegisterIntClient(client models.IntClient) (models.IntClient, error) {
|
||||
if client.PrivateKey == "" {
|
||||
privateKey, err := wgtypes.GeneratePrivateKey()
|
||||
|
|
|
@ -56,16 +56,15 @@ func Join(cfg config.ClientConfig) error {
|
|||
}
|
||||
|
||||
func CheckIn(cfg config.ClientConfig) error {
|
||||
if cfg.Network == "nonetwork" || cfg.Network == "" {
|
||||
log.Println("Required, '-n'. No network provided. Exiting.")
|
||||
os.Exit(1)
|
||||
}
|
||||
log.Println("Beginning node check in for network " + cfg.Network)
|
||||
err := functions.CheckIn(cfg.Network)
|
||||
if err != nil {
|
||||
log.Println("Error checking in: ", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
if cfg.Network == "all" || cfg.Network == "" {
|
||||
log.Println("Required, '-n'. No network provided. Exiting.")
|
||||
os.Exit(1)
|
||||
}
|
||||
err := functions.CheckIn(cfg.Network)
|
||||
if err != nil {
|
||||
log.Println("Error checking in: ", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -78,13 +77,53 @@ func Leave(cfg config.ClientConfig) error {
|
|||
}
|
||||
|
||||
func Push(cfg config.ClientConfig) error {
|
||||
log.Println("pushing to network")
|
||||
return nil
|
||||
var err error
|
||||
if cfg.Network == "all" {
|
||||
log.Println("No network selected. Running Push for all networks.")
|
||||
networks, err := functions.GetNetworks()
|
||||
if err != nil {
|
||||
log.Println("Error retrieving networks. Exiting.")
|
||||
return err
|
||||
}
|
||||
for _, network := range networks {
|
||||
err = functions.Push(network)
|
||||
if err != nil {
|
||||
log.Printf("Error pushing network configs for " + network + " network: ", err)
|
||||
} else {
|
||||
log.Println("pushed network config for " + network)
|
||||
}
|
||||
}
|
||||
err = nil
|
||||
} else {
|
||||
err = functions.Push(cfg.Network)
|
||||
}
|
||||
log.Println("Completed pushing network configs to remote server.")
|
||||
return err
|
||||
}
|
||||
|
||||
func Pull(cfg config.ClientConfig) error {
|
||||
log.Println("pulling from network")
|
||||
return nil
|
||||
var err error
|
||||
if cfg.Network == "all" {
|
||||
log.Println("No network selected. Running Pull for all networks.")
|
||||
networks, err := functions.GetNetworks()
|
||||
if err != nil {
|
||||
log.Println("Error retrieving networks. Exiting.")
|
||||
return err
|
||||
}
|
||||
for _, network := range networks {
|
||||
err = functions.Pull(network)
|
||||
if err != nil {
|
||||
log.Printf("Error pulling network config for " + network + " network: ", err)
|
||||
} else {
|
||||
log.Println("pulled network config for " + network)
|
||||
}
|
||||
}
|
||||
err = nil
|
||||
} else {
|
||||
err = functions.Pull(cfg.Network)
|
||||
}
|
||||
log.Println("Completed pulling network and peer configs.")
|
||||
return err
|
||||
}
|
||||
|
||||
func List(cfg config.ClientConfig) error {
|
||||
|
@ -92,11 +131,6 @@ func List(cfg config.ClientConfig) error {
|
|||
return err
|
||||
}
|
||||
|
||||
func Status(cfg config.ClientConfig) error {
|
||||
log.Println("retrieving network status")
|
||||
return nil
|
||||
}
|
||||
|
||||
func Uninstall(cfg config.GlobalConfig) error {
|
||||
log.Println("Uninstalling netclient")
|
||||
err := functions.Uninstall()
|
||||
|
|
|
@ -284,3 +284,80 @@ func CheckIn(network string) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func Pull (network string) error{
|
||||
node := server.GetNode(network)
|
||||
cfg, err := config.ReadConfig(network)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
servercfg := cfg.Server
|
||||
var header metadata.MD
|
||||
|
||||
var wcclient nodepb.NodeServiceClient
|
||||
var requestOpts grpc.DialOption
|
||||
requestOpts = grpc.WithInsecure()
|
||||
conn, err := grpc.Dial(servercfg.GRPCAddress, requestOpts)
|
||||
if err != nil {
|
||||
fmt.Printf("Cant dial GRPC server: %v", err)
|
||||
return err
|
||||
}
|
||||
wcclient = nodepb.NewNodeServiceClient(conn)
|
||||
|
||||
ctx := context.Background()
|
||||
ctx, err = auth.SetJWT(wcclient, network)
|
||||
if err != nil {
|
||||
fmt.Printf("Failed to authenticate: %v", err)
|
||||
return err
|
||||
}
|
||||
|
||||
req := &nodepb.ReadNodeReq{
|
||||
Macaddress: node.Macaddress,
|
||||
Network: node.Nodenetwork,
|
||||
}
|
||||
readres, err := wcclient.ReadNode(ctx, req, grpc.Header(&header))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = config.ModConfig(readres.Node)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = wireguard.SetWGConfig(network)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func Push (network string) error{
|
||||
postnode := server.GetNode(network)
|
||||
cfg, err := config.ReadConfig(network)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
servercfg := cfg.Server
|
||||
var header metadata.MD
|
||||
|
||||
var wcclient nodepb.NodeServiceClient
|
||||
var requestOpts grpc.DialOption
|
||||
requestOpts = grpc.WithInsecure()
|
||||
conn, err := grpc.Dial(servercfg.GRPCAddress, requestOpts)
|
||||
if err != nil {
|
||||
fmt.Printf("Cant dial GRPC server: %v", err)
|
||||
return err
|
||||
}
|
||||
wcclient = nodepb.NewNodeServiceClient(conn)
|
||||
|
||||
ctx := context.Background()
|
||||
ctx, err = auth.SetJWT(wcclient, network)
|
||||
if err != nil {
|
||||
fmt.Printf("Failed to authenticate: %v", err)
|
||||
return err
|
||||
}
|
||||
|
||||
req := &nodepb.UpdateNodeReq{
|
||||
Node: &postnode,
|
||||
}
|
||||
_, err = wcclient.UpdateNode(ctx, req, grpc.Header(&header))
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -16,10 +16,11 @@ import (
|
|||
func RunCmds(commands []string) error {
|
||||
var err error
|
||||
for _, command := range commands {
|
||||
fmt.Println("Running command: " + command)
|
||||
args := strings.Fields(command)
|
||||
out, err := exec.Command(args[0], args[1:]...).Output()
|
||||
fmt.Println(string(out))
|
||||
if string(out) != "" {
|
||||
fmt.Println(string(out))
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -85,13 +85,11 @@ func RemoveNetwork(network string) error {
|
|||
wcclient = nodepb.NewNodeServiceClient(conn)
|
||||
|
||||
ctx := context.Background()
|
||||
fmt.Println("Authenticating with GRPC Server")
|
||||
ctx, err = auth.SetJWT(wcclient, network)
|
||||
if err != nil {
|
||||
//return err
|
||||
log.Printf("Failed to authenticate: %v", err)
|
||||
} else {
|
||||
fmt.Println("Authenticated")
|
||||
|
||||
var header metadata.MD
|
||||
|
||||
|
@ -120,8 +118,6 @@ func RemoveNetwork(network string) error {
|
|||
return err
|
||||
log.Printf("Unable to remove systemd services: %v", err)
|
||||
}
|
||||
fmt.Printf("Please investigate any stated errors to ensure proper removal.")
|
||||
fmt.Printf("Failure to delete node from server via gRPC will mean node still exists and needs to be manually deleted by administrator.")
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -256,7 +252,6 @@ func GetPeers(macaddress string, network string, server string, dualstack bool,
|
|||
extPeers, err := GetExtPeers(macaddress, network, server, dualstack)
|
||||
if err == nil {
|
||||
peers = append(peers, extPeers...)
|
||||
fmt.Println("Added " + strconv.Itoa(len(extPeers)) + " external clients.")
|
||||
} else {
|
||||
fmt.Println("ERROR RETRIEVING EXTERNAL PEERS")
|
||||
fmt.Println(err)
|
||||
|
@ -274,7 +269,6 @@ func GetExtPeers(macaddress string, network string, server string, dualstack boo
|
|||
}
|
||||
nodecfg := cfg.Node
|
||||
|
||||
fmt.Println("Registering with GRPC Server")
|
||||
requestOpts := grpc.WithInsecure()
|
||||
conn, err := grpc.Dial(server, requestOpts)
|
||||
if err != nil {
|
||||
|
|
|
@ -184,7 +184,7 @@ func RemoveNetwork(network string) (bool, error) {
|
|||
log.Println("could not find /etc/netclient")
|
||||
return false, err
|
||||
}
|
||||
cmdoutput, err := exec.Command("/etc/netclient/netclient","-c","remove","-n",network).Output()
|
||||
cmdoutput, err := exec.Command("/etc/netclient/netclient","leave","-n",network).Output()
|
||||
if err != nil {
|
||||
log.Println(string(cmdoutput))
|
||||
return false, err
|
||||
|
@ -229,7 +229,7 @@ func AddNetwork(network string) (bool, error) {
|
|||
return false, err
|
||||
}
|
||||
log.Println("Client is ready. Running install.")
|
||||
out, err := exec.Command("/etc/netclient/netclient","-c","install","-t",token,"-name","netmaker","-ip4",pubip).Output()
|
||||
out, err := exec.Command("/etc/netclient/netclient","join","-t",token,"-name","netmaker","-endpoint",pubip).Output()
|
||||
log.Println(string(out))
|
||||
if err != nil {
|
||||
return false, errors.New(string(out) + err.Error())
|
||||
|
|
Loading…
Reference in a new issue