Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[7.17](backport #39362) [Auditbeat/FIM/fsnotify]: prevent losing events for recursive mode on OS X #39374

Merged
merged 5 commits into from
May 7, 2024
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
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d


- Prevent scenario of losing children-related file events in a directory for recursive fsnotify backend of auditbeat file integrity module {pull}39133[39133]
- Fix losing events in FIM for OS X by allowing always to walk an added directory to monitor {pull}39362[39362]


*Filebeat*
Expand Down
2 changes: 1 addition & 1 deletion auditbeat/module/file_integrity/monitor/monitor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

import (
"errors"
"io/ioutil"

Check failure on line 25 in auditbeat/module/file_integrity/monitor/monitor_test.go

View workflow job for this annotation

GitHub Actions / lint (darwin)

SA1019: "io/ioutil" has been deprecated since Go 1.19: As of Go 1.16, the same functionality is now provided by package [io] or package [os], and those implementations should be preferred in new code. See the specific function documentation for details. (staticcheck)
"os"
"path/filepath"
"runtime"
Expand Down Expand Up @@ -59,7 +59,7 @@
testDirOps(t, dir, watcher)

subdir := filepath.Join(dir, "subdir")
os.Mkdir(subdir, 0750)

Check failure on line 62 in auditbeat/module/file_integrity/monitor/monitor_test.go

View workflow job for this annotation

GitHub Actions / lint (darwin)

Error return value of `os.Mkdir` is not checked (errcheck)

ev, err := readTimeout(t, watcher)
assertNoError(t, err)
Expand Down Expand Up @@ -107,7 +107,7 @@
testDirOps(t, dir, watcher)

subdir := filepath.Join(dir, "subdir")
os.Mkdir(subdir, 0750)

Check failure on line 110 in auditbeat/module/file_integrity/monitor/monitor_test.go

View workflow job for this annotation

GitHub Actions / lint (darwin)

Error return value of `os.Mkdir` is not checked (errcheck)

ev, err := readTimeout(t, watcher)
assertNoError(t, err)
Expand Down Expand Up @@ -232,7 +232,7 @@

ev, err := readTimeout(t, watcher)
assert.Equal(t, errReadTimeout, err)
if err != errReadTimeout {
if !errors.Is(err, errReadTimeout) {
t.Fatalf("Expected timeout, got event %+v", ev)
}

Expand Down Expand Up @@ -331,7 +331,7 @@

ev, err := readTimeout(t, watcher)
assert.Equal(t, errReadTimeout, err)
if err != errReadTimeout {

Check failure on line 334 in auditbeat/module/file_integrity/monitor/monitor_test.go

View workflow job for this annotation

GitHub Actions / lint (darwin)

comparing with != will fail on wrapped errors. Use errors.Is to check for a specific error (errorlint)
t.Fatalf("Expected timeout, got event %+v", ev)
}

Expand All @@ -346,7 +346,7 @@
for {
// No event is received
ev, err := readTimeout(t, watcher)
if err == errReadTimeout {

Check failure on line 349 in auditbeat/module/file_integrity/monitor/monitor_test.go

View workflow job for this annotation

GitHub Actions / lint (darwin)

comparing with == will fail on wrapped errors. Use errors.Is to check for a specific error (errorlint)
break
}
assertNoError(t, err)
Expand Down Expand Up @@ -389,12 +389,12 @@
for i := 0; i < 3; i++ {
f, err := os.OpenFile(fpath, os.O_RDWR|os.O_APPEND, 0640)
assertNoError(t, err)
f.WriteString(" world\n")

Check failure on line 392 in auditbeat/module/file_integrity/monitor/monitor_test.go

View workflow job for this annotation

GitHub Actions / lint (darwin)

Error return value of `f.WriteString` is not checked (errcheck)
f.Sync()

Check failure on line 393 in auditbeat/module/file_integrity/monitor/monitor_test.go

View workflow job for this annotation

GitHub Actions / lint (darwin)

Error return value of `f.Sync` is not checked (errcheck)
f.Close()

ev, err = readTimeout(t, watcher)
if err == nil || err != errReadTimeout {

Check failure on line 397 in auditbeat/module/file_integrity/monitor/monitor_test.go

View workflow job for this annotation

GitHub Actions / lint (darwin)

comparing with != will fail on wrapped errors. Use errors.Is to check for a specific error (errorlint)
break
}
}
Expand Down
4 changes: 2 additions & 2 deletions auditbeat/module/file_integrity/monitor/recursive.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

"github.com/fsnotify/fsnotify"
"github.com/joeshaw/multierror"
"github.com/pkg/errors"

Check failure on line 27 in auditbeat/module/file_integrity/monitor/recursive.go

View workflow job for this annotation

GitHub Actions / lint (darwin)

import of package `github.com/pkg/errors` is blocked because the module is in the blocked modules list. `errors` and `fmt` are recommended modules. This package is deprecated, use `fmt.Errorf` with `%!w(MISSING)` instead. (gomodguard)

"github.com/elastic/beats/v7/libbeat/logp"
)
Expand Down Expand Up @@ -55,7 +55,7 @@

func (watcher *recursiveWatcher) Start() error {
watcher.done = make(chan bool, 1)
go watcher.forwardEvents()

Check failure on line 58 in auditbeat/module/file_integrity/monitor/recursive.go

View workflow job for this annotation

GitHub Actions / lint (darwin)

Error return value of `watcher.forwardEvents` is not checked (errcheck)
return nil
}

Expand Down Expand Up @@ -114,11 +114,11 @@
return nil
}

var errs multierror.Errors
if err := watcher.watchFile(path, nil); err != nil {
return fmt.Errorf("failed adding watcher to '%s': %w", path, err)
errs = append(errs, fmt.Errorf("failed adding watcher to '%s': %w", path, err))
}

var errs multierror.Errors
err := filepath.Walk(path, func(walkPath string, info os.FileInfo, fnErr error) error {
if walkPath == path {
return nil
Expand Down
Loading