Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Respect Existing Config Values #678

Merged
merged 1 commit into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions server/modules/elastalert/elastalert.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ const (
DEFAULT_AI_REPO_BRANCH = "generated-summaries-published"
DEFAULT_AI_REPO_PATH = "/opt/sensoroni/ai_summary_repos"
DEFAULT_SHOW_AI_SUMMARIES = true
DEFAULT_AUTO_UPDATE_ENABLED = false
)

var ( // treat as constant
Expand Down Expand Up @@ -120,6 +121,7 @@ type ElastAlertEngine struct {
aiRepoBranch string
aiRepoPath string
customAlerters *map[string]interface{}
autoUpdateEnabled bool
detections.SyncSchedulerParams
detections.IntegrityCheckerData
detections.IOManager
Expand Down Expand Up @@ -191,6 +193,7 @@ func (e *ElastAlertEngine) Init(config module.ModuleConfig) (err error) {
e.highSeverityAlerterParams = module.GetStringDefault(config, "additionalSev4AlertersParams", "")
e.criticalSeverityAlerters = module.GetStringArrayDefault(config, "additionalSev5Alerters", []string{})
e.criticalSeverityAlerterParams = module.GetStringDefault(config, "additionalSev5AlertersParams", "")
e.autoUpdateEnabled = module.GetBoolDefault(config, "autoUpdateEnabled", DEFAULT_AUTO_UPDATE_ENABLED)

if custom, ok := config["additionalUserDefinedNotifications"]; ok {
switch ct := custom.(type) {
Expand Down Expand Up @@ -527,6 +530,15 @@ func (e *ElastAlertEngine) Sync(logger *log.Entry, forceSync bool) error {

e.writeNoRead = nil

if !e.autoUpdateEnabled && !forceSync {
logger.WithFields(log.Fields{
"autoUpdateEnabled": e.autoUpdateEnabled,
"forceSync": forceSync,
}).Info("skipping sync")

return nil
}

if e.showAiSummaries {
err := detections.RefreshAiSummaries(e, model.SigLangSigma, &e.isRunning, e.aiRepoPath, e.aiRepoUrl, e.aiRepoBranch, logger, e.IOManager)
if err != nil {
Expand Down
37 changes: 35 additions & 2 deletions server/modules/elastalert/elastalert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"testing"
"time"

"github.com/security-onion-solutions/securityonion-soc/config"
"github.com/security-onion-solutions/securityonion-soc/licensing"
"github.com/security-onion-solutions/securityonion-soc/model"
"github.com/security-onion-solutions/securityonion-soc/module"
Expand Down Expand Up @@ -1501,8 +1502,9 @@ func TestSyncIncrementalNoChanges(t *testing.T) {
IntegrityCheckerData: detections.IntegrityCheckerData{
IsRunning: true,
},
IOManager: iom,
showAiSummaries: false,
IOManager: iom,
showAiSummaries: false,
autoUpdateEnabled: true,
}

logger := log.WithField("detectionEngine", "test-elastalert")
Expand Down Expand Up @@ -1549,6 +1551,37 @@ func TestSyncIncrementalNoChanges(t *testing.T) {
assert.False(t, eng.EngineState.SyncFailure)
}

func TestSyncDisabled(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()

detStore := servermock.NewMockDetectionstore(ctrl)
iom := mock.NewMockIOManager(ctrl)

eng := &ElastAlertEngine{
srv: &server.Server{
Detectionstore: detStore,
Config: &config.ServerConfig{},
},
isRunning: true,
IOManager: iom,
showAiSummaries: true,
autoUpdateEnabled: false,
}

logger := log.WithField("detectionEngine", "test-elastalert")

err := eng.Sync(logger, false)
assert.NoError(t, err)

assert.False(t, eng.EngineState.Syncing)
assert.False(t, eng.EngineState.IntegrityFailure)
assert.False(t, eng.EngineState.Migrating)
assert.False(t, eng.EngineState.MigrationFailure)
assert.False(t, eng.EngineState.Importing)
assert.False(t, eng.EngineState.SyncFailure)
}

func TestSyncChanges(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()
Expand Down
12 changes: 12 additions & 0 deletions server/modules/strelka/strelka.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ const (
DEFAULT_AI_REPO_BRANCH = "generated-summaries-published"
DEFAULT_AI_REPO_PATH = "/opt/sensoroni/ai_summary_repos"
DEFAULT_SHOW_AI_SUMMARIES = true
DEFAULT_AUTO_UPDATE_ENABLED = false
)

var titleUpdater = regexp.MustCompile(`(?im)rule\s+(\w+)(\s+:(\s*[^{]+))?(\s+)(//.*$)?(\n?){`)
Expand All @@ -76,6 +77,7 @@ type StrelkaEngine struct {
aiRepoUrl string
aiRepoBranch string
aiRepoPath string
autoUpdateEnabled bool
detections.SyncSchedulerParams
detections.IntegrityCheckerData
detections.IOManager
Expand Down Expand Up @@ -123,6 +125,7 @@ func (e *StrelkaEngine) Init(config module.ModuleConfig) (err error) {
e.CommunityRulesImportErrorSeconds = module.GetIntDefault(config, "communityRulesImportErrorSeconds", DEFAULT_COMMUNITY_RULES_IMPORT_ERROR_SECS)
e.failAfterConsecutiveErrorCount = module.GetIntDefault(config, "failAfterConsecutiveErrorCount", DEFAULT_FAIL_AFTER_CONSECUTIVE_ERROR_COUNT)
e.IntegrityCheckerData.FrequencySeconds = module.GetIntDefault(config, "integrityCheckFrequencySeconds", DEFAULT_INTEGRITY_CHECK_FREQUENCY_SECONDS)
e.autoUpdateEnabled = module.GetBoolDefault(config, "autoUpdateEnabled", DEFAULT_AUTO_UPDATE_ENABLED)

e.rulesRepos, err = model.GetReposDefault(config, "rulesRepos", []*model.RuleRepo{
{
Expand Down Expand Up @@ -307,6 +310,15 @@ func (e *StrelkaEngine) Sync(logger *log.Entry, forceSync bool) error {

e.writeNoRead = nil

if !e.autoUpdateEnabled && !forceSync {
logger.WithFields(log.Fields{
"autoUpdateEnabled": e.autoUpdateEnabled,
"forceSync": forceSync,
}).Info("skipping sync")

return nil
}

if e.showAiSummaries {
err := detections.RefreshAiSummaries(e, model.SigLangYara, &e.isRunning, e.aiRepoPath, e.aiRepoUrl, e.aiRepoBranch, logger, e.IOManager)
if err != nil {
Expand Down
37 changes: 35 additions & 2 deletions server/modules/strelka/strelka_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"testing"
"time"

"github.com/security-onion-solutions/securityonion-soc/config"
"github.com/security-onion-solutions/securityonion-soc/model"
"github.com/security-onion-solutions/securityonion-soc/module"
"github.com/security-onion-solutions/securityonion-soc/server"
Expand Down Expand Up @@ -1016,8 +1017,9 @@ func TestSyncIncrementalNoChanges(t *testing.T) {
IntegrityCheckerData: detections.IntegrityCheckerData{
IsRunning: true,
},
IOManager: iom,
showAiSummaries: false,
IOManager: iom,
showAiSummaries: false,
autoUpdateEnabled: true,
}

logger := log.WithField("detectionEngine", "test-strelka")
Expand Down Expand Up @@ -1050,6 +1052,37 @@ func TestSyncIncrementalNoChanges(t *testing.T) {
assert.False(t, eng.EngineState.SyncFailure)
}

func TestSyncDisabled(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()

detStore := servermock.NewMockDetectionstore(ctrl)
iom := mock.NewMockIOManager(ctrl)

eng := &StrelkaEngine{
srv: &server.Server{
Detectionstore: detStore,
Config: &config.ServerConfig{},
},
isRunning: true,
IOManager: iom,
showAiSummaries: true,
autoUpdateEnabled: false,
}

logger := log.WithField("detectionEngine", "test-strelka")

err := eng.Sync(logger, false)
assert.NoError(t, err)

assert.False(t, eng.EngineState.Syncing)
assert.False(t, eng.EngineState.IntegrityFailure)
assert.False(t, eng.EngineState.Migrating)
assert.False(t, eng.EngineState.MigrationFailure)
assert.False(t, eng.EngineState.Importing)
assert.False(t, eng.EngineState.SyncFailure)
}

func TestSyncChanges(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()
Expand Down
12 changes: 12 additions & 0 deletions server/modules/suricata/suricata.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ const (
DEFAULT_AI_REPO_BRANCH = "generated-summaries-published"
DEFAULT_AI_REPO_PATH = "/opt/sensoroni/ai_summary_repos"
DEFAULT_SHOW_AI_SUMMARIES = true
DEFAULT_AUTO_UPDATE_ENABLED = false

CUSTOM_RULE_LOC = "/nsm/rules/detect-suricata/custom_temp"
)
Expand Down Expand Up @@ -89,6 +90,7 @@ type SuricataEngine struct {
aiRepoUrl string
aiRepoBranch string
aiRepoPath string
autoUpdateEnabled bool
detections.SyncSchedulerParams
detections.IntegrityCheckerData
detections.IOManager
Expand Down Expand Up @@ -132,6 +134,7 @@ func (e *SuricataEngine) Init(config module.ModuleConfig) (err error) {
e.CommunityRulesImportErrorSeconds = module.GetIntDefault(config, "communityRulesImportErrorSeconds", DEFAULT_COMMUNITY_RULES_IMPORT_ERROR_SECS)
e.failAfterConsecutiveErrorCount = module.GetIntDefault(config, "failAfterConsecutiveErrorCount", DEFAULT_FAIL_AFTER_CONSECUTIVE_ERROR_COUNT)
e.IntegrityCheckerData.FrequencySeconds = module.GetIntDefault(config, "integrityCheckFrequencySeconds", DEFAULT_INTEGRITY_CHECK_FREQUENCY_SECONDS)
e.autoUpdateEnabled = module.GetBoolDefault(config, "autoUpdateEnabled", DEFAULT_AUTO_UPDATE_ENABLED)

enable := module.GetStringArrayDefault(config, "enableRegex", DEFAULT_ENABLE_REGEX)
disable := module.GetStringArrayDefault(config, "disableRegex", DEFAULT_DISABLE_REGEX)
Expand Down Expand Up @@ -367,6 +370,15 @@ func (e *SuricataEngine) Sync(logger *log.Entry, forceSync bool) error {

e.writeNoRead = nil

if !e.autoUpdateEnabled && !forceSync {
logger.WithFields(log.Fields{
"autoUpdateEnabled": e.autoUpdateEnabled,
"forceSync": forceSync,
}).Info("skipping sync")

return nil
}

if e.showAiSummaries {
err := detections.RefreshAiSummaries(e, model.SigLangSuricata, &e.isRunning, e.aiRepoPath, e.aiRepoUrl, e.aiRepoBranch, logger, e.IOManager)
if err != nil {
Expand Down
37 changes: 35 additions & 2 deletions server/modules/suricata/suricata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"testing"
"time"

"github.com/security-onion-solutions/securityonion-soc/config"
"github.com/security-onion-solutions/securityonion-soc/model"
"github.com/security-onion-solutions/securityonion-soc/module"
"github.com/security-onion-solutions/securityonion-soc/server"
Expand Down Expand Up @@ -2197,8 +2198,9 @@ func TestSyncIncrementalNoChanges(t *testing.T) {
IntegrityCheckerData: detections.IntegrityCheckerData{
IsRunning: true,
},
IOManager: iom,
showAiSummaries: false,
IOManager: iom,
showAiSummaries: false,
autoUpdateEnabled: true,
}

logger := log.WithField("detectionEngine", "test-suricata")
Expand Down Expand Up @@ -2227,6 +2229,37 @@ func TestSyncIncrementalNoChanges(t *testing.T) {
assert.True(t, migrationChecked)
}

func TestSyncDisabled(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()

detStore := servermock.NewMockDetectionstore(ctrl)
iom := mock.NewMockIOManager(ctrl)

eng := &SuricataEngine{
srv: &server.Server{
Detectionstore: detStore,
Config: &config.ServerConfig{},
},
isRunning: true,
IOManager: iom,
showAiSummaries: true,
autoUpdateEnabled: false,
}

logger := log.WithField("detectionEngine", "test-suricata")

err := eng.Sync(logger, false)
assert.NoError(t, err)

assert.False(t, eng.EngineState.Syncing)
assert.False(t, eng.EngineState.IntegrityFailure)
assert.False(t, eng.EngineState.Migrating)
assert.False(t, eng.EngineState.MigrationFailure)
assert.False(t, eng.EngineState.Importing)
assert.False(t, eng.EngineState.SyncFailure)
}

func TestSyncChanges(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()
Expand Down
Loading