Skip to content

Commit 3a13a8e

Browse files
authored
Report NGINX App Protect instances (#1122)
1 parent 3524bcf commit 3a13a8e

15 files changed

+654
-355
lines changed

api/grpc/mpi/v1/command.pb.go

Lines changed: 16 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/grpc/mpi/v1/command.pb.validate.go

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/grpc/mpi/v1/command.proto

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ message InstanceRuntime {
296296
// the process identifier
297297
int32 process_id = 1;
298298
// the binary path location
299-
string binary_path = 2 [(buf.validate.field).string.prefix = "/"];
299+
string binary_path = 2 [(buf.validate.field).string.pattern = "^\\/.*|^$"];
300300
// the config path location
301301
string config_path = 3 [(buf.validate.field).string.pattern = "^\\/.*|^$"];
302302
// more detailed runtime objects
@@ -362,6 +362,8 @@ message NGINXAppProtectRuntimeInfo {
362362
string attack_signature_version = 2;
363363
// Threat campaign version
364364
string threat_campaign_version = 3;
365+
// Enforcer engine version
366+
string enforcer_engine_version = 4;
365367
}
366368

367369
// A set of actions that can be performed on an instance

docs/proto/protos.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1053,6 +1053,7 @@ A set of runtime NGINX App Protect settings
10531053
| release | [string](#string) | | NGINX App Protect Release |
10541054
| attack_signature_version | [string](#string) | | Attack signature version |
10551055
| threat_campaign_version | [string](#string) | | Threat campaign version |
1056+
| enforcer_engine_version | [string](#string) | | Enforcer engine version |
10561057

10571058

10581059

internal/watcher/instance/instance_watcher_service.go

Lines changed: 21 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,17 @@ type (
3939
}
4040

4141
InstanceWatcherService struct {
42-
processOperator process.ProcessOperatorInterface
43-
nginxConfigParser parser.ConfigParser
44-
executer exec.ExecInterface
45-
enabled *atomic.Bool
46-
agentConfig *config.Config
47-
instanceCache map[string]*mpi.Instance
48-
nginxConfigCache map[string]*model.NginxConfigContext
49-
instancesChannel chan<- InstanceUpdatesMessage
50-
nginxConfigContextChannel chan<- NginxConfigContextMessage
51-
nginxParser processParser
52-
nginxAppProtectProcessParser processParser
53-
cacheMutex sync.Mutex
42+
processOperator process.ProcessOperatorInterface
43+
nginxConfigParser parser.ConfigParser
44+
executer exec.ExecInterface
45+
enabled *atomic.Bool
46+
agentConfig *config.Config
47+
instanceCache map[string]*mpi.Instance
48+
nginxConfigCache map[string]*model.NginxConfigContext
49+
instancesChannel chan<- InstanceUpdatesMessage
50+
nginxConfigContextChannel chan<- NginxConfigContextMessage
51+
nginxParser processParser
52+
cacheMutex sync.Mutex
5453
}
5554

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

7776
return &InstanceWatcherService{
78-
agentConfig: agentConfig,
79-
processOperator: process.NewProcessOperator(),
80-
nginxParser: NewNginxProcessParser(),
81-
nginxAppProtectProcessParser: NewNginxAppProtectProcessParser(),
82-
nginxConfigParser: parser.NewNginxConfigParser(agentConfig),
83-
instanceCache: make(map[string]*mpi.Instance),
84-
cacheMutex: sync.Mutex{},
85-
nginxConfigCache: make(map[string]*model.NginxConfigContext),
86-
executer: &exec.Exec{},
87-
enabled: enabled,
77+
agentConfig: agentConfig,
78+
processOperator: process.NewProcessOperator(),
79+
nginxParser: NewNginxProcessParser(),
80+
nginxConfigParser: parser.NewNginxConfigParser(agentConfig),
81+
instanceCache: make(map[string]*mpi.Instance),
82+
cacheMutex: sync.Mutex{},
83+
nginxConfigCache: make(map[string]*model.NginxConfigContext),
84+
executer: &exec.Exec{},
85+
enabled: enabled,
8886
}
8987
}
9088

@@ -265,7 +263,7 @@ func (iw *InstanceWatcherService) instanceUpdates(ctx context.Context) (
265263
) {
266264
iw.cacheMutex.Lock()
267265
defer iw.cacheMutex.Unlock()
268-
nginxProcesses, nginxAppProtectProcesses, err := iw.processOperator.Processes(ctx)
266+
nginxProcesses, err := iw.processOperator.Processes(ctx)
269267
if err != nil {
270268
return instanceUpdates, err
271269
}
@@ -280,10 +278,6 @@ func (iw *InstanceWatcherService) instanceUpdates(ctx context.Context) (
280278
instancesFound[instance.GetInstanceMeta().GetInstanceId()] = instance
281279
}
282280

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

289283
instanceUpdates.NewInstances = newInstances

internal/watcher/instance/instance_watcher_service_test.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func TestInstanceWatcherService_checkForUpdates(t *testing.T) {
2828
nginxConfigContext := testModel.ConfigContext()
2929

3030
fakeProcessWatcher := &processfakes.FakeProcessOperatorInterface{}
31-
fakeProcessWatcher.ProcessesReturns(nil, nil, nil)
31+
fakeProcessWatcher.ProcessesReturns(nil, nil)
3232

3333
fakeProcessParser := &instancefakes.FakeProcessParser{}
3434
fakeProcessParser.ParseReturns(map[string]*mpi.Instance{
@@ -44,7 +44,6 @@ func TestInstanceWatcherService_checkForUpdates(t *testing.T) {
4444
instanceWatcherService := NewInstanceWatcherService(types.AgentConfig())
4545
instanceWatcherService.processOperator = fakeProcessWatcher
4646
instanceWatcherService.nginxParser = fakeProcessParser
47-
instanceWatcherService.nginxAppProtectProcessParser = fakeProcessParser
4847
instanceWatcherService.nginxConfigParser = fakeNginxConfigParser
4948
instanceWatcherService.instancesChannel = instanceUpdatesChannel
5049
instanceWatcherService.nginxConfigContextChannel = nginxConfigContextChannel
@@ -132,7 +131,7 @@ func TestInstanceWatcherService_instanceUpdates(t *testing.T) {
132131
for _, test := range tests {
133132
t.Run(test.name, func(tt *testing.T) {
134133
fakeProcessWatcher := &processfakes.FakeProcessOperatorInterface{}
135-
fakeProcessWatcher.ProcessesReturns(nil, nil, nil)
134+
fakeProcessWatcher.ProcessesReturns(nil, nil)
136135

137136
fakeProcessParser := &instancefakes.FakeProcessParser{}
138137
fakeProcessParser.ParseReturns(test.parsedInstances)
@@ -144,7 +143,6 @@ func TestInstanceWatcherService_instanceUpdates(t *testing.T) {
144143
instanceWatcherService := NewInstanceWatcherService(types.AgentConfig())
145144
instanceWatcherService.processOperator = fakeProcessWatcher
146145
instanceWatcherService.nginxParser = fakeProcessParser
147-
instanceWatcherService.nginxAppProtectProcessParser = fakeProcessParser
148146
instanceWatcherService.instanceCache = test.oldInstances
149147
instanceWatcherService.executer = fakeExec
150148

internal/watcher/instance/instancefakes/fake_instance_finder.go

Lines changed: 110 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)