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
13 changes: 12 additions & 1 deletion lib/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -722,7 +722,18 @@ func (c *NodeClient) TransferFiles(ctx context.Context, cfg *sftp.Config) error
)
defer span.End()

return trace.Wrap(cfg.TransferFiles(ctx, c.Client.Client))
if err := cfg.TransferFiles(ctx, c.Client.Client); err != nil {
// TODO(tross): DELETE IN 19.0.0 - Older versions of Teleport would return
// a trace.BadParameter error when ~user path expansion was rejected, and
// reauthentication logic is attempted on BadParameter errors.
if trace.IsBadParameter(err) && strings.Contains(err.Error(), "expanding remote ~user paths is not supported") {
return trace.Wrap(&NonRetryableError{Err: err})
}

return trace.Wrap(err)
}

return nil
}

type netDialer interface {
Expand Down
16 changes: 13 additions & 3 deletions lib/sshutils/sftp/sftp.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,21 +329,31 @@ func (c *Config) expandPaths(srcIsRemote, dstIsRemote bool) (err error) {
for i, srcPath := range c.srcPaths {
c.srcPaths[i], err = expandPath(srcPath)
if err != nil {
return trace.Wrap(err, "error expanding %q", srcPath)
return trace.Wrap(err)
}
}
}

if dstIsRemote {
c.dstPath, err = expandPath(c.dstPath)
if err != nil {
return trace.Wrap(err, "error expanding %q", c.dstPath)
return trace.Wrap(err)
}
}

return nil
}

// PathExpansionError is an [error] indicating that
// path expansion was rejected.
type PathExpansionError struct {
path string
}

func (p PathExpansionError) Error() string {
return fmt.Sprintf("expanding remote ~user paths is not supported, specify an absolute path instead of %q", p.path)
}

func expandPath(pathStr string) (string, error) {
pfxLen, ok := homeDirPrefixLen(pathStr)
if !ok {
Expand All @@ -358,7 +368,7 @@ func expandPath(pathStr string) (string, error) {
return ".", nil
}
if pfxLen == 1 && len(pathStr) > 1 {
return "", trace.BadParameter("expanding remote ~user paths is not supported, specify an absolute path instead")
return "", trace.Wrap(PathExpansionError{path: pathStr})
}

// if an SFTP path is not absolute, it is assumed to start at the user's
Expand Down
3 changes: 1 addition & 2 deletions lib/sshutils/sftp/sftp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import (
"testing"

"github.com/google/go-cmp/cmp"
"github.com/gravitational/trace"
"github.com/stretchr/testify/require"

"github.com/gravitational/teleport/lib/utils"
Expand Down Expand Up @@ -585,7 +584,7 @@ func TestHomeDirExpansion(t *testing.T) {
name: "~user path",
path: "~user/foo",
errCheck: func(t require.TestingT, err error, i ...interface{}) {
require.True(t, trace.IsBadParameter(err))
require.ErrorIs(t, err, PathExpansionError{path: "~user/foo"})
},
},
}
Expand Down