Help us shape the future of Go! Take the 2026 Go Developer Survey

nodeconfig

package
v0.6.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 24, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package nodeconfig validates and applies per-node osquery configuration overrides on top of an environment's configuration.

Index

Constants

View Source
const ReportFreshness = 15 * time.Minute

ReportFreshness is how long an osctrld health report counts as current.

Variables

This section is empty.

Functions

func FlagOptionConflicts

func FlagOptionConflicts(override string, configs ...string) []string

FlagOptionConflicts returns, sorted, the flag names of a flags override that are also keys of "options" in any of the given JSON configurations. Flags and options both set osquery options, so the same one in both is ambiguous. Configurations that are not valid JSON are ignored.

func Merge

func Merge(envConfig, override string) (string, error)

Merge deep-merges override on top of envConfig and returns the indented JSON. Objects merge key by key; any other override value (including arrays) replaces the environment's. An empty envConfig is treated as an empty object.

func MergeFlags

func MergeFlags(envFlags, override string) (string, error)

MergeFlags applies a flags override to an environment flagfile. Each override flag replaces every environment line with the same name in place, keeping that line's dash prefix; flags the environment lacks are appended in override order. The output is deterministic for the same inputs.

func ProtectedFlag

func ProtectedFlag(name string) bool

ProtectedFlag reports whether an osquery flag controls the connection to osctrl and so cannot be set by a node flags override.

func ProtectedOption

func ProtectedOption(name string) bool

ProtectedOption reports whether an osquery option controls the connection to osctrl and so cannot be set by a node override.

func ValidEventID

func ValidEventID(id string) bool

ValidEventID reports whether id has the rollback event id format.

func ValidStage

func ValidStage(kind, stage string) bool

ValidStage reports whether stage is a known rollback stage for kind ("flags" or "extensions").

func ValidUpgrade

func ValidUpgrade(u types.OsctrldUpgrade) bool

ValidUpgrade reports whether u is a well-formed osquery upgrade result.

func ValidUpgradeReason

func ValidUpgradeReason(r string) bool

ValidUpgradeReason reports whether r is a known upgrade reason.

func Validate

func Validate(override string) error

Validate checks that an override is a JSON object that is safe to merge: known sections are objects, no value is null and no protected option is set.

func ValidateFlagsOverride

func ValidateFlagsOverride(override string) error

ValidateFlagsOverride checks that an override is a list of osquery flags, one per line, with no protected flag, no flag repeated and at least one flag. Blank lines and # comments are ignored.

Types

type FlagsManager

type FlagsManager struct {
	// contains filtered or unexported fields
}

FlagsManager stores per-node flags overrides and osctrld status in SQL, with the same cache protocol as Manager in front of the overrides.

func NewFlagsManager

func NewFlagsManager(db *gorm.DB, client *redis.Client) (*FlagsManager, error)

NewFlagsManager migrates the tables. client may be nil, which disables the cache.

func (*FlagsManager) Active

func (m *FlagsManager) Active(ctx context.Context, nodeUUID string, envID uint, now time.Time) (*FlagsOverride, error)

Active returns the node's flags override if it exists, belongs to envID and has not expired. It does not validate the stored flags; callers re-validate.

func (*FlagsManager) CountDown

func (m *FlagsManager) CountDown(now time.Time) (map[uint]int, error)

CountDown returns, per environment, the nodes whose fresh report says osqueryd is not running.

func (*FlagsManager) Delete

func (m *FlagsManager) Delete(ctx context.Context, nodeUUID string) error

Delete hard-deletes the node's flags override, then caches its absence.

func (*FlagsManager) DeleteStatus

func (m *FlagsManager) DeleteStatus(nodeUUID string) error

DeleteStatus hard-deletes the node's osctrld status.

func (*FlagsManager) Get

func (m *FlagsManager) Get(nodeUUID string) (*FlagsOverride, error)

Get returns the node's flags override straight from SQL, or nil if there is none.

func (*FlagsManager) RecordFetch

func (m *FlagsManager) RecordFetch(nodeUUID string, envID uint, at time.Time, apply *types.OsctrldApplyStatus) error

RecordFetch upserts the node's osctrld status. A nil apply keeps the previously reported apply fields.

func (*FlagsManager) RecordReport

func (m *FlagsManager) RecordReport(nodeUUID string, envID uint, r types.OsctrldStatusRequest, at time.Time) ([]string, error)

RecordReport stores an osctrld health report. A kind (flags/extensions) with an invalid stage or event id is dropped, keeping its stored values; so is an invalid upgrade result. A rejected upgrade reports the kind "upgrade". It returns the kinds whose non-none event id was not seen before; the compare-and-set on the event id column counts an event once across replicas.

func (*FlagsManager) Set

Set validates and upserts the flags override for o.NodeUUID, then caches it.

func (*FlagsManager) Status

func (m *FlagsManager) Status(nodeUUID string) (*OsctrldStatus, error)

Status returns the node's osctrld status, or nil if it never fetched flags.

type FlagsOverride

type FlagsOverride struct {
	gorm.Model
	NodeUUID      string `gorm:"uniqueIndex:idx_node_flags_overrides_node_uuid;size:255"`
	EnvironmentID uint   `gorm:"index:idx_node_flags_overrides_env"`
	Flags         string
	ExpiresAt     *time.Time
	UpdatedBy     string
}

FlagsOverride is a per-node osquery flags override: flagfile lines merged over the environment flags osctrld fetches.

func (*FlagsOverride) Expired

func (o *FlagsOverride) Expired(now time.Time) bool

Expired reports whether the override has an expiry that is not after now.

func (FlagsOverride) TableName

func (FlagsOverride) TableName() string

TableName keeps the table name stable.

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

Manager stores per-node configuration overrides in SQL, with a Redis cache in front of the read path osctrl-tls takes on every osquery config request.

SQL is the source of truth. Set and Delete write the full state into the cache after the SQL commit (never delete the key); Active only refills a cache miss with setNX, so it can never overwrite a newer write.

func NewManager

func NewManager(db *gorm.DB, client *redis.Client) (*Manager, error)

NewManager migrates the table. client may be nil, which disables the cache.

func (*Manager) Active

func (m *Manager) Active(ctx context.Context, nodeUUID string, envID uint, now time.Time) (*Override, error)

Active returns the node's override if it exists, belongs to envID and has not expired. It does not validate the stored config; callers re-validate.

func (*Manager) Delete

func (m *Manager) Delete(ctx context.Context, nodeUUID string) error

Delete hard-deletes the node's override, then caches its absence.

func (*Manager) Get

func (m *Manager) Get(nodeUUID string) (*Override, error)

Get returns the node's override straight from SQL, or nil if there is none.

func (*Manager) Set

func (m *Manager) Set(ctx context.Context, o Override) (*Override, error)

Set validates and upserts the override for o.NodeUUID, then caches it.

type OsctrldStatus

type OsctrldStatus struct {
	gorm.Model
	NodeUUID      string `gorm:"uniqueIndex:idx_osctrld_status_node_uuid;size:255"`
	EnvironmentID uint
	LastFetchedAt time.Time
	ApplyResult   string
	ApplySHA256   string
	ApplyError    string
	ApplyAt       *time.Time

	// Health report fields, written by RecordReport only.
	OsqueryRunning    *bool
	DownSince         *time.Time
	ReportedAt        *time.Time `gorm:"index"`
	FlagsStage        string     `gorm:"default:''"`
	ExtensionsStage   string     `gorm:"default:''"`
	FlagsEventID      string     `gorm:"default:''"`
	ExtensionsEventID string     `gorm:"default:''"`

	// Osquery upgrade result, written by RecordReport only.
	UpgradeResult     string `gorm:"default:''"`
	UpgradeVersion    string `gorm:"default:''"`
	UpgradeReason     string `gorm:"default:''"`
	UpgradeRequestID  string `gorm:"default:''"`
	UpgradeEventID    string `gorm:"default:''"`
	UpgradeReportedAt *time.Time
	// UpgradeEventAt is the server time UpgradeEventID was first recorded.
	UpgradeEventAt *time.Time
}

OsctrldStatus is the last flags fetch by a node's osctrld and the result of its last flags apply, as reported by osctrld.

func (OsctrldStatus) TableName

func (OsctrldStatus) TableName() string

TableName keeps the table name stable.

type Override

type Override struct {
	gorm.Model
	NodeUUID      string `gorm:"uniqueIndex;size:255"`
	EnvironmentID uint   `gorm:"index"`
	Config        string
	ExpiresAt     *time.Time
	UpdatedBy     string
}

Override is a per-node osquery configuration override.

func (*Override) Expired

func (o *Override) Expired(now time.Time) bool

Expired reports whether the override has an expiry that is not after now.

func (Override) TableName

func (Override) TableName() string

TableName keeps the table name stable.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL