Skip to content

Update SO sigma pipeline #712

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

Draft
wants to merge 2 commits into
base: 2.4/dev
Choose a base branch
from
Draft
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
73 changes: 60 additions & 13 deletions server/modules/elastalert/elastalert.go
Original file line number Diff line number Diff line change
Expand Up @@ -635,19 +635,6 @@ func (e *ElastAlertEngine) Sync(logger *log.Entry, forceSync bool) error {
// announce the beginning of the sync
e.EngineState.Syncing = true

// Check to see if the sigma processing pipelines have changed.
// If they have, set forceSync to true to regenerate the elastalert rule files.
regenNeeded, sigmaPipelineNewHash, err := e.checkSigmaPipelines()
if err != nil {
logger.WithField("sigmaPipelineError", err).Error("failed to check the sigma processing pipelines")
} else {
logger.Info("successfully checked the sigma processing pipelines")
}

if regenNeeded {
forceSync = true
}

var zips map[string][]byte
var errMap map[string]error

Expand Down Expand Up @@ -697,6 +684,25 @@ func (e *ElastAlertEngine) Sync(logger *log.Entry, forceSync bool) error {
zipHashes[pkg] = base64.StdEncoding.EncodeToString(h[:])
}

// Check to see if the SO Sigma Processing Pipeline needs to be updated
pipelineUpdated, err := e.updateSigmaPipeline()
if err != nil {
logger.WithFields(log.Fields{"sigmaPipelineUpdateError": err.Error()}).Error("failed to update SO sigma processing pipeline")
}

// Check to see if the sigma processing pipelines have changed.
// If they have, set forceSync to true to regenerate the elastalert rule files.
regenNeeded, sigmaPipelineNewHash, err := e.checkSigmaPipelines()
if err != nil {
logger.WithField("sigmaPipelineError", err).Error("failed to check the sigma processing pipelines")
} else {
logger.Info("successfully checked the sigma processing pipelines")
}

if pipelineUpdated || regenNeeded {
forceSync = true
}

if !forceSync {
// if we're not forcing a sync, check to see if anything has changed
// if nothing has changed, the sync is finished
Expand Down Expand Up @@ -2107,3 +2113,44 @@ func (e *ElastAlertEngine) getDeployedPublicIds() (publicIds []string, err error

return publicIds, nil
}

func (e *ElastAlertEngine) updateSigmaPipeline() (bool, error) {
sourcePath := filepath.Join(e.reposFolder, "securityonion-resources", "so_sigma_processing_pipeline.yaml")

// Check if source exists
if _, err := os.Stat(sourcePath); os.IsNotExist(err) {
return false, fmt.Errorf("source pipeline file does not exist: %s", sourcePath)
}

// Get hash of source file
sourceHash, err := e.hashFile(sourcePath)
if err != nil {
return false, fmt.Errorf("failed to hash source pipeline file: %v", err)
}

// If destination exists, compare hashes
if _, err := os.Stat(e.sigmaPipelineSO); err == nil {
destHash, err := e.hashFile(e.sigmaPipelineSO)
if err != nil {
return false, fmt.Errorf("failed to hash destination pipeline file: %v", err)
}

// If hashes match, no update needed
if sourceHash == destHash {
return false, nil
}
}

// Copy the file
sourceData, err := os.ReadFile(sourcePath)
if err != nil {
return false, fmt.Errorf("failed to read source pipeline file: %v", err)
}

err = os.WriteFile(e.sigmaPipelineSO, sourceData, 0644)
if err != nil {
return false, fmt.Errorf("failed to write destination pipeline file: %v", err)
}

return true, nil
}
Loading