diff --git a/management/server/posture/checks.go b/management/server/posture/checks.go index 1b1f9d322..647e58312 100644 --- a/management/server/posture/checks.go +++ b/management/server/posture/checks.go @@ -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 } diff --git a/management/server/posture/checks_test.go b/management/server/posture/checks_test.go index d36d4f50c..41e1c2d78 100644 --- a/management/server/posture/checks_test.go +++ b/management/server/posture/checks_test.go @@ -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() diff --git a/management/server/posture/process.go b/management/server/posture/process.go new file mode 100644 index 000000000..fba3f928f --- /dev/null +++ b/management/server/posture/process.go @@ -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 +} diff --git a/management/server/posture/process_test.go b/management/server/posture/process_test.go new file mode 100644 index 000000000..5917c9125 --- /dev/null +++ b/management/server/posture/process_test.go @@ -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) + }) + } +}