Skip to content

Commit

Permalink
internal/coordinator/remote: set up enviroment for SSH clients
Browse files Browse the repository at this point in the history
Fixes golang/go#32430

Change-Id: I84281077328c864fb3ba6f81e3a4453848ce741e
Reviewed-on: https://go-review.googlesource.com/c/build/+/418104
Reviewed-by: Bryan Mills <[email protected]>
Reviewed-by: Jenny Rakoczy <[email protected]>
Run-TryBot: Ian Lance Taylor <[email protected]>
TryBot-Result: Gopher Robot <[email protected]>
  • Loading branch information
ianlancetaylor authored and Ian Lance Taylor committed Jul 20, 2022
1 parent 529c4e3 commit b00b977
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions internal/coordinator/remote/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@ func (ss *SSHServer) legacyIncomingSSHPostAuth(s gssh.Session, rb *Buildlet) {
}
}()
go func() {
ss.setupRemoteSSHEnv(bconf, workDir, f)
io.Copy(f, s) // stdin
}()
io.Copy(s, f) // stdout
Expand Down Expand Up @@ -476,13 +477,39 @@ func (ss *SSHServer) IncomingSSHPostAuth(s gssh.Session, rs *Session) {
}
}()
go func() {
ss.setupRemoteSSHEnv(bconf, workDir, f)
io.Copy(f, s) // stdin
}()
io.Copy(s, f) // stdout
cmd.Process.Kill()
cmd.Wait()
}

// setupRemoteSSHEnv sets up environment variables on the remote system.
// This makes the new SSH session easier to use for Go testing.
func (ss *SSHServer) setupRemoteSSHEnv(bconf *dashboard.BuildConfig, workDir string, f io.Writer) {
switch bconf.GOOS() {
default:
// A Unix system.
for _, env := range bconf.Env() {
fmt.Fprintln(f, env)
}
fmt.Fprintf(f, "GOPATH=%s/gopath\n", workDir)
fmt.Fprintf(f, "PATH=$PATH:%s/go/bin\n", workDir)
fmt.Fprintf(f, "export GOPATH PATH\n")
fmt.Fprintf(f, "cd %s/go/src\n", workDir)
case "windows":
for _, env := range bconf.Env() {
fmt.Fprintf(f, "set %s\n", env)
}
fmt.Fprintf(f, `set GOPATH=%s\gopath`+"\n", workDir)
fmt.Fprintf(f, `set PATH=$PATH;%s\go\bin`+"\n", workDir)
fmt.Fprintf(f, `cd %s\go\src`+"\n", workDir)
case "plan9":
// TODO
}
}

// WriteSSHPrivateKeyToTempFile writes a key to a temporary file on the local file system. It also
// sets the permissions on the file to what is expected by OpenSSH implementations of SSH.
func WriteSSHPrivateKeyToTempFile(key []byte) (path string, err error) {
Expand Down

0 comments on commit b00b977

Please sign in to comment.