diff --git a/management/server/http/api/openapi.yml b/management/server/http/api/openapi.yml index b5fdd304eae..e74e06919e0 100644 --- a/management/server/http/api/openapi.yml +++ b/management/server/http/api/openapi.yml @@ -1888,8 +1888,9 @@ paths: /api/rules: get: summary: List all Rules - description: Returns a list of all rules + description: Returns a list of all rules. This will be deprecated in favour of `/api/policies`. tags: [ Rules ] + deprecated: true security: - BearerAuth: [ ] - TokenAuth: [ ] @@ -1912,7 +1913,8 @@ paths: "$ref": "#/components/responses/internal_error" post: summary: Create a Rule - description: Creates a rule + description: Creates a rule. This will be deprecated in favour of `/api/policies`. + deprecated: true tags: [ Rules ] security: - BearerAuth: [ ] @@ -1933,7 +1935,8 @@ paths: /api/rules/{ruleId}: get: summary: Retrieve a Rule - description: Get information about a rules + description: Get information about a rules. This will be deprecated in favour of `/api/policies/{policyID}`. + deprecated: true tags: [ Rules ] security: - BearerAuth: [ ] @@ -1962,7 +1965,8 @@ paths: "$ref": "#/components/responses/internal_error" put: summary: Update a Rule - description: Update/Replace a rule + description: Update/Replace a rule. This will be deprecated in favour of `/api/policies/{policyID}`. + deprecated: true tags: [ Rules ] security: - BearerAuth: [ ] @@ -1997,7 +2001,8 @@ paths: "$ref": "#/components/responses/internal_error" delete: summary: Delete a Rule - description: Delete a rule + description: Delete a rule. This will be deprecated in favour of `/api/policies/{policyID}`. + deprecated: true tags: [ Rules ] security: - BearerAuth: [ ] 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 +}