Skip to content

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

Closed

Description

@mafredri

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

Activity

  1. added
    api
    on Aug 22, 2022
  2. kylecarbs commented on Sep 23, 2022

    @kylecarbs
    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.

  3. added a commit that references this issue on Oct 21, 2022
    173b7a2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    api

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions