Compare commits

...

4 Commits

Author SHA1 Message Date
Maycon Santos
2d350b2522 update protocol 2024-03-14 15:34:40 +01:00
Maycon Santos
d18d2db9ee use config struct 2024-03-13 15:37:56 +01:00
Maycon Santos
c3a1e1ca2c refactor function 2024-03-12 23:58:16 +01:00
Maycon Santos
c9acd2f880 Send ssh and rosenpass config meta 2024-03-12 23:44:27 +01:00
14 changed files with 653 additions and 502 deletions

View File

@@ -38,7 +38,7 @@ func IsLoginRequired(ctx context.Context, privateKey string, mgmURL *url.URL, ss
return false, err return false, err
} }
_, err = doMgmLogin(ctx, mgmClient, pubSSHKey) _, err = doMgmLogin(ctx, mgmClient, pubSSHKey, &Config{})
if isLoginNeeded(err) { if isLoginNeeded(err) {
return true, nil return true, nil
} }
@@ -67,7 +67,7 @@ func Login(ctx context.Context, config *Config, setupKey string, jwtToken string
return err return err
} }
serverKey, err := doMgmLogin(ctx, mgmClient, pubSSHKey) serverKey, err := doMgmLogin(ctx, mgmClient, pubSSHKey, config)
if isRegistrationNeeded(err) { if isRegistrationNeeded(err) {
log.Debugf("peer registration required") log.Debugf("peer registration required")
_, err = registerPeer(ctx, *serverKey, mgmClient, setupKey, jwtToken, pubSSHKey) _, err = registerPeer(ctx, *serverKey, mgmClient, setupKey, jwtToken, pubSSHKey)
@@ -99,14 +99,14 @@ func getMgmClient(ctx context.Context, privateKey string, mgmURL *url.URL) (*mgm
return mgmClient, err return mgmClient, err
} }
func doMgmLogin(ctx context.Context, mgmClient *mgm.GrpcClient, pubSSHKey []byte) (*wgtypes.Key, error) { func doMgmLogin(ctx context.Context, mgmClient *mgm.GrpcClient, pubSSHKey []byte, config *Config) (*wgtypes.Key, error) {
serverKey, err := mgmClient.GetServerPublicKey() serverKey, err := mgmClient.GetServerPublicKey()
if err != nil { if err != nil {
log.Errorf("failed while getting Management Service public key: %v", err) log.Errorf("failed while getting Management Service public key: %v", err)
return nil, err return nil, err
} }
sysInfo := system.GetInfo(ctx) sysInfo := system.GetInfo(ctx, *config)
_, err = mgmClient.Login(*serverKey, sysInfo, pubSSHKey) _, err = mgmClient.Login(*serverKey, sysInfo, pubSSHKey)
return serverKey, err return serverKey, err
} }
@@ -120,7 +120,7 @@ func registerPeer(ctx context.Context, serverPublicKey wgtypes.Key, client *mgm.
} }
log.Debugf("sending peer registration request to Management Service") log.Debugf("sending peer registration request to Management Service")
info := system.GetInfo(ctx) info := system.GetInfo(ctx, Config{})
loginResp, err := client.Register(serverPublicKey, validSetupKey.String(), jwtToken, info, pubSSHKey) loginResp, err := client.Register(serverPublicKey, validSetupKey.String(), jwtToken, info, pubSSHKey)
if err != nil { if err != nil {
log.Errorf("failed registering peer %v,%s", err, validSetupKey.String()) log.Errorf("failed registering peer %v,%s", err, validSetupKey.String())

View File

@@ -30,6 +30,12 @@ type Environment struct {
Platform string Platform string
} }
type Config struct {
RosenpassEnabled bool
RosenpassPermissive bool
ServerSSHAllowed bool
}
// Info is an object that contains machine information // Info is an object that contains machine information
// Most of the code is taken from https://github.com/matishsiao/goInfo // Most of the code is taken from https://github.com/matishsiao/goInfo
type Info struct { type Info struct {
@@ -48,6 +54,14 @@ type Info struct {
SystemProductName string SystemProductName string
SystemManufacturer string SystemManufacturer string
Environment Environment Environment Environment
Config Config
}
// GetInfo retrieves and parses the system information
func GetInfo(ctx context.Context, config Config) *Info {
info := getInfo(ctx)
info.Config = config
return info
} }
// extractUserAgent extracts Netbird's agent (client) name and version from the outgoing context // extractUserAgent extracts Netbird's agent (client) name and version from the outgoing context

View File

@@ -15,8 +15,7 @@ import (
"github.com/netbirdio/netbird/version" "github.com/netbirdio/netbird/version"
) )
// GetInfo retrieves and parses the system information func getInfo(ctx context.Context) *Info {
func GetInfo(ctx context.Context) *Info {
kernel := "android" kernel := "android"
osInfo := uname() osInfo := uname()
if len(osInfo) == 2 { if len(osInfo) == 2 {
@@ -28,7 +27,16 @@ func GetInfo(ctx context.Context) *Info {
kernelVersion = osInfo[2] kernelVersion = osInfo[2]
} }
gio := &Info{Kernel: kernel, Platform: "unknown", OS: "android", OSVersion: osVersion(), GoOS: runtime.GOOS, CPUs: runtime.NumCPU(), KernelVersion: kernelVersion} gio := &Info{
Kernel: kernel,
Platform: "unknown",
OS: "android",
OSVersion: osVersion(),
GoOS: runtime.GOOS,
CPUs: runtime.NumCPU(),
KernelVersion: kernelVersion,
}
gio.Hostname = extractDeviceName(ctx, "android") gio.Hostname = extractDeviceName(ctx, "android")
gio.WiretrusteeVersion = version.NetbirdVersion() gio.WiretrusteeVersion = version.NetbirdVersion()
gio.UIVersion = extractUserAgent(ctx) gio.UIVersion = extractUserAgent(ctx)

View File

@@ -20,8 +20,7 @@ import (
"github.com/netbirdio/netbird/version" "github.com/netbirdio/netbird/version"
) )
// GetInfo retrieves and parses the system information func getInfo(ctx context.Context) *Info {
func GetInfo(ctx context.Context) *Info {
utsname := unix.Utsname{} utsname := unix.Utsname{}
err := unix.Uname(&utsname) err := unix.Uname(&utsname)
if err != nil { if err != nil {

View File

@@ -15,8 +15,7 @@ import (
"github.com/netbirdio/netbird/version" "github.com/netbirdio/netbird/version"
) )
// GetInfo retrieves and parses the system information func getInfo(ctx context.Context) *Info {
func GetInfo(ctx context.Context) *Info {
out := _getInfo() out := _getInfo()
for strings.Contains(out, "broken pipe") { for strings.Contains(out, "broken pipe") {
out = _getInfo() out = _getInfo()
@@ -31,7 +30,15 @@ func GetInfo(ctx context.Context) *Info {
Platform: detect_platform.Detect(ctx), Platform: detect_platform.Detect(ctx),
} }
gio := &Info{Kernel: osInfo[0], Platform: runtime.GOARCH, OS: osInfo[2], GoOS: runtime.GOOS, CPUs: runtime.NumCPU(), KernelVersion: osInfo[1], Environment: env} gio := &Info{
Kernel: osInfo[0],
Platform: runtime.GOARCH,
OS: osInfo[2],
GoOS: runtime.GOOS,
CPUs: runtime.NumCPU(),
KernelVersion: osInfo[1],
Environment: env,
}
systemHostname, _ := os.Hostname() systemHostname, _ := os.Hostname()
gio.Hostname = extractDeviceName(ctx, systemHostname) gio.Hostname = extractDeviceName(ctx, systemHostname)

View File

@@ -10,14 +10,21 @@ import (
"github.com/netbirdio/netbird/version" "github.com/netbirdio/netbird/version"
) )
// GetInfo retrieves and parses the system information func getInfo(ctx context.Context) *Info {
func GetInfo(ctx context.Context) *Info {
// Convert fixed-size byte arrays to Go strings // Convert fixed-size byte arrays to Go strings
sysName := extractOsName(ctx, "sysName") sysName := extractOsName(ctx, "sysName")
swVersion := extractOsVersion(ctx, "swVersion") swVersion := extractOsVersion(ctx, "swVersion")
gio := &Info{Kernel: sysName, OSVersion: swVersion, Platform: "unknown", OS: sysName, GoOS: runtime.GOOS, CPUs: runtime.NumCPU(), KernelVersion: swVersion} gio := &Info{
Kernel: sysName,
OSVersion: swVersion,
Platform: "unknown",
OS: sysName,
GoOS: runtime.GOOS,
CPUs: runtime.NumCPU(),
KernelVersion: swVersion,
}
gio.Hostname = extractDeviceName(ctx, "hostname") gio.Hostname = extractDeviceName(ctx, "hostname")
gio.WiretrusteeVersion = version.NetbirdVersion() gio.WiretrusteeVersion = version.NetbirdVersion()
gio.UIVersion = extractUserAgent(ctx) gio.UIVersion = extractUserAgent(ctx)

View File

@@ -20,8 +20,7 @@ import (
"github.com/netbirdio/netbird/version" "github.com/netbirdio/netbird/version"
) )
// GetInfo retrieves and parses the system information func getInfo(ctx context.Context) *Info {
func GetInfo(ctx context.Context) *Info {
info := _getInfo() info := _getInfo()
for strings.Contains(info, "broken pipe") { for strings.Contains(info, "broken pipe") {
info = _getInfo() info = _getInfo()

View File

@@ -8,7 +8,6 @@ import (
"strings" "strings"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"github.com/yusufpapurcu/wmi"
"golang.org/x/sys/windows/registry" "golang.org/x/sys/windows/registry"
"github.com/netbirdio/netbird/client/system/detect_cloud" "github.com/netbirdio/netbird/client/system/detect_cloud"
@@ -32,8 +31,7 @@ type Win32_BIOS struct {
SerialNumber string SerialNumber string
} }
// GetInfo retrieves and parses the system information func getInfo(ctx context.Context) *Info {
func GetInfo(ctx context.Context) *Info {
osName, osVersion := getOSNameAndVersion() osName, osVersion := getOSNameAndVersion()
buildVersion := getBuildVersion() buildVersion := getBuildVersion()

View File

@@ -163,7 +163,7 @@ func TestClient_LoginUnregistered_ShouldThrow_401(t *testing.T) {
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
sysInfo := system.GetInfo(context.TODO()) sysInfo := &system.Info{Hostname: "test"}
_, err = client.Login(*key, sysInfo, nil) _, err = client.Login(*key, sysInfo, nil)
if err == nil { if err == nil {
t.Error("expecting err on unregistered login, got nil") t.Error("expecting err on unregistered login, got nil")
@@ -191,7 +191,7 @@ func TestClient_LoginRegistered(t *testing.T) {
if err != nil { if err != nil {
t.Error(err) t.Error(err)
} }
info := system.GetInfo(context.TODO()) info := &system.Info{Hostname: "test"}
resp, err := client.Register(*key, ValidKey, "", info, nil) resp, err := client.Register(*key, ValidKey, "", info, nil)
if err != nil { if err != nil {
t.Error(err) t.Error(err)
@@ -221,7 +221,7 @@ func TestClient_Sync(t *testing.T) {
t.Error(err) t.Error(err)
} }
info := system.GetInfo(context.TODO()) info := &system.Info{Hostname: "test"}
_, err = client.Register(*serverKey, ValidKey, "", info, nil) _, err = client.Register(*serverKey, ValidKey, "", info, nil)
if err != nil { if err != nil {
t.Error(err) t.Error(err)
@@ -237,7 +237,6 @@ func TestClient_Sync(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
info = system.GetInfo(context.TODO())
_, err = remoteClient.Register(*serverKey, ValidKey, "", info, nil) _, err = remoteClient.Register(*serverKey, ValidKey, "", info, nil)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
@@ -335,7 +334,7 @@ func Test_SystemMetaDataFromClient(t *testing.T) {
}, nil }, nil
} }
info := system.GetInfo(context.TODO()) info := &system.Info{Hostname: "test"}
_, err = testClient.Register(*key, ValidKey, "", info, nil) _, err = testClient.Register(*key, ValidKey, "", info, nil)
if err != nil { if err != nil {
t.Errorf("error while trying to register client: %v", err) t.Errorf("error while trying to register client: %v", err)

View File

@@ -480,5 +480,10 @@ func infoToMetaData(info *system.Info) *proto.PeerSystemMeta {
Cloud: info.Environment.Cloud, Cloud: info.Environment.Cloud,
Platform: info.Environment.Platform, Platform: info.Environment.Platform,
}, },
Config: &proto.Config{
RosenpassEnabled: info.Config.RosenpassEnabled,
RosenpassPermissive: info.Config.RosenpassPermissive,
ServerSSHAllowed: info.Config.ServerSSHAllowed,
},
} }
} }

File diff suppressed because it is too large Load Diff

View File

@@ -100,6 +100,13 @@ message Environment {
string platform = 2; string platform = 2;
} }
// Config is a message with local configuration settings of the peer
message Config {
bool rosenpassEnabled = 1;
bool rosenpassPermissive = 2;
bool serverSSHAllowed = 3;
}
// PeerSystemMeta is machine meta data like OS and version. // PeerSystemMeta is machine meta data like OS and version.
message PeerSystemMeta { message PeerSystemMeta {
string hostname = 1; string hostname = 1;
@@ -117,6 +124,7 @@ message PeerSystemMeta {
string sysProductName = 13; string sysProductName = 13;
string sysManufacturer = 14; string sysManufacturer = 14;
Environment environment = 15; Environment environment = 15;
Config config = 16;
} }
message LoginResponse { message LoginResponse {

View File

@@ -292,6 +292,9 @@ func extractPeerMeta(loginReq *proto.LoginRequest) nbpeer.PeerSystemMeta {
Cloud: loginReq.GetMeta().GetEnvironment().GetCloud(), Cloud: loginReq.GetMeta().GetEnvironment().GetCloud(),
Platform: loginReq.GetMeta().GetEnvironment().GetPlatform(), Platform: loginReq.GetMeta().GetEnvironment().GetPlatform(),
}, },
RosenpassEnabled: loginReq.GetMeta().GetRosenpassEnabled(),
RosenpassPermissive: loginReq.GetMeta().GetRosenpassPermissive(),
ServerSSHAllowed: loginReq.GetMeta().GetServerSSHAllowed(),
} }
} }

View File

@@ -81,21 +81,24 @@ type Environment struct {
// PeerSystemMeta is a metadata of a Peer machine system // PeerSystemMeta is a metadata of a Peer machine system
type PeerSystemMeta struct { //nolint:revive type PeerSystemMeta struct { //nolint:revive
Hostname string Hostname string
GoOS string GoOS string
Kernel string Kernel string
Core string Core string
Platform string Platform string
OS string OS string
OSVersion string OSVersion string
WtVersion string WtVersion string
UIVersion string UIVersion string
KernelVersion string KernelVersion string
NetworkAddresses []NetworkAddress `gorm:"serializer:json"` NetworkAddresses []NetworkAddress `gorm:"serializer:json"`
SystemSerialNumber string SystemSerialNumber string
SystemProductName string SystemProductName string
SystemManufacturer string SystemManufacturer string
Environment Environment `gorm:"serializer:json"` Environment Environment `gorm:"serializer:json"`
RosenpassEnabled bool
RosenpassPermissive bool
ServerSSHAllowed bool
} }
func (p PeerSystemMeta) isEqual(other PeerSystemMeta) bool { func (p PeerSystemMeta) isEqual(other PeerSystemMeta) bool {
@@ -130,7 +133,10 @@ func (p PeerSystemMeta) isEqual(other PeerSystemMeta) bool {
p.SystemProductName == other.SystemProductName && p.SystemProductName == other.SystemProductName &&
p.SystemManufacturer == other.SystemManufacturer && p.SystemManufacturer == other.SystemManufacturer &&
p.Environment.Cloud == other.Environment.Cloud && p.Environment.Cloud == other.Environment.Cloud &&
p.Environment.Platform == other.Environment.Platform p.Environment.Platform == other.Environment.Platform &&
p.RosenpassEnabled == other.RosenpassEnabled &&
p.RosenpassPermissive == other.RosenpassPermissive &&
p.ServerSSHAllowed == other.ServerSSHAllowed
} }
// AddedWithSSOLogin indicates whether this peer has been added with an SSO login by a user. // AddedWithSSOLogin indicates whether this peer has been added with an SSO login by a user.