Conversation
There was a problem hiding this comment.
Convention: methods starting with make are just constructors - they always return an event.
Methods starting with on may or may not return an event (some of these just update the internal state for future events).
There was a problem hiding this comment.
Note to self to inline this.
There was a problem hiding this comment.
This is the new type which holds on to a lot of common state (so that we don't have to pass these values around every time we want to emit an event).
The other change worth noting is this thing only build events - it's up to the caller to decide whether the event gets emitted to the audit log, recorded to the session recording, or both.
There was a problem hiding this comment.
We've removed one layer of indirection here. An audit cache is associated to a single session, so the top level map of session ID to entry no longer needs to exist.
(And all the method signatures have been updated to remove the session ID argument)
There was a problem hiding this comment.
This callback is now purely authorization and no longer grabs the windowsUser variable - we get that from the client instead.
(There was actually a subtle bug here in that sometimes we would try to emit audit events before we had a Windows username.)
There was a problem hiding this comment.
Closing the connection on error was moved from audit.go (which is just about building audit events) to windows_server.go (where the rest of the connection management logic is.
There was a problem hiding this comment.
This test was moved to audit_test.go.
There was a problem hiding this comment.
Most of these tests got a bit simpler, as we no longer need to emit the event and then ask a mock emitter what was emitted, we just build the event and it's already the type we expect.
There was a problem hiding this comment.
The changes in this file look scary, but it's very mechanical.
- moved a bunch of constants to the top rather than repeat them dozens of times
- no longer need to build send/receive handlers and encode TDP messages - instead we operate on the new audit event builder in a strongly-typed manner
ibeckermayer
left a comment
There was a problem hiding this comment.
Logs are working for me
There was a problem hiding this comment.
I'm not super familiar with this code but isn't there potential for the username to empty if this is called before the username has been read and assigned in readClientUsername below? What are the implications if that happens?
There was a problem hiding this comment.
Yep, there is the potential. The implications are that the username would be missing from the audit event. This would only be the case if we failed to initialize a client in this branch:
2f4baae to
ae98b45
Compare
Our methods for emitting audit events take 10 arguments already, and we need to add more as part of the work in #30417. To make this more manageable, create an auditor struct that will hold on to state that is shared for all audit events in a session (ID, user identity, the desktop we're connecting to, etc.) As a result, the "audit cache" for directory sharing events is also simplified - we now create one of these per-session rather than maintaining one large cache for all sessions.
ae98b45 to
42c1cfc
Compare
|
Going to abandon the v13/v12 backports. I was only backporting this to those versions to try to avoid future conflicts, but there's conflicts here already. Edit: I want to see Telemetry for v13 agents, which will still be around for a bit, so I opened a manual v13 backport. |
Our methods for emitting audit events take 10 arguments already, and we need to add more as part of the work in #30417. To make this more manageable, create an auditor struct that will hold on to state that is shared for all audit events in a session (ID, user identity, the desktop we're connecting to, etc.)
As a result, the "audit cache" for directory sharing events is also simplified - we now create one of these per-session rather than maintaining one large cache for all sessions.