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

Cherry-pick #24414 to 7.12: [fix][auditbeat] Reset file offset when re-reading from the beginning #24418

Merged
merged 1 commit into from
Mar 15, 2021

Conversation

marc-gr
Copy link
Contributor

@marc-gr marc-gr commented Mar 8, 2021

Cherry-pick of PR #24414 to 7.12 branch. Original message:

What does this PR do?

When a utmp file is read and its size is smaller than before (which can be caused by an inode reuse, for example), we have to reset its offset, also, otherwise it will ignore any new events in that file until the size is bigger than its previous value.

Why is it important?

We were missing events in some edge cases.

Checklist

  • My code follows the style guidelines of this project
  • I have commented my code, particularly in hard-to-understand areas
    - [ ] I have made corresponding changes to the documentation
    - [ ] I have made corresponding change to the default configuration files
  • I have added tests that prove my fix is effective or that my feature works
  • I have added an entry in CHANGELOG.next.asciidoc or CHANGELOG-developer.next.asciidoc.

Logs

The logs of the bug:

2021-03-01T17:16:07.665+1000	WARN	[login]	login/utmp.go:190	Unexpectedly, the file /var/log/wtmp is smaller than before (new: 35712, old: 39552) - reading whole file.
2021-03-01T17:16:07.665+1000	DEBUG	[login]	login/utmp.go:204	Reading file /var/log/wtmp (utmpFile={Inode:14 Path:/var/log/wtmp Size:35712 Offset:39552 Type:0})
2021-03-01T17:16:07.665+1000	DEBUG	[login]	login/utmp.go:279	Saving UTMP file record ({Inode:14 Path:/var/log/wtmp Size:35712 Offset:39552 Type:0})

As you can see, it is reading from an invalid offset and saving it.

2021-03-01T17:16:17.666+1000	DEBUG	[login]	login/utmp.go:204	Reading file /var/log/wtmp (utmpFile={Inode:14 Path:/var/log/wtmp Size:36096 Offset:39552 Type:0})
2021-03-01T17:16:17.666+1000	DEBUG	[login]	login/utmp.go:279	Saving UTMP file record ({Inode:14 Path:/var/log/wtmp Size:36096 Offset:39552 Type:0})
2021-03-01T17:16:17.666+1000	DEBUG	[login]	login/login.go:130	0 new login records.

Subsequent calls still ignore new events even if the size has grown.

@marc-gr marc-gr requested a review from a team as a code owner March 8, 2021 13:50
@botelastic botelastic bot added the needs_team Indicates that the issue/PR needs a Team:* label label Mar 8, 2021
@elasticmachine
Copy link
Collaborator

Pinging @elastic/security-external-integrations (Team:Security-External Integrations)

@botelastic botelastic bot removed the needs_team Indicates that the issue/PR needs a Team:* label label Mar 8, 2021
@marc-gr marc-gr force-pushed the backport_24414_7.12 branch 2 times, most recently from 1f978ae to 997161c Compare March 8, 2021 13:52
@elasticmachine
Copy link
Collaborator

elasticmachine commented Mar 8, 2021

💚 Build Succeeded

the below badges are clickable and redirect to their specific view in the CI or DOCS
Pipeline View Test View Changes Artifacts preview

Expand to view the summary

Build stats

  • Build Cause: Pull request #24418 updated

  • Start Time: 2021-03-15T11:50:19.134+0000

  • Duration: 41 min 43 sec

  • Commit: cd6b1d4

Test stats 🧪

Test Results
Failed 0
Passed 337
Skipped 145
Total 482

Trends 🧪

Image of Build Times

Image of Tests

💚 Flaky test report

Tests succeeded.

Expand to view the summary

Test stats 🧪

Test Results
Failed 0
Passed 337
Skipped 145
Total 482

@marc-gr marc-gr force-pushed the backport_24414_7.12 branch 2 times, most recently from 9000922 to 62aa1c0 Compare March 10, 2021 13:02
Copy link
Member

@P1llus P1llus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@marc-gr marc-gr force-pushed the backport_24414_7.12 branch from 62aa1c0 to 74fc1e3 Compare March 15, 2021 10:54
@marc-gr marc-gr force-pushed the backport_24414_7.12 branch from 74fc1e3 to cd6b1d4 Compare March 15, 2021 11:49
@marc-gr marc-gr merged commit 516198a into elastic:7.12 Mar 15, 2021
@marc-gr marc-gr deleted the backport_24414_7.12 branch March 15, 2021 13:49
@zube zube bot removed the [zube]: Done label Jun 14, 2021
leweafan pushed a commit to leweafan/beats that referenced this pull request Apr 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants