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

SSH connection hand-over #38545

Merged
merged 18 commits into from
Feb 29, 2024
Merged

SSH connection hand-over #38545

merged 18 commits into from
Feb 29, 2024

Conversation

espadolini
Copy link
Contributor

@espadolini espadolini commented Feb 22, 2024

This PR implements SSH connection hand-over, allowing SSH connections to be resumed across different Teleport processes during a graceful shutdown procedure.

Implements part of #38183
Part of #30415

changelog: SSH connection resumption will now work during graceful upgrades of the Teleport agent

@espadolini espadolini marked this pull request as ready for review February 26, 2024 16:15
lib/resumption/handover_unix.go Outdated Show resolved Hide resolved
}
}

paths, firstErr := filterNonConnectableSockets(ctx, paths)
Copy link
Contributor

Choose a reason for hiding this comment

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

Got tripped up by the function naming here, which to me sounds like you're filtering out non-connectable sockets, consider chnaging to retainNonConnectableSockets or filterOutConnectableSockets

Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't we check firstErr for the case where len(paths) >= 1 but we got an error (i.e. we got an error after having already added some non-connectable sockets to paths)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We return (and then log into the void) an aggregate including firstErr, but we might as well clean up the paths that we got that we know are from sockets that exist and returned ECONNREFUSED before returning - a partial cleanup is better than no cleanup.

lib/resumption/handover_unix.go Outdated Show resolved Hide resolved
Comment on lines 99 to 102
lastErr = trace.ConvertSystemError(err)
}

return filtered, lastErr
Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like we only return lastErr = trace.ConvertSystemError(err) for errors that aren't os.ErrNotExist or syscall.ECONNREFUSED if they occurred on the last item in paths, which seems like a bug since there's nothing significant about the last item.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think it'd be super useful to collect all the errors, this is basically just to log the error to identify potential issues during cleanup (say, after changing the user that runs Teleport or something like that). That's why I'm only keeping the last one that occurred.

Copy link
Contributor

Choose a reason for hiding this comment

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

That reasoning doesn't really make sense to me, if we want to identify potential issues during cleanup then we'd want to see all the errors in case there were multiple different ones.

If you're adamant that this is the correct approach then I won't fight you further, but you should at least add a comment explaining why you're doing something non-standard.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm just not sure of what'll happen when we aggregate a potentially unbound amount of errors; I'm already kind of spooked by the potential for weirdness as we aggregate errors for all the Remove()s at the end of the cleanup function, and there's going to be a lot more existing sockets than sockets we decide to remove.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've capped the amount of errors when aggregating in f434358, in both retainNonConnectableSockets and handoverCleanup. WDYT?

lib/resumption/handover_unix.go Outdated Show resolved Hide resolved
lib/resumption/server_exchange.go Outdated Show resolved Hide resolved
lib/resumption/handover.go Outdated Show resolved Hide resolved
lib/resumption/handover.go Outdated Show resolved Hide resolved
lib/resumption/handover.go Show resolved Hide resolved
lib/resumption/handover_unix.go Outdated Show resolved Hide resolved

func (r *SSHServerWrapper) resumeConnection(entry *connEntry, conn net.Conn, remoteIP netip.Addr) {
if entry.remoteIP != remoteIP {
r.log.Warn("Resumable connection attempted resumption from a different remote address.")
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: isn't this an r.log.Error?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm a bit reluctant to run it as an error because it can kind of happen naturally even if there's no bad actors involved, just as a result of changing network conditions.

Comment on lines +71 to +75
var remoteIP netip.Addr
if t, _ := conn.RemoteAddr().(*net.TCPAddr); t != nil {
remoteIP, _ = netip.AddrFromSlice(t.IP)
}
remoteIP16 := remoteIP.As16()
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
var remoteIP netip.Addr
if t, _ := conn.RemoteAddr().(*net.TCPAddr); t != nil {
remoteIP, _ = netip.AddrFromSlice(t.IP)
}
remoteIP16 := remoteIP.As16()
var remoteIP netip.Addr
if t, ok := conn.RemoteAddr().(*net.TCPAddr); ok {
remoteIP, ok = netip.AddrFromSlice(t.IP)
if !ok {
r.log.Error("Failed to convert TCPAddr IP to netip.Addr")
return
}
} else {
r.log.Warn("Remote address is not a *net.TCPAddr, handover failed")
return
}
remoteIP16 := remoteIP.As16()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm comfortable leaving the remote IP slice as all zeroes and let the server decide if that's good enough or not, rather than prohibit it in the client side.

lib/resumption/handover.go Outdated Show resolved Hide resolved
@public-teleport-github-review-bot public-teleport-github-review-bot bot removed the request for review from kimlisa February 29, 2024 19:53
@espadolini espadolini added this pull request to the merge queue Feb 29, 2024
Merged via the queue into master with commit e8e88a2 Feb 29, 2024
33 checks passed
@espadolini espadolini deleted the espadolini/resumption-handover branch February 29, 2024 20:16
@public-teleport-github-review-bot

@espadolini See the table below for backport results.

Branch Result
branch/v15 Create PR

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.

3 participants