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

[v15] Remove tcp app session recording #45642

Merged
merged 2 commits into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 3 additions & 19 deletions lib/srv/app/connections_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -384,25 +384,9 @@ func (c *ConnectionsHandler) sessionStartTime(ctx context.Context) time.Time {
// newTCPServer creates a server that proxies TCP applications.
func (c *ConnectionsHandler) newTCPServer() (*tcpServer, error) {
return &tcpServer{
newAudit: func(ctx context.Context, sessionID string) (common.Audit, error) {
// Audit stream is using server context, not session context,
// to make sure that session is uploaded even after it is closed.
rec, err := c.newSessionRecorder(c.closeContext, c.sessionStartTime(ctx), sessionID)
if err != nil {
return nil, trace.Wrap(err)
}
audit, err := common.NewAudit(common.AuditConfig{
Emitter: c.cfg.Emitter,
Recorder: rec,
})
if err != nil {
return nil, trace.Wrap(err)
}

return audit, nil
},
hostID: c.cfg.HostID,
log: c.log,
emitter: c.cfg.Emitter,
hostID: c.cfg.HostID,
log: c.log,
}, nil
}

Expand Down
16 changes: 12 additions & 4 deletions lib/srv/app/tcpserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,17 @@ import (

apidefaults "github.com/gravitational/teleport/api/defaults"
apitypes "github.com/gravitational/teleport/api/types"
apievents "github.com/gravitational/teleport/api/types/events"
"github.com/gravitational/teleport/lib/events"
"github.com/gravitational/teleport/lib/srv/app/common"
"github.com/gravitational/teleport/lib/tlsca"
"github.com/gravitational/teleport/lib/utils"
)

type tcpServer struct {
newAudit func(ctx context.Context, sessionID string) (common.Audit, error)
hostID string
log *slog.Logger
emitter apievents.Emitter
hostID string
log *slog.Logger
}

// handleConnection handles connection from a TCP application.
Expand All @@ -55,14 +57,20 @@ func (s *tcpServer) handleConnection(ctx context.Context, clientConn net.Conn, i
return trace.Wrap(err)
}

audit, err := s.newAudit(ctx, identity.RouteToApp.SessionID)
audit, err := common.NewAudit(common.AuditConfig{
Emitter: s.emitter,
Recorder: events.WithNoOpPreparer(events.NewDiscardRecorder()),
})
if err != nil {
return trace.Wrap(err)
}

if err := audit.OnSessionStart(ctx, s.hostID, identity, app); err != nil {
return trace.Wrap(err)
}
defer func() {
// The connection context may be closed once the connection is closed.
ctx := context.Background()
if err := audit.OnSessionEnd(ctx, s.hostID, identity, app); err != nil {
s.log.WarnContext(ctx, "Failed to emit session end event for app.", "app", app.GetName(), "error", err)
}
Expand Down
Loading