-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Backport 7.63.x] [CWS] use iterator name as cache key (#33460)
Co-authored-by: Sylvain Afchain <[email protected]>
- Loading branch information
1 parent
d8e9761
commit 01fe91d
Showing
8 changed files
with
372 additions
and
307 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// Unless explicitly stated otherwise all files in this repository are licensed | ||
// under the Apache License Version 2.0. | ||
// This product includes software developed at Datadog (https://www.datadoghq.com/). | ||
// Copyright 2016-present Datadog, Inc. | ||
|
||
//go:build linux | ||
|
||
// Package rules holds rules related files | ||
package rules | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/DataDog/datadog-agent/pkg/security/secl/compiler/ast" | ||
"github.com/DataDog/datadog-agent/pkg/security/secl/compiler/eval" | ||
"github.com/DataDog/datadog-agent/pkg/security/secl/model" | ||
) | ||
|
||
func TestIteratorCache(t *testing.T) { | ||
event := model.NewFakeEvent() | ||
|
||
event.Exec = model.ExecEvent{ | ||
Process: &model.Process{ | ||
FileEvent: model.FileEvent{ | ||
FileFields: model.FileFields{ | ||
UID: 22, | ||
}, | ||
}, | ||
}, | ||
} | ||
event.ProcessContext = &model.ProcessContext{ | ||
Ancestor: &model.ProcessCacheEntry{ | ||
ProcessContext: model.ProcessContext{ | ||
Process: model.Process{ | ||
PIDContext: model.PIDContext{ | ||
Pid: 111, | ||
}, | ||
PPid: 111, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
evalRule, err := eval.NewRule("test", `exec.file.uid == 22 && process.ancestors.pid == 111 && process.ancestors.ppid == 111`, ast.NewParsingContext(false), &eval.Opts{}) | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
|
||
rule := &Rule{ | ||
Rule: evalRule, | ||
} | ||
|
||
err = rule.GenEvaluator(&model.Model{}) | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
|
||
ctx := eval.NewContext(event) | ||
|
||
rule.Eval(ctx) | ||
|
||
if len(ctx.IteratorCountCache) != 1 || ctx.IteratorCountCache["BaseEvent.ProcessContext.Ancestor"] != 1 { | ||
t.Errorf("wrong iterator cache entries: %+v", ctx.IteratorCountCache) | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.