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

wintest: new package to provide support for winlogbeat ingest node pipeline testing #31833

Merged
merged 8 commits into from
Jun 23, 2022

Conversation

efd6
Copy link
Contributor

@efd6 efd6 commented Jun 6, 2022

What does this PR do?

This adds infrastructure for testing ingest pipelines in winlogbeat.

Why is it important?

Winlogbeat's ingest pipelines are currently untested and provisional testing shows that there will be failures when testing is instituted. Tests will make it possible to fix these problems.

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.

Author's Checklist

  • Testing needs to be run with -p 1, otherwise there is contention for the container's network port if package test globbing is used.
  • The linter complaint can be completely ignored; it is due to staticcheck knowing that a t.Skip is a terminating statement and so that later uses are not ever executed. Tests are now passing, so no Skip is being done.
  • The tests are currently in unittest, but it could be argued they should be in integ test. I'm not wedded to either, but it was easier to work without build constraints. I don't believe that the CI is currently running the tests here, and I'm not sure how to wire them in. So help there would be appreciated.

Failing in Powershell:

--- FAIL: TestPowerShellIngest (25.85s)
    --- FAIL: TestPowerShellIngest/800.evtx.golden.json (0.00s)
        testing.go:158: unexpected ingest error for event 2: unexpected pipeline error: [scripting] Regular expression considered too many characters, pattern: [^(.+)\\((.+)\\)\\:\\s*(.+)?$], limit factor: [6], char limit: [1386], count: [1387], wrapped: [NonTerminatingError(Import-LocalizedData): \"Cannot find the W...], this limit can be changed by changed by the [script.painless.regex.limit-factor] setting
        testing.go:165: 
            	Error Trace:	testing.go:328
            	            				testing.go:165
            	Error:      	Field not documented
            	Test:       	TestPowerShellIngest/800.evtx.golden.json
            	Messages:   	Key '_temp.details' found in event is not documented.
        testing.go:165: 
            	Error Trace:	testing.go:328
            	            				testing.go:165
            	Error:      	Field not documented
            	Test:       	TestPowerShellIngest/800.evtx.golden.json
            	Messages:   	Key '_temp.user_parts' found in event is not documented.
        testing.go:158: unexpected ingest error for event 3: unexpected pipeline error: [scripting] Regular expression considered too many characters, pattern: [^(.+)\\((.+)\\)\\:\\s*(.+)?$], limit factor: [6], char limit: [1470], count: [1471], wrapped: [ParameterBinding(Out-Default): name=\"InputObject\"; value=\"Can...], this limit can be changed by changed by the [script.painless.regex.limit-factor] setting
        testing.go:165: 
            	Error Trace:	testing.go:328
            	            				testing.go:165
            	Error:      	Field not documented
            	Test:       	TestPowerShellIngest/800.evtx.golden.json
            	Messages:   	Key '_temp.details' found in event is not documented.
        testing.go:165: 
            	Error Trace:	testing.go:328
            	            				testing.go:165
            	Error:      	Field not documented
            	Test:       	TestPowerShellIngest/800.evtx.golden.json
            	Messages:   	Key '_temp.user_parts' found in event is not documented.
FAIL

Failing in Security:

--- FAIL: TestSecurityIngest (26.16s)
    --- FAIL: TestSecurityIngest/4706_WindowsSrv2016.evtx.golden.json (0.00s)
        testing.go:165: 
            	Error Trace:	testing.go:328
            	            				testing.go:165
            	Error:      	Field not documented
            	Test:       	TestSecurityIngest/4706_WindowsSrv2016.evtx.golden.json
            	Messages:   	Key 'winlog.trustAttribute' found in event is not documented.
        testing.go:165: 
            	Error Trace:	testing.go:328
            	            				testing.go:165
            	Error:      	Field not documented
            	Test:       	TestSecurityIngest/4706_WindowsSrv2016.evtx.golden.json
            	Messages:   	Key 'winlog.trustDirection' found in event is not documented.
        testing.go:165: 
            	Error Trace:	testing.go:328
            	            				testing.go:165
            	Error:      	Field not documented
            	Test:       	TestSecurityIngest/4706_WindowsSrv2016.evtx.golden.json
            	Messages:   	Key 'winlog.trustType' found in event is not documented.
    --- FAIL: TestSecurityIngest/4716_WindowsSrv2016.evtx.golden.json (0.00s)
        testing.go:165: 
            	Error Trace:	testing.go:328
            	            				testing.go:165
            	Error:      	Field not documented
            	Test:       	TestSecurityIngest/4716_WindowsSrv2016.evtx.golden.json
            	Messages:   	Key 'winlog.trustDirection' found in event is not documented.
        testing.go:165: 
            	Error Trace:	testing.go:328
            	            				testing.go:165
            	Error:      	Field not documented
            	Test:       	TestSecurityIngest/4716_WindowsSrv2016.evtx.golden.json
            	Messages:   	Key 'winlog.trustType' found in event is not documented.
        testing.go:165: 
            	Error Trace:	testing.go:328
            	            				testing.go:165
            	Error:      	Field not documented
            	Test:       	TestSecurityIngest/4716_WindowsSrv2016.evtx.golden.json
            	Messages:   	Key 'winlog.trustAttribute' found in event is not documented.
    --- FAIL: TestSecurityIngest/4741.evtx.golden.json (0.00s)
        testing.go:165: 
            	Error Trace:	testing.go:328
            	            				testing.go:165
            	Error:      	Field not documented
            	Test:       	TestSecurityIngest/4741.evtx.golden.json
            	Messages:   	Key 'winlog.computerObject.domain' found in event is not documented.
        testing.go:165: 
            	Error Trace:	testing.go:328
            	            				testing.go:165
            	Error:      	Field not documented
            	Test:       	TestSecurityIngest/4741.evtx.golden.json
            	Messages:   	Key 'winlog.computerObject.id' found in event is not documented.
        testing.go:165: 
            	Error Trace:	testing.go:328
            	            				testing.go:165
            	Error:      	Field not documented
            	Test:       	TestSecurityIngest/4741.evtx.golden.json
            	Messages:   	Key 'winlog.computerObject.name' found in event is not documented.
    --- FAIL: TestSecurityIngest/4742.evtx.golden.json (0.00s)
        testing.go:165: 
            	Error Trace:	testing.go:328
            	            				testing.go:165
            	Error:      	Field not documented
            	Test:       	TestSecurityIngest/4742.evtx.golden.json
            	Messages:   	Key 'winlog.computerObject.name' found in event is not documented.
        testing.go:165: 
            	Error Trace:	testing.go:328
            	            				testing.go:165
            	Error:      	Field not documented
            	Test:       	TestSecurityIngest/4742.evtx.golden.json
            	Messages:   	Key 'winlog.computerObject.id' found in event is not documented.
        testing.go:165: 
            	Error Trace:	testing.go:328
            	            				testing.go:165
            	Error:      	Field not documented
            	Test:       	TestSecurityIngest/4742.evtx.golden.json
            	Messages:   	Key 'winlog.computerObject.domain' found in event is not documented.
    --- FAIL: TestSecurityIngest/4743.evtx.golden.json (0.00s)
        testing.go:165: 
            	Error Trace:	testing.go:328
            	            				testing.go:165
            	Error:      	Field not documented
            	Test:       	TestSecurityIngest/4743.evtx.golden.json
            	Messages:   	Key 'winlog.computerObject.id' found in event is not documented.
        testing.go:165: 
            	Error Trace:	testing.go:328
            	            				testing.go:165
            	Error:      	Field not documented
            	Test:       	TestSecurityIngest/4743.evtx.golden.json
            	Messages:   	Key 'winlog.computerObject.name' found in event is not documented.
        testing.go:165: 
            	Error Trace:	testing.go:328
            	            				testing.go:165
            	Error:      	Field not documented
            	Test:       	TestSecurityIngest/4743.evtx.golden.json
            	Messages:   	Key 'winlog.computerObject.domain' found in event is not documented.
    --- FAIL: TestSecurityIngest/4908_WindowsSrv2016.evtx.golden.json (0.00s)
        testing.go:150: unexpected error: unexpected response status for simulate: 400 Bad Request (400): elasticsearch error (type=illegal_argument_exception): unexpected value type [class [Ljava.lang.String;]
            Root cause:
            [
              {
                "type": "illegal_argument_exception",
                "reason": "unexpected value type [class [Ljava.lang.String;]",
                "position": {
                  "offset": 0,
                  "start": 0,
                  "end": 0
                }
              }
            ]
    --- FAIL: TestSecurityIngest/security-windows2012_4674.evtx.golden.json (0.00s)
        testing.go:158: unexpected ingest error for event 0: unexpected pipeline error: Processor "script" with tag "Decode message table" in pipeline "" failed with message "For input string: \"%%1538\n\t\t\t\t%%1542\n\t\t\t\t\""
    --- FAIL: TestSecurityIngest/security-windows2012_4768.evtx.golden.json (0.00s)
        testing.go:197: Expected and actual are different:
            --- Expected
            +++ Actual
            @@ -63,4 +63,4 @@
                     "Forwardable",
            +        "Renewable",
                     "Renewable-ok",
            -        "Renewable",
                     "Name-canonicalize"
    --- FAIL: TestSecurityIngest/security-windows2012_4771.evtx.golden.json (0.00s)
        testing.go:197: Expected and actual are different:
            --- Expected
            +++ Actual
            @@ -58,4 +58,4 @@
                     "Forwardable",
            +        "Renewable",
                     "Renewable-ok",
            -        "Renewable",
                     "Name-canonicalize"
FAIL

Note that the final two failures in Security look to be due to instability in the ordering of addition to an array and this may need a fix in the comparison code in the module test.

How to test this PR locally

Related issues

Use cases

Screenshots

Logs

@efd6 efd6 self-assigned this Jun 6, 2022
@botelastic botelastic bot added needs_team Indicates that the issue/PR needs a Team:* label and removed needs_team Indicates that the issue/PR needs a Team:* label labels Jun 6, 2022
@efd6 efd6 force-pushed the wintest/docker branch from fdf49a6 to 8bf9afd Compare June 6, 2022 11:59
@elasticmachine
Copy link
Collaborator

elasticmachine commented Jun 6, 2022

💚 Flaky test report

Tests succeeded.

🤖 GitHub comments

To re-run your PR in the CI, just comment with:

  • /test : Re-trigger the build.

  • /package : Generate the packages and run the E2E tests.

  • /beats-tester : Run the installation tests with beats-tester.

  • run elasticsearch-ci/docs : Re-trigger the docs validation. (use unformatted text in the comment!)

@efd6 efd6 force-pushed the wintest/docker branch 5 times, most recently from ebe7550 to 67c624d Compare June 8, 2022 00:07
@efd6 efd6 marked this pull request as ready for review June 8, 2022 00:11
@efd6 efd6 requested review from a team as code owners June 8, 2022 00:11
@efd6 efd6 requested review from rdner and cmacknz and removed request for a team June 8, 2022 00:11
@elasticmachine
Copy link
Collaborator

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

@efd6 efd6 force-pushed the wintest/docker branch from 67c624d to b4d95fd Compare June 8, 2022 00:14
@efd6 efd6 force-pushed the wintest/docker branch 6 times, most recently from a52f1ac to 8dfeec6 Compare June 8, 2022 09:33
Copy link
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.

I'm part way through the changes. I'll finish up tomorrow. Looks good.

x-pack/winlogbeat/module/testing.go Show resolved Hide resolved
@efd6 efd6 force-pushed the wintest/docker branch 3 times, most recently from 231bcbd to dd6ae23 Compare June 9, 2022 06:11

// This list is constructed through iteration over a Java hashmap
// and so is not consistently ordered.
"winlog.event_data.TicketOptionsDescription",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The inconsistency in this could be avoided by using bit operations in the painless rather than the map iteration that is currently done.

I expect, but have not observed, that the same issue will be present in the AccessMaskDescription processing.

ctx.winlog.event_data.put("AccessMask", list);
}

ArrayList desc = new ArrayList();
for (entry in params.AccessMaskDescriptions.entrySet()) {
Copy link
Contributor Author

@efd6 efd6 Jun 9, 2022

Choose a reason for hiding this comment

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

The fix would be to iterate over the word size of the flags, e.g. for the AccessMaskDescription case

for (def b = 0; b < 32; b++) {
    long accessFlag = 1L << b;
    if (accessMask&accessFlag == accessFlag) {

and an appropriate access to the parameter map — maybe via a hex string format of the accessFlag if an integer map key is not possible.

The equivalent change can be made for TicketOptionsDescription at line 876 in this file.

@mergify
Copy link
Contributor

mergify bot commented Jun 9, 2022

This pull request is now in conflicts. Could you fix it? 🙏
To fixup this pull request, you can check out it locally. See documentation: https://help.github.com/articles/checking-out-pull-requests-locally/

git fetch upstream
git checkout -b wintest/docker upstream/wintest/docker
git merge upstream/main
git push upstream wintest/docker

@efd6 efd6 force-pushed the wintest/docker branch 2 times, most recently from 08fd54d to 8050192 Compare June 14, 2022 04:53
@efd6
Copy link
Contributor Author

efd6 commented Jun 14, 2022

AFAICS the E2E failures are unrelated.

@cmacknz
Copy link
Member

cmacknz commented Jun 14, 2022

AFAICS the E2E failures are unrelated.

Yes the E2E tests have been unstable for a few weeks, I am looking into disabling the flakiest ones when triggered from beats but not from agent.

@efd6 efd6 force-pushed the wintest/docker branch from 8050192 to 82205dd Compare June 15, 2022 10:11
x-pack/winlogbeat/magefile.go Show resolved Hide resolved
x-pack/winlogbeat/module/testing.go Outdated Show resolved Hide resolved
@efd6 efd6 force-pushed the wintest/docker branch from 82205dd to 72b5324 Compare June 23, 2022 00:01
@efd6
Copy link
Contributor Author

efd6 commented Jun 23, 2022

Rebased with the hope that the tests pass.

@efd6
Copy link
Contributor Author

efd6 commented Jun 23, 2022

E2E failure is unrelated, End-To-End Tests / fleet_ debian_10_arm64_fleet_mode_agent:

[2022-06-23T02:24:58.636Z] [INFO] withAPMEnv: is enabled.
Cannot get property 'shell_type' on null object

@efd6 efd6 merged commit a401b8e into elastic:main Jun 23, 2022
chrisberkhout pushed a commit that referenced this pull request Jun 1, 2023
…peline testing (#31833)

- powershell: fix regexp constraints in event 800 parameter detail processing
- security: fix documentation
- security: fix sidlist processing
- security: fix access mask and access list processing
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
8.4-candidate backport-skip Skip notification from the automated backport with mergify enhancement Winlogbeat
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants