Merge pull request #1031 from gravitl/feature_v0.13.0_reorder_join_register

gen new key and re-register on pull
This commit is contained in:
dcarns 2022-04-25 14:32:54 -04:00 committed by GitHub
commit 6c024dd5e5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 3 deletions

View file

@ -1,6 +1,8 @@
package command
import (
"crypto/ed25519"
"crypto/rand"
"strings"
"github.com/gravitl/netmaker/logger"
@ -8,6 +10,7 @@ import (
"github.com/gravitl/netmaker/netclient/daemon"
"github.com/gravitl/netmaker/netclient/functions"
"github.com/gravitl/netmaker/netclient/ncutils"
"github.com/gravitl/netmaker/tls"
)
// Join - join command to run from cli
@ -87,7 +90,20 @@ func Pull(cfg *config.ClientConfig) error {
}
err = nil
} else {
_, err = functions.Pull(cfg.Network, true)
_, newKey, kerr := ed25519.GenerateKey(rand.Reader)
if kerr == nil {
if kerr := tls.SaveKey(ncutils.GetNetclientPath(), "/client.key", newKey); err != nil {
logger.Log(0, "error saving key", kerr.Error())
} else {
if kerr = functions.RegisterWithServer(&newKey, cfg); err != nil {
logger.Log(0, "registration error", kerr.Error())
} else {
daemon.Restart()
}
}
}
}
logger.Log(1, "reset network and peer configs")
if err == nil {

View file

@ -19,7 +19,7 @@ import (
)
// Pull - pulls the latest config from the server, if manual it will overwrite
func Pull(network string, manual bool) (*models.Node, error) {
func Pull(network string, iface bool) (*models.Node, error) {
cfg, err := config.ReadConfig(network)
if err != nil {
return nil, err
@ -52,7 +52,7 @@ func Pull(network string, manual bool) (*models.Node, error) {
}
// ensure that the OS never changes
resNode.OS = runtime.GOOS
if manual {
if iface {
// check for interface change
if cfg.Node.Interface != resNode.Interface {
if err = DeleteInterface(cfg.Node.Interface, cfg.Node.PostDown); err != nil {
@ -78,6 +78,5 @@ func Pull(network string, manual bool) (*models.Node, error) {
if bkupErr != nil {
logger.Log(0, "unable to update backup file")
}
return &resNode, err
}