Skip to content

Commit

Permalink
Merge pull request #2792 from gravitl/release-v0.22.0
Browse files Browse the repository at this point in the history
Release v0.22.0
  • Loading branch information
abhishek9686 authored Jan 24, 2024
2 parents dc8f9b1 + 1d1b9bb commit 790f118
Show file tree
Hide file tree
Showing 12 changed files with 521 additions and 383 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ If you're just looking to use Netmaker, you can create an account for free at [n

# Self-Hosted Quick Start

These are the instructions for deploying a Netmaker server on your own cloud VM as quickly as possible. For more detailed instructions, visit the [Install Docs](https://netmaker.readthedocs.io/en/master/install.html).
These are the instructions for deploying a Netmaker server on your own cloud VM as quickly as possible. For more detailed instructions, visit the [Install Docs](https://docs.netmaker.io/install.html).

1. Get a cloud VM with Ubuntu 22.04 and a public IP.
2. Open ports 443, 80, 3479, 8089 and 51821-51830/udp on the VM firewall and in cloud security settings.
Expand All @@ -68,7 +68,7 @@ This script gives you the option to deploy the Community or Enterprise version o
<img src="https://raw.githubusercontent.com/gravitl/netmaker-docs/master/images/netmaker-github/readme.gif" />
</p>

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://www.netmaker.io/blog) for different use cases, including Kubernetes.
After installing Netmaker, check out the [Walkthrough](https://itnext.io/getting-started-with-netmaker-a-wireguard-virtual-networking-platform-3d563fbd87f0) and [Getting Started](https://docs.netmaker.io/getting-started.html) guides to learn more about configuring networks. Or, check out some of our other [Tutorials](https://www.netmaker.io/blog) for different use cases, including Kubernetes.

# Get Support

Expand Down
33 changes: 24 additions & 9 deletions controllers/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"net/http"
"strings"
"syscall"
"time"

"github.com/gorilla/mux"
"golang.org/x/exp/slog"
Expand Down Expand Up @@ -109,22 +110,36 @@ func getUsage(w http.ResponseWriter, _ *http.Request) {
// 200: serverConfigResponse
func getStatus(w http.ResponseWriter, r *http.Request) {
type status struct {
DB bool `json:"db_connected"`
Broker bool `json:"broker_connected"`
LicenseError string `json:"license_error"`
IsPro bool `json:"is_pro"`
DB bool `json:"db_connected"`
Broker bool `json:"broker_connected"`
LicenseError string `json:"license_error"`
IsPro bool `json:"is_pro"`
TrialEndDate time.Time `json:"trial_end_date"`
IsOnTrialLicense bool `json:"is_on_trial_license"`
}

licenseErr := ""
if servercfg.ErrLicenseValidation != nil {
licenseErr = servercfg.ErrLicenseValidation.Error()
}

var trialEndDate time.Time
var err error
isOnTrial := false
if servercfg.IsPro && (servercfg.GetLicenseKey() == "" || servercfg.GetNetmakerTenantID() == "") {
trialEndDate, err = logic.GetTrialEndDate()
if err != nil {
slog.Error("failed to get trial end date", "error", err)
} else {
isOnTrial = true
}
}
currentServerStatus := status{
DB: database.IsConnected(),
Broker: mq.IsConnected(),
LicenseError: licenseErr,
IsPro: servercfg.IsPro,
DB: database.IsConnected(),
Broker: mq.IsConnected(),
LicenseError: licenseErr,
IsPro: servercfg.IsPro,
TrialEndDate: trialEndDate,
IsOnTrialLicense: isOnTrial,
}

w.Header().Set("Content-Type", "application/json")
Expand Down
44 changes: 22 additions & 22 deletions database/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,29 +124,29 @@ func InitializeDatabase() error {
}

func createTables() {
createTable(NETWORKS_TABLE_NAME)
createTable(NODES_TABLE_NAME)
createTable(CERTS_TABLE_NAME)
createTable(DELETED_NODES_TABLE_NAME)
createTable(USERS_TABLE_NAME)
createTable(DNS_TABLE_NAME)
createTable(EXT_CLIENT_TABLE_NAME)
createTable(PEERS_TABLE_NAME)
createTable(SERVERCONF_TABLE_NAME)
createTable(SERVER_UUID_TABLE_NAME)
createTable(GENERATED_TABLE_NAME)
createTable(NODE_ACLS_TABLE_NAME)
createTable(SSO_STATE_CACHE)
createTable(METRICS_TABLE_NAME)
createTable(NETWORK_USER_TABLE_NAME)
createTable(USER_GROUPS_TABLE_NAME)
createTable(CACHE_TABLE_NAME)
createTable(HOSTS_TABLE_NAME)
createTable(ENROLLMENT_KEYS_TABLE_NAME)
createTable(HOST_ACTIONS_TABLE_NAME)
CreateTable(NETWORKS_TABLE_NAME)
CreateTable(NODES_TABLE_NAME)
CreateTable(CERTS_TABLE_NAME)
CreateTable(DELETED_NODES_TABLE_NAME)
CreateTable(USERS_TABLE_NAME)
CreateTable(DNS_TABLE_NAME)
CreateTable(EXT_CLIENT_TABLE_NAME)
CreateTable(PEERS_TABLE_NAME)
CreateTable(SERVERCONF_TABLE_NAME)
CreateTable(SERVER_UUID_TABLE_NAME)
CreateTable(GENERATED_TABLE_NAME)
CreateTable(NODE_ACLS_TABLE_NAME)
CreateTable(SSO_STATE_CACHE)
CreateTable(METRICS_TABLE_NAME)
CreateTable(NETWORK_USER_TABLE_NAME)
CreateTable(USER_GROUPS_TABLE_NAME)
CreateTable(CACHE_TABLE_NAME)
CreateTable(HOSTS_TABLE_NAME)
CreateTable(ENROLLMENT_KEYS_TABLE_NAME)
CreateTable(HOST_ACTIONS_TABLE_NAME)
}

func createTable(tableName string) error {
func CreateTable(tableName string) error {
return getCurrentDB()[CREATE_TABLE].(func(string) error)(tableName)
}

Expand Down Expand Up @@ -194,7 +194,7 @@ func DeleteAllRecords(tableName string) error {
if err != nil {
return err
}
err = createTable(tableName)
err = CreateTable(tableName)
if err != nil {
return err
}
Expand Down
47 changes: 14 additions & 33 deletions logic/peers.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ var (
ResetFailedOverPeer = func(failedOverNode *models.Node) error {
return nil
}
// GetFailOverPeerIps - gets failover peerips
GetFailOverPeerIps = func(peer, node *models.Node) []net.IPNet {
return []net.IPNet{}
}
)

// GetPeerUpdateForHost - gets the consolidated peer update for the host from all networks
Expand Down Expand Up @@ -144,16 +148,18 @@ func GetPeerUpdateForHost(network string, host *models.Host, allNodes []models.N
hostPeerUpdate.EgressRoutes = append(hostPeerUpdate.EgressRoutes, getExtpeersExtraRoutes(peer.Network)...)
}
_, isFailOverPeer := node.FailOverPeers[peer.ID.String()]
if (node.IsRelayed && node.RelayedBy != peer.ID.String()) ||
(peer.IsRelayed && peer.RelayedBy != node.ID.String()) || isFailOverPeer {
// if node is relayed and peer is not the relay, set remove to true
if _, ok := peerIndexMap[peerHost.PublicKey.String()]; ok {
if servercfg.IsPro {
if (node.IsRelayed && node.RelayedBy != peer.ID.String()) ||
(peer.IsRelayed && peer.RelayedBy != node.ID.String()) || isFailOverPeer {
// if node is relayed and peer is not the relay, set remove to true
if _, ok := peerIndexMap[peerHost.PublicKey.String()]; ok {
continue
}
peerConfig.Remove = true
hostPeerUpdate.Peers = append(hostPeerUpdate.Peers, peerConfig)
peerIndexMap[peerHost.PublicKey.String()] = len(hostPeerUpdate.Peers) - 1
continue
}
peerConfig.Remove = true
hostPeerUpdate.Peers = append(hostPeerUpdate.Peers, peerConfig)
peerIndexMap[peerHost.PublicKey.String()] = len(hostPeerUpdate.Peers) - 1
continue
}

uselocal := false
Expand Down Expand Up @@ -362,31 +368,6 @@ func GetAllowedIPs(node, peer *models.Node, metrics *models.Metrics) []net.IPNet
return allowedips
}

func GetFailOverPeerIps(peer, node *models.Node) []net.IPNet {
allowedips := []net.IPNet{}
for failOverpeerID := range node.FailOverPeers {
failOverpeer, err := GetNodeByID(failOverpeerID)
if err == nil && failOverpeer.FailedOverBy == peer.ID {
if failOverpeer.Address.IP != nil {
allowed := net.IPNet{
IP: failOverpeer.Address.IP,
Mask: net.CIDRMask(32, 32),
}
allowedips = append(allowedips, allowed)
}
if failOverpeer.Address6.IP != nil {
allowed := net.IPNet{
IP: failOverpeer.Address6.IP,
Mask: net.CIDRMask(128, 128),
}
allowedips = append(allowedips, allowed)
}

}
}
return allowedips
}

func GetEgressIPs(peer *models.Node) []net.IPNet {

peerHost, err := GetHost(peer.HostID.String())
Expand Down
40 changes: 6 additions & 34 deletions logic/serverconf.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package logic

import (
"encoding/json"
"time"

"github.com/gravitl/netmaker/database"
"github.com/gravitl/netmaker/servercfg"
)
Expand All @@ -19,46 +21,16 @@ var (
EgressesLimit = 1000000000
// FreeTier - specifies if free tier
FreeTier = false

GetTrialEndDate = func() (time.Time, error) {
return time.Time{}, nil
}
)

type serverData struct {
PrivateKey string `json:"privatekey,omitempty" bson:"privatekey,omitempty"`
}

// StorePrivKey - stores server client WireGuard privatekey if needed
func StorePrivKey(serverID string, privateKey string) error {
var newData = serverData{}
var err error
var data []byte
newData.PrivateKey = privateKey
data, err = json.Marshal(&newData)
if err != nil {
return err
}
return database.Insert(serverID, string(data), database.SERVERCONF_TABLE_NAME)
}

// FetchPrivKey - fetches private key
func FetchPrivKey(serverID string) (string, error) {
var dbData string
var err error
var fetchedData = serverData{}
dbData, err = database.FetchRecord(database.SERVERCONF_TABLE_NAME, serverID)
if err != nil {
return "", err
}
err = json.Unmarshal([]byte(dbData), &fetchedData)
if err != nil {
return "", err
}
return fetchedData.PrivateKey, nil
}

// RemovePrivKey - removes a private key
func RemovePrivKey(serverID string) error {
return database.DeleteRecord(database.SERVERCONF_TABLE_NAME, serverID)
}

// FetchJWTSecret - fetches jwt secret from db
func FetchJWTSecret() (string, error) {
var dbData string
Expand Down
12 changes: 6 additions & 6 deletions logic/telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ func sendTelemetry() error {
return nil
}

var telRecord, err = fetchTelemetryRecord()
var telRecord, err = FetchTelemetryRecord()
if err != nil {
return err
}
// get telemetry data
d, err := fetchTelemetryData()
d, err := FetchTelemetryData()
if err != nil {
return err
}
Expand Down Expand Up @@ -71,8 +71,8 @@ func sendTelemetry() error {
})
}

// fetchTelemetry - fetches telemetry data: count of various object types in DB
func fetchTelemetryData() (telemetryData, error) {
// FetchTelemetryData - fetches telemetry data: count of various object types in DB
func FetchTelemetryData() (telemetryData, error) {
var data telemetryData

data.IsPro = servercfg.IsPro
Expand Down Expand Up @@ -138,8 +138,8 @@ func getClientCount(nodes []models.Node) clientCount {
return count
}

// fetchTelemetryRecord - get the existing UUID and Timestamp from the DB
func fetchTelemetryRecord() (models.Telemetry, error) {
// FetchTelemetryRecord - get the existing UUID and Timestamp from the DB
func FetchTelemetryRecord() (models.Telemetry, error) {
var rawData string
var telObj models.Telemetry
var err error
Expand Down
7 changes: 4 additions & 3 deletions logic/timer.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ package logic
import (
"context"
"fmt"
"github.com/gravitl/netmaker/logger"
"golang.org/x/exp/slog"
"sync"
"time"

"github.com/gravitl/netmaker/logger"
"golang.org/x/exp/slog"

"github.com/gravitl/netmaker/models"
)

Expand All @@ -24,7 +25,7 @@ var HookManagerCh = make(chan models.HookDetails, 3)
// TimerCheckpoint - Checks if 24 hours has passed since telemetry was last sent. If so, sends telemetry data to posthog
func TimerCheckpoint() error {
// get the telemetry record in the DB, which contains a timestamp
telRecord, err := fetchTelemetryRecord()
telRecord, err := FetchTelemetryRecord()
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions logic/traffic.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package logic

// RetrievePrivateTrafficKey - retrieves private key of server
func RetrievePrivateTrafficKey() ([]byte, error) {
var telRecord, err = fetchTelemetryRecord()
var telRecord, err = FetchTelemetryRecord()
if err != nil {
return nil, err
}
Expand All @@ -12,7 +12,7 @@ func RetrievePrivateTrafficKey() ([]byte, error) {

// RetrievePublicTrafficKey - retrieves public key of server
func RetrievePublicTrafficKey() ([]byte, error) {
var telRecord, err = fetchTelemetryRecord()
var telRecord, err = FetchTelemetryRecord()
if err != nil {
return nil, err
}
Expand Down
Loading

0 comments on commit 790f118

Please sign in to comment.