Skip to content
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

Add remote port forwarding for Teleport nodes #38828

Merged
merged 2 commits into from
Mar 15, 2024
Merged

Conversation

atburke
Copy link
Contributor

@atburke atburke commented Mar 1, 2024

This change adds support for remote port forwarding (ssh -R) for Teleport nodes.

Changelog: Added remote port forwarding for Teleport nodes

Copy link
Contributor

@Joerger Joerger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lib/sshutils/utils.go Outdated Show resolved Hide resolved
lib/sshutils/tcpip.go Outdated Show resolved Hide resolved
lib/srv/regular/sshserver.go Outdated Show resolved Hide resolved
Copy link
Contributor

@espadolini espadolini left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

first pass

lib/sshutils/tcpip.go Show resolved Hide resolved
Comment on lines +105 to +96
if err != nil {
if !utils.IsOKNetworkError(err) {
log.WithError(err).Warn("failed to accept connection")
}
return
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The net/http server will check if the error is temporary and if so, it'll continue accepting after a small delay; it's a pattern that I've been using, but I'm not sure if it's actually necessary.

lib/sshutils/tcpip.go Show resolved Hide resolved
lib/srv/regular/sshserver.go Outdated Show resolved Hide resolved
Comment on lines 1275 to 1285
// Verify that reuse is not enabled on the socket
if reuseAddr, err := unix.GetsockoptInt(int(listenerFD.Fd()), unix.SOL_SOCKET, unix.SO_REUSEADDR); err != nil {
return trace.Wrap(err)
} else if reuseAddr != 0 {
return trace.AccessDenied("SO_REUSEADDR is enabled on the socket")
}
if reusePort, err := unix.GetsockoptInt(int(listenerFD.Fd()), unix.SOL_SOCKET, unix.SO_REUSEPORT); err != nil {
// Some systems may not support SO_REUSEPORT, so we ignore the error here
} else if reusePort != 0 {
return trace.AccessDenied("SO_REUSEPORT is enabled on the socket")
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we check GOOS to see which of those are supposed to be supported?

lib/srv/regular/sshserver.go Outdated Show resolved Hide resolved
lib/srv/regular/sshserver.go Outdated Show resolved Hide resolved
lib/srv/regular/sshserver.go Outdated Show resolved Hide resolved
lib/srv/regular/sshserver.go Outdated Show resolved Hide resolved
lib/srv/regular/sshserver.go Outdated Show resolved Hide resolved
lib/srv/regular/sshserver.go Outdated Show resolved Hide resolved

// remoteForwardingMap holds the remote port forwarding listeners that need
// to be closed when forwarding finishes, keyed by listen addr.
remoteForwardingMap utils.SyncMap[string, io.Closer]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there some extra synchronization that prevents new additions to remoteForwardingMap while the *Server is being closed or is closed?

lib/srv/regular/sshserver.go Show resolved Hide resolved
lib/srv/regular/sshserver.go Outdated Show resolved Hide resolved
lib/srv/regular/sshserver.go Outdated Show resolved Hide resolved
lib/srv/regular/sshserver.go Outdated Show resolved Hide resolved
_, fn, err := localConn.ReadWithFDs(nil, fbuf)
if err != nil || fn == 0 {
fileCh <- nil
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not entirely sure one can recvmsg() and get data and an error, but we shouldn't risk it:

Suggested change
_, fn, err := localConn.ReadWithFDs(nil, fbuf)
if err != nil || fn == 0 {
fileCh <- nil
}
if _, fn, _ := localConn.ReadWithFDs(nil, fbuf); fn == 0 {
fileCh <- nil
}

if err != nil || fn == 0 {
fileCh <- nil
}
fileCh <- fbuf[0]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might get stuck if the reader is gone.

Suggested change
fileCh <- fbuf[0]
select {
case fileCh <- fbuf[0]:
case <-proc.Done:
fbuf[0].Close()
}

@atburke atburke enabled auto-merge March 15, 2024 20:58
@atburke atburke added this pull request to the merge queue Mar 15, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Mar 15, 2024
@atburke atburke enabled auto-merge March 15, 2024 22:03
This change adds support for remote port forwarding (ssh -R) for
Teleport nodes.
@atburke atburke added this pull request to the merge queue Mar 15, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Mar 15, 2024
@atburke atburke added this pull request to the merge queue Mar 15, 2024
@atburke atburke removed this pull request from the merge queue due to a manual request Mar 15, 2024
@atburke atburke enabled auto-merge March 15, 2024 22:41
@atburke atburke added this pull request to the merge queue Mar 15, 2024
Merged via the queue into master with commit 491130b Mar 15, 2024
34 checks passed
@atburke atburke deleted the atburke/rpf-node branch March 15, 2024 23:17
@public-teleport-github-review-bot

@atburke See the table below for backport results.

Branch Result
branch/v15 Failed

atburke added a commit that referenced this pull request Mar 15, 2024
* Add remote port forwarding for Teleport nodes

This change adds support for remote port forwarding (ssh -R) for
Teleport nodes.

* Fix windows build
atburke added a commit that referenced this pull request Mar 16, 2024
* Add remote port forwarding for Teleport nodes

This change adds support for remote port forwarding (ssh -R) for
Teleport nodes.

* Fix windows build
atburke added a commit that referenced this pull request Mar 16, 2024
* Add remote port forwarding for Teleport nodes

This change adds support for remote port forwarding (ssh -R) for
Teleport nodes.

* Fix windows build
github-merge-queue bot pushed a commit that referenced this pull request Mar 16, 2024
* Add remote port forwarding for Teleport nodes

This change adds support for remote port forwarding (ssh -R) for
Teleport nodes.

* Fix windows build
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants