Documentation
¶
Overview ¶
Package config parses and validates Keep rule files, profiles, and starter packs.
Index ¶
- Variables
- func IsParamsPath(path string) bool
- func LoadPacks(dir string) (map[string]*StarterPack, error)
- func LoadProfiles(dir string) (map[string]*Profile, error)
- func LoadRules(dir string) (map[string]*RuleFile, error)
- func Validate(rf *RuleFile) error
- func ValidateFieldPath(path string) error
- type Action
- type ErrorMode
- type LintWarning
- type LoadResult
- type LogConfig
- type Match
- type Mode
- type PackRef
- type Profile
- type RedactPattern
- type RedactSpec
- type Rule
- type RuleFile
- type StarterPack
Constants ¶
This section is empty.
Variables ¶
var ReservedNames = map[string]bool{ "params": true, "context": true, "now": true, "size": true, "has": true, "matches": true, "startsWith": true, "endsWith": true, "contains": true, "exists": true, "all": true, "filter": true, "exists_one": true, "containsAny": true, "estimateTokens": true, "inTimeWindow": true, "rateCount": true, "lower": true, "upper": true, "matchesDomain": true, "dayOfWeek": true, "hasSecrets": true, "int": true, "uint": true, "double": true, "bool": true, "string": true, "bytes": true, "list": true, "map": true, "type": true, "null_type": true, "true": true, "false": true, "null": true, }
ReservedNames is the unified set of identifiers that must not be used as def names or profile alias names because they shadow CEL built-in variables, operators, or Keep-specific functions.
Functions ¶
func IsParamsPath ¶
IsParamsPath returns true if the path starts with "params.".
func LoadPacks ¶
func LoadPacks(dir string) (map[string]*StarterPack, error)
LoadPacks reads all .yaml and .yml files from dir and parses them as starter packs. Returns packs indexed by name. Returns an empty map if dir is empty or does not exist.
func LoadProfiles ¶
LoadProfiles reads all .yaml and .yml files from dir, parses them as profiles, and validates alias names and targets. Returns profiles indexed by name. Returns an empty map if dir is empty or does not exist.
func LoadRules ¶
LoadRules reads all .yaml and .yml files from dir, parses them as rule files, validates each one, and checks scope uniqueness across all files. Returns the parsed files indexed by scope name. Errors from all files are accumulated and returned together.
func Validate ¶
Validate checks that rf is a well-formed rule file. It accumulates all validation errors and returns them joined.
func ValidateFieldPath ¶
ValidateFieldPath checks that a dot-separated path is syntactically valid. Each segment must be a valid identifier (ASCII letter or underscore followed by ASCII alphanumeric/underscores). ASCII-only identifiers are required to prevent Unicode homoglyph confusion.
Types ¶
type ErrorMode ¶
type ErrorMode string
ErrorMode controls behavior when a CEL expression errors at eval time.
type LintWarning ¶ added in v0.2.0
LintWarning is a non-fatal issue found during linting.
func Lint ¶ added in v0.2.0
func Lint(rf *RuleFile) []LintWarning
Lint checks a rule file for style issues that are not errors but may indicate mistakes. Currently checks for uppercase characters in string literals within when expressions (case-insensitive mode normalizes inputs to lowercase, so uppercase literals would never match).
func LintAll ¶ added in v0.2.0
func LintAll(lr *LoadResult) []LintWarning
LintAll runs lint checks across all scopes in a load result.
func (LintWarning) String ¶ added in v0.2.0
func (w LintWarning) String() string
type LoadResult ¶
type LoadResult struct {
// Scopes contains the raw parsed rule files before pack resolution.
// Use ResolvedRules for the authoritative post-resolution rule list.
Scopes map[string]*RuleFile
// ResolvedRules maps scope name to the merged rule list (packs + inline).
ResolvedRules map[string][]Rule
// Profiles maps profile name to its parsed profile.
Profiles map[string]*Profile
}
LoadResult holds all parsed and resolved configuration.
func LoadAll ¶
func LoadAll(rulesDir string, profilesDir string, packsDir string) (*LoadResult, error)
LoadAll reads rules, profiles, and packs from their respective directories, validates everything, resolves pack references and overrides, and returns the fully resolved configuration. profilesDir and packsDir may be empty strings if not needed.
type LogConfig ¶
type LogConfig struct {
Format string `yaml:"format,omitempty"`
Output string `yaml:"output,omitempty"`
}
LogConfig controls log format and output destination. Used by both relay and gateway configurations.
type Match ¶
type Match struct {
Operation string `yaml:"operation,omitempty"`
When string `yaml:"when,omitempty"`
}
Match determines when a rule applies.
type PackRef ¶
type PackRef struct {
Name string `yaml:"name"`
Overrides map[string]interface{} `yaml:"overrides,omitempty"`
}
PackRef references a starter pack with optional overrides.
type RedactPattern ¶
RedactPattern is a regex pattern and its replacement.
type RedactSpec ¶
type RedactSpec struct {
Target string `yaml:"target"`
Secrets bool `yaml:"secrets,omitempty"`
Patterns []RedactPattern `yaml:"patterns,omitempty"`
}
RedactSpec defines what to redact and how.
type Rule ¶
type Rule struct {
Name string `yaml:"name"`
Description string `yaml:"description,omitempty"`
Match Match `yaml:"match,omitempty"`
Action Action `yaml:"action"`
Message string `yaml:"message,omitempty"`
Redact *RedactSpec `yaml:"redact,omitempty"`
}
Rule is an atomic unit of policy.
func ResolvePacks ¶
func ResolvePacks(rf *RuleFile, packs map[string]*StarterPack) ([]Rule, error)
ResolvePacks takes a rule file's pack references, looks them up in the loaded packs, applies overrides, and returns the merged rule list (pack rules first, then inline rules).
type RuleFile ¶
type RuleFile struct {
Scope string `yaml:"scope"`
Profile string `yaml:"profile,omitempty"`
Mode Mode `yaml:"mode,omitempty"`
OnError ErrorMode `yaml:"on_error,omitempty"`
CaseSensitive bool `yaml:"case_sensitive,omitempty"`
Defs map[string]string `yaml:"defs,omitempty"`
Packs []PackRef `yaml:"packs,omitempty"`
Rules []Rule `yaml:"rules"`
}
RuleFile is the parsed representation of a single YAML rule file.
func ParseRuleFile ¶ added in v0.2.1
ParseRuleFile parses and validates a single rule file from raw YAML bytes. It does not resolve pack references — callers that need pack resolution should use LoadAll instead.
type StarterPack ¶
type StarterPack struct {
Name string `yaml:"name"`
Profile string `yaml:"profile,omitempty"`
Rules []Rule `yaml:"rules"`
}
StarterPack is a reusable set of rules.