mirror of
https://github.com/netbirdio/netbird.git
synced 2026-09-01 20:41:28 +02:00
wip: add process check posture
This commit is contained in:
@@ -14,6 +14,7 @@ const (
|
||||
OSVersionCheckName = "OSVersionCheck"
|
||||
GeoLocationCheckName = "GeoLocationCheck"
|
||||
PeerNetworkRangeCheckName = "PeerNetworkRangeCheck"
|
||||
ProcessCheckName = "ProcessCheck"
|
||||
|
||||
CheckActionAllow string = "allow"
|
||||
CheckActionDeny string = "deny"
|
||||
@@ -48,6 +49,7 @@ type ChecksDefinition struct {
|
||||
OSVersionCheck *OSVersionCheck `json:",omitempty"`
|
||||
GeoLocationCheck *GeoLocationCheck `json:",omitempty"`
|
||||
PeerNetworkRangeCheck *PeerNetworkRangeCheck `json:",omitempty"`
|
||||
ProcessCheck *ProcessCheck `json:"process_check"`
|
||||
}
|
||||
|
||||
// Copy returns a copy of a checks definition.
|
||||
@@ -93,6 +95,13 @@ func (cd ChecksDefinition) Copy() ChecksDefinition {
|
||||
}
|
||||
copy(cdCopy.PeerNetworkRangeCheck.Ranges, peerNetRangeCheck.Ranges)
|
||||
}
|
||||
if cd.ProcessCheck != nil {
|
||||
processCheck := cd.ProcessCheck
|
||||
cdCopy.ProcessCheck = &ProcessCheck{
|
||||
Processes: make([]Process, len(processCheck.Processes)),
|
||||
}
|
||||
copy(cdCopy.ProcessCheck.Processes, processCheck.Processes)
|
||||
}
|
||||
return cdCopy
|
||||
}
|
||||
|
||||
@@ -133,6 +142,9 @@ func (pc *Checks) GetChecks() []Check {
|
||||
if pc.Checks.PeerNetworkRangeCheck != nil {
|
||||
checks = append(checks, pc.Checks.PeerNetworkRangeCheck)
|
||||
}
|
||||
if pc.Checks.ProcessCheck != nil {
|
||||
checks = append(checks, pc.Checks.ProcessCheck)
|
||||
}
|
||||
return checks
|
||||
}
|
||||
|
||||
|
||||
@@ -261,6 +261,14 @@ func TestChecks_Copy(t *testing.T) {
|
||||
},
|
||||
Action: CheckActionDeny,
|
||||
},
|
||||
ProcessCheck: &ProcessCheck{
|
||||
Processes: []Process{
|
||||
{
|
||||
Path: "/Applications/NetBird.app/Contents/MacOS/netbird",
|
||||
WindowsPath: "C:\\ProgramData\\NetBird\\netbird.exe",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
checkCopy := check.Copy()
|
||||
|
||||
24
management/server/posture/process.go
Normal file
24
management/server/posture/process.go
Normal file
@@ -0,0 +1,24 @@
|
||||
package posture
|
||||
|
||||
import (
|
||||
nbpeer "github.com/netbirdio/netbird/management/server/peer"
|
||||
)
|
||||
|
||||
type Process struct {
|
||||
Path string
|
||||
WindowsPath string
|
||||
}
|
||||
|
||||
type ProcessCheck struct {
|
||||
Processes []Process
|
||||
}
|
||||
|
||||
var _ Check = (*ProcessCheck)(nil)
|
||||
|
||||
func (p *ProcessCheck) Check(peer nbpeer.Peer) (bool, error) {
|
||||
return false, nil
|
||||
}
|
||||
|
||||
func (p *ProcessCheck) Name() string {
|
||||
return ProcessCheckName
|
||||
}
|
||||
33
management/server/posture/process_test.go
Normal file
33
management/server/posture/process_test.go
Normal file
@@ -0,0 +1,33 @@
|
||||
package posture
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"github.com/netbirdio/netbird/management/server/peer"
|
||||
)
|
||||
|
||||
func TestProcessCheck_Check(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
input peer.Peer
|
||||
check ProcessCheck
|
||||
wantErr bool
|
||||
isValid bool
|
||||
}{
|
||||
{},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
isValid, err := tt.check.Check(tt.input)
|
||||
if tt.wantErr {
|
||||
assert.Error(t, err)
|
||||
} else {
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
assert.Equal(t, tt.isValid, isValid)
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user