Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions procmon_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,7 @@ func (p *ProcessMonitor) MonitorProcesses(errc chan error) {
workingDirectory = "/home/runner"
}

auditRule := fmt.Sprintf("-a exit,always -F dir=%s -F perm=wa -S open -S openat -S rename -S renameat -k %s", workingDirectory, fileMonitorTag)
if runtime.GOARCH == "arm64" {
auditRule = fmt.Sprintf("-a exit,always -F dir=%s -F perm=wa -S openat -S renameat -k %s", workingDirectory, fileMonitorTag)
}
auditRule := fileMonitorAuditRule(workingDirectory, runtime.GOARCH)

r, _ := flags.Parse(auditRule)

Expand Down Expand Up @@ -157,6 +154,14 @@ func (p *ProcessMonitor) MonitorProcesses(errc chan error) {
p.receive(client)
}

func fileMonitorAuditRule(workingDirectory, goarch string) string {
if goarch == "arm64" {
return fmt.Sprintf("-a exit,always -F dir=%s -F perm=wa -S openat -S renameat -k %s", workingDirectory, fileMonitorTag)
}

return fmt.Sprintf("-a exit,always -F dir=%s -F perm=wa -S open -S openat -S rename -S renameat -k %s", workingDirectory, fileMonitorTag)
}

func (p *ProcessMonitor) receive(r *libaudit.AuditClient) error {

p.Events = make(map[int]*Event)
Expand Down
30 changes: 30 additions & 0 deletions procmon_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,36 @@ import (
"testing"
)

func Test_fileMonitorAuditRule(t *testing.T) {
tests := []struct {
name string
workingDirectory string
goarch string
want string
}{
{
name: "arm64 excludes unsupported syscalls",
workingDirectory: "/home/runner/work/repo",
goarch: "arm64",
want: "-a exit,always -F dir=/home/runner/work/repo -F perm=wa -S openat -S renameat -k filemon",
},
{
name: "default includes open and rename syscalls",
workingDirectory: "/home/runner/work/repo",
goarch: "amd64",
want: "-a exit,always -F dir=/home/runner/work/repo -F perm=wa -S open -S openat -S rename -S renameat -k filemon",
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := fileMonitorAuditRule(tt.workingDirectory, tt.goarch); got != tt.want {
t.Errorf("fileMonitorAuditRule() = %q, want %q", got, tt.want)
}
})
}
}

func Test_getProcessExe(t *testing.T) {
type args struct {
pid string
Expand Down
Loading