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

[v13] Fix tsh relogin on not found errors #27974

Merged
merged 2 commits into from Jun 19, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/client/api.go
Expand Up @@ -586,7 +586,8 @@ func RetryWithRelogin(ctx context.Context, tc *TeleportClient, fn func() error)
func IsErrorResolvableWithRelogin(err error) bool {
// Assume that failed handshake is a result of expired credentials.
return utils.IsHandshakeFailedError(err) || utils.IsCertExpiredError(err) ||
trace.IsBadParameter(err) || trace.IsTrustError(err) || keys.IsPrivateKeyPolicyError(err) || trace.IsNotFound(err)
trace.IsBadParameter(err) || trace.IsTrustError(err) ||
keys.IsPrivateKeyPolicyError(err) || IsNoCredentialsError(err)
}

// GetProfile gets the profile for the specified proxy address, or
Expand Down
19 changes: 17 additions & 2 deletions lib/client/client_store.go
Expand Up @@ -14,6 +14,7 @@ limitations under the License.
package client

import (
"errors"
"net/url"
"os"
"time"
Expand Down Expand Up @@ -76,11 +77,25 @@ func (s *Store) AddKey(key *Key) error {
return nil
}

// ErrNoCredentials is returned by the client store when a specific key is not found.
// This error can be used to determine whether a client should retrieve new credentials,
// like how it is used with lib/client.RetryWithRelogin.
var ErrNoCredentials = trace.NotFound("no credentials")

// IsNoCredentialsError returns whether the given error is an ErrNoCredentials error.
func IsNoCredentialsError(err error) bool {
return errors.Is(err, ErrNoCredentials)
}

// GetKey gets the requested key with trusted the requested certificates. The key's
// trusted certs will be retrieved from the trusted certs store.
// trusted certs will be retrieved from the trusted certs store. If the key is not
// found or is missing data (certificates, etc.), then an ErrNoCredentials error
// is returned.
func (s *Store) GetKey(idx KeyIndex, opts ...CertOption) (*Key, error) {
key, err := s.KeyStore.GetKey(idx, opts...)
if err != nil {
if trace.IsNotFound(err) {
return nil, trace.Wrap(ErrNoCredentials, err.Error())
} else if err != nil {
return nil, trace.Wrap(err)
}

Expand Down