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

[receiver/windowseventlogreceiver] Add remote log collection support #33601

Conversation

JonathanWamsley
Copy link
Contributor

@JonathanWamsley JonathanWamsley commented Jun 17, 2024

Description:

This PR adds remote log collection for the windows event log receiver.
A config supports a single server configuration, multiple servers with multiple credentials configuration and multiple servers with single credentials configuration.

Link to tracking Issue:
#33100

Testing:
Added relevant test to the test files that existed.
This was tested on a single remote and with a valid / invalid remote to ensure successful collection of logs. Gather local logs was also tested to make sure old functionality is consistent too.

Documentation:
Updated Read me documentation

@JonathanWamsley JonathanWamsley marked this pull request as ready for review June 17, 2024 18:15
@JonathanWamsley JonathanWamsley requested a review from a team June 17, 2024 18:15
Copy link
Contributor

@pjanotti pjanotti left a comment

Choose a reason for hiding this comment

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

Nice!

My main feedback is regarding failure to reach one server causing others to be ignored. The other is that omitting the credentials should be allowed, meaning that the credentials of the current user will be used instead.

pkg/stanza/operator/input/windows/api.go Show resolved Hide resolved

// RemoteGroup is a group of remote servers.
type RemoteGroup struct {
Credentials RemoteCredentials `mapstructure:",squash"`
Copy link
Contributor

Choose a reason for hiding this comment

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

This may be better was a pointer so if omitted you could use the current user credentials by passing NULL for user, password, and domain - see https://learn.microsoft.com/en-us/windows/win32/wes/accessing-remote-computers

Copy link
Contributor

Choose a reason for hiding this comment

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

It will be fine to do it in a separate PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will look more into this after applying initial feedback.

pkg/stanza/operator/input/windows/input.go Outdated Show resolved Hide resolved
pkg/stanza/operator/input/windows/api.go Outdated Show resolved Hide resolved
receiver/windowseventlogreceiver/README.md Show resolved Hide resolved
pkg/stanza/operator/input/windows/subscription.go Outdated Show resolved Hide resolved
@JonathanWamsley JonathanWamsley force-pushed the windowseventlogreceiver-remote-collection branch 2 times, most recently from 4f70195 to 194da09 Compare June 18, 2024 15:52
@JonathanWamsley JonathanWamsley force-pushed the windowseventlogreceiver-remote-collection branch 2 times, most recently from e2f76ef to c883a5e Compare June 19, 2024 17:25
Copy link
Contributor

@pjanotti pjanotti left a comment

Choose a reason for hiding this comment

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

@JonathanWamsley could you please add a test? It will have to be skipped on CI but at least one could run it locally when updating the feature. It could check for some env var, TEST_REMOTE_WINDOWS_EVENTLOG_* where one could put the server and credentials. When these are not defined than the test is skipped.

pkg/stanza/operator/input/windows/api.go Outdated Show resolved Hide resolved
pkg/stanza/operator/input/windows/api.go Outdated Show resolved Hide resolved
pkg/stanza/operator/input/windows/input.go Outdated Show resolved Hide resolved
#### Remote Configuration

If collection of the local event log is desired, a separate receiver needs to be created.

Copy link
Contributor

Choose a reason for hiding this comment

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

We need also to include a mention of the requirements on the remote server:

the remote computer must enable the "Remote Event Log Management" Windows Firewall exception; otherwise, when you try to use the session handle, the call will error with RPC_S_SERVER_UNAVAILABLE. The computer to which you are connecting must be running Windows Vista or later.

Source: https://learn.microsoft.com/en-us/windows/win32/wes/accessing-remote-computers

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated in readme @pjanotti

@crobert-1 crobert-1 added the Run Windows Enable running windows test on a PR label Jun 20, 2024
@JonathanWamsley JonathanWamsley force-pushed the windowseventlogreceiver-remote-collection branch 2 times, most recently from 574734d to c87ec8a Compare June 25, 2024 14:55
@JonathanWamsley JonathanWamsley force-pushed the windowseventlogreceiver-remote-collection branch from 1cc9d3c to 631954a Compare June 26, 2024 13:45
@JonathanWamsley
Copy link
Contributor Author

Hey @djaglowski , I believe every time I update and run the CI tests, a different test fails with the exception of 2 of them in the last couple iterations. I don't think they are specific to the changes I made. I have not seen the tests fail from what I have created. Is there something else that needs to be done? Thanks.

@djaglowski
Copy link
Member

We seems to be struggling with flaky tests. I believe some have been unrelated, but there is at least one WEL test which failed the most recent run: https://github.com/open-telemetry/opentelemetry-collector-contrib/actions/runs/10145674230/job/28051942532?pr=33601#step:6:245

@djaglowski djaglowski merged commit 35fb4a2 into open-telemetry:main Aug 7, 2024
170 checks passed
@github-actions github-actions bot added this to the next release milestone Aug 7, 2024
@JonathanWamsley JonathanWamsley deleted the windowseventlogreceiver-remote-collection branch August 8, 2024 13:31
@@ -31,6 +31,7 @@ type EventXML struct {
Security *Security `xml:"System>Security"`
Execution *Execution `xml:"System>Execution"`
EventData EventData `xml:"EventData"`
RemoteServer string `xml:"RemoteServer,omitempty"`
Copy link
Member

Choose a reason for hiding this comment

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

@JonathanWamsley @pjanotti Do we actually ever expect this field to be present in the XML? Looking at this more closely I think maybe we just added it to the struct so it could be passed along conveniently, but we're always setting it based on the config value. Does that seem right?

Copy link
Contributor

Choose a reason for hiding this comment

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

Good point @djaglowski - the same information is already on the event XML returned by the event APIs, see https://learn.microsoft.com/en-us/windows/win32/wes/eventschema-computer-systempropertiestype-element

We don't need this field.

Copy link
Member

Choose a reason for hiding this comment

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

I went ahead and moved the remote server info to an attribute in #34720, but if it's always the same value then I suppose we don't even need the attribute. Any idea how to assess if these might sometimes be different in a meaningful way?

Copy link
Contributor

Choose a reason for hiding this comment

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

Per doc above, Computer records where the event happened. This sounds to me that it can be different than the remote computer that we are targeting. @JonathanWamsley can you help us by testing that?

f7o pushed a commit to f7o/opentelemetry-collector-contrib that referenced this pull request Sep 12, 2024
…pen-telemetry#33601)

**Description:** <Describe what has changed.>
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue.
Ex. Adding a feature - Explain what this achieves.-->
This PR adds remote log collection for the windows event log receiver. 
A config supports a single server configuration, multiple servers with
multiple credentials configuration and multiple servers with single
credentials configuration.

**Link to tracking Issue:** <Issue number if applicable>
open-telemetry#33100 

**Testing:** <Describe what testing was performed and which tests were
added.>
Added relevant test to the test files that existed.
This was tested on a single remote and with a valid / invalid remote to
ensure successful collection of logs. Gather local logs was also tested
to make sure old functionality is consistent too.

**Documentation:** <Describe the documentation added.>
Updated Read me documentation

---------

Co-authored-by: Daniel Jaglowski <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg/stanza receiver/windowseventlog Run Windows Enable running windows test on a PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants