Skip to content

Report NGINX App Protect instances #1122

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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
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
14 changes: 12 additions & 2 deletions api/grpc/mpi/v1/command.pb.go

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

2 changes: 2 additions & 0 deletions api/grpc/mpi/v1/command.pb.validate.go

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

2 changes: 2 additions & 0 deletions api/grpc/mpi/v1/command.proto
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,8 @@ message NGINXAppProtectRuntimeInfo {
string attack_signature_version = 2;
// Threat campaign version
string threat_campaign_version = 3;
// Enforcer engine version
string enforcer_engine_version = 4;
}

// A set of actions that can be performed on an instance
Expand Down
1 change: 1 addition & 0 deletions docs/proto/protos.md
Original file line number Diff line number Diff line change
Expand Up @@ -1053,6 +1053,7 @@ A set of runtime NGINX App Protect settings
| release | [string](#string) | | NGINX App Protect Release |
| attack_signature_version | [string](#string) | | Attack signature version |
| threat_campaign_version | [string](#string) | | Threat campaign version |
| enforcer_engine_version | [string](#string) | | Enforcer engine version |



Expand Down
48 changes: 21 additions & 27 deletions internal/watcher/instance/instance_watcher_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,17 @@ type (
}

InstanceWatcherService struct {
processOperator process.ProcessOperatorInterface
nginxConfigParser parser.ConfigParser
executer exec.ExecInterface
enabled *atomic.Bool
agentConfig *config.Config
instanceCache map[string]*mpi.Instance
nginxConfigCache map[string]*model.NginxConfigContext
instancesChannel chan<- InstanceUpdatesMessage
nginxConfigContextChannel chan<- NginxConfigContextMessage
nginxParser processParser
nginxAppProtectProcessParser processParser
cacheMutex sync.Mutex
processOperator process.ProcessOperatorInterface
nginxConfigParser parser.ConfigParser
executer exec.ExecInterface
enabled *atomic.Bool
agentConfig *config.Config
instanceCache map[string]*mpi.Instance
nginxConfigCache map[string]*model.NginxConfigContext
instancesChannel chan<- InstanceUpdatesMessage
nginxConfigContextChannel chan<- NginxConfigContextMessage
nginxParser processParser
cacheMutex sync.Mutex
}

InstanceUpdates struct {
Expand All @@ -75,16 +74,15 @@ func NewInstanceWatcherService(agentConfig *config.Config) *InstanceWatcherServi
enabled.Store(true)

return &InstanceWatcherService{
agentConfig: agentConfig,
processOperator: process.NewProcessOperator(),
nginxParser: NewNginxProcessParser(),
nginxAppProtectProcessParser: NewNginxAppProtectProcessParser(),
nginxConfigParser: parser.NewNginxConfigParser(agentConfig),
instanceCache: make(map[string]*mpi.Instance),
cacheMutex: sync.Mutex{},
nginxConfigCache: make(map[string]*model.NginxConfigContext),
executer: &exec.Exec{},
enabled: enabled,
agentConfig: agentConfig,
processOperator: process.NewProcessOperator(),
nginxParser: NewNginxProcessParser(),
nginxConfigParser: parser.NewNginxConfigParser(agentConfig),
instanceCache: make(map[string]*mpi.Instance),
cacheMutex: sync.Mutex{},
nginxConfigCache: make(map[string]*model.NginxConfigContext),
executer: &exec.Exec{},
enabled: enabled,
}
}

Expand Down Expand Up @@ -265,7 +263,7 @@ func (iw *InstanceWatcherService) instanceUpdates(ctx context.Context) (
) {
iw.cacheMutex.Lock()
defer iw.cacheMutex.Unlock()
nginxProcesses, nginxAppProtectProcesses, err := iw.processOperator.Processes(ctx)
nginxProcesses, err := iw.processOperator.Processes(ctx)
if err != nil {
return instanceUpdates, err
}
Expand All @@ -280,10 +278,6 @@ func (iw *InstanceWatcherService) instanceUpdates(ctx context.Context) (
instancesFound[instance.GetInstanceMeta().GetInstanceId()] = instance
}

nginxAppProtectInstances := iw.nginxAppProtectProcessParser.Parse(ctx, nginxAppProtectProcesses)
for _, instance := range nginxAppProtectInstances {
instancesFound[instance.GetInstanceMeta().GetInstanceId()] = instance
}
newInstances, updatedInstances, deletedInstances := compareInstances(iw.instanceCache, instancesFound)

instanceUpdates.NewInstances = newInstances
Expand Down
6 changes: 2 additions & 4 deletions internal/watcher/instance/instance_watcher_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func TestInstanceWatcherService_checkForUpdates(t *testing.T) {
nginxConfigContext := testModel.ConfigContext()

fakeProcessWatcher := &processfakes.FakeProcessOperatorInterface{}
fakeProcessWatcher.ProcessesReturns(nil, nil, nil)
fakeProcessWatcher.ProcessesReturns(nil, nil)

fakeProcessParser := &instancefakes.FakeProcessParser{}
fakeProcessParser.ParseReturns(map[string]*mpi.Instance{
Expand All @@ -44,7 +44,6 @@ func TestInstanceWatcherService_checkForUpdates(t *testing.T) {
instanceWatcherService := NewInstanceWatcherService(types.AgentConfig())
instanceWatcherService.processOperator = fakeProcessWatcher
instanceWatcherService.nginxParser = fakeProcessParser
instanceWatcherService.nginxAppProtectProcessParser = fakeProcessParser
instanceWatcherService.nginxConfigParser = fakeNginxConfigParser
instanceWatcherService.instancesChannel = instanceUpdatesChannel
instanceWatcherService.nginxConfigContextChannel = nginxConfigContextChannel
Expand Down Expand Up @@ -132,7 +131,7 @@ func TestInstanceWatcherService_instanceUpdates(t *testing.T) {
for _, test := range tests {
t.Run(test.name, func(tt *testing.T) {
fakeProcessWatcher := &processfakes.FakeProcessOperatorInterface{}
fakeProcessWatcher.ProcessesReturns(nil, nil, nil)
fakeProcessWatcher.ProcessesReturns(nil, nil)

fakeProcessParser := &instancefakes.FakeProcessParser{}
fakeProcessParser.ParseReturns(test.parsedInstances)
Expand All @@ -144,7 +143,6 @@ func TestInstanceWatcherService_instanceUpdates(t *testing.T) {
instanceWatcherService := NewInstanceWatcherService(types.AgentConfig())
instanceWatcherService.processOperator = fakeProcessWatcher
instanceWatcherService.nginxParser = fakeProcessParser
instanceWatcherService.nginxAppProtectProcessParser = fakeProcessParser
instanceWatcherService.instanceCache = test.oldInstances
instanceWatcherService.executer = fakeExec

Expand Down
110 changes: 110 additions & 0 deletions internal/watcher/instance/instancefakes/fake_instance_finder.go

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

Loading