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

Airgap Check for AI Summaries #640

Merged
merged 2 commits into from
Sep 24, 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
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ require (
github.com/pierrec/lz4/v4 v4.1.21
github.com/pkg/errors v0.9.1
github.com/samber/lo v1.47.0
github.com/tj/assert v0.0.3
go.uber.org/mock v0.4.0
golang.org/x/mod v0.20.0
)
Expand Down
2 changes: 1 addition & 1 deletion model/custom_ruleset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ package model
import (
"testing"

"github.com/tj/assert"
"github.com/stretchr/testify/assert"
)

func TestGetCustomRulesetsDefault(t *testing.T) {
Expand Down
3 changes: 2 additions & 1 deletion model/detection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import (
"testing"

"github.com/security-onion-solutions/securityonion-soc/util"
"github.com/tj/assert"

"github.com/stretchr/testify/assert"
)

func TestDetectionOverrideValidate(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion model/rulerepo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

"github.com/security-onion-solutions/securityonion-soc/util"

"github.com/tj/assert"
"github.com/stretchr/testify/assert"
)

func TestGetRepos(t *testing.T) {
Expand Down
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
25 changes: 20 additions & 5 deletions server/modules/detections/ai_summary_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ import (
"testing"
"time"

"github.com/apex/log"
"github.com/security-onion-solutions/securityonion-soc/model"
"github.com/security-onion-solutions/securityonion-soc/server/modules/detections/mock"

"github.com/tj/assert"
"github.com/apex/log"
"github.com/apex/log/handlers/memory"
"github.com/stretchr/testify/assert"
"go.uber.org/mock/gomock"
)

Expand All @@ -26,6 +27,22 @@ func TestRefreshAiSummaries(t *testing.T) {
iom := mock.NewMockIOManager(ctrl)
loader := mock.NewMockAiLoader(ctrl)

h := memory.New()
lg := &log.Logger{Handler: h, Level: log.DebugLevel}
logger := lg.WithField("test", true)

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

err := RefreshAiSummaries(loader, model.SigLanguage(""), nil, "", "", "", logger, nil)
assert.NoError(t, err)

assert.Equal(t, len(h.Entries), 1)

msg := h.Entries[0]
assert.Equal(t, msg.Message, "skipping AI summary update because airgap is enabled")
assert.Equal(t, msg.Level, log.DebugLevel)

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 +71,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)
}
2 changes: 1 addition & 1 deletion server/modules/detections/detengine_helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"github.com/security-onion-solutions/securityonion-soc/util"

"github.com/go-git/go-git/v5/plumbing/transport"
"github.com/tj/assert"
"github.com/stretchr/testify/assert"
"go.uber.org/mock/gomock"
)

Expand Down
2 changes: 1 addition & 1 deletion server/modules/detections/errortracker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"errors"
"testing"

"github.com/tj/assert"
"github.com/stretchr/testify/assert"
)

func TestErrorTracker(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion server/modules/detections/integrity_check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"sort"
"testing"

"github.com/tj/assert"
"github.com/stretchr/testify/assert"
)

func TestDiffLists(t *testing.T) {
Expand Down
3 changes: 2 additions & 1 deletion server/modules/detections/io_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import (
"testing"

"github.com/security-onion-solutions/securityonion-soc/config"
"github.com/tj/assert"

"github.com/stretchr/testify/assert"
)

func TestBuildHttpClient(t *testing.T) {
Expand Down
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
2 changes: 1 addition & 1 deletion server/modules/strelka/strelka_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (
"github.com/apex/log"
"github.com/elastic/go-elasticsearch/v8/esutil"
"github.com/samber/lo"
"github.com/tj/assert"
"github.com/stretchr/testify/assert"
"go.uber.org/mock/gomock"
)

Expand Down
2 changes: 1 addition & 1 deletion server/modules/suricata/migration-2.4.70_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
"github.com/security-onion-solutions/securityonion-soc/server/modules/detections/mock"
"github.com/security-onion-solutions/securityonion-soc/util"

"github.com/tj/assert"
"github.com/stretchr/testify/assert"
"go.uber.org/mock/gomock"
)

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
2 changes: 1 addition & 1 deletion util/strings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ package util
import (
"testing"

"github.com/tj/assert"
"github.com/stretchr/testify/assert"
)

func TestUnquote(t *testing.T) {
Expand Down
Loading