Skip to content

Commit

Permalink
Implement posture checks in policy processing in network map gen
Browse files Browse the repository at this point in the history
  • Loading branch information
bcmmbaga committed Jan 15, 2024
1 parent d855c3f commit 496e474
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions management/server/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/netbirdio/netbird/management/proto"
"github.com/netbirdio/netbird/management/server/activity"
nbpeer "github.com/netbirdio/netbird/management/server/peer"
"github.com/netbirdio/netbird/management/server/posture"
"github.com/netbirdio/netbird/management/server/status"
)

Expand Down Expand Up @@ -219,6 +220,25 @@ func (a *Account) getPeerConnectionResources(peerID string) ([]*nbpeer.Peer, []*
continue
}

peer, ok := a.Peers[peerID]
if !ok && peer == nil {
continue
}

for _, postureChecksID := range policy.SourcePostureChecks {
postureChecks := getPostureCheck(a, postureChecksID)
if postureChecks == nil {
continue
}

for _, check := range postureChecks.Checks {
if err := check.Check(*peer); err != nil {
log.Debugf("an error occurred on check %s: %s", check.Name(), err.Error())
continue
}
}
}

for _, rule := range policy.Rules {
if !rule.Enabled {
continue
Expand Down Expand Up @@ -512,3 +532,12 @@ func getAllPeersFromGroups(account *Account, groups []string, peerID string) ([]
}
return filteredPeers, peerInGroups
}

func getPostureCheck(account *Account, postureChecksID string) *posture.Checks {
for _, postureChecks := range account.PostureChecks {
if postureChecks.ID == postureChecksID {
return postureChecks
}
}
return nil
}

0 comments on commit 496e474

Please sign in to comment.