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

Improving SSH port forwarding audit logs #50932

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

eriktate
Copy link
Contributor

@eriktate eriktate commented Jan 9, 2025

This PR emits some additional events for SSH port forwarding and adds some context around local/remote when possible. The emitted events should look like the following:

  • Local port forwarding logs a start and end event per connection.
  • Remote port forwarding for the regular SSH server logs a start and end event per forwarding session as well as per connection.
  • Remote and local port forwarding for the forward SSH server log an event for everything, but the session-level events do not differentiate between remote/local.

Every event should contain the remote, local, and target address where applicable. For remote forwarding, session-level events will show the requester as the remote address whereas connection-level events should show the client address initiating the connection.

@github-actions github-actions bot added audit-log Issues related to Teleports Audit Log size/md labels Jan 9, 2025
fmt.Fprint(w, "Hello, world")
}))
t.Cleanup(tsrv.Close)
testSrvConn, err := net.Dial("tcp", tsrv.Listener.Addr().String())
Copy link
Contributor

Choose a reason for hiding this comment

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

is this a conn that needs to be closed on cleanup as well?

func (c *ServerContext) GetPortForwardEvent() apievents.PortForward {
sconn := c.ConnectionContext.ServerConn
func (c *ServerContext) GetPortForwardEvent(evType, code string) apievents.PortForward {
sconn := c.ServerConn
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggestion: Prefer being explicit over relying on the fact that ConnectionContext is embedded in ServerContext here

Suggested change
sconn := c.ServerConn
sconn := c. ConnectionContext.ServerConn

@@ -648,6 +648,47 @@ func (s *Server) Serve() {

succeeded = true

if err := s.EmitAuditEvent(ctx, &apievents.PortForward{
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this the right place to emit this event? Isn't this the entrypoint for all connections established to the forward server? Won't this cause the event to be emitted any time a user connects to an agentless host or a host in proxy recording mode?

Comment on lines +706 to +708
CloseCancel: func() {
s.connectionContext.Close()
},
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggestion: revert changes to preserve the original blame here

}

if err := utils.ProxyConn(ctx, client, server); err != nil {
s.logger.ErrorContext(ctx, "PROXY CONN FAILURE", "error", err)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggestion: remove the CAPS?

}
}

s.logger.ErrorContext(ctx, "PROXY CONN DONE")
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggestion: remove the CAPS?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
audit-log Issues related to Teleports Audit Log size/md
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants