From 916fe5220c92b0143d2a2298b272bce3107d1a90 Mon Sep 17 00:00:00 2001 From: mustard Date: Mon, 20 Jun 2022 06:56:35 +0000 Subject: [PATCH 1/3] [supervisor] remove sshd debug mode --- components/supervisor/pkg/supervisor/ssh.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/supervisor/pkg/supervisor/ssh.go b/components/supervisor/pkg/supervisor/ssh.go index 67aa96967df148..c5b0534ea5e93f 100644 --- a/components/supervisor/pkg/supervisor/ssh.go +++ b/components/supervisor/pkg/supervisor/ssh.go @@ -85,7 +85,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", From 30d42494fea8276cff28cdbef311a12bf4bc937a Mon Sep 17 00:00:00 2001 From: mustard Date: Mon, 20 Jun 2022 06:57:26 +0000 Subject: [PATCH 2/3] [supervisor] change default directory of ssh --- components/supervisor/pkg/supervisor/ssh.go | 15 +++++++++++++++ .../supervisor/pkg/supervisor/supervisor.go | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/components/supervisor/pkg/supervisor/ssh.go b/components/supervisor/pkg/supervisor/ssh.go index c5b0534ea5e93f..d7416974b3cc6f 100644 --- a/components/supervisor/pkg/supervisor/ssh.go +++ b/components/supervisor/pkg/supervisor/ssh.go @@ -213,3 +213,18 @@ 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) + 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") + } +} diff --git a/components/supervisor/pkg/supervisor/supervisor.go b/components/supervisor/pkg/supervisor/supervisor.go index 37504bc44a3f28..a5d2a2084242df 100644 --- a/components/supervisor/pkg/supervisor/supervisor.go +++ b/components/supervisor/pkg/supervisor/supervisor.go @@ -1234,7 +1234,7 @@ func startSSHServer(ctx context.Context, cfg *Config, wg *sync.WaitGroup, childP log.WithError(err).Error("err creating SSH server") return } - + configureSSHDefaultDir(cfg) err = ssh.listenAndServe() if err != nil { log.WithError(err).Error("err starting SSH server") From 2c423a3fe3480ffe713a96030a01601229968837 Mon Sep 17 00:00:00 2001 From: mustard Date: Mon, 20 Jun 2022 06:58:27 +0000 Subject: [PATCH 3/3] [supervisor] welcome message for ssh conn --- components/supervisor/pkg/supervisor/ssh.go | 19 +++++++++++++++++++ .../supervisor/pkg/supervisor/supervisor.go | 1 + 2 files changed, 20 insertions(+) diff --git a/components/supervisor/pkg/supervisor/ssh.go b/components/supervisor/pkg/supervisor/ssh.go index d7416974b3cc6f..fe879592f07d0e 100644 --- a/components/supervisor/pkg/supervisor/ssh.go +++ b/components/supervisor/pkg/supervisor/ssh.go @@ -8,6 +8,7 @@ import ( "bufio" "context" "fmt" + "io/ioutil" "net" "os" "os/exec" @@ -228,3 +229,21 @@ func configureSSHDefaultDir(cfg *Config) { 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 + + 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") + } +} diff --git a/components/supervisor/pkg/supervisor/supervisor.go b/components/supervisor/pkg/supervisor/supervisor.go index a5d2a2084242df..a7ba8b6929a0b9 100644 --- a/components/supervisor/pkg/supervisor/supervisor.go +++ b/components/supervisor/pkg/supervisor/supervisor.go @@ -1235,6 +1235,7 @@ func startSSHServer(ctx context.Context, cfg *Config, wg *sync.WaitGroup, childP return } configureSSHDefaultDir(cfg) + configureSSHMessageOfTheDay() err = ssh.listenAndServe() if err != nil { log.WithError(err).Error("err starting SSH server")