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 teleport networking subprocess for port/agent/x11 forwarding #43756

Merged
merged 45 commits into from
Aug 13, 2024

Conversation

Joerger
Copy link
Contributor

@Joerger Joerger commented Jul 2, 2024

Add a unified networking subprocess to handle port/agent/x11 forwarding requests. This subprocess is designed to run as the local user being connected to, including any modifications done to that user via the node's PAM stack.

Fixes #17029

Note: this also fixes agent/port forwarding on new auto-provisioned users, which previously failed on the first attempt (or always with insecure-drop). This worked with X11 forwarding before with a more intricate solution, which has been replaced with the simpler "run-as-user" method.

Closes #44479
Closes #43623

@Joerger Joerger changed the title add teleport networkingsubprocess for port/agent/x11 forwarding add teleport networking subprocess for port/agent/x11 forwarding Jul 2, 2024
@Joerger Joerger changed the title add teleport networking subprocess for port/agent/x11 forwarding Add teleport networking subprocess for port/agent/x11 forwarding Jul 2, 2024
@Joerger Joerger force-pushed the joerger/teleport-networking-subprocess branch from ed31990 to a58d9cb Compare July 4, 2024 00:30
@Joerger Joerger requested a review from espadolini July 4, 2024 00:52
@Joerger Joerger marked this pull request as ready for review July 4, 2024 00:52
Copy link

github-actions bot commented Jul 4, 2024

The PR changelog entry failed validation: Changelog entry not found in the PR body. Please add a "no-changelog" label to the PR, or changelog lines starting with changelog: followed by the changelog entries for the PR.

@github-actions github-actions bot requested review from AntonAM and r0mant July 4, 2024 00:53
@Joerger Joerger added the no-changelog Indicates that a PR does not require a changelog entry label Jul 4, 2024
@Joerger Joerger force-pushed the joerger/teleport-networking-subprocess branch 2 times, most recently from 0a5d488 to 7d965f1 Compare July 4, 2024 01:04
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.

lib/sshutils/networking would benefit from some package-level docstring to explain the IPC protocol, since socketpairs passed around like this can be a bit confusing for the reader.

lib/sshutils/networking/networking.go Outdated Show resolved Hide resolved
lib/sshutils/networking/networking.go Outdated Show resolved Hide resolved
lib/sshutils/networking/networking.go Outdated Show resolved Hide resolved
lib/sshutils/networking/networking.go Outdated Show resolved Hide resolved
lib/sshutils/networking/networking.go Outdated Show resolved Hide resolved
lib/srv/reexec.go Outdated Show resolved Hide resolved
lib/srv/reexec.go Outdated Show resolved Hide resolved
lib/srv/reexec.go Outdated Show resolved Hide resolved
var err error
err2 := conn.Control(func(descriptor uintptr) {
// Disable address reuse to prevent socket replacement.
err = syscall.SetsockoptInt(int(descriptor), syscall.SOL_SOCKET, syscall.SO_REUSEADDR, 0)
Copy link
Contributor

Choose a reason for hiding this comment

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

Is SO_REUSEADDR ever enabled by default?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Re-tested this and it seems it's only enabled by default for tcp listeners.

Copy link
Contributor

Choose a reason for hiding this comment

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

Is this necessary? If so, for what? SO_REUSEADDR allows listeners to be opened on top of sockets in TIME_WAIT state, opening multiple listeners on the same bind address at the same time is done with SO_REUSEPORT.

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 not sure, I've preserved this from the remote port forwarding implementation. @atburke is this check necessary for some purpose or can it be removed?

Copy link
Contributor

Choose a reason for hiding this comment

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

I believe SO_REUSEADDR was added here to prevent some malicious process from being able to hijack the address. You'd probably be able to get a more complete answer from @jentfoo.

lib/srv/reexec.go Show resolved Hide resolved
@Joerger Joerger force-pushed the joerger/teleport-networking-subprocess branch 3 times, most recently from d374507 to 8bad5d5 Compare July 10, 2024 00:44
@Joerger Joerger requested a review from espadolini July 10, 2024 01:32
lib/srv/reexec.go Outdated Show resolved Hide resolved
@Joerger Joerger requested a review from espadolini July 10, 2024 23:11
lib/srv/reexec.go Outdated Show resolved Hide resolved
@Joerger Joerger requested a review from espadolini July 17, 2024 00:47
lib/srv/reexec.go Outdated Show resolved Hide resolved
lib/srv/reexec.go Outdated Show resolved Hide resolved
lib/srv/reexec.go Outdated Show resolved Hide resolved
lib/srv/reexec.go Outdated Show resolved Hide resolved
lib/srv/reexec.go Outdated Show resolved Hide resolved
var err error
err2 := conn.Control(func(descriptor uintptr) {
// Disable address reuse to prevent socket replacement.
err = syscall.SetsockoptInt(int(descriptor), syscall.SOL_SOCKET, syscall.SO_REUSEADDR, 0)
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this necessary? If so, for what? SO_REUSEADDR allows listeners to be opened on top of sockets in TIME_WAIT state, opening multiple listeners on the same bind address at the same time is done with SO_REUSEPORT.

Comment on lines +703 to +722
// direct-streamlocal@openssh.com extension, we should revisit this multithreading limitation
// to prevent performance degradation.
Copy link
Contributor

@espadolini espadolini Jul 17, 2024

Choose a reason for hiding this comment

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

for future readers: possible options are:

  • doing manual async operations with nonblocking connect and select/epoll
  • opening some amount of goroutines that lock the OS thread and open a pam context, and fanning out operations to be done in one of these PAM-enabled threads

Comment on lines 698 to 709
// There are currently no known issues with tcp listen/dial in a multithreaded PAM context.
go handleNetworkingRequest(ctx, controlConn, req)
Copy link
Contributor

Choose a reason for hiding this comment

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

Until someone comes along and really wants to use a random pam module that does network namespacing 😬

lib/sshutils/networking/networking.go Outdated Show resolved Hide resolved
lib/sshutils/networking/networking.go Outdated Show resolved Hide resolved
lib/sshutils/networking/networking.go Outdated Show resolved Hide resolved
var err error
err2 := conn.Control(func(descriptor uintptr) {
// Disable address reuse to prevent socket replacement.
err = syscall.SetsockoptInt(int(descriptor), syscall.SOL_SOCKET, syscall.SO_REUSEADDR, 0)
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe SO_REUSEADDR was added here to prevent some malicious process from being able to hijack the address. You'd probably be able to get a more complete answer from @jentfoo.

@Joerger Joerger force-pushed the joerger/teleport-networking-subprocess branch from 701712b to dabdd1c Compare July 20, 2024 01:43
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.

Still 100% unconvinced about the utility of unsetting SO_REUSEADDR or of validateListenerSocket in general.

lib/sshutils/networking/networking.go Outdated Show resolved Hide resolved
lib/sshutils/networking/networking.go Outdated Show resolved Hide resolved
lib/sshutils/networking/networking.go Show resolved Hide resolved
lib/sshutils/networking/networking.go Outdated Show resolved Hide resolved
lib/sshutils/networking/networking.go Outdated Show resolved Hide resolved
lib/sshutils/networking/networking.go Outdated Show resolved Hide resolved
lib/sshutils/networking/networking.go Outdated Show resolved Hide resolved
lib/srv/reexec.go Outdated Show resolved Hide resolved
@Joerger Joerger force-pushed the joerger/teleport-networking-subprocess branch from dabdd1c to 57fba88 Compare July 22, 2024 20:14
@Joerger Joerger force-pushed the joerger/teleport-networking-subprocess branch from b9062c7 to d697c84 Compare July 27, 2024 02:27
@Joerger Joerger enabled auto-merge July 27, 2024 03:36
@rosstimothy rosstimothy disabled auto-merge July 29, 2024 13:03
@Joerger Joerger force-pushed the joerger/teleport-networking-subprocess branch from c6b5534 to 386ac4f Compare August 12, 2024 22:52
@Joerger Joerger force-pushed the joerger/teleport-networking-subprocess branch from 386ac4f to 9070a43 Compare August 13, 2024 01:23
@Joerger
Copy link
Contributor Author

Joerger commented Aug 13, 2024

@rosstimothy All tests are passing, just needs a flaky test skip. I double checked that TestRootNetworkingCommand isn't flaky, it just ends with an error when the flaky test detector times out at 10m.

@Joerger Joerger enabled auto-merge August 13, 2024 17:58
@rosstimothy
Copy link
Contributor

/excludeflake *

@Joerger Joerger added this pull request to the merge queue Aug 13, 2024
Merged via the queue into master with commit d26ca00 Aug 13, 2024
34 checks passed
@Joerger Joerger deleted the joerger/teleport-networking-subprocess branch August 13, 2024 22:19
@public-teleport-github-review-bot

@Joerger See the table below for backport results.

Branch Result
branch/v15 Failed
branch/v16 Failed

@webvictim
Copy link
Contributor

This PR was not backported because it introduces a lot of changes. It may be backported later, assuming the v17 test plan doesn't surface any issues with the new functionality.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
no-changelog Indicates that a PR does not require a changelog entry size/sm
Projects
None yet
6 participants