filter

package
v0.16.4 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2026 License: BSD-3-Clause, GPL-3.0 Imports: 17 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

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CompileExpression

func CompileExpression(expression string, recordType types.Type) (*vm.Program, error)

CompileExpression compiles an expr-lang expression for a specific audit record type. The expression has access to all fields of the audit record and helper functions.

func Contains

func Contains(slice any, value any) bool

Contains checks if a slice contains a specific value. Supports []string, []int, and []int32 (common in protobuf).

func ContainsAny

func ContainsAny(str string, substrs []string) bool

ContainsAny checks if a string contains any of the provided substrings.

func CreateEnvironment

func CreateEnvironment(record types.AuditRecord) map[string]any

CreateEnvironment creates an expression environment from an audit record. This makes all fields of the record accessible in expressions. Note: Helper functions are declared via expr.Function() in CompileExpression() with explicit type signatures.

func DNSResolutionMatches added in v0.15.4

func DNSResolutionMatches(state, name string, answeredAt, at int64, domain string, maxAgeNS int64) bool

DNSResolutionMatches evaluates only the immutable fields of the observation. Matching is exact after DNS case/trailing-dot normalization, never a regex.

func DurationSince

func DurationSince(ts int64) int64

DurationSince returns the duration in nanoseconds since a given timestamp.

func EvaluateExpression

func EvaluateExpression(program *vm.Program, record types.AuditRecord) (bool, error)

EvaluateExpression evaluates a compiled expression against an audit record. Returns true if the record matches the filter, false otherwise.

func FormatTime

func FormatTime(ts int64, format string) string

FormatTime formats a timestamp (nanoseconds) according to the provided format string. Uses Go's time format layout (e.g., "2006-01-02 15:04:05").

func HasKey

func HasKey(m any, key string) bool

HasKey checks if a map contains a specific key. Supports map[string]string and map[string]interface{}.

func HourOfDay added in v0.15.4

func HourOfDay(ts int64) int

HourOfDay returns the local hour-of-day (0-23) for a nanosecond timestamp. This is a first-class helper for temporal-anomaly hunting (e.g. S7comm activity during off-hours), which the AA26-231A hunt explicitly calls for.

func InAllowlist added in v0.15.4

func InAllowlist(ip string) bool

InAllowlist is an alias for IsApprovedWorkstation, provided for readability in rule expressions where the semantic intent is a generic authorization check.

func InSubnet

func InSubnet(ip, cidr string) bool

InSubnet checks if an IP address is within a given CIDR subnet.

func IsApprovedWorkstation added in v0.15.4

func IsApprovedWorkstation(ip string) bool

IsApprovedWorkstation reports whether the given IP address is in the approved engineering-workstation allowlist. Returns false when the allowlist is empty.

func IsBusinessHours added in v0.15.4

func IsBusinessHours(ts int64, startHour, endHour int) bool

IsBusinessHours reports whether the local time of the given nanosecond timestamp falls within [startHour, endHour) on a weekday (Mon-Fri). startHour and endHour are 24-hour clock hours; the range is half-open on the end hour (e.g. startHour=8, endHour=18 covers 08:00:00-17:59:59).

This lets rules escalate activity outside the maintenance/change window, e.g. `!IsBusinessHours(Timestamp, 8, 18)` for off-hours S7comm operations.

func IsPrivateIP

func IsPrivateIP(ip string) bool

IsPrivateIP checks if an IP address is in a private range.

func IsPublicIP

func IsPublicIP(ip string) bool

IsPublicIP checks if an IP address is a public (non-private) address.

func LoadApprovedWorkstationsFromFile added in v0.15.4

func LoadApprovedWorkstationsFromFile(path string) error

LoadApprovedWorkstationsFromFile loads the approved-workstation allowlist from a file and installs it via SetApprovedWorkstations. Two line formats are accepted (and may be mixed):

10.0.0.5             # a bare IP address
eng-ws-01,10.0.0.5   # a "name,ip" CSV row (compatible with ip-whitelist.csv)

Blank lines and lines beginning with '#' or '*' are ignored. The last comma- separated field of a CSV row is taken as the IP.

func MatchesPattern

func MatchesPattern(str, pattern string) bool

MatchesPattern checks if a string matches a regular expression pattern. Compiled regexes are cached to avoid recompilation on repeated calls.

When the binary is built with `-tags hyperscan` and the pattern is one Hyperscan accepts, the boolean answer is taken directly from a per-pattern Hyperscan database (single-pattern block-mode DBs return the same true/false predicate as RE2 for the HS-supported subset of PCRE). Patterns Hyperscan refuses to compile transparently fall through to the existing RE2 cache path so behaviour is preserved.

func MustCompileExpression

func MustCompileExpression(expression string, recordType types.Type) *vm.Program

MustCompileExpression compiles an expression and panics on error. Useful for static expressions that are known to be valid.

func ParsePort

func ParsePort(port string) int

ParsePort converts a port string to an integer. Returns 0 if the string cannot be parsed.

func PortInRange

func PortInRange(port, start, end int) bool

PortInRange checks if a port is within a given range (inclusive).

func SetApprovedWorkstations added in v0.15.4

func SetApprovedWorkstations(ips []string)

SetApprovedWorkstations replaces the approved-workstation allowlist with the provided set of IP addresses. Passing nil or an empty slice clears the set, which causes IsApprovedWorkstation to always return false (every source is then treated as non-approved and subject to escalation).

func TimeInRange

func TimeInRange(ts, start, end int64) bool

TimeInRange checks if a timestamp (nanoseconds) is within a given range.

func Weekday added in v0.15.4

func Weekday(ts int64) int

Weekday returns the local day-of-week (0=Sunday .. 6=Saturday) for a nanosecond timestamp.

Types

type CompiledFilter

type CompiledFilter struct {
	Program    *vm.Program
	RecordType types.Type
	Expression string
}

CompiledFilter wraps a compiled expression program with its record type.

type FilterHyperscanStatus added in v0.9.1

type FilterHyperscanStatus struct {
	Enabled        bool   `json:"enabled"`
	LibVersion     string `json:"lib_version"`
	PatternsCached int    `json:"patterns_cached"`
	PatternsHS     int    `json:"patterns_hyperscan"`
	PatternsRE2    int    `json:"patterns_re2_only"`
	HSDecisions    uint64 `json:"hs_decisions"`
	HSEarlyExits   uint64 `json:"hs_early_exits"`
	HSScanErrors   uint64 `json:"hs_scan_errors"`
}

FilterHyperscanStatus mirrors the tagged-build type so the web UI handler renders the same JSON schema in both build configurations.

func GetFilterHyperscanStatus added in v0.9.1

func GetFilterHyperscanStatus() FilterHyperscanStatus

GetFilterHyperscanStatus reports a "disabled" snapshot.

Jump to

Keyboard shortcuts

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