Skip to content

agent regression fix #936

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

Merged
merged 1 commit into from
Apr 17, 2017
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
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