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

Fix remote port forwarding reporting wrong hostname #48831

Merged
merged 1 commit into from
Nov 14, 2024

Conversation

atburke
Copy link
Contributor

@atburke atburke commented Nov 12, 2024

This change fixes a bug in remote port forwarding where Teleport reports the hostname from the created remote listener, rather than the hostname requested in the tcpip-forward request. In particular, clients that request a listener at localhost would eventually receive a forwarded-tcpip channel request from 127.0.0.1, which the client would not be able to map to the listener it requested.

Fixes #48254.

Changelog: Fixed OpenSSH remote port forwarding not working for localhost

Copy link

This pull request is automatically being deployed by Amplify Hosting (learn more).

Access this pull request here: https://pr-48831.d3pp5qlev8mo18.amplifyapp.com

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.

Tested with root/leaf Teleport/Agentless nodes 👍

@rosstimothy rosstimothy requested a review from eriktate November 13, 2024 14:26
// Dial the test server over the SSH connection.
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
t.Cleanup(cancel)
req, err := http.NewRequestWithContext(ctx, http.MethodGet, ts.URL, &bytes.Buffer{})
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
req, err := http.NewRequestWithContext(ctx, http.MethodGet, ts.URL, &bytes.Buffer{})
req, err := http.NewRequestWithContext(ctx, http.MethodGet, ts.URL, nil)

Comment on lines 752 to 753
client := &http.Client{}
resp, err := client.Do(req)
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
client := &http.Client{}
resp, err := client.Do(req)
resp, err := ts.Client().Do(req)

@@ -2194,8 +2194,17 @@ func (s *Server) handleTCPIPForwardRequest(ctx context.Context, ccx *sshutils.Co
return trace.Wrap(err)
}

// Set the src addr again since it may have been updated with a new port.
scx.SrcAddr = listener.Addr().String()
// Update the src addr port.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggestion: expand this comment to include why this needs to happen.

@public-teleport-github-review-bot public-teleport-github-review-bot bot removed the request for review from zmb3 November 14, 2024 19:37
This change fixes a bug in remote port forwarding where Teleport reports
the hostname from the created remote listener, rather than the
hostname requested in the tcpip-forward request.
@atburke atburke force-pushed the atburke/rpf-addr-fix branch from 66dbb95 to ba6abfe Compare November 14, 2024 20:51
@atburke atburke enabled auto-merge November 14, 2024 20:51
@atburke atburke added this pull request to the merge queue Nov 14, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Nov 14, 2024
@atburke atburke added this pull request to the merge queue Nov 14, 2024
Merged via the queue into master with commit b8522ff Nov 14, 2024
40 checks passed
@atburke atburke deleted the atburke/rpf-addr-fix branch November 14, 2024 21:55
@public-teleport-github-review-bot

@atburke See the table below for backport results.

Branch Result
branch/v15 Create PR
branch/v16 Create PR
branch/v17 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.

ssh -R fails for Teleport nodes
4 participants