decide

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2026 License: AGPL-3.0 Imports: 3 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package decide is the runtime sensor's verdict engine: given a rule match, what does the sensor do about it, right now, on this host.

Three modes:

  • monitor reports every match and blocks nothing.
  • guard holds a match on a rule safe to block (a request denied, an exec refused, a connection dropped) until a person confirms a block or releases it on the resolve pages, or the hold lapses to allow.
  • enforce blocks matches on rules safe to block, without asking.

The rules that keep it from causing the outage it exists to prevent:

  • Only a reversible action is ever held. Stopping a process cannot be undone when the hold is released, so a hold never stops one.
  • A rule not from a verified feed, or one whose own start mode is log, is reported and never blocked, in any mode.
  • A health check is never held: a held probe takes the workload out of its load balancer, which is the outage.
  • A rule that holds too many distinct subjects in a short window trips a breaker and reverts to reporting until a person decides about it. A misfiring rule in guard mode would otherwise hold every request.
  • A hold that lapses unanswered allows that subject from then on, rather than holding it again, which would turn guard into enforce by neglect.

The engine is pure: time is passed in, nothing is read from the host.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ValidMode

func ValidMode(m string) bool

ValidMode reports whether m is one of the three modes.

Types

type Action

type Action string

Action is what the sensor did.

const (
	Allowed Action = "allowed"
	Held    Action = "held"
	Blocked Action = "blocked"
)

type Config

type Config struct {
	// Hold is how long a guard-mode hold waits for a person.
	Hold time.Duration
	// BreakerSubjects distinct subjects held by one rule inside
	// BreakerWindow trips that rule's breaker.
	BreakerSubjects int
	BreakerWindow   time.Duration
}

Config tunes the engine.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig is fifteen minutes to decide, and a breaker at twenty distinct subjects in five minutes.

type Decision

type Decision struct {
	UUID      string
	Rule      RuleRef
	Subject   string // "*" for the whole rule
	Verdict   string // block | allow | promote | demote | mode
	Value     string // the mode, for verdict "mode"
	Until     time.Time
	Revoked   bool
	DecidedAt time.Time
}

Decision is a person's decision, as the platform sends it.

type Engine

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

Engine holds the sensor's state. Safe for concurrent use.

func New

func New(mode Mode, cfg Config) *Engine

New returns an engine in the given mode with no rules loaded.

func (*Engine) Apply

func (e *Engine) Apply(d Decision)

Apply takes a person's decision into account.

func (*Engine) Decide

func (e *Engine) Decide(m Match, now time.Time) Verdict

Decide answers one match.

func (*Engine) Mode

func (e *Engine) Mode() Mode

Mode returns the current mode.

func (*Engine) Pending

func (e *Engine) Pending(now time.Time) []PendingHold

func (*Engine) Rule

func (e *Engine) Rule(ref RuleRef) (Rule, bool)

Rule returns a loaded rule's effective state.

func (*Engine) SetHold

func (e *Engine) SetHold(d time.Duration)

SetHold changes how long a new hold waits. Holds already running keep their expiry.

func (*Engine) SetMode

func (e *Engine) SetMode(m Mode)

SetMode changes the mode, as a profile change does. An invalid mode is ignored.

func (*Engine) SetRules

func (e *Engine) SetRules(rules []Rule)

SetRules replaces the loaded rule set. Holds and decisions about rules that are gone are kept: a rule dropped and re-added keeps its history.

func (*Engine) Tripped

func (e *Engine) Tripped() []RuleRef

Tripped lists rules whose breaker is open.

type Match

type Match struct {
	Rule    RuleRef
	Subject string
	// Reversible is true when the response to this match can be undone: a
	// denied request, a refused exec, a dropped new connection, a quarantined
	// file. Stopping a running process is not.
	Reversible bool
	// HealthCheck marks a request on a path the operator named as a health
	// check. It is never held.
	HealthCheck bool
}

Match is one rule firing on one subject.

type Mode

type Mode string

Mode is the sensor's mode.

const (
	Monitor Mode = "monitor"
	Guard   Mode = "guard"
	Enforce Mode = "enforce"
)

type PendingHold

type PendingHold struct {
	Rule    RuleRef
	Subject string
	Until   time.Time
}

Pending lists live holds, soonest to lapse first.

type Rule

type Rule struct {
	Ref  RuleRef
	Mode RuleMode
	// FeedMode is the start mode the feed gave the rule, which a revoked
	// promote or demote returns it to.
	FeedMode RuleMode
	// Verified is true when the rule came from a feed whose signature and
	// file hashes checked out. An unverified rule never blocks.
	Verified bool
}

Rule is one loaded rule.

type RuleMode

type RuleMode string

RuleMode is the mode a rule runs in: block, or log only.

const (
	Block RuleMode = "block"
	Log   RuleMode = "log"
)

type RuleRef

type RuleRef struct {
	Table string
	UUID  string
}

RuleRef names a rule the way the platform does.

type Verdict

type Verdict struct {
	Action    Action
	HoldUntil time.Time
	// Reason is one short phrase saying why, reported with the event.
	Reason string
}

Verdict is the engine's answer.

Jump to

Keyboard shortcuts

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