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
21 changes: 21 additions & 0 deletions api/client/errors.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright 2024 Gravitational, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package client

import "github.com/gravitational/trace"

// ErrClientCredentialsHaveExpired means that the credentials expired on
// the server-side and the user should relogin.
var ErrClientCredentialsHaveExpired = &trace.AccessDeniedError{Message: "access denied: client credentials have expired, please relogin."}
2 changes: 1 addition & 1 deletion lib/auth/auth_with_roles.go
Original file line number Diff line number Diff line change
Expand Up @@ -2898,7 +2898,7 @@ func (a *ServerWithRoles) generateUserCerts(ctx context.Context, req proto.UserC
return nil, trace.AccessDenied("access denied")
}
if req.Expires.Before(a.authServer.GetClock().Now()) {
return nil, trace.AccessDenied("access denied: client credentials have expired, please relogin.")
return nil, trace.Wrap(client.ErrClientCredentialsHaveExpired)
}

if identity.Renewable || isRoleImpersonation(req) {
Expand Down
12 changes: 11 additions & 1 deletion lib/client/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,17 @@ func IsErrorResolvableWithRelogin(err error) bool {
// https://github.com/gravitational/teleport/pull/30578.
var remoteErr *interceptors.RemoteError
if errors.As(err, &remoteErr) {
return false
// Exception for the two "retryable" errors that come from RPCs.
//
// Since Connect no longer checks the user cert before making an RPC,
// it has to be able to properly recognize "expired certs" errors
// that come from the server (to show a re-login dialog).
//
// TODO(gzdunek): These manual checks should be replaced with retryable
// errors returned explicitly, as described below by codingllama.
isClientCredentialsHaveExpired := errors.Is(err, client.ErrClientCredentialsHaveExpired)
isTLSExpiredCertificate := strings.Contains(err.Error(), "tls: expired certificate")
return isClientCredentialsHaveExpired || isTLSExpiredCertificate
}

return keys.IsPrivateKeyPolicyError(err) ||
Expand Down