Skip to content
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
6 changes: 5 additions & 1 deletion lib/auth/grpcserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -2565,6 +2565,10 @@ func isDBLocalProxyTunnelCertReq(req *proto.UserCertsRequest) bool {
req.RequesterName == proto.UserCertsRequest_TSH_DB_LOCAL_PROXY_TUNNEL
}

// ErrNoMFADevices is returned when an MFA ceremony is performed without possible devices to
// complete the challenge with.
var ErrNoMFADevices = trace.AccessDenied("MFA is required to access this resource but user has no MFA devices; use 'tsh mfa add' to register MFA devices")

func userSingleUseCertsAuthChallenge(gctx *grpcContext, stream proto.AuthService_GenerateUserSingleUseCertsServer, mfaRequired proto.MFARequired) (*types.MFADevice, error) {
ctx := stream.Context()
auth := gctx.authServer
Expand All @@ -2576,7 +2580,7 @@ func userSingleUseCertsAuthChallenge(gctx *grpcContext, stream proto.AuthService
return nil, trace.Wrap(err)
}
if challenge.TOTP == nil && challenge.WebauthnChallenge == nil {
return nil, trace.AccessDenied("MFA is required to access this resource but user has no MFA devices; use 'tsh mfa add' to register MFA devices")
return nil, ErrNoMFADevices
}

challenge.MFARequired = mfaRequired
Expand Down
12 changes: 12 additions & 0 deletions lib/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"context"
"crypto/tls"
"encoding/json"
"errors"
"fmt"
"io"
"net"
Expand All @@ -30,6 +31,7 @@ import (
"time"

"github.com/gravitational/trace"
"github.com/gravitational/trace/trail"
"github.com/moby/term"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/propagation"
Expand Down Expand Up @@ -570,6 +572,16 @@ func (proxy *ProxyClient) IssueUserCertsWithMFA(ctx context.Context, params Reis

resp, err := stream.Recv()
if err != nil {
// Older versions will NOT reply with a MFARequired response in the
// challenge and will terminate the stream with an auth.ErrNoMFADevices error.
// In this case for all protocols other than SSH fall back to reissuing
// certs without MFA.
if errors.Is(trail.FromGRPC(err), auth.ErrNoMFADevices) {
if params.usage() != proto.UserCertsRequest_SSH {
return proxy.reissueUserCerts(ctx, CertCacheKeep, params)
}
}

return nil, trace.Wrap(err)
}
mfaChal := resp.GetMFAChallenge()
Expand Down