Skip to content

Commit

Permalink
Airgap Check for AI Summaries
Browse files Browse the repository at this point in the history
If the server is configured with AirgapEnabled = true, then the call to RefreshAiSummaries will log a debug statement, do nothing, and return no error. Otherwise the repo will be updated as usual.
  • Loading branch information
coreyogburn committed Sep 24, 2024
1 parent 75b35ce commit 903aea7
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 3 deletions.
6 changes: 6 additions & 0 deletions server/modules/detections/ai_summary.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,17 @@ var lastSuccessfulAiUpdate time.Time

type AiLoader interface {
LoadAuxiliaryData(summaries []*model.AiSummary) error
IsAirgapped() bool
}

//go:generate mockgen -destination mock/mock_ailoader.go -package mock . AiLoader

func RefreshAiSummaries(eng AiLoader, lang model.SigLanguage, isRunning *bool, aiRepoPath string, aiRepoUrl string, aiRepoBranch string, logger *log.Entry, iom IOManager) error {
if eng.IsAirgapped() {
logger.Debug("skipping AI summary update because airgap is enabled")
return nil
}

err := updateAiRepo(isRunning, aiRepoPath, aiRepoUrl, aiRepoBranch, iom)
if err != nil {
if errors.Is(err, ErrModuleStopped) {
Expand Down
11 changes: 8 additions & 3 deletions server/modules/detections/ai_summary_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,14 @@ func TestRefreshAiSummaries(t *testing.T) {

iom := mock.NewMockIOManager(ctrl)
loader := mock.NewMockAiLoader(ctrl)
logger := log.WithField("test", true)

loader.EXPECT().IsAirgapped().Return(true)

err := RefreshAiSummaries(loader, model.SigLangSigma, &isRunning, "baseRepoFolder", repo, branch, logger, iom)
assert.NoError(t, err)

loader.EXPECT().IsAirgapped().Return(false)
iom.EXPECT().ReadDir("baseRepoFolder").Return([]fs.DirEntry{}, nil)
iom.EXPECT().CloneRepo(gomock.Any(), "baseRepoFolder/repo1", repo, &branch).Return(nil)
iom.EXPECT().ReadFile("baseRepoFolder/repo1/detections-ai/sigma_summaries.yaml").Return([]byte(summaries), nil)
Expand Down Expand Up @@ -54,10 +61,8 @@ func TestRefreshAiSummaries(t *testing.T) {
return nil
})

logger := log.WithField("test", true)

lastSuccessfulAiUpdate = time.Time{}

err := RefreshAiSummaries(loader, model.SigLangSigma, &isRunning, "baseRepoFolder", repo, branch, logger, iom)
err = RefreshAiSummaries(loader, model.SigLangSigma, &isRunning, "baseRepoFolder", repo, branch, logger, iom)
assert.NoError(t, err)
}
14 changes: 14 additions & 0 deletions server/modules/detections/mock/mock_ailoader.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions server/modules/elastalert/elastalert.go
Original file line number Diff line number Diff line change
Expand Up @@ -1556,6 +1556,10 @@ func (e *ElastAlertEngine) DuplicateDetection(ctx context.Context, detection *mo
return det, nil
}

func (e *ElastAlertEngine) IsAirgapped() bool {
return e.srv.Config.AirgapEnabled
}

func (e *ElastAlertEngine) LoadAuxiliaryData(summaries []*model.AiSummary) error {
sum := &sync.Map{}
for _, summary := range summaries {
Expand Down
4 changes: 4 additions & 0 deletions server/modules/strelka/strelka.go
Original file line number Diff line number Diff line change
Expand Up @@ -1136,6 +1136,10 @@ func (e *StrelkaEngine) DuplicateDetection(ctx context.Context, detection *model
return det, nil
}

func (e *StrelkaEngine) IsAirgapped() bool {
return e.srv.Config.AirgapEnabled
}

func (e *StrelkaEngine) LoadAuxiliaryData(summaries []*model.AiSummary) error {
sum := &sync.Map{}
for _, summary := range summaries {
Expand Down
4 changes: 4 additions & 0 deletions server/modules/suricata/suricata.go
Original file line number Diff line number Diff line change
Expand Up @@ -1746,6 +1746,10 @@ func (e *SuricataEngine) DuplicateDetection(ctx context.Context, detection *mode
return det, nil
}

func (e *SuricataEngine) IsAirgapped() bool {
return e.srv.Config.AirgapEnabled
}

func (e *SuricataEngine) LoadAuxiliaryData(summaries []*model.AiSummary) error {
sum := &sync.Map{}
for _, summary := range summaries {
Expand Down

0 comments on commit 903aea7

Please sign in to comment.