Skip to content

Commit 1ada2fa

Browse files
authored
feat(config): Permit disabling rule engine (#236)
1 parent c97b0ae commit 1ada2fa

5 files changed

Lines changed: 26 additions & 5 deletions

File tree

configs/fibratus.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,15 @@ filament:
103103
# rules from different directory locations.
104104
filters:
105105
rules:
106+
# Indicates if the rule engine is enabled and rules loaded
107+
enabled: true
108+
109+
# The list of file system paths were rule files are located. Supports glob expressions in path names.
106110
from-paths:
107111
# - C:\Program Files\Fibratus\Rules\*.yml
108112
#from-urls:
109113
macros:
114+
# The list of file system paths were macro library files are located. Supports glob expressions in path names.
110115
from-paths:
111116
#- C:\Program Files\Fibratus\Rules\Macros\*.yml
112117

internal/bootstrap/bootstrap.go

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -171,10 +171,15 @@ func (f *App) Run(args []string) error {
171171
return err
172172
}
173173
// initialize rules engine
174-
rules := filter.NewRules(f.psnap, cfg)
175-
err = rules.Compile()
176-
if err != nil {
177-
return err
174+
var rules *filter.Rules
175+
if f.config.Filters.Rules.Enabled {
176+
rules = filter.NewRules(f.psnap, cfg)
177+
err = rules.Compile()
178+
if err != nil {
179+
return err
180+
}
181+
} else {
182+
log.Info("rule engine is disabled")
178183
}
179184
// build the filter from the CLI argument. If we got
180185
// a valid expression the filter is attached to the
@@ -228,7 +233,9 @@ func (f *App) Run(args []string) error {
228233
f.consumer.RegisterEventListener(f.symbolizer)
229234
}
230235
// register rule engine
231-
f.consumer.RegisterEventListener(rules)
236+
if rules != nil {
237+
f.consumer.RegisterEventListener(rules)
238+
}
232239
// register YARA scanner
233240
if cfg.Yara.Enabled {
234241
scanner, err := yara.NewScanner(f.psnap, cfg.Yara)

pkg/config/config_windows.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,7 @@ func (c *Config) addFlags() {
361361
}
362362
dir := filepath.Join(filepath.Dir(exe), "..", "Rules")
363363

364+
c.flags.Bool(rulesEnabled, true, "Indicates if the rule engine is enabled and rules loaded")
364365
c.flags.StringSlice(rulesFromPaths, []string{filepath.Join(dir, "*")}, "Comma-separated list of rules files")
365366
c.flags.StringSlice(macrosFromPaths, []string{filepath.Join(dir, "Macros", "*")}, "Comma-separated list of macro files")
366367
c.flags.StringSlice(rulesFromURLs, []string{}, "Comma-separated list of rules URL resources")

pkg/config/filters.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ func FiltersWithMacros(macros map[string]*Macro) *Filters {
136136
// Rules contains attributes that describe the location of
137137
// rule resources.
138138
type Rules struct {
139+
Enabled bool `json:"enabled" yaml:"enabled"`
139140
FromPaths []string `json:"from-paths" yaml:"from-paths"`
140141
FromURLs []string `json:"from-urls" yaml:"from-urls"`
141142
}
@@ -171,12 +172,14 @@ type ActionContext struct {
171172
}
172173

173174
const (
175+
rulesEnabled = "filters.rules.enabled"
174176
rulesFromPaths = "filters.rules.from-paths"
175177
rulesFromURLs = "filters.rules.from-urls"
176178
macrosFromPaths = "filters.macros.from-paths"
177179
)
178180

179181
func (f *Filters) initFromViper(v *viper.Viper) {
182+
f.Rules.Enabled = v.GetBool(rulesEnabled)
180183
f.Rules.FromPaths = v.GetStringSlice(rulesFromPaths)
181184
f.Rules.FromURLs = v.GetStringSlice(rulesFromURLs)
182185
f.Macros.FromPaths = v.GetStringSlice(macrosFromPaths)
@@ -307,6 +310,10 @@ func (f *Filters) LoadGroups() error {
307310
f.groups = append(f.groups, groups...)
308311
}
309312

313+
if len(f.groups) == 0 {
314+
log.Warnf("no rules were loaded from [%s] path(s)", strings.Join(f.Rules.FromPaths, ","))
315+
}
316+
310317
// check for duplicate rule groups
311318
groupNames := make(map[string]bool)
312319
for _, group := range f.groups {

pkg/config/schema_windows.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ var schema = `
129129
"rules": {
130130
"type": "object",
131131
"properties": {
132+
"enabled": {"type": "boolean"},
132133
"from-paths": {"type": ["array", "null"], "items": [{"type": "string", "minLength": 4}]},
133134
"from-urls": {"type": ["array", "null"], "items": [{"type": "string", "minLength": 8}]}
134135
},

0 commit comments

Comments
 (0)