Skip to content

Commit 40e616a

Browse files
authored
Merge pull request #2204 from Ishaanj18/feat/structured-data-field
feat: add EventData field to KubeArmor telemetry
2 parents d9af2f8 + 51a17c5 commit 40e616a

File tree

5 files changed

+300
-214
lines changed

5 files changed

+300
-214
lines changed

KubeArmor/feeder/feeder.go

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,31 @@ import (
3030
"google.golang.org/grpc/keepalive"
3131
)
3232

33+
// parseDataString parses a space-separated key=value string into a map
34+
func parseDataString(data string) map[string]string {
35+
if data == "" {
36+
return nil
37+
}
38+
39+
result := make(map[string]string)
40+
pairs := strings.Fields(data) // Split by whitespace
41+
42+
for _, pair := range pairs {
43+
if strings.Contains(pair, "=") {
44+
parts := strings.SplitN(pair, "=", 2) // Split only on first "="
45+
if len(parts) == 2 {
46+
key := parts[0]
47+
if len(key) > 0 {
48+
key = strings.ToUpper(key[:1]) + key[1:]
49+
}
50+
result[key] = parts[1]
51+
}
52+
}
53+
}
54+
55+
return result
56+
}
57+
3358
// ============ //
3459
// == Global == //
3560
// ============ //
@@ -531,6 +556,7 @@ func (fd *Feeder) PushMessage(level, message string) {
531556
}
532557
}
533558

559+
// PushLog Function
534560
// PushLog Function
535561
func (fd *Feeder) PushLog(log tp.Log) {
536562
/* if enforcer == BPFLSM and log.Enforcer == ebpfmonitor ( block and default Posture Alerts from System
@@ -583,6 +609,25 @@ func (fd *Feeder) PushLog(log tp.Log) {
583609
// set hostname
584610
log.HostName = cfg.GlobalCfg.Host
585611

612+
// populate EventData by merging structured data from Data and Resource
613+
var mergedEventData map[string]string
614+
if len(log.Data) > 0 {
615+
mergedEventData = parseDataString(log.Data)
616+
}
617+
// populate Resource data only for Network operations
618+
if len(log.Resource) > 0 && log.Operation == "Network" {
619+
if mergedEventData == nil {
620+
mergedEventData = parseDataString(log.Resource)
621+
} else {
622+
for k, v := range parseDataString(log.Resource) {
623+
mergedEventData[k] = v
624+
}
625+
}
626+
}
627+
if mergedEventData != nil {
628+
log.EventData = mergedEventData
629+
}
630+
586631
// remove flags
587632
log.PolicyEnabled = 0
588633
log.ProcessVisibilityEnabled = false
@@ -696,6 +741,9 @@ func (fd *Feeder) PushLog(log tp.Log) {
696741
if len(log.Data) > 0 {
697742
pbAlert.Data = log.Data
698743
}
744+
if log.EventData != nil {
745+
pbAlert.EventData = log.EventData
746+
}
699747
pbAlert.ProcessHash = log.ProcessHash[:]
700748
pbAlert.ParentHash = log.ParentHash[:]
701749
pbAlert.ResourceHash = log.ResourceHash[:]
@@ -787,6 +835,9 @@ func (fd *Feeder) PushLog(log tp.Log) {
787835
if len(log.Data) > 0 {
788836
pbLog.Data = log.Data
789837
}
838+
if log.EventData != nil {
839+
pbLog.EventData = log.EventData
840+
}
790841
pbLog.ProcessHash = log.ProcessHash[:]
791842
pbLog.ParentHash = log.ParentHash[:]
792843
pbLog.ResourceHash = log.ResourceHash[:]

KubeArmor/types/types.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,8 @@ type Log struct {
282282
Cwd string `json:"cwd"`
283283
TTY string `json:"tty,omitempty"`
284284
OID int32 `json:"oid"`
285-
Data string `json:"data,omitempty"`
285+
Data string `json:"data,omitempty"`
286+
EventData map[string]string `json:"eventData,omitempty"`
286287
ProcessHash string `json:"processHash,omitempty"`
287288
ParentHash string `json:"parentHash,omitempty"`
288289
ResourceHash string `json:"resourceHash,omitempty"`

0 commit comments

Comments
 (0)