-
Notifications
You must be signed in to change notification settings - Fork 165
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #95 from psanford/cgroup-extras
Cgroup extras.
- Loading branch information
Showing
2 changed files
with
58 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/spf13/viper" | ||
) | ||
|
||
func init() { | ||
RegisterExtraParser(func(config *viper.Viper) (ExtraParser, error) { | ||
if config.GetBool("extras.cgroups.enabled") { | ||
l.Printf("cgroup parser enabled") | ||
return &CgroupParser{}, nil | ||
} | ||
return nil, nil | ||
}) | ||
} | ||
|
||
type CgroupParser struct { | ||
} | ||
|
||
func (p *CgroupParser) Parse(am *AuditMessage) { | ||
switch am.Type { | ||
case 1300, 1302, 1309, 1326: // AUDIT_SYSCALL, AUDIT_PATH, AUDIT_EXECVE, AUDIT_SECCOMP | ||
pid, _ := getPid(am.Data) | ||
cgroup := p.getCgroupRootForPid(pid) | ||
if cgroup != "" { | ||
am.Extras = &AuditExtras{CgroupRoot: cgroup} | ||
} | ||
} | ||
} | ||
|
||
func (p *CgroupParser) getCgroupRootForPid(pid int) string { | ||
if pid == 0 { | ||
return "" | ||
} | ||
|
||
var v1PidPath string | ||
cgroups, err := taskControlGroups(pid, pid) | ||
if err != nil { | ||
return "" | ||
} | ||
|
||
for _, cgroup := range cgroups { | ||
if cgroup.ID == 0 { | ||
// v2 path | ||
return cgroup.Path | ||
} else if len(cgroup.Controllers) > 0 && cgroup.Controllers[0] == "pids" { | ||
// fall back to cgroup v1 pid path if we don't have cgroups v2 | ||
v1PidPath = cgroup.Path | ||
} | ||
} | ||
|
||
return v1PidPath | ||
} |
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