Skip to content

Commit cb4cbb7

Browse files
committed
x-pack/auditbeat/module/system/process Report Linux capabilities
Implements #36404 ECS: https://www.elastic.co/guide/en/ecs/master/ecs-process.html#field-process-thread-capabilities-effective Example output: ``` { "@timestamp": "2023-12-05T19:34:54.425Z", "@metadata": { "beat": "auditbeat", "type": "_doc", "version": "8.12.0" }, "process": { "thread": { "capabilities": { "effective": [ "CAP_DAC_READ_SEARCH", "CAP_SYS_RESOURCE" ], "permitted": [ "CAP_DAC_READ_SEARCH", "CAP_SYS_RESOURCE" ] } }, "entity_id": "DADEDQU03GoDNhc1", "pid": 2841325, "start": "2023-12-05T19:32:53.180Z", "args": [ "systemd-userwork: waiting..." ], ... ... ``` Don't merge, this depends on two external PRs: elastic/go-sysinfo#196 elastic/go-sysinfo#197 Next step is adding the same to add_process_metadata
1 parent 62c5e91 commit cb4cbb7

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

x-pack/auditbeat/module/system/process/process.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ type Process struct {
105105
UserInfo *types.UserInfo
106106
User *user.User
107107
Group *user.Group
108+
CapabilityInfo *types.CapabilityInfo
108109
Hashes map[hasher.HashType]hasher.Digest
109110
Error error
110111
}
@@ -353,6 +354,17 @@ func (ms *MetricSet) processEvent(process *Process, eventType string, action eve
353354
},
354355
}
355356

357+
if process.CapabilityInfo != nil {
358+
if len(process.CapabilityInfo.Effective) > 0 {
359+
event.RootFields.Put("process.thread.capabilities.effective",
360+
process.CapabilityInfo.Effective)
361+
}
362+
if len(process.CapabilityInfo.Permitted) > 0 {
363+
event.RootFields.Put("process.thread.capabilities.permitted",
364+
process.CapabilityInfo.Permitted)
365+
}
366+
}
367+
356368
if process.UserInfo != nil {
357369
putIfNotEmpty(&event.RootFields, "user.id", process.UserInfo.UID)
358370
putIfNotEmpty(&event.RootFields, "user.group.id", process.UserInfo.GID)
@@ -488,6 +500,13 @@ func (ms *MetricSet) getProcesses() ([]*Process, error) {
488500
process.UserInfo = &userInfo
489501
}
490502

503+
if capIface, ok := sysinfoProc.(types.Capabilities); ok {
504+
process.CapabilityInfo, err = capIface.Capabilities();
505+
if err != nil && process.Error == nil {
506+
process.Error = fmt.Errorf("failed to load capabilities for PID %d: %w",
507+
sysinfoProc.PID(), err)
508+
}
509+
}
491510
// Exclude Linux kernel processes, they are not very interesting.
492511
if runtime.GOOS == "linux" && userInfo.UID == "0" && process.Info.Exe == "" {
493512
continue

0 commit comments

Comments
 (0)