Files
netmaker/schema/posture_check.go
Abhishek Kondur 12cc967ba1 Fixes/v1.5.1 (#3938)
* fix(go): set persistent keep alive when registering host using sso;

* fix(go): run posture check violations on delete;

* fix(go): upsert node on approving pending host;

* fix(go): resolve concurrency issues during group delete cleanup;

* fix(go): update doc links;

* fix(go): add created and updated fields to host;

* fix(go): skip delete and update superadmin on sync users;

* fix(go): use conn directly for now;

* fix(go): remove acl for idp groups;

* fix(go): quote fields;

* fix(go): use filters with count;

* feat(go): add a search query;

* fix(go): cleanup acls;

* fix(go): review fixes;

* fix(go): remove additional loop;

* fix(go): fix

* v1.5.1: separate out idp sync and reset signals for HA

* v1.5.1: add grps with name for logging

* v1.5.1: clear posture check violations when all checks are deleted

* v1.5.1: set static when default host

* v1.5.1: fix db status check

* rm set max conns

* v1.5.1: reset auto assigned gw when disconnected

* fix(go): skip global network admin and user groups when splitting;

* v1.5.1: fix update node call from client

* fix(go): separate out migration from normal usage;

* fix(go): skip default groups;

* fix(go): create policies for existing groups on network create;

* fix(go): skip fatal log on clickhouse conn;

* fix(go): add posture check cleanup;

---------

Co-authored-by: VishalDalwadi <dalwadivishal26@gmail.com>
Co-authored-by: Vishal Dalwadi <51291657+VishalDalwadi@users.noreply.github.com>
2026-03-28 01:08:59 +05:30

139 lines
4.0 KiB
Go

package schema
import (
"context"
"time"
"github.com/gravitl/netmaker/db"
"gorm.io/datatypes"
)
type Attribute string
type Values string
type Severity int
const (
OS Attribute = "os"
OSVersion Attribute = "os_version"
OSFamily Attribute = "os_family"
KernelVersion Attribute = "kernel_version"
AutoUpdate Attribute = "auto_update"
ClientVersion Attribute = "client_version"
ClientLocation Attribute = "client_location"
)
const (
SeverityUnknown Severity = iota
SeverityLow
SeverityMedium
SeverityHigh
SeverityCritical
)
var PostureCheckAttrs = []Attribute{
ClientLocation,
ClientVersion,
OS,
OSVersion,
OSFamily,
KernelVersion,
AutoUpdate,
}
var PostureCheckAttrValuesMap = map[Attribute]map[string]struct{}{
ClientLocation: {
"any_valid_iso_country_codes": {},
},
ClientVersion: {
"any_valid_semantic_version": {},
},
OS: {
"linux": {},
"darwin": {},
"windows": {},
"ios": {},
"android": {},
},
OSVersion: {
"any_valid_semantic_version": {},
},
OSFamily: {
"linux-debian": {},
"linux-redhat": {},
"linux-suse": {},
"linux-arch": {},
"linux-gentoo": {},
"linux-other": {},
"darwin": {},
"windows": {},
"ios": {},
"android": {},
},
KernelVersion: {
"any_valid_semantic_version": {},
},
AutoUpdate: {
"true": {},
"false": {},
},
}
var PostureCheckAttrValues = map[Attribute][]string{
ClientLocation: {"any_valid_iso_country_codes"},
ClientVersion: {"any_valid_semantic_version"},
OS: {"linux", "darwin", "windows", "ios", "android"},
OSVersion: {"any_valid_semantic_version"},
OSFamily: {"linux-debian", "linux-redhat", "linux-suse", "linux-arch", "linux-gentoo", "linux-other", "darwin", "windows", "ios", "android"},
KernelVersion: {"any_valid_semantic_version"},
AutoUpdate: {"true", "false"},
}
type PostureCheck struct {
ID string `gorm:"primaryKey" json:"id"`
Name string `gorm:"name" json:"name"`
NetworkID NetworkID `gorm:"network_id" json:"network_id"`
Description string `gorm:"description" json:"description"`
Attribute Attribute `gorm:"attribute" json:"attribute"`
Values datatypes.JSONSlice[string] `gorm:"values" json:"values"`
Severity Severity `gorm:"severity" json:"severity"`
Tags datatypes.JSONMap `gorm:"tags" json:"tags"`
UserGroups datatypes.JSONMap `gorm:"user_groups" json:"user_groups"`
Status bool `gorm:"status" json:"status"`
CreatedBy string `gorm:"created_by" json:"created_by"`
CreatedAt time.Time `gorm:"created_at" json:"created_at"`
UpdatedAt time.Time `gorm:"updated_at" json:"updated_at"`
}
func (p *PostureCheck) Get(ctx context.Context) error {
return db.FromContext(ctx).Model(&PostureCheck{}).First(&p).Where("id = ?", p.ID).Error
}
func (p *PostureCheck) Update(ctx context.Context) error {
return db.FromContext(ctx).Model(&PostureCheck{}).Where("id = ?", p.ID).Updates(&p).Error
}
func (p *PostureCheck) Create(ctx context.Context) error {
return db.FromContext(ctx).Model(&PostureCheck{}).Create(&p).Error
}
func (p *PostureCheck) ListAll(ctx context.Context) ([]PostureCheck, error) {
var postureChecks []PostureCheck
err := db.FromContext(ctx).Model(&PostureCheck{}).Find(&postureChecks).Error
return postureChecks, err
}
func (p *PostureCheck) ListByNetwork(ctx context.Context) (pcli []PostureCheck, err error) {
err = db.FromContext(ctx).Model(&PostureCheck{}).Where("network_id = ?", p.NetworkID).Find(&pcli).Error
return
}
func (p *PostureCheck) Delete(ctx context.Context) error {
return db.FromContext(ctx).Model(&PostureCheck{}).Where("id = ?", p.ID).Delete(&p).Error
}
func (p *PostureCheck) UpdateStatus(ctx context.Context) error {
return db.FromContext(ctx).Model(&PostureCheck{}).Where("id = ?", p.ID).Updates(map[string]any{
"status": p.Status,
}).Error
}