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] Display more user friendly error for invalid os logins in Web UI #47579

Merged
merged 1 commit into from
Oct 17, 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
4 changes: 4 additions & 0 deletions lib/web/apiserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7535,6 +7535,10 @@ type authProviderMock struct {
server types.ServerV2
}

func (mock authProviderMock) ListUnifiedResources(ctx context.Context, req *authproto.ListUnifiedResourcesRequest) (*authproto.ListUnifiedResourcesResponse, error) {
return nil, nil
}

func (mock authProviderMock) GetNode(ctx context.Context, namespace, name string) (types.Server, error) {
return &mock.server, nil
}
Expand Down
17 changes: 17 additions & 0 deletions lib/web/terminal.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"context"
"encoding/json"
"errors"
"fmt"
"io"
"net"
"net/http"
Expand Down Expand Up @@ -104,6 +105,7 @@ type UserAuthClient interface {
CreateAuthenticateChallenge(ctx context.Context, req *authproto.CreateAuthenticateChallengeRequest) (*authproto.MFAAuthenticateChallenge, error)
GenerateUserCerts(ctx context.Context, req authproto.UserCertsRequest) (*authproto.Certs, error)
MaintainSessionPresence(ctx context.Context) (authproto.AuthService_MaintainSessionPresenceClient, error)
ListUnifiedResources(ctx context.Context, req *authproto.ListUnifiedResourcesRequest) (*authproto.ListUnifiedResourcesResponse, error)
}

// NewTerminal creates a web-based terminal based on WebSockets and returns a
Expand Down Expand Up @@ -911,6 +913,21 @@ func (t *sshBaseHandler) connectToNode(ctx context.Context, ws terminal.WSConn,
// The close error is ignored instead of using [trace.NewAggregate] because
// aggregate errors do not allow error inspection with things like [trace.IsAccessDenied].
_ = conn.Close()

// Since connection attempts are made via UUID and not hostname, any access denied errors
// will not contain the resolved host address. To provide an easier troubleshooting experience
// for users, attempt to resolve the hostname of the server and augment the error message with it.
if trace.IsAccessDenied(err) {
if resp, err := t.userAuthClient.ListUnifiedResources(ctx, &authproto.ListUnifiedResourcesRequest{
SortBy: types.SortBy{Field: types.ResourceKind},
Kinds: []string{types.KindNode},
Limit: 1,
PredicateExpression: fmt.Sprintf(`resource.metadata.name == "%s"`, t.sessionData.ServerID),
}); err == nil && len(resp.Resources) > 0 {
return nil, trace.AccessDenied("access denied to %q connecting to %v", sshConfig.User, resp.Resources[0].GetNode().GetHostname())
}
}

return nil, trace.Wrap(err)
}

Expand Down
Loading