Skip to content

SFTP sessions start in /tmp/coder.KnYnxH (instead of $HOME) #3620

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

Closed
mafredri opened this issue Aug 22, 2022 · 1 comment · Fixed by #4549
Closed

SFTP sessions start in /tmp/coder.KnYnxH (instead of $HOME) #3620

mafredri opened this issue Aug 22, 2022 · 1 comment · Fixed by #4549
Labels
api Area: HTTP API

Comments

@mafredri
Copy link
Member

Since we are starting the coder agent in the tmpdir, SFTP sessions also start in that folder.

Arguably, the session should start in $HOME because this is my experience with OpenSSH and it's more useful when doing sftp followed by ls (list files) or doing something with home-relative paths.

sftp coder.work.main
Connected to coder.work.main.
sftp> pwd
Remote working directory: /tmp/coder.KnYnxH

There are (potentially) two ways to fix this:

  1. Run os.Chdir in an early part of coder agent startup to change the default working directory by anything started by the agent
  2. Switch out sftp.Server for sftp.RequestServer (e.g. sftp.NewRequestServer(session, sftp.InMemHandler(), sftp.WithStartDirectory(os.Getenv("HOME"))))

Re: 2, I don't know if sftp.RequestServer can work as a drop-in replacement, the documentation is quite vague.

Definition of done

  • The user lands in $HOME when using sftp
@mafredri mafredri added bug api Area: HTTP API labels Aug 22, 2022
@kylecarbs
Copy link
Member

I investigated this a bit... it's quite involved.

We'll have to implement file handlers ourselves since their implementation is in-memory only. See: https://github.com/pkg/sftp/blob/811ed177f06e87f233019bf6eb908c0c73095d15/request-example.go#L24

Apart from that, it seems like we could just swap it out.

mafredri added a commit that referenced this issue Oct 7, 2022
This is a simple fix for #3620 by changing the working directory of
`coder agent` at runtime.

Since the agent doesn't write files to it's working directory, I can't
think of any downsides to this method. It does not, however, exclude
that we rewrite the SFTP implementation to use the modernized
`RequestServer` sometime in the future.

Opted to place this in agent init vs `cli/agent` because of portability
of fix, tests don't usually use `cli/agent`.

Fixes #3620
mafredri added a commit that referenced this issue Oct 14, 2022
This commit switches to our fork of `pkg/sftp` which includes a Server
option for changing the current working directory.

Attempt to upstream: pkg/sftp#528

Supercedes and closes #4420

Fixes #3620
mafredri added a commit that referenced this issue Oct 14, 2022
This commit switches to our fork of `pkg/sftp` which includes a Server
option for changing the current working directory.

Attempt to upstream: pkg/sftp#528

Supercedes and closes #4420

Fixes #3620
kylecarbs pushed a commit that referenced this issue Oct 21, 2022
* 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: pkg/sftp#528

Supercedes and closes #4420

Fixes #3620

* Update fork
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api Area: HTTP API
Projects
None yet
2 participants