From 496e4743216fd3dae9255154f7972a864b20b55c Mon Sep 17 00:00:00 2001 From: bcmmbaga Date: Fri, 12 Jan 2024 13:54:02 +0300 Subject: [PATCH] Implement posture checks in policy processing in network map gen --- management/server/policy.go | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/management/server/policy.go b/management/server/policy.go index 294d699c796..8fa1363925a 100644 --- a/management/server/policy.go +++ b/management/server/policy.go @@ -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" ) @@ -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 @@ -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 +}