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

[v10] Fix nil pointer exception when joining non-existent session #13846

Merged
merged 10 commits into from
Jun 29, 2022
5 changes: 4 additions & 1 deletion api/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2687,7 +2687,10 @@ func (c *Client) CreateSessionTracker(ctx context.Context, st types.SessionTrack
func (c *Client) GetSessionTracker(ctx context.Context, sessionID string) (types.SessionTracker, error) {
req := &proto.GetSessionTrackerRequest{SessionID: sessionID}
resp, err := c.grpc.GetSessionTracker(ctx, req, c.callOpts...)
return resp, trail.FromGRPC(err)
if err != nil {
return nil, trail.FromGRPC(err)
}
return resp, nil
}

// GetActiveSessionTrackers returns a list of active session trackers.
Expand Down
10 changes: 4 additions & 6 deletions lib/client/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -1950,7 +1950,6 @@ func (tc *TeleportClient) Join(ctx context.Context, mode types.SessionParticipan
if sessionID.Check() != nil {
return trace.Errorf("Invalid session ID format: %s", string(sessionID))
}
notFoundErrorMessage := fmt.Sprintf("session '%s' not found or it has ended", sessionID)

// connect to proxy:
if !tc.Config.ProxySpecified() {
Expand All @@ -1974,14 +1973,13 @@ func (tc *TeleportClient) Join(ctx context.Context, mode types.SessionParticipan
}

session, err := site.GetSessionTracker(ctx, string(sessionID))
if err != nil && !trace.IsNotFound(err) {
if err != nil {
if trace.IsNotFound(err) {
return trace.NotFound("session %q not found or it has ended", sessionID)
}
return trace.Wrap(err)
}

if session == nil {
return trace.NotFound(notFoundErrorMessage)
}

if session.GetSessionKind() != types.SSHSessionKind {
return trace.BadParameter("session joining is only supported for ssh sessions, not %q sessions", session.GetSessionKind())
}
Expand Down