mirror of
https://github.com/netbirdio/netbird.git
synced 2024-12-13 18:31:18 +01:00
add policy posture checks
This commit is contained in:
parent
e69039f68e
commit
26e931b5fc
42
management/server/checks/posture_checks.go
Normal file
42
management/server/checks/posture_checks.go
Normal file
@ -0,0 +1,42 @@
|
||||
package checks
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
nbpeer "github.com/netbirdio/netbird/management/server/peer"
|
||||
)
|
||||
|
||||
type PostureCheck struct {
|
||||
// ID of the policy rule
|
||||
ID string `gorm:"primaryKey"`
|
||||
|
||||
// PolicyID is a reference to Policy that this object belongs
|
||||
PolicyID string `json:"-" gorm:"index"`
|
||||
|
||||
NBVersionCheck NBVersionPostureCheck `gorm:"embedded;embeddedPrefix:nb_version_check_"`
|
||||
OSVersionCheck OSVersionPostureCheck `gorm:"embedded;embeddedPrefix:os_version_check_"`
|
||||
}
|
||||
|
||||
type NBVersionPostureCheck struct {
|
||||
Enabled bool
|
||||
MinimumVersionAllowed string
|
||||
}
|
||||
|
||||
func (n *NBVersionPostureCheck) Check(peer nbpeer.Peer) error {
|
||||
if peer.Meta.WtVersion >= n.MinimumVersionAllowed {
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("peer nb version is not supported")
|
||||
}
|
||||
|
||||
type OSVersionPostureCheck struct {
|
||||
Enabled bool
|
||||
MinimumVersionAllowed string
|
||||
}
|
||||
|
||||
func (o *OSVersionPostureCheck) Check(peer nbpeer.Peer) error {
|
||||
if peer.Meta.WtVersion >= o.MinimumVersionAllowed {
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("peer OS version is not supported")
|
||||
}
|
@ -10,6 +10,7 @@ import (
|
||||
|
||||
"github.com/netbirdio/netbird/management/proto"
|
||||
"github.com/netbirdio/netbird/management/server/activity"
|
||||
"github.com/netbirdio/netbird/management/server/checks"
|
||||
nbpeer "github.com/netbirdio/netbird/management/server/peer"
|
||||
"github.com/netbirdio/netbird/management/server/status"
|
||||
)
|
||||
@ -150,6 +151,9 @@ type Policy struct {
|
||||
|
||||
// Rules of the policy
|
||||
Rules []*PolicyRule `gorm:"foreignKey:PolicyID;references:id"`
|
||||
|
||||
// PostureCheck of the policy
|
||||
PostureCheck checks.PostureCheck `gorm:"foreignKey:PolicyID;references:id"`
|
||||
}
|
||||
|
||||
// Copy returns a copy of the policy.
|
||||
|
Loading…
Reference in New Issue
Block a user