Jelajahi Sumber

config/version: switch VERSION to constant

Switches Version from a runtime var to a constant.
This constant, VERSION, should be updated manually
with each semantic version change & commit to master.

The format is:

	semvar-commithash[:7]

For example:

	v0.12.1-c784f99

Hardcoding the semantic version as a constant allows us to implement
controls for preventing mismatched net{client,maker}
binaries from interacting.

These controls become critical to the security of netmaker networks
in the event of a vulnerability wherein the resolving patch increments
the semnatic version. In this scenario, controls to automatically
prevent vulernable (read: out-of-date) binaries from interacting
with the latest, patched binaries are crucial.

Signed-off-by: John Sahhar <[email protected]>
John Sahhar 3 tahun lalu
induk
melakukan
399f04a012

+ 5 - 0
config/version.go

@@ -0,0 +1,5 @@
+package config
+
+const (
+	VERSION = "v0.12.1-c784f99"
+)

+ 2 - 1
logic/server.go

@@ -10,6 +10,7 @@ import (
 	"strings"
 	"time"
 
+	"github.com/gravitl/netmaker/config"
 	"github.com/gravitl/netmaker/logger"
 	"github.com/gravitl/netmaker/logic/acls"
 	"github.com/gravitl/netmaker/logic/acls/nodeacls"
@@ -70,7 +71,7 @@ func ServerJoin(networkSettings *models.Network) (models.Node, error) {
 		IsLocal:      networkSettings.IsLocal,
 		LocalRange:   networkSettings.LocalRange,
 		OS:           runtime.GOOS,
-		Version:      servercfg.Version,
+		Version:      config.VERSION,
 		IsHub:        ishub,
 	}
 

+ 2 - 1
logic/telemetry.go

@@ -4,6 +4,7 @@ import (
 	"encoding/json"
 	"time"
 
+	"github.com/gravitl/netmaker/config"
 	"github.com/gravitl/netmaker/database"
 	"github.com/gravitl/netmaker/models"
 	"github.com/gravitl/netmaker/servercfg"
@@ -64,7 +65,7 @@ func fetchTelemetryData() (telemetryData, error) {
 	data.ExtClients = getDBLength(database.EXT_CLIENT_TABLE_NAME)
 	data.Users = getDBLength(database.USERS_TABLE_NAME)
 	data.Networks = getDBLength(database.NETWORKS_TABLE_NAME)
-	data.Version = servercfg.GetVersion()
+	data.Version = config.VERSION
 	nodes, err := GetAllNodes()
 	if err == nil {
 		data.Nodes = len(nodes)

+ 0 - 3
main.go

@@ -26,11 +26,8 @@ import (
 	"google.golang.org/grpc"
 )
 
-var version = "dev"
-
 // Start DB Connection and start API Request Handler
 func main() {
-	servercfg.SetVersion(version)
 	fmt.Println(models.RetrieveLogo()) // print the logo
 	initialize()                       // initial db and grpc server
 	setGarbageCollection()

+ 3 - 1
netclient/functions/join.go

@@ -10,6 +10,8 @@ import (
 	"runtime"
 
 	nodepb "github.com/gravitl/netmaker/grpc"
+
+	_cfg "github.com/gravitl/netmaker/config"
 	"github.com/gravitl/netmaker/logger"
 	"github.com/gravitl/netmaker/models"
 	"github.com/gravitl/netmaker/netclient/auth"
@@ -146,7 +148,7 @@ func JoinNetwork(cfg *config.ClientConfig, privateKey string, iscomms bool) erro
 		UDPHolePunch:        cfg.Node.UDPHolePunch,
 		TrafficKeys:         cfg.Node.TrafficKeys,
 		OS:                  runtime.GOOS,
-		Version:             ncutils.Version,
+		Version:             _cfg.VERSION,
 	}
 
 	logger.Log(0, "joining "+cfg.Network+" at "+cfg.Server.GRPCAddress)

+ 2 - 1
netclient/functions/mqpublish.go

@@ -10,6 +10,7 @@ import (
 	"github.com/gravitl/netmaker/logger"
 	"github.com/gravitl/netmaker/netclient/auth"
 	"github.com/gravitl/netmaker/netclient/config"
+	cfg "github.com/gravitl/netmaker/config"
 	"github.com/gravitl/netmaker/netclient/ncutils"
 )
 
@@ -106,7 +107,7 @@ func PublishNodeUpdate(commsCfg, nodeCfg *config.ClientConfig) error {
 
 // Hello -- ping the broker to let server know node it's alive and well
 func Hello(commsCfg, nodeCfg *config.ClientConfig) {
-	if err := publish(commsCfg, nodeCfg, fmt.Sprintf("ping/%s", nodeCfg.Node.ID), []byte(ncutils.Version), 0); err != nil {
+	if err := publish(commsCfg, nodeCfg, fmt.Sprintf("ping/%s", nodeCfg.Node.ID), []byte(cfg.VERSION), 0); err != nil {
 		logger.Log(0, fmt.Sprintf("error publishing ping, %v", err))
 		logger.Log(0, "running pull on "+commsCfg.Node.Network+" to reconnect")
 		_, err := Pull(commsCfg.Node.Network, true)

+ 2 - 4
netclient/main.go

@@ -7,20 +7,18 @@ import (
 	"os"
 	"runtime/debug"
 
+	cfg "github.com/gravitl/netmaker/config"
 	"github.com/gravitl/netmaker/netclient/cli_options"
 	"github.com/gravitl/netmaker/netclient/ncutils"
 	"github.com/gravitl/netmaker/netclient/ncwindows"
 	"github.com/urfave/cli/v2"
 )
 
-var version = "dev"
-
 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 = version
-	ncutils.SetVersion(version)
+	app.Version = cfg.VERSION
 
 	cliFlags := cli_options.GetFlags(ncutils.GetHostname())
 	app.Commands = cli_options.GetCommands(cliFlags[:])

+ 0 - 8
netclient/ncutils/netclientutils.go

@@ -27,9 +27,6 @@ import (
 	"google.golang.org/grpc/credentials"
 )
 
-// Version - version of the netclient
-var Version = "dev"
-
 // src - for random strings
 var src = rand.NewSource(time.Now().UnixNano())
 
@@ -71,11 +68,6 @@ const (
 	letterIdxMax  = 63 / letterIdxBits   // # of letter indices fitting in 63 bits
 )
 
-// SetVersion -- set netclient version for use by other packages
-func SetVersion(ver string) {
-	Version = ver
-}
-
 // IsWindows - checks if is windows
 func IsWindows() bool {
 	return runtime.GOOS == "windows"

+ 1 - 12
servercfg/serverconf.go

@@ -17,7 +17,6 @@ import (
 )
 
 var (
-	Version = "dev"
 	commsID = ""
 )
 
@@ -78,7 +77,7 @@ func GetServerConfig() config.ServerConfig {
 	}
 	cfg.Database = GetDB()
 	cfg.Platform = GetPlatform()
-	cfg.Version = GetVersion()
+	cfg.Version = config.VERSION
 
 	// == auth config ==
 	var authInfo = GetAuthProviderInfo()
@@ -123,16 +122,6 @@ func GetAPIConnString() string {
 	return conn
 }
 
-// SetVersion - set version of netmaker
-func SetVersion(v string) {
-	Version = v
-}
-
-// GetVersion - version of netmaker
-func GetVersion() string {
-	return Version
-}
-
 // GetDB - gets the database type
 func GetDB() string {
 	database := "sqlite"