Skip to content

Commit 9539bb9

Browse files
committed
Better naming & test clean-up
1 parent e9645f3 commit 9539bb9

File tree

7 files changed

+208
-365
lines changed

7 files changed

+208
-365
lines changed

agent-smith.cm.yaml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
apiVersion: v1
2+
data:
3+
config.json: |-
4+
{
5+
"wsman": {
6+
"address": "ws-manager-mk2:8080",
7+
"tls": {
8+
"ca": "/wsman-certs/ca.crt",
9+
"crt": "/wsman-certs/tls.crt",
10+
"key": "/wsman-certs/tls.key"
11+
}
12+
},
13+
"gitpodAPI": {
14+
"hostURL": "",
15+
"apiToken": "b71ffa6eda1f61661367af8fede961f0a0968bee720ffc63d558dc8e304e"
16+
},
17+
"enforcement": {},
18+
"kubernetes": {
19+
"enabled": true
20+
},
21+
"blocklists": {
22+
"audit": {
23+
"binaries": [],
24+
"signatures": [
25+
{
26+
"name": "this-is-a-test",
27+
"filenames": ["*/data.txt"],
28+
"domain": "filesystem",
29+
"pattern": "Zm9vYmFy"
30+
}
31+
]
32+
}
33+
},
34+
"filesystemScanning": {
35+
"enabled": true,
36+
"scanInterval": "1m",
37+
"maxFileSize": 1024,
38+
"workingArea": "/mnt/workingarea-mk2"
39+
},
40+
"namespace": "default",
41+
"pprofAddr": "127.0.0.1:6060",
42+
"prometheusAddr": "127.0.0.1:9500"
43+
}
44+
kind: ConfigMap
45+
metadata:
46+
creationTimestamp: "2025-08-14T15:57:16Z"
47+
labels:
48+
app: gitpod
49+
component: agent-smith
50+
name: agent-smith
51+
namespace: default
52+
resourceVersion: "189849"
53+
uid: cb87159c-384b-428a-adb4-ab1579c76221
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
apiVersion: v1
2+
data:
3+
config.json: |-
4+
{
5+
"wsman": {
6+
"address": "ws-manager-mk2:8080",
7+
"tls": {
8+
"ca": "/wsman-certs/ca.crt",
9+
"crt": "/wsman-certs/tls.crt",
10+
"key": "/wsman-certs/tls.key"
11+
}
12+
},
13+
"gitpodAPI": {
14+
"hostURL": "",
15+
"apiToken": "b71ffa6eda1f61661367af8fede961f0a0968bee720ffc63d558dc8e304e"
16+
},
17+
"enforcement": {},
18+
"kubernetes": {
19+
"enabled": true
20+
},
21+
"blocklists": {
22+
"audit": {
23+
"binaries": [],
24+
"signatures": [
25+
{
26+
"name": "this-is-a-test",
27+
"filenames": ["*/data.txt"],
28+
"domain": "filesystem",
29+
"pattern": "Zm9vYmFy"
30+
}
31+
]
32+
}
33+
},
34+
"filesystemScanning": {
35+
"enabled": true,
36+
"scanInterval": "1m",
37+
"workingArea": "/mnt/workingarea-mk2"
38+
},
39+
"namespace": "default",
40+
"pprofAddr": "127.0.0.1:6060",
41+
"prometheusAddr": "127.0.0.1:9500"
42+
}
43+
kind: ConfigMap
44+
metadata:
45+
creationTimestamp: "2025-08-14T15:57:16Z"
46+
labels:
47+
app: gitpod
48+
component: agent-smith
49+
name: agent-smith
50+
namespace: default
51+
resourceVersion: "196508"
52+
uid: cb87159c-384b-428a-adb4-ab1579c76221

components/ee/agent-smith/pkg/agent/agent.go

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,10 @@ type Smith struct {
5151
timeElapsedHandler func(t time.Time) time.Duration
5252
notifiedInfringements *lru.Cache
5353

54-
detector detector.ProcessDetector
55-
classifier classifier.ProcessClassifier
56-
filesystemDetector detector.FileDetector
57-
filesystemClassifier classifier.FilesystemClassifier
54+
detector detector.ProcessDetector
55+
classifier classifier.ProcessClassifier
56+
fileDetector detector.FileDetector
57+
FileClassifier classifier.FileClassifier
5858
}
5959

6060
// NewAgentSmith creates a new agent smith
@@ -139,7 +139,7 @@ func NewAgentSmith(cfg config.Config) (*Smith, error) {
139139

140140
// Initialize filesystem detection if enabled
141141
var filesystemDetec detector.FileDetector
142-
var filesystemClass classifier.FilesystemClassifier
142+
var filesystemClass classifier.FileClassifier
143143
if cfg.FilesystemScanning != nil && cfg.FilesystemScanning.Enabled {
144144
// Create filesystem detector config
145145
fsConfig := detector.FilesystemScanningConfig{
@@ -150,9 +150,9 @@ func NewAgentSmith(cfg config.Config) (*Smith, error) {
150150
}
151151

152152
// Check if the main classifier supports filesystem detection
153-
if fsc, ok := class.(classifier.FilesystemClassifier); ok {
153+
if fsc, ok := class.(classifier.FileClassifier); ok {
154154
filesystemClass = fsc
155-
filesystemDetec, err = detector.NewFilesystemDetector(fsConfig, filesystemClass)
155+
filesystemDetec, err = detector.NewfileDetector(fsConfig, filesystemClass)
156156
if err != nil {
157157
log.WithError(err).Warn("failed to create filesystem detector")
158158
}
@@ -176,10 +176,10 @@ func NewAgentSmith(cfg config.Config) (*Smith, error) {
176176

177177
wsman: wsman,
178178

179-
detector: detec,
180-
classifier: class,
181-
filesystemDetector: filesystemDetec,
182-
filesystemClassifier: filesystemClass,
179+
detector: detec,
180+
classifier: class,
181+
fileDetector: filesystemDetec,
182+
FileClassifier: filesystemClass,
183183

184184
notifiedInfringements: lru.New(notificationCacheSize),
185185
metrics: m,
@@ -270,8 +270,8 @@ func (agent *Smith) Start(ctx context.Context, callback func(InfringingWorkspace
270270

271271
// Start filesystem detection if enabled
272272
var fs <-chan detector.File
273-
if agent.filesystemDetector != nil {
274-
fs, err = agent.filesystemDetector.DiscoverFiles(ctx)
273+
if agent.fileDetector != nil {
274+
fs, err = agent.fileDetector.DiscoverFiles(ctx)
275275
if err != nil {
276276
log.WithError(err).Warn("cannot start filesystem detector")
277277
}
@@ -314,14 +314,14 @@ func (agent *Smith) Start(ctx context.Context, callback func(InfringingWorkspace
314314
}
315315

316316
// Filesystem classification workers (fewer than process workers)
317-
if agent.filesystemClassifier != nil {
317+
if agent.FileClassifier != nil {
318318
for i := 0; i < 5; i++ {
319319
wg.Add(1)
320320
go func() {
321321
defer wg.Done()
322322
for file := range fli {
323323
log.Infof("Classifying filesystem file: %s", file.Path)
324-
class, err := agent.filesystemClassifier.MatchesFile(file.Path)
324+
class, err := agent.FileClassifier.MatchesFile(file.Path)
325325
// Early out for no matches
326326
if err == nil && class.Level == classifier.LevelNoMatch {
327327
log.Infof("File classification: no match - %s", file.Path)
@@ -522,22 +522,22 @@ func (agent *Smith) Describe(d chan<- *prometheus.Desc) {
522522
agent.metrics.Describe(d)
523523
agent.classifier.Describe(d)
524524
agent.detector.Describe(d)
525-
if agent.filesystemDetector != nil {
526-
agent.filesystemDetector.Describe(d)
525+
if agent.fileDetector != nil {
526+
agent.fileDetector.Describe(d)
527527
}
528-
if agent.filesystemClassifier != nil {
529-
agent.filesystemClassifier.Describe(d)
528+
if agent.FileClassifier != nil {
529+
agent.FileClassifier.Describe(d)
530530
}
531531
}
532532

533533
func (agent *Smith) Collect(m chan<- prometheus.Metric) {
534534
agent.metrics.Collect(m)
535535
agent.classifier.Collect(m)
536536
agent.detector.Collect(m)
537-
if agent.filesystemDetector != nil {
538-
agent.filesystemDetector.Collect(m)
537+
if agent.fileDetector != nil {
538+
agent.fileDetector.Collect(m)
539539
}
540-
if agent.filesystemClassifier != nil {
541-
agent.filesystemClassifier.Collect(m)
540+
if agent.FileClassifier != nil {
541+
agent.FileClassifier.Collect(m)
542542
}
543543
}

components/ee/agent-smith/pkg/classifier/classifier.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ type ProcessClassifier interface {
4848
Matches(executable string, cmdline []string) (*Classification, error)
4949
}
5050

51-
// FilesystemClassifier matches filesystem files against signatures
52-
type FilesystemClassifier interface {
51+
// FileClassifier matches filesystem files against signatures
52+
type FileClassifier interface {
5353
prometheus.Collector
5454

5555
MatchesFile(filePath string) (*Classification, error)
@@ -201,7 +201,7 @@ type SignatureMatchClassifier struct {
201201
}
202202

203203
var _ ProcessClassifier = &SignatureMatchClassifier{}
204-
var _ FilesystemClassifier = &SignatureMatchClassifier{}
204+
var _ FileClassifier = &SignatureMatchClassifier{}
205205

206206
var sigNoMatch = &Classification{Level: LevelNoMatch, Classifier: ClassifierSignature}
207207

@@ -509,7 +509,7 @@ func (cl *CountingMetricsClassifier) Matches(executable string, cmdline []string
509509

510510
func (cl *CountingMetricsClassifier) MatchesFile(filePath string) (*Classification, error) {
511511
cl.callCount.Inc()
512-
if fsc, ok := cl.D.(FilesystemClassifier); ok {
512+
if fsc, ok := cl.D.(FileClassifier); ok {
513513
return fsc.MatchesFile(filePath)
514514
}
515515
return sigNoMatch, nil
@@ -526,7 +526,7 @@ func (cl *CountingMetricsClassifier) Collect(m chan<- prometheus.Metric) {
526526
}
527527

528528
func (cl *CountingMetricsClassifier) GetFileSignatures() []*Signature {
529-
if fsc, ok := cl.D.(FilesystemClassifier); ok {
529+
if fsc, ok := cl.D.(FileClassifier); ok {
530530
return fsc.GetFileSignatures()
531531
}
532532
return nil
@@ -545,7 +545,7 @@ func (cl GradedClassifier) MatchesFile(filePath string) (*Classification, error)
545545
continue
546546
}
547547

548-
if fsc, ok := classifier.(FilesystemClassifier); ok {
548+
if fsc, ok := classifier.(FileClassifier); ok {
549549
c, err = fsc.MatchesFile(filePath)
550550
if err != nil {
551551
return nil, err
@@ -569,7 +569,7 @@ func (cl GradedClassifier) GetFileSignatures() []*Signature {
569569
var allSignatures []*Signature
570570

571571
for _, classifier := range cl {
572-
if fsc, ok := classifier.(FilesystemClassifier); ok {
572+
if fsc, ok := classifier.(FileClassifier); ok {
573573
signatures := fsc.GetFileSignatures()
574574
allSignatures = append(allSignatures, signatures...)
575575
}
@@ -584,7 +584,7 @@ func (cl CompositeClassifier) MatchesFile(filePath string) (*Classification, err
584584
err error
585585
)
586586
for _, classifier := range cl {
587-
if fsc, ok := classifier.(FilesystemClassifier); ok {
587+
if fsc, ok := classifier.(FileClassifier); ok {
588588
c, err = fsc.MatchesFile(filePath)
589589
if err != nil {
590590
return nil, err
@@ -612,7 +612,7 @@ func (cl CompositeClassifier) GetFileSignatures() []*Signature {
612612
var allSignatures []*Signature
613613

614614
for _, classifier := range cl {
615-
if fsc, ok := classifier.(FilesystemClassifier); ok {
615+
if fsc, ok := classifier.(FileClassifier); ok {
616616
signatures := fsc.GetFileSignatures()
617617
allSignatures = append(allSignatures, signatures...)
618618
}

components/ee/agent-smith/pkg/classifier/classifier_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,8 @@ func TestCountingMetricsClassifierFilesystemInterface(t *testing.T) {
106106
sigClassifier := classifier.NewSignatureMatchClassifier("test", classifier.LevelAudit, signatures)
107107
countingClassifier := classifier.NewCountingMetricsClassifier("counting", sigClassifier)
108108

109-
// Test that CountingMetricsClassifier implements FilesystemClassifier
110-
var fsc classifier.FilesystemClassifier = countingClassifier
109+
// Test that CountingMetricsClassifier implements FileClassifier
110+
var fsc classifier.FileClassifier = countingClassifier
111111

112112
// Test filesystem file matching (file doesn't exist, should return no match without error)
113113
result, err := fsc.MatchesFile("/nonexistent/path/malware.exe")

0 commit comments

Comments
 (0)