-
Notifications
You must be signed in to change notification settings - Fork 894
feat: add GPG forwarding to coder ssh #5482
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
Changes from 1 commit
b7bc639
c270898
6c10fa4
9ebf840
d85dc66
e203bf0
a90d3d6
e07d204
216c028
a0f70de
17c7f99
ed5ff26
130ddfd
9c6cfba
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,7 +44,7 @@ func (h *forwardedUnixHandler) HandleSSHRequest(ctx ssh.Context, _ *ssh.Server, | |
conn, ok := ctx.Value(ssh.ContextKeyConn).(*gossh.ServerConn) | ||
if !ok { | ||
h.log.Warn(ctx, "SSH unix forward request from client with no gossh connection") | ||
return false, []byte{} | ||
return false, nil | ||
} | ||
|
||
switch req.Type { | ||
|
@@ -53,7 +53,7 @@ func (h *forwardedUnixHandler) HandleSSHRequest(ctx ssh.Context, _ *ssh.Server, | |
err := gossh.Unmarshal(req.Payload, &reqPayload) | ||
if err != nil { | ||
h.log.Warn(ctx, "parse [email protected] request payload from client", slog.Error(err)) | ||
return false, []byte{} | ||
return false, nil | ||
} | ||
|
||
addr := reqPayload.SocketPath | ||
|
@@ -64,7 +64,7 @@ func (h *forwardedUnixHandler) HandleSSHRequest(ctx ssh.Context, _ *ssh.Server, | |
h.log.Warn(ctx, "SSH unix forward request for socket path that is already being forwarded (maybe to another client?)", | ||
slog.F("socket_path", addr), | ||
) | ||
return false, []byte{} | ||
return false, nil | ||
} | ||
|
||
// Create socket parent dir if not exists. | ||
|
@@ -76,7 +76,7 @@ func (h *forwardedUnixHandler) HandleSSHRequest(ctx ssh.Context, _ *ssh.Server, | |
slog.F("socket_path", addr), | ||
slog.Error(err), | ||
) | ||
return false, []byte{} | ||
return false, nil | ||
} | ||
|
||
ln, err := net.Listen("unix", addr) | ||
|
@@ -85,19 +85,20 @@ func (h *forwardedUnixHandler) HandleSSHRequest(ctx ssh.Context, _ *ssh.Server, | |
slog.F("socket_path", addr), | ||
slog.Error(err), | ||
) | ||
return false, []byte{} | ||
return false, nil | ||
} | ||
|
||
// The listener needs to successfully start before it can be added to | ||
// the map, so we don't have to worry about checking for an existing | ||
// listener. | ||
// | ||
// This is also what the upstream TCP version of this code does. | ||
h.Lock() | ||
h.forwards[addr] = ln | ||
h.Unlock() | ||
go func() { | ||
<-ctx.Done() | ||
h.Lock() | ||
ln, ok := h.forwards[addr] | ||
h.Unlock() | ||
if ok { | ||
_ = ln.Close() | ||
} | ||
_ = ln.Close() | ||
}() | ||
go func() { | ||
for { | ||
|
@@ -109,6 +110,7 @@ func (h *forwardedUnixHandler) HandleSSHRequest(ctx ssh.Context, _ *ssh.Server, | |
slog.Error(err), | ||
) | ||
} | ||
// closed below | ||
break | ||
deansheather marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
payload := gossh.Marshal(&forwardedStreamLocalPayload{ | ||
|
@@ -129,9 +131,14 @@ func (h *forwardedUnixHandler) HandleSSHRequest(ctx ssh.Context, _ *ssh.Server, | |
Bicopy(ctx, ch, c) | ||
}() | ||
} | ||
|
||
h.Lock() | ||
delete(h.forwards, addr) | ||
ln2, ok := h.forwards[addr] | ||
if ok && ln2 == ln { | ||
deansheather marked this conversation as resolved.
Show resolved
Hide resolved
|
||
delete(h.forwards, addr) | ||
} | ||
h.Unlock() | ||
_ = ln.Close() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is the ctx/cancel necessary at all since we manually close here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need the ctx.Done() goroutine to kill the listener so we can free up that goroutine when i.e. the connection dies, however if the listener errors we need to cancel the context so we can free up that goroutine as well. |
||
}() | ||
|
||
return true, nil | ||
|
Uh oh!
There was an error while loading. Please reload this page.