mirror of
https://github.com/netbirdio/netbird.git
synced 2024-12-15 11:21:04 +01:00
9bc7b9e897
This PR implements the following posture checks: * Agent minimum version allowed * OS minimum version allowed * Geo-location based on connection IP For the geo-based location, we rely on GeoLite2 databases which are free IP geolocation databases. MaxMind was tested and we provide a script that easily allows to download of all necessary files, see infrastructure_files/download-geolite2.sh. The OpenAPI spec should extensively cover the life cycle of current version posture checks.
40 lines
804 B
Go
40 lines
804 B
Go
package posture
|
|
|
|
import (
|
|
"github.com/hashicorp/go-version"
|
|
log "github.com/sirupsen/logrus"
|
|
|
|
nbpeer "github.com/netbirdio/netbird/management/server/peer"
|
|
)
|
|
|
|
type NBVersionCheck struct {
|
|
MinVersion string
|
|
}
|
|
|
|
var _ Check = (*NBVersionCheck)(nil)
|
|
|
|
func (n *NBVersionCheck) Check(peer nbpeer.Peer) (bool, error) {
|
|
peerNBVersion, err := version.NewVersion(peer.Meta.WtVersion)
|
|
if err != nil {
|
|
return false, err
|
|
}
|
|
|
|
constraints, err := version.NewConstraint(">= " + n.MinVersion)
|
|
if err != nil {
|
|
return false, err
|
|
}
|
|
|
|
if constraints.Check(peerNBVersion) {
|
|
return true, nil
|
|
}
|
|
|
|
log.Debugf("peer %s NB version %s is older than minimum allowed version %s",
|
|
peer.ID, peer.Meta.WtVersion, n.MinVersion)
|
|
|
|
return false, nil
|
|
}
|
|
|
|
func (n *NBVersionCheck) Name() string {
|
|
return NBVersionCheckName
|
|
}
|