Skip to content

Winlogbeat: Fix compatibility problems with newer OS versions in CI#22362

Merged
adriansr merged 8 commits intoelastic:masterfrom
adriansr:wb_32bit_wineventlog
Nov 11, 2020
Merged

Winlogbeat: Fix compatibility problems with newer OS versions in CI#22362
adriansr merged 8 commits intoelastic:masterfrom
adriansr:wb_32bit_wineventlog

Conversation

@adriansr
Copy link
Copy Markdown
Contributor

@adriansr adriansr commented Nov 2, 2020

This PR includes a collection of fixes for different issues found in Winlogbeat after enabling CI testing for previously untested versions of Windows.

Two bugs have been fixed (only affected 32bit binaries):

  • Bad EVT_VARIANT struct definition, caused errors formatting events.
    The first field of the structure, a union, didn't have the right size when compiled for 32-bits, causing "invalid argument" errors when the struct was passed to an API. Also, some EVT_VARIANT types weren't being handled properly.

  • Failed to seek to a saved state in an .evtx file.
    This is caused by a helper tool in Go (mkwinsyscall) not generating correct syscall calls under GOARCH=386 (or any 32-bit arch). This only affects functions that receive a 64-bit parameter, in the case of Beats, only EvtSeek is affected. (Bug report).

The rest are changes to tests due to inconsistent behaviors of different Windows versions:

  • Remove formatting assertion in TestFormatMessage
    Under most Windows versions, GUID values cannot be substituted with string values. However, this is not the case under at least Win7 32bit. Just disable the testing assertion as it has no impact.

  • Disable TestFormatMessage/no_metadata tests
    Under Windows 10, event formatting is not failing with an error even though not metadata is being passed.

  • Check for errors on publishing events to an event log
    Under Windows 7 and Windows 10, writes to a newly created event log fail occasionally. It seems that there is a delay between when an event log is created and publishing events to it is allowed.

  • Sysmon: Ignore winlog.user.* fields during test
    For some reason, the following fields:

    • winlog.user.type
    • winlog.user.name
    • winlog.user.domain

    are not populated by the Sysmon module under Windows 7 32-bit. I couldn't reproduce outside of CI, where it's failing to lookup SID S-1-5-18.

Fixes #19798
Fixes #19829
Fixes #22046
Fixes #22302

@botelastic botelastic bot added the needs_team Indicates that the issue/PR needs a Team:* label label Nov 2, 2020
@botelastic botelastic bot removed the needs_team Indicates that the issue/PR needs a Team:* label label Nov 2, 2020
@adriansr adriansr added windows-10 Enable builds in the CI for windows-10 windows-2008 Enable builds in the CI for windows-2008 windows-2012 Enable builds in the CI for windows-2012 windows-2016 Enable builds in the CI for windows-2016 windows-7 Enable builds in the CI for windows-7 windows-7-32 Enable builds in the CI for windows-7 32 bits windows-8 Enable builds in the CI for windows-8 labels Nov 2, 2020
@adriansr adriansr force-pushed the wb_32bit_wineventlog branch from 5c6b19e to 833b5d0 Compare November 3, 2020 13:23
@elasticmachine
Copy link
Copy Markdown
Contributor

elasticmachine commented Nov 3, 2020

💚 Flaky test report

Tests succeeded.

Expand to view the summary

Test stats 🧪

Test Results
Failed 0
Passed 2192
Skipped 24
Total 2216

@elasticmachine
Copy link
Copy Markdown
Contributor

elasticmachine commented Nov 3, 2020

💚 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 #22362 updated]

  • Start Time: 2020-11-10T16:59:39.157+0000

  • Duration: 32 min 56 sec

Test stats 🧪

Test Results
Failed 0
Passed 2192
Skipped 24
Total 2216

@adriansr
Copy link
Copy Markdown
Contributor Author

adriansr commented Nov 3, 2020

jenkins, test this

@adriansr adriansr force-pushed the wb_32bit_wineventlog branch 3 times, most recently from a1e53f2 to 50b5421 Compare November 10, 2020 16:13
The first field of the structure, a union, didn't have the proper size
when compiled for 32-bits, causing "invalid argument" errors when the
struct was passed to an API.

Also, some EVT_VARIANT types weren't being handled properly.
Under most Windows versions, GUID values cannot be substituted with
string values. However, this is not the case under at least Win7 32bit.

Just disable the testing assertion as it has no impact.
Go's mkwinsyscall is generating syscall invocations that don't work properly
under GOARCH=386 (or any 32-bit arch). This only affects functions that
receive a 64-bit parameter, in this case only EvtSeek is affected.

This replaces `mkwinsyscall` with a patched one that adds some workaround
code.
Under Windows 10, event formatting is not failing with an error even though
not metadata is being passed.
Under Windows 7 and Windows 10, writes to a newly created event log fail
occasionally. It seems that there is a delay between when an event log is
created and publishing events to it is allowed.

This commit updates the tests to retry on failure when creating an event
log for testing.
For some reason, the following fields:
- winlog.user.type
- winlog.user.name
- winlog.user.domain

are not populated by the Sysmon module under Windows 7 32-bit. I couldn't
reproduce outside of CI, where it's failing to lookup SID `S-1-5-18`:

```
testing_windows.go:69: Expected and actual are different:
        --- Expected
        +++ Actual
        @@ -47,6 +47,3 @@
             "user": {
        -      "domain": "NT AUTHORITY",
        -      "identifier": "S-1-5-18",
        -      "name": "SYSTEM",
        -      "type": "Well Known Group"
        +      "identifier": "S-1-5-18"
             },
```

This commit updates the test to ignore those fields and removes them from
the golden files.
Under Windows 10, writing large events (31800 bytes) results in an empty
event log. Seems that the events are being silently dropped due to being
too big.
@adriansr adriansr force-pushed the wb_32bit_wineventlog branch from 50b5421 to 6834315 Compare November 10, 2020 16:58
@adriansr adriansr changed the title WIP: Winlogbeat 32-bit new eventlog Winlogbeat: Fix compatibility problems with newer OS versions in the support matrix Nov 10, 2020
@adriansr adriansr changed the title Winlogbeat: Fix compatibility problems with newer OS versions in the support matrix Winlogbeat: Fix compatibility problems with newer OS versions in CI Nov 10, 2020
@adriansr adriansr marked this pull request as ready for review November 10, 2020 17:40
@adriansr adriansr requested a review from a team as a code owner November 10, 2020 17:40
@elasticmachine
Copy link
Copy Markdown
Contributor

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

@adriansr adriansr requested review from a team and removed request for a team November 10, 2020 17:40
@adriansr adriansr added needs_backport PR is waiting to be backported to other branches. review labels Nov 10, 2020
Copy link
Copy Markdown
Member

@andrewkroh andrewkroh left a comment

Choose a reason for hiding this comment

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

LGTM. Thank you for tackling this.

func safeWriteEvent(t testing.TB, log *eventlog.Log, etype uint16, eid uint32, msgs []string) {
deadline := time.Now().Add(time.Second * 10)
for {
err := log.Report(etype, eid, msgs)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Curious what the story is behind this. What kind of temporary errors were you seeing?

Copy link
Copy Markdown
Contributor Author

@adriansr adriansr Nov 10, 2020

Choose a reason for hiding this comment

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

You get an access denied error if you try to publish too shortly after creating the event log

@adriansr adriansr merged commit d97fe08 into elastic:master Nov 11, 2020
adriansr added a commit to adriansr/beats that referenced this pull request Nov 24, 2020
…lastic#22362)

* Fix EVT_VARIANT struct definition for GOARCH=386

The first field of the structure, a union, didn't have the proper size
when compiled for 32-bits, causing "invalid argument" errors when the
struct was passed to an API.

Also, some EVT_VARIANT types weren't being handled properly.

* Remove formatting assertion in TestFormatMessage

Under most Windows versions, GUID values cannot be substituted with
string values. However, this is not the case under at least Win7 32bit.

Just disable the testing assertion as it has no impact.

* Update generated syscalls to avoid bug under 32-bit

Go's mkwinsyscall is generating syscall invocations that don't work properly
under GOARCH=386 (or any 32-bit arch). This only affects functions that
receive a 64-bit parameter, in this case only EvtSeek is affected.

This replaces `mkwinsyscall` with a patched one that adds some workaround
code.

* Enable all windows tests

* Disable TestFormatMessage/no_metadata tests

Under Windows 10, event formatting is not failing with an error even though
not metadata is being passed.

* Testing: Error check on publishing events to an event log

Under Windows 7 and Windows 10, writes to a newly created event log fail
occasionally. It seems that there is a delay between when an event log is
created and publishing events to it is allowed.

This commit updates the tests to retry on failure when creating an event
log for testing.

* Sysmon: Ignore winlog.user.* fields during test

For some reason, the following fields:
- winlog.user.type
- winlog.user.name
- winlog.user.domain

are not populated by the Sysmon module under Windows 7 32-bit. I couldn't
reproduce outside of CI, where it's failing to lookup SID `S-1-5-18`:

```
testing_windows.go:69: Expected and actual are different:
        --- Expected
        +++ Actual
        @@ -47,6 +47,3 @@
             "user": {
        -      "domain": "NT AUTHORITY",
        -      "identifier": "S-1-5-18",
        -      "name": "SYSTEM",
        -      "type": "Well Known Group"
        +      "identifier": "S-1-5-18"
             },
```

This commit updates the test to ignore those fields and removes them from
the golden files.

* Testing: limit event size in testWindowsEventLog

Under Windows 10, writing large events (31800 bytes) results in an empty
event log. Seems that the events are being silently dropped due to being
too big.

(cherry picked from commit d97fe08)
@adriansr adriansr added v7.11.0 and removed needs_backport PR is waiting to be backported to other branches. labels Nov 24, 2020
adriansr added a commit to adriansr/beats that referenced this pull request Nov 24, 2020
…lastic#22362)

* Fix EVT_VARIANT struct definition for GOARCH=386

The first field of the structure, a union, didn't have the proper size
when compiled for 32-bits, causing "invalid argument" errors when the
struct was passed to an API.

Also, some EVT_VARIANT types weren't being handled properly.

* Remove formatting assertion in TestFormatMessage

Under most Windows versions, GUID values cannot be substituted with
string values. However, this is not the case under at least Win7 32bit.

Just disable the testing assertion as it has no impact.

* Update generated syscalls to avoid bug under 32-bit

Go's mkwinsyscall is generating syscall invocations that don't work properly
under GOARCH=386 (or any 32-bit arch). This only affects functions that
receive a 64-bit parameter, in this case only EvtSeek is affected.

This replaces `mkwinsyscall` with a patched one that adds some workaround
code.

* Enable all windows tests

* Disable TestFormatMessage/no_metadata tests

Under Windows 10, event formatting is not failing with an error even though
not metadata is being passed.

* Testing: Error check on publishing events to an event log

Under Windows 7 and Windows 10, writes to a newly created event log fail
occasionally. It seems that there is a delay between when an event log is
created and publishing events to it is allowed.

This commit updates the tests to retry on failure when creating an event
log for testing.

* Sysmon: Ignore winlog.user.* fields during test

For some reason, the following fields:
- winlog.user.type
- winlog.user.name
- winlog.user.domain

are not populated by the Sysmon module under Windows 7 32-bit. I couldn't
reproduce outside of CI, where it's failing to lookup SID `S-1-5-18`:

```
testing_windows.go:69: Expected and actual are different:
        --- Expected
        +++ Actual
        @@ -47,6 +47,3 @@
             "user": {
        -      "domain": "NT AUTHORITY",
        -      "identifier": "S-1-5-18",
        -      "name": "SYSTEM",
        -      "type": "Well Known Group"
        +      "identifier": "S-1-5-18"
             },
```

This commit updates the test to ignore those fields and removes them from
the golden files.

* Testing: limit event size in testWindowsEventLog

Under Windows 10, writing large events (31800 bytes) results in an empty
event log. Seems that the events are being silently dropped due to being
too big.

(cherry picked from commit d97fe08)
adriansr added a commit that referenced this pull request Nov 24, 2020
…22362) (#22727)

* Fix EVT_VARIANT struct definition for GOARCH=386

The first field of the structure, a union, didn't have the proper size
when compiled for 32-bits, causing "invalid argument" errors when the
struct was passed to an API.

Also, some EVT_VARIANT types weren't being handled properly.

* Remove formatting assertion in TestFormatMessage

Under most Windows versions, GUID values cannot be substituted with
string values. However, this is not the case under at least Win7 32bit.

Just disable the testing assertion as it has no impact.

* Update generated syscalls to avoid bug under 32-bit

Go's mkwinsyscall is generating syscall invocations that don't work properly
under GOARCH=386 (or any 32-bit arch). This only affects functions that
receive a 64-bit parameter, in this case only EvtSeek is affected.

This replaces `mkwinsyscall` with a patched one that adds some workaround
code.

* Enable all windows tests

* Disable TestFormatMessage/no_metadata tests

Under Windows 10, event formatting is not failing with an error even though
not metadata is being passed.

* Testing: Error check on publishing events to an event log

Under Windows 7 and Windows 10, writes to a newly created event log fail
occasionally. It seems that there is a delay between when an event log is
created and publishing events to it is allowed.

This commit updates the tests to retry on failure when creating an event
log for testing.

* Sysmon: Ignore winlog.user.* fields during test

For some reason, the following fields:
- winlog.user.type
- winlog.user.name
- winlog.user.domain

are not populated by the Sysmon module under Windows 7 32-bit. I couldn't
reproduce outside of CI, where it's failing to lookup SID `S-1-5-18`:

```
testing_windows.go:69: Expected and actual are different:
        --- Expected
        +++ Actual
        @@ -47,6 +47,3 @@
             "user": {
        -      "domain": "NT AUTHORITY",
        -      "identifier": "S-1-5-18",
        -      "name": "SYSTEM",
        -      "type": "Well Known Group"
        +      "identifier": "S-1-5-18"
             },
```

This commit updates the test to ignore those fields and removes them from
the golden files.

* Testing: limit event size in testWindowsEventLog

Under Windows 10, writing large events (31800 bytes) results in an empty
event log. Seems that the events are being silently dropped due to being
too big.

(cherry picked from commit d97fe08)
adriansr added a commit that referenced this pull request Nov 24, 2020
…22362) (#22728)

* Fix EVT_VARIANT struct definition for GOARCH=386

The first field of the structure, a union, didn't have the proper size
when compiled for 32-bits, causing "invalid argument" errors when the
struct was passed to an API.

Also, some EVT_VARIANT types weren't being handled properly.

* Remove formatting assertion in TestFormatMessage

Under most Windows versions, GUID values cannot be substituted with
string values. However, this is not the case under at least Win7 32bit.

Just disable the testing assertion as it has no impact.

* Update generated syscalls to avoid bug under 32-bit

Go's mkwinsyscall is generating syscall invocations that don't work properly
under GOARCH=386 (or any 32-bit arch). This only affects functions that
receive a 64-bit parameter, in this case only EvtSeek is affected.

This replaces `mkwinsyscall` with a patched one that adds some workaround
code.

* Enable all windows tests

* Disable TestFormatMessage/no_metadata tests

Under Windows 10, event formatting is not failing with an error even though
not metadata is being passed.

* Testing: Error check on publishing events to an event log

Under Windows 7 and Windows 10, writes to a newly created event log fail
occasionally. It seems that there is a delay between when an event log is
created and publishing events to it is allowed.

This commit updates the tests to retry on failure when creating an event
log for testing.

* Sysmon: Ignore winlog.user.* fields during test

For some reason, the following fields:
- winlog.user.type
- winlog.user.name
- winlog.user.domain

are not populated by the Sysmon module under Windows 7 32-bit. I couldn't
reproduce outside of CI, where it's failing to lookup SID `S-1-5-18`:

```
testing_windows.go:69: Expected and actual are different:
        --- Expected
        +++ Actual
        @@ -47,6 +47,3 @@
             "user": {
        -      "domain": "NT AUTHORITY",
        -      "identifier": "S-1-5-18",
        -      "name": "SYSTEM",
        -      "type": "Well Known Group"
        +      "identifier": "S-1-5-18"
             },
```

This commit updates the test to ignore those fields and removes them from
the golden files.

* Testing: limit event size in testWindowsEventLog

Under Windows 10, writing large events (31800 bytes) results in an empty
event log. Seems that the events are being silently dropped due to being
too big.

(cherry picked from commit d97fe08)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

review v7.10.1 v7.11.0 windows-7-32 Enable builds in the CI for windows-7 32 bits windows-7 Enable builds in the CI for windows-7 windows-8 Enable builds in the CI for windows-8 windows-10 Enable builds in the CI for windows-10 windows-2008 Enable builds in the CI for windows-2008 windows-2012 Enable builds in the CI for windows-2012 windows-2016 Enable builds in the CI for windows-2016

Projects

None yet

3 participants