Documentation ¶
Overview ¶
Package rules holds rules related files
Package rules holds rules related files ¶
Package rules holds rules related files ¶
Package rules holds rules related files ¶
Package rules holds rules related files ¶
Package rules holds rules related files ¶
Package rules holds rules related files ¶
Package rules holds rules related files ¶
Package rules holds rules related files ¶
Package rules holds rules related files ¶
Package rules holds rules related files ¶
Package rules holds rules related files ¶
Package rules holds rules related files ¶
Package rules holds rules related files ¶
Package rules holds rules related files ¶
Package rules holds rules related files
Index ¶
- Constants
- Variables
- func AddTestRuleExpr(t testing.TB, rs *RuleSet, exprs ...string)
- func GetRuleEventType(rule *eval.Rule) (eval.EventType, error)
- func IsDiscarder(ctx *eval.Context, field eval.Field, rules []*Rule) (bool, error)
- func NewEvalOpts() *eval.Opts
- type ActionDefinition
- type ActionName
- type AgentVersionFilter
- type Approvers
- type CollectedEvent
- type CombinePolicy
- type CoreDumpDefinition
- type ErrActionFilter
- type ErrFieldTypeUnknown
- type ErrMacroLoad
- type ErrNoApprover
- type ErrNoEventTypeBucket
- type ErrPoliciesLoad
- type ErrPolicyLoad
- type ErrRuleLoad
- type ErrRuleSyntax
- type ErrValueTypeUnknown
- type EvaluationSet
- type EventCollector
- type FieldCapabilities
- type FieldCapability
- type FilterValue
- type FilterValues
- type HashDefinition
- type InternalCallbackDefinition
- type KillDefinition
- type Macro
- type MacroDefinition
- type MacroFilter
- type MacroID
- type MultiDiscarder
- type MultiDiscarderEntry
- type Opts
- func (o *Opts) WithEventTypeEnabled(eventTypes map[eval.EventType]bool) *Opts
- func (o *Opts) WithLogger(logger log.Logger) *Opts
- func (o *Opts) WithReservedRuleIDs(ruleIds []RuleID) *Opts
- func (o *Opts) WithRuleSetTag(tagValue eval.RuleSetTagValue) *Opts
- func (o *Opts) WithStateScopes(stateScopes map[Scope]VariableProviderFactory) *Opts
- func (o *Opts) WithSupportedDiscarders(discarders map[eval.Field]bool) *Opts
- func (o *Opts) WithSupportedMultiDiscarder(discarders []*MultiDiscarder) *Opts
- type OverrideField
- type OverrideOptions
- type PoliciesDirProvider
- func (p *PoliciesDirProvider) Close() error
- func (p *PoliciesDirProvider) LoadPolicies(macroFilters []MacroFilter, ruleFilters []RuleFilter) ([]*Policy, *multierror.Error)
- func (p *PoliciesDirProvider) SetOnNewPoliciesReadyCb(cb func())
- func (p *PoliciesDirProvider) Start()
- func (p *PoliciesDirProvider) Type() string
- type Policy
- type PolicyDef
- type PolicyLoader
- type PolicyLoaderOpts
- type PolicyProvider
- type Rule
- type RuleBucket
- type RuleDefinition
- type RuleFilter
- type RuleID
- type RuleIDFilter
- type RuleLoadErrType
- type RuleSet
- func (rs *RuleSet) AddFields(fields []eval.EventType)
- func (rs *RuleSet) AddListener(listener RuleSetListener)
- func (rs *RuleSet) AddMacro(parsingContext *ast.ParsingContext, macroDef *MacroDefinition) (*eval.Macro, error)
- func (rs *RuleSet) AddMacros(parsingContext *ast.ParsingContext, macros []*MacroDefinition) *multierror.Error
- func (rs *RuleSet) AddRule(parsingContext *ast.ParsingContext, ruleDef *RuleDefinition) (*eval.Rule, error)
- func (rs *RuleSet) AddRules(parsingContext *ast.ParsingContext, rules []*RuleDefinition) *multierror.Error
- func (rs *RuleSet) Evaluate(event eval.Event) bool
- func (rs *RuleSet) EvaluateDiscarders(event eval.Event)
- func (rs *RuleSet) GetApprovers(fieldCaps map[eval.EventType]FieldCapabilities) (map[eval.EventType]Approvers, error)
- func (rs *RuleSet) GetBucket(eventType eval.EventType) *RuleBucket
- func (rs *RuleSet) GetEventApprovers(eventType eval.EventType, fieldCaps FieldCapabilities) (Approvers, error)
- func (rs *RuleSet) GetEventTypes() []eval.EventType
- func (rs *RuleSet) GetFieldValues(field eval.Field) []eval.FieldValue
- func (rs *RuleSet) GetRuleSetTag() eval.RuleSetTagValue
- func (rs *RuleSet) GetRules() map[eval.RuleID]*Rule
- func (rs *RuleSet) HasRulesForEventType(eventType eval.EventType) bool
- func (rs *RuleSet) IsDiscarder(event eval.Event, field eval.Field) (bool, error)
- func (rs *RuleSet) ListFields() []string
- func (rs *RuleSet) ListMacroIDs() []MacroID
- func (rs *RuleSet) ListRuleIDs() []RuleID
- func (rs *RuleSet) NewEvent() eval.Event
- func (rs *RuleSet) NotifyDiscarderFound(event eval.Event, field eval.Field, eventType eval.EventType)
- func (rs *RuleSet) NotifyRuleMatch(rule *Rule, event eval.Event)
- func (rs *RuleSet) StopEventCollector() []CollectedEvent
- type RuleSetListener
- type SECLRuleFilter
- type Scope
- type SetDefinition
- type VariableProvider
- type VariableProviderFactory
Constants ¶
const ( PolicyProviderTypeDir = "file" // PolicyProviderTypeDir defines directory policy provider PolicyProviderTypeRC = "remote-config" // PolicyProviderTypeRC defines RC policy provider PolicyProviderTypeBundled = "bundled" // PolicyProviderTypeBundled defines the bundled policy provider )
const ( RuleSetTagKey = "ruleset" DefaultRuleSetTagValue = "probe_evaluation" )
Ruleset loading operations
const DefaultPolicyName = "default.policy"
DefaultPolicyName is the name of the default policy the default policy has a slightly privileged position when loading the rules
Variables ¶
var ( // ErrRuleWithoutID is returned when there is no ID ErrRuleWithoutID = errors.New("no rule ID") // ErrRuleWithoutExpression is returned when there is no expression ErrRuleWithoutExpression = errors.New("no rule expression") // ErrRuleIDPattern is returned when there is no expression ErrRuleIDPattern = errors.New("rule ID pattern error") // ErrRuleWithoutEvent is returned when no event type was inferred from the rule ErrRuleWithoutEvent = errors.New("no event in the rule definition") // ErrRuleWithMultipleEvents is returned when multiple event type were inferred from the rule ErrRuleWithMultipleEvents = errors.New("rule with multiple events is not supported") // ErrDefinitionIDConflict is returned when multiple rules use the same ID ErrDefinitionIDConflict = errors.New("multiple definition with the same ID") // ErrInternalIDConflict is returned when a user defined rule use an internal ID ErrInternalIDConflict = errors.New("internal rule ID conflict") // ErrEventTypeNotEnabled is returned when an event is not enabled ErrEventTypeNotEnabled = errors.New("event type not enabled") // ErrCannotMergeExpression is returned when trying to merge SECL expression ErrCannotMergeExpression = errors.New("cannot merge expression") // ErrRuleAgentVersion is returned when there is an agent version error ErrRuleAgentVersion = errors.New("agent version incompatible") // ErrRuleAgentFilter is returned when an agent rule was filtered ErrRuleAgentFilter = errors.New("agent rule filtered") // ErrNoRuleSetsInEvaluationSet is returned when no rule sets were provided to instantiate an evaluation set ErrNoRuleSetsInEvaluationSet = errors.New("no rule sets provided to instantiate an evaluation set") // ErrCannotChangeTagAfterLoading is returned when an attempt was made to change the tag on a ruleset that already has rules loaded ErrCannotChangeTagAfterLoading = errors.New("cannot change tag on a rule set that already has rules loaded") )
Functions ¶
func AddTestRuleExpr ¶ added in v0.55.0
AddTestRuleExpr adds a rule expression
func GetRuleEventType ¶ added in v0.34.0
GetRuleEventType return the rule EventType. Currently rules support only one eventType
func IsDiscarder ¶ added in v0.41.0
IsDiscarder partially evaluates an Event against a field
Types ¶
type ActionDefinition ¶ added in v0.35.0
type ActionDefinition struct { Filter *string `yaml:"filter"` Set *SetDefinition `yaml:"set"` Kill *KillDefinition `yaml:"kill"` CoreDump *CoreDumpDefinition `yaml:"coredump"` Hash *HashDefinition `yaml:"hash"` // internal InternalCallback *InternalCallbackDefinition FilterEvaluator *eval.RuleEvaluator }
ActionDefinition describes a rule action section
func (*ActionDefinition) Check ¶ added in v0.35.0
func (a *ActionDefinition) Check(opts PolicyLoaderOpts) error
Check returns an error if the action in invalid
func (*ActionDefinition) CompileFilter ¶ added in v0.51.0
func (a *ActionDefinition) CompileFilter(parsingContext *ast.ParsingContext, model eval.Model, evalOpts *eval.Opts) error
CompileFilter compiles the filter expression
func (*ActionDefinition) IsAccepted ¶ added in v0.51.0
func (a *ActionDefinition) IsAccepted(ctx *eval.Context) bool
IsAccepted returns whether a filter is accepted and has to be executed
type ActionName ¶ added in v0.51.0
type ActionName = string
ActionName defines an action name
const ( // KillAction name a the kill action KillAction ActionName = "kill" )
type AgentVersionFilter ¶ added in v0.39.0
type AgentVersionFilter struct {
// contains filtered or unexported fields
}
AgentVersionFilter defines a agent version filter
func NewAgentVersionFilter ¶ added in v0.40.0
func NewAgentVersionFilter(version *semver.Version) (*AgentVersionFilter, error)
NewAgentVersionFilter returns a new agent version based rule filter
func (*AgentVersionFilter) IsMacroAccepted ¶ added in v0.40.0
func (r *AgentVersionFilter) IsMacroAccepted(macro *MacroDefinition) (bool, error)
IsMacroAccepted checks whether the macro is accepted
func (*AgentVersionFilter) IsRuleAccepted ¶ added in v0.40.0
func (r *AgentVersionFilter) IsRuleAccepted(rule *RuleDefinition) (bool, error)
IsRuleAccepted checks whether the rule is accepted
type Approvers ¶
type Approvers map[eval.Field]FilterValues
Approvers are just filter values indexed by field
func GetApprovers ¶ added in v0.36.0
GetApprovers returns approvers for the given rules
type CollectedEvent ¶ added in v0.48.0
CollectedEvent defines a collected event
type CombinePolicy ¶ added in v0.35.0
type CombinePolicy = string
CombinePolicy represents the policy to use to combine rules and macros
const ( NoPolicy CombinePolicy = "" MergePolicy CombinePolicy = "merge" OverridePolicy CombinePolicy = "override" )
Combine policies
type CoreDumpDefinition ¶ added in v0.55.0
type CoreDumpDefinition struct { Process bool `yaml:"process"` Mount bool `yaml:"mount"` Dentry bool `yaml:"dentry"` NoCompression bool `yaml:"no_compression"` }
CoreDumpDefinition describes the 'coredump' action
type ErrActionFilter ¶ added in v0.51.0
ErrActionFilter is on filter definition error
func (ErrActionFilter) Error ¶ added in v0.51.0
func (e ErrActionFilter) Error() string
type ErrFieldTypeUnknown ¶
type ErrFieldTypeUnknown struct {
Field string
}
ErrFieldTypeUnknown is returned when a field has an unknown type
func (*ErrFieldTypeUnknown) Error ¶
func (e *ErrFieldTypeUnknown) Error() string
type ErrMacroLoad ¶
type ErrMacroLoad struct { Definition *MacroDefinition Err error }
ErrMacroLoad is on macro definition error
func (ErrMacroLoad) Error ¶
func (e ErrMacroLoad) Error() string
type ErrNoApprover ¶
type ErrNoApprover struct {
Fields []string
}
ErrNoApprover is returned when no approver was found for a set of rules
func (ErrNoApprover) Error ¶
func (e ErrNoApprover) Error() string
type ErrNoEventTypeBucket ¶
type ErrNoEventTypeBucket struct {
EventType string
}
ErrNoEventTypeBucket is returned when no bucket could be found for an event type
func (ErrNoEventTypeBucket) Error ¶
func (e ErrNoEventTypeBucket) Error() string
type ErrPoliciesLoad ¶
ErrPoliciesLoad is returned on policies dir error
func (ErrPoliciesLoad) Error ¶
func (e ErrPoliciesLoad) Error() string
type ErrPolicyLoad ¶
ErrPolicyLoad is returned on policy file error
func (ErrPolicyLoad) Error ¶
func (e ErrPolicyLoad) Error() string
type ErrRuleLoad ¶
type ErrRuleLoad struct { Definition *RuleDefinition Err error }
ErrRuleLoad is on rule definition error
func (ErrRuleLoad) Error ¶
func (e ErrRuleLoad) Error() string
func (ErrRuleLoad) Type ¶ added in v0.41.0
func (e ErrRuleLoad) Type() RuleLoadErrType
Type return the type of the error
type ErrRuleSyntax ¶ added in v0.41.0
type ErrRuleSyntax struct {
Err error
}
ErrRuleSyntax is returned when there is a syntax error
func (*ErrRuleSyntax) Error ¶ added in v0.41.0
func (e *ErrRuleSyntax) Error() string
type ErrValueTypeUnknown ¶
type ErrValueTypeUnknown struct {
Field string
}
ErrValueTypeUnknown is returned when the value of a field has an unknown type
func (*ErrValueTypeUnknown) Error ¶
func (e *ErrValueTypeUnknown) Error() string
type EvaluationSet ¶ added in v0.46.0
type EvaluationSet struct {
RuleSets map[eval.RuleSetTagValue]*RuleSet
}
EvaluationSet defines an evalation set
func NewEvaluationSet ¶ added in v0.46.0
func NewEvaluationSet(ruleSetsToInclude []*RuleSet) (*EvaluationSet, error)
NewEvaluationSet returns a new policy set for the specified data model
func (*EvaluationSet) GetPolicies ¶ added in v0.46.0
func (es *EvaluationSet) GetPolicies() []*Policy
GetPolicies returns the policies
func (*EvaluationSet) LoadPolicies ¶ added in v0.46.0
func (es *EvaluationSet) LoadPolicies(loader *PolicyLoader, opts PolicyLoaderOpts) *multierror.Error
LoadPolicies load policies
type EventCollector ¶ added in v0.48.0
type EventCollector struct { }
EventCollector defines an event collector
func (*EventCollector) CollectEvent ¶ added in v0.48.0
func (ec *EventCollector) CollectEvent(_ *RuleSet, _ eval.Event, _ bool)
CollectEvent collects event
func (*EventCollector) Stop ¶ added in v0.48.0
func (ec *EventCollector) Stop() []CollectedEvent
Stop stops the event collector
type FieldCapabilities ¶
type FieldCapabilities []FieldCapability
FieldCapabilities holds a list of field capabilities
func (FieldCapabilities) GetFields ¶
func (fcs FieldCapabilities) GetFields() []eval.Field
GetFields returns all the fields of FieldCapabilities
func (FieldCapabilities) Validate ¶
func (fcs FieldCapabilities) Validate(filterValues FilterValues) bool
Validate ensures all the filter values match field capabilities
type FieldCapability ¶
type FieldCapability struct { Field eval.Field Types eval.FieldValueType ValidateFnc func(FilterValue) bool FilterWeight int }
FieldCapability represents a field and the type of its value (scalar, pattern, bitmask, ...)
type FilterValue ¶
type FilterValue struct { Field eval.Field Value interface{} Type eval.FieldValueType }
FilterValue represents a field, its value, its type and whether it's a used to compare with or against its value
type FilterValues ¶
type FilterValues []FilterValue
FilterValues is a list of FilterValue
func (FilterValues) Merge ¶
func (fv FilterValues) Merge(n ...FilterValue) FilterValues
Merge merges to FilterValues ensuring there is no duplicate value
type HashDefinition ¶ added in v0.55.0
type HashDefinition struct{}
HashDefinition describes the 'hash' section of a rule action
type InternalCallbackDefinition ¶ added in v0.49.0
type InternalCallbackDefinition struct{}
InternalCallbackDefinition describes an internal rule action
type KillDefinition ¶ added in v0.50.0
KillDefinition describes the 'kill' section of a rule action
type Macro ¶
type Macro struct { *eval.Macro Definition *MacroDefinition }
Macro describes a macro of a ruleset
type MacroDefinition ¶
type MacroDefinition struct { ID MacroID `yaml:"id"` Expression string `yaml:"expression"` Description string `yaml:"description"` AgentVersionConstraint string `yaml:"agent_version"` Filters []string `yaml:"filters"` Values []string `yaml:"values"` Combine CombinePolicy `yaml:"combine"` }
MacroDefinition holds the definition of a macro
func (*MacroDefinition) MergeWith ¶ added in v0.35.0
func (m *MacroDefinition) MergeWith(m2 *MacroDefinition) error
MergeWith merges macro m2 into m
type MacroFilter ¶ added in v0.40.0
type MacroFilter interface {
IsMacroAccepted(*MacroDefinition) (bool, error)
}
MacroFilter definition of a macro filter
type MultiDiscarder ¶ added in v0.54.0
type MultiDiscarder struct { Entries []MultiDiscarderEntry FinalField string FinalEventType model.EventType }
MultiDiscarder represents a multi discarder, i.e. a discarder across multiple rule buckets
type MultiDiscarderEntry ¶ added in v0.54.0
MultiDiscarderEntry represents a multi discarder entry (a field, and associated event type)
type Opts ¶
type Opts struct { RuleSetTag map[string]eval.RuleSetTagValue SupportedDiscarders map[eval.Field]bool SupportedMultiDiscarders []*MultiDiscarder ReservedRuleIDs []RuleID EventTypeEnabled map[eval.EventType]bool StateScopes map[Scope]VariableProviderFactory Logger log.Logger }
Opts defines rules set options
func NewBothOpts ¶ added in v0.55.0
NewBothOpts returns rule and eval options
func NewRuleOpts ¶ added in v0.55.0
NewRuleOpts returns rule options
func (*Opts) WithEventTypeEnabled ¶ added in v0.34.0
WithEventTypeEnabled set event types enabled
func (*Opts) WithLogger ¶ added in v0.34.0
WithLogger set logger
func (*Opts) WithReservedRuleIDs ¶ added in v0.34.0
WithReservedRuleIDs set reserved rule ids
func (*Opts) WithRuleSetTag ¶ added in v0.46.0
func (o *Opts) WithRuleSetTag(tagValue eval.RuleSetTagValue) *Opts
WithRuleSetTag sets the rule set tag with the value of the tag of the rules that belong in this rule set
func (*Opts) WithStateScopes ¶ added in v0.35.0
func (o *Opts) WithStateScopes(stateScopes map[Scope]VariableProviderFactory) *Opts
WithStateScopes set state scopes
func (*Opts) WithSupportedDiscarders ¶ added in v0.34.0
WithSupportedDiscarders set supported discarders
func (*Opts) WithSupportedMultiDiscarder ¶ added in v0.54.0
func (o *Opts) WithSupportedMultiDiscarder(discarders []*MultiDiscarder) *Opts
WithSupportedMultiDiscarder set supported multi discarders
type OverrideField ¶ added in v0.52.0
type OverrideField = string
OverrideField defines a combine field
const ( // OverrideAllFields used to override all the fields OverrideAllFields OverrideField = "all" // OverrideExpressionField used to override the expression OverrideExpressionField OverrideField = "expression" // OverrideActionFields used to override the actions OverrideActionFields OverrideField = "actions" // OverrideEveryField used to override the every field OverrideEveryField OverrideField = "every" // OverrideTagsField used to override the tags OverrideTagsField OverrideField = "tags" )
type OverrideOptions ¶ added in v0.52.0
type OverrideOptions struct {
Fields []OverrideField `yaml:"fields"`
}
OverrideOptions defines combine options
type PoliciesDirProvider ¶ added in v0.38.0
type PoliciesDirProvider struct { PoliciesDir string // contains filtered or unexported fields }
PoliciesDirProvider defines a new policy dir provider
func NewPoliciesDirProvider ¶ added in v0.38.0
func NewPoliciesDirProvider(policiesDir string, watch bool) (*PoliciesDirProvider, error)
NewPoliciesDirProvider returns providers for the given policies dir
func (*PoliciesDirProvider) Close ¶ added in v0.38.0
func (p *PoliciesDirProvider) Close() error
Close stops policy provider interface
func (*PoliciesDirProvider) LoadPolicies ¶ added in v0.38.0
func (p *PoliciesDirProvider) LoadPolicies(macroFilters []MacroFilter, ruleFilters []RuleFilter) ([]*Policy, *multierror.Error)
LoadPolicies implements the policy provider interface
func (*PoliciesDirProvider) SetOnNewPoliciesReadyCb ¶ added in v0.38.0
func (p *PoliciesDirProvider) SetOnNewPoliciesReadyCb(cb func())
SetOnNewPoliciesReadyCb implements the policy provider interface
func (*PoliciesDirProvider) Start ¶ added in v0.38.0
func (p *PoliciesDirProvider) Start()
Start starts the policy dir provider
func (*PoliciesDirProvider) Type ¶ added in v0.47.0
func (p *PoliciesDirProvider) Type() string
Type returns the type of policy dir provider
type Policy ¶
type Policy struct { Name string Source string Version string Rules []*RuleDefinition Macros []*MacroDefinition IsInternal bool }
Policy represents a policy file which is composed of a list of rules and macros
func LoadPolicy ¶
func LoadPolicy(name string, source string, reader io.Reader, macroFilters []MacroFilter, ruleFilters []RuleFilter) (*Policy, error)
LoadPolicy load a policy
func (*Policy) AddMacro ¶ added in v0.38.0
func (p *Policy) AddMacro(def *MacroDefinition)
AddMacro add a macro to the policy
func (*Policy) AddRule ¶ added in v0.38.0
func (p *Policy) AddRule(def *RuleDefinition)
AddRule adds a rule to the policy
type PolicyDef ¶ added in v0.38.0
type PolicyDef struct { Version string `yaml:"version"` Rules []*RuleDefinition `yaml:"rules"` Macros []*MacroDefinition `yaml:"macros"` }
PolicyDef represents a policy file definition
type PolicyLoader ¶ added in v0.38.0
type PolicyLoader struct { sync.RWMutex Providers []PolicyProvider // contains filtered or unexported fields }
PolicyLoader defines a policy loader
func NewPolicyLoader ¶ added in v0.38.0
func NewPolicyLoader(providers ...PolicyProvider) *PolicyLoader
NewPolicyLoader returns a new loader
func (*PolicyLoader) LoadPolicies ¶ added in v0.38.0
func (p *PolicyLoader) LoadPolicies(opts PolicyLoaderOpts) ([]*Policy, *multierror.Error)
LoadPolicies gathers the policies in the correct precedence order and ensuring there's only 1 default policy. RC Default replaces Local Default and takes precedence above any other policies, and RC Custom takes precedence over Local Custom.
func (*PolicyLoader) NewPolicyReady ¶ added in v0.38.0
func (p *PolicyLoader) NewPolicyReady() <-chan struct{}
NewPolicyReady returns chan to listen new policy ready event
func (*PolicyLoader) SetProviders ¶ added in v0.38.0
func (p *PolicyLoader) SetProviders(providers []PolicyProvider)
SetProviders set providers
type PolicyLoaderOpts ¶ added in v0.39.0
type PolicyLoaderOpts struct { MacroFilters []MacroFilter RuleFilters []RuleFilter DisableEnforcement bool }
PolicyLoaderOpts options used during the loading
type PolicyProvider ¶ added in v0.38.0
type PolicyProvider interface { LoadPolicies([]MacroFilter, []RuleFilter) ([]*Policy, *multierror.Error) SetOnNewPoliciesReadyCb(func()) Start() Close() error // Type returns the type of policy provider, like 'directoryPolicyProvider' Type() string }
PolicyProvider defines a rule provider
type Rule ¶
type Rule struct { *eval.Rule Definition *RuleDefinition }
Rule describes a rule of a ruleset
type RuleBucket ¶
type RuleBucket struct {
// contains filtered or unexported fields
}
RuleBucket groups rules with the same event type
func (*RuleBucket) AddRule ¶
func (rb *RuleBucket) AddRule(rule *Rule) error
AddRule adds a rule to the bucket
func (*RuleBucket) GetRules ¶
func (rb *RuleBucket) GetRules() []*Rule
GetRules returns the bucket rules
type RuleDefinition ¶
type RuleDefinition struct { ID RuleID `yaml:"id"` Version string `yaml:"version"` Expression string `yaml:"expression"` Description string `yaml:"description"` Tags map[string]string `yaml:"tags"` AgentVersionConstraint string `yaml:"agent_version"` Filters []string `yaml:"filters"` Disabled bool `yaml:"disabled"` Combine CombinePolicy `yaml:"combine"` OverrideOptions OverrideOptions `yaml:"override_options"` Actions []*ActionDefinition `yaml:"actions"` Every time.Duration `yaml:"every"` Silent bool `yaml:"silent"` GroupID string `yaml:"group_id"` Policy *Policy }
RuleDefinition holds the definition of a rule
func (*RuleDefinition) GetTag ¶ added in v0.44.0
func (rd *RuleDefinition) GetTag(tagKey string) (string, bool)
GetTag returns the tag value associated with a tag key
func (*RuleDefinition) MergeWith ¶ added in v0.35.0
func (rd *RuleDefinition) MergeWith(rd2 *RuleDefinition) error
MergeWith merges rule rd2 into rd
type RuleFilter ¶ added in v0.39.0
type RuleFilter interface {
IsRuleAccepted(*RuleDefinition) (bool, error)
}
RuleFilter definition of a rule filter
type RuleIDFilter ¶ added in v0.39.0
type RuleIDFilter struct {
ID string
}
RuleIDFilter defines a ID based filter
func (*RuleIDFilter) IsRuleAccepted ¶ added in v0.40.0
func (r *RuleIDFilter) IsRuleAccepted(rule *RuleDefinition) (bool, error)
IsRuleAccepted checks whether the rule is accepted
type RuleLoadErrType ¶ added in v0.41.0
type RuleLoadErrType string
RuleLoadErrType defines an rule error type
const ( // AgentVersionErrType agent version incompatible AgentVersionErrType RuleLoadErrType = "agent_version_error" // AgentFilterErrType agent filter do not match AgentFilterErrType RuleLoadErrType = "agent_filter_error" // EventTypeNotEnabledErrType event type not enabled EventTypeNotEnabledErrType RuleLoadErrType = "event_type_disabled" // SyntaxErrType syntax error SyntaxErrType RuleLoadErrType = "syntax_error" // UnknownErrType undefined error UnknownErrType RuleLoadErrType = "error" )
type RuleSet ¶
type RuleSet struct {
// contains filtered or unexported fields
}
RuleSet holds a list of rules, grouped in bucket. An event can be evaluated against it. If the rule matches, the listeners for this rule set are notified
func NewRuleSet ¶
func NewRuleSet(model eval.Model, eventCtor func() eval.Event, opts *Opts, evalOpts *eval.Opts) *RuleSet
NewRuleSet returns a new ruleset for the specified data model
func (*RuleSet) AddFields ¶
AddFields merges the provided set of fields with the existing set of fields of the ruleset
func (*RuleSet) AddListener ¶
func (rs *RuleSet) AddListener(listener RuleSetListener)
AddListener adds a listener on the ruleset
func (*RuleSet) AddMacro ¶
func (rs *RuleSet) AddMacro(parsingContext *ast.ParsingContext, macroDef *MacroDefinition) (*eval.Macro, error)
AddMacro parses the macro AST and adds it to the list of macros of the ruleset
func (*RuleSet) AddMacros ¶
func (rs *RuleSet) AddMacros(parsingContext *ast.ParsingContext, macros []*MacroDefinition) *multierror.Error
AddMacros parses the macros AST and adds them to the list of macros of the ruleset
func (*RuleSet) AddRule ¶
func (rs *RuleSet) AddRule(parsingContext *ast.ParsingContext, ruleDef *RuleDefinition) (*eval.Rule, error)
AddRule creates the rule evaluator and adds it to the bucket of its events
func (*RuleSet) AddRules ¶
func (rs *RuleSet) AddRules(parsingContext *ast.ParsingContext, rules []*RuleDefinition) *multierror.Error
AddRules adds rules to the ruleset and generate their partials
func (*RuleSet) EvaluateDiscarders ¶ added in v0.45.0
EvaluateDiscarders evaluates the discarders for the given event if any
func (*RuleSet) GetApprovers ¶
func (rs *RuleSet) GetApprovers(fieldCaps map[eval.EventType]FieldCapabilities) (map[eval.EventType]Approvers, error)
GetApprovers returns all approvers
func (*RuleSet) GetBucket ¶
func (rs *RuleSet) GetBucket(eventType eval.EventType) *RuleBucket
GetBucket returns rule bucket for the given event type
func (*RuleSet) GetEventApprovers ¶
func (rs *RuleSet) GetEventApprovers(eventType eval.EventType, fieldCaps FieldCapabilities) (Approvers, error)
GetEventApprovers returns approvers for the given event type and the fields
func (*RuleSet) GetEventTypes ¶
GetEventTypes returns all the event types handled by the ruleset
func (*RuleSet) GetFieldValues ¶
func (rs *RuleSet) GetFieldValues(field eval.Field) []eval.FieldValue
GetFieldValues returns all the values of the given field
func (*RuleSet) GetRuleSetTag ¶ added in v0.46.0
func (rs *RuleSet) GetRuleSetTag() eval.RuleSetTagValue
GetRuleSetTag gets the value of the "ruleset" tag, which is the tag of the rules that belong in this rule set
func (*RuleSet) HasRulesForEventType ¶
HasRulesForEventType returns if there is at least one rule for the given event type
func (*RuleSet) IsDiscarder ¶
IsDiscarder partially evaluates an Event against a field
func (*RuleSet) ListFields ¶ added in v0.44.0
ListFields returns all the fields accessed by all rules of this rule set
func (*RuleSet) ListMacroIDs ¶
ListMacroIDs returns the list of MacroIDs from the ruleset
func (*RuleSet) ListRuleIDs ¶
ListRuleIDs returns the list of RuleIDs from the ruleset
func (*RuleSet) NewEvent ¶ added in v0.43.0
NewEvent returns a new event using the embedded constructor
func (*RuleSet) NotifyDiscarderFound ¶
func (rs *RuleSet) NotifyDiscarderFound(event eval.Event, field eval.Field, eventType eval.EventType)
NotifyDiscarderFound notifies all the ruleset listeners that a discarder was found for an event
func (*RuleSet) NotifyRuleMatch ¶
NotifyRuleMatch notifies all the ruleset listeners that an event matched a rule
func (*RuleSet) StopEventCollector ¶ added in v0.48.0
func (rs *RuleSet) StopEventCollector() []CollectedEvent
StopEventCollector stops the event collector
type RuleSetListener ¶
type RuleSetListener interface { RuleMatch(rule *Rule, event eval.Event) bool EventDiscarderFound(rs *RuleSet, event eval.Event, field eval.Field, eventType eval.EventType) }
RuleSetListener describes the methods implemented by an object used to be notified of events on a rule set.
type SECLRuleFilter ¶ added in v0.41.0
type SECLRuleFilter struct {
// contains filtered or unexported fields
}
SECLRuleFilter defines a SECL rule filter
func NewSECLRuleFilter ¶ added in v0.41.0
func NewSECLRuleFilter(model eval.Model) *SECLRuleFilter
NewSECLRuleFilter returns a new agent version based rule filter
func (*SECLRuleFilter) IsMacroAccepted ¶ added in v0.41.0
func (r *SECLRuleFilter) IsMacroAccepted(macro *MacroDefinition) (bool, error)
IsMacroAccepted checks whether the macro is accepted
func (*SECLRuleFilter) IsRuleAccepted ¶ added in v0.41.0
func (r *SECLRuleFilter) IsRuleAccepted(rule *RuleDefinition) (bool, error)
IsRuleAccepted checks whether the rule is accepted
type SetDefinition ¶ added in v0.35.0
type SetDefinition struct { Name string `yaml:"name"` Value interface{} `yaml:"value"` Field string `yaml:"field"` Append bool `yaml:"append"` Scope Scope `yaml:"scope"` }
SetDefinition describes the 'set' section of a rule action
type VariableProvider ¶ added in v0.35.0
type VariableProvider interface {
GetVariable(name string, value interface{}) (eval.VariableValue, error)
}
VariableProvider is the interface implemented by SECL variable providers
type VariableProviderFactory ¶ added in v0.35.0
type VariableProviderFactory func() VariableProvider
VariableProviderFactory describes a function called to instantiate a variable provider