@@ -33,9 +33,9 @@ func newSSHServer(ctx context.Context, cfg *Config, envvars []string) (*sshServe
33
33
return nil , xerrors .Errorf ("unexpected error creating SSH key: %w" , err )
34
34
}
35
35
}
36
- err = writeSSHEnv (cfg , envvars )
36
+ err = ensureSSHDir (cfg )
37
37
if err != nil {
38
- return nil , xerrors .Errorf ("unexpected error creating SSH env : %w" , err )
38
+ return nil , xerrors .Errorf ("unexpected error creating SSH dir : %w" , err )
39
39
}
40
40
41
41
return & sshServer {
@@ -103,6 +103,18 @@ func (s *sshServer) handleConn(ctx context.Context, conn net.Conn) {
103
103
"-oLogLevel DEBUG" , // enabled DEBUG mode by default
104
104
}
105
105
106
+ envs := make ([]string , 0 )
107
+ for _ , env := range s .envvars {
108
+ s := strings .SplitN (env , "=" , 2 )
109
+ if len (s ) != 2 {
110
+ continue
111
+ }
112
+ envs = append (envs , fmt .Sprintf ("%s=%s" , s [0 ], fmt .Sprintf ("\" %s\" " , strings .ReplaceAll (s [1 ], "\" " , "\\ \" " ))))
113
+ }
114
+ if len (envs ) > 0 {
115
+ args = append (args , fmt .Sprintf ("-oSetEnv %s" , strings .Join (envs , " " )))
116
+ }
117
+
106
118
socketFD , err := conn .(* net.TCPConn ).File ()
107
119
if err != nil {
108
120
log .WithError (err ).Error ("cannot start SSH server" )
@@ -189,21 +201,14 @@ func prepareSSHKey(ctx context.Context, sshkey string) error {
189
201
return nil
190
202
}
191
203
192
- func writeSSHEnv (cfg * Config , envvars [] string ) error {
204
+ func ensureSSHDir (cfg * Config ) error {
193
205
home := "/home/gitpod"
194
206
195
207
d := filepath .Join (home , ".ssh" )
196
208
err := os .MkdirAll (d , 0o700 )
197
209
if err != nil {
198
210
return xerrors .Errorf ("cannot create $HOME/.ssh: %w" , err )
199
211
}
200
-
201
- fn := filepath .Join (d , "supervisor_env" )
202
- err = os .WriteFile (fn , []byte (strings .Join (envvars , "\n " )), 0o644 )
203
- if err != nil {
204
- return xerrors .Errorf ("cannot write %s: %w" , fn , err )
205
- }
206
-
207
212
_ = exec .Command ("chown" , "-R" , fmt .Sprintf ("%d:%d" , gitpodUID , gitpodGID ), d ).Run ()
208
213
209
214
return nil
0 commit comments