mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
fix: Start SFTP sessions in user home (working directory) (#4549)
* fix: Start SFTP sessions in user home (working directory) This commit switches to our fork of `pkg/sftp` which includes a Server option for changing the current working directory. Attempt to upstream: https://github.com/pkg/sftp/pull/528 Supercedes and closes #4420 Fixes #3620 * Update fork
This commit is contained in:
+12
-1
@@ -448,7 +448,18 @@ func (a *agent) init(ctx context.Context) {
|
||||
"sftp": func(session ssh.Session) {
|
||||
session.DisablePTYEmulation()
|
||||
|
||||
server, err := sftp.NewServer(session)
|
||||
var opts []sftp.ServerOption
|
||||
// Change current working directory to the users home
|
||||
// directory so that SFTP connections land there.
|
||||
// https://github.com/coder/coder/issues/3620
|
||||
u, err := user.Current()
|
||||
if err != nil {
|
||||
a.logger.Warn(ctx, "get sftp working directory failed, unable to get current user", slog.Error(err))
|
||||
} else {
|
||||
opts = append(opts, sftp.WithServerWorkingDirectory(u.HomeDir))
|
||||
}
|
||||
|
||||
server, err := sftp.NewServer(session, opts...)
|
||||
if err != nil {
|
||||
a.logger.Debug(session.Context(), "initialize sftp server", slog.Error(err))
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user