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

[supervisor] improve ssh connected behaviors #10736

Merged
merged 3 commits into from
Jun 21, 2022
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
36 changes: 35 additions & 1 deletion components/supervisor/pkg/supervisor/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"bufio"
"context"
"fmt"
"io/ioutil"
"net"
"os"
"os/exec"
Expand Down Expand Up @@ -85,7 +86,7 @@ func (s *sshServer) handleConn(ctx context.Context, conn net.Conn) {
}

args := []string{
"-iedD", "-f/dev/null",
"-ieD", "-f/dev/null",
"-oProtocol 2",
"-oAllowUsers gitpod",
"-oPasswordAuthentication no",
Expand Down Expand Up @@ -213,3 +214,36 @@ func writeSSHEnv(cfg *Config, envvars []string) error {

return nil
}

func configureSSHDefaultDir(cfg *Config) {
if cfg.RepoRoot == "" {
log.Error("cannot configure ssh default dir with empty repo root")
return
}
file, err := os.OpenFile("/home/gitpod/.bashrc", os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0o644)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

~/.ssh/rc with -oPermitUserRC not works, don't know why, so we choose .bashrc to do it

if err != nil {
log.WithError(err).Error("cannot write .bashrc")
}
defer file.Close()
if _, err := file.WriteString(fmt.Sprintf("\nif [[ -n $SSH_CONNECTION ]]; then cd \"%s\"; fi\n", cfg.RepoRoot)); err != nil {
log.WithError(err).Error("write .bashrc failed")
}
}

func configureSSHMessageOfTheDay() {
msg := []byte(`Welcome to Gitpod: Always ready to code. Try the following commands to get started:

gp tasks list List all your defined tasks in .gitpod.yml
gp tasks attach Attach your terminal to a workspace task

mustard-mh marked this conversation as resolved.
Show resolved Hide resolved
gp ports list Lists workspace ports and their states
gp stop Stop current workspace
gp help To learn about the gp CLI commands

For more information, see the Gitpod documentation: https://gitpod.io/docs
`)

if err := ioutil.WriteFile("/etc/motd", msg, 0o644); err != nil {
log.WithError(err).Error("write /etc/motd failed")
}
}
3 changes: 2 additions & 1 deletion components/supervisor/pkg/supervisor/supervisor.go
Original file line number Diff line number Diff line change
Expand Up @@ -1234,7 +1234,8 @@ func startSSHServer(ctx context.Context, cfg *Config, wg *sync.WaitGroup, childP
log.WithError(err).Error("err creating SSH server")
return
}

configureSSHDefaultDir(cfg)
configureSSHMessageOfTheDay()
err = ssh.listenAndServe()
if err != nil {
log.WithError(err).Error("err starting SSH server")
Expand Down