Skip to content

Commit

Permalink
agent regression fix
Browse files Browse the repository at this point in the history
  • Loading branch information
klizhentas committed Apr 17, 2017
1 parent ef0a8ee commit 9e1891f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/reversetunnel/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,9 @@ func (a *Agent) runHeartbeat(conn *ssh.Client) {
// when this happens, this is #1 issue we have right now with Teleport. So I'm making
// it EASY to see in the logs. This condition should never be permanent (like repeates
// every XX seconds)
log.Warn(err)
if err != nil {
log.Warn(err)
}

if err != nil || conn == nil {
select {
Expand Down
8 changes: 8 additions & 0 deletions lib/srv/sshserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -882,7 +882,14 @@ func (s *Server) handleAgentForward(ch ssh.Channel, req *ssh.Request, ctx *ctx)
if err != nil {
return trace.Wrap(err)
}
dirCloser := &utils.RemoveDirCloser{Path: socketDir}
socketPath := filepath.Join(socketDir, fmt.Sprintf("teleport-%v.socket", pid))
if err := os.Chown(socketDir, uid, gid); err != nil {
if err := dirCloser.Close(); err != nil {
log.Warn("failed to remove directory: %v", err)
}
return trace.ConvertSystemError(err)
}

agentServer := &teleagent.AgentServer{Agent: clientAgent}
err = agentServer.ListenUnixSocket(socketPath, uid, gid, 0600)
Expand All @@ -895,6 +902,7 @@ func (s *Server) handleAgentForward(ch ssh.Channel, req *ssh.Request, ctx *ctx)
ctx.setEnv(teleport.SSHAuthSock, socketPath)
ctx.setEnv(teleport.SSHAgentPID, fmt.Sprintf("%v", pid))
ctx.addCloser(agentServer)
ctx.addCloser(dirCloser)
ctx.Debugf("[SSH:node] opened agent channel for teleport user %v and socket %v", ctx.teleportUser, socketPath)
go agentServer.Serve()

Expand Down
11 changes: 11 additions & 0 deletions lib/utils/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,17 @@ import (
"github.com/gravitational/trace"
)

// RemoveDirCloser removes directory and all it's contents
// when Close is called
type RemoveDirCloser struct {
Path string
}

// Close removes directory and all it's contents
func (r *RemoveDirCloser) Close() error {
return trace.ConvertSystemError(os.RemoveAll(r.Path))
}

// IsFile returns true if a given file path points to an existing file
func IsFile(fp string) bool {
fi, err := os.Stat(fp)
Expand Down

0 comments on commit 9e1891f

Please sign in to comment.