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

VNet: Refuse conn if local port doesn't match app spec #49944

Merged
merged 16 commits into from
Dec 11, 2024

Conversation

ravicious
Copy link
Member

@ravicious ravicious commented Dec 9, 2024

This PR implements the scenario described in the "Incorrect port" section of the RFD. The port is checked against the app spec that VNet already has. This version does not implement any kind of cache refresh that was discussed in #46169 (comment).

From the UX perspective, I made it so that error notifications can be automatically dismissed on a per-notification basis. My worry was that if a 3rd-party client would repeatedly try to open many new connections on ports that are not in the spec, the user would have dozens of error notifications in Connect that would need to be manually closed. Instead, I made it so that error notifications about invalid port are automatically dismissed after 5 seconds, similar to non-error notifications in the app.

The first half of the PR is focused on Go, the other on JS.

invalid-port
VNet is ready.
multi-port-example.teleport-local.dev:876: Connection refused, port not included in target ports of app "multi-port-example". Valid ports: 5434, 8765, 63636-64321.

@ravicious ravicious added no-changelog Indicates that a PR does not require a changelog entry backport/branch/v17 labels Dec 9, 2024
@github-actions github-actions bot added application-access size/md tsh tsh - Teleport's command line tool for logging into nodes running Teleport. ui labels Dec 9, 2024
@github-actions github-actions bot requested a review from ryanclark December 9, 2024 17:00
@ravicious ravicious removed the request for review from ryanclark December 9, 2024 17:00
api/types/app.go Outdated Show resolved Hide resolved
}
case 'invalidLocalPort': {
return {
title: `Invalid local port for ${publicAddrWithTargetPort(routeToApp)}`,
Copy link
Member Author

Choose a reason for hiding this comment

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

Gah, this shouldn't say "local port", I'll change it to just "port" tomorrow.

One more change that I'm considering is listing all valid ports in this notification. The problem is that the list is going to get unwieldy to display, so I suppose I could do so only when there's less than 10 port ranges in the app spec I guess?

The Electron app doesn't have access to the app spec, so the list of valid ports would have to be sent over RPC.

Copy link
Contributor

Choose a reason for hiding this comment

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

One more change that I'm considering is listing all valid ports in this notification. The problem is that the list is going to get unwieldy to display, so I suppose I could do so only when there's less than 10 port ranges in the app spec I guess?

If it's not too much work, I think it's worth adding. Alternatively, we could say 'Verify available ports for the app in the resources tab' or something like that :)

Copy link
Member Author

Choose a reason for hiding this comment

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

tsh and Connect now show valid ports if there's less than 10 port ranges.

api/types/app.go Outdated Show resolved Hide resolved
lib/vnet/app_resolver.go Outdated Show resolved Hide resolved
tool/tsh/common/vnet_common.go Outdated Show resolved Hide resolved
@ravicious ravicious requested a review from nklaassen December 10, 2024 11:49
if clusterClient.ClusterName() != profileName {
leafClusterName = clusterClient.ClusterName()
clusterName := clusterClient.ClusterName()
if clusterName != "" && clusterName != profileName && clusterName != clusterClient.RootClusterName() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Just curious: is it possible to clusterName == profileName but clusterName != clusterClient.RootClusterName()?

Copy link
Member Author

Choose a reason for hiding this comment

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

That would be possible if you have a root cluster with the name foo available at foo.com and a leaf cluster with the name of foo.com.

Which is not very likely, but I suppose to be correct, we should perhaps only compare ClusterName to RootClusterName.

The problem with the previous implementation was that if the name of the root cluster was not equal to its proxy host (and thus the profile name), VNet would set leafClusterName to that of the root cluster. This worked fine in the client cache. However, in methods such as OnInvalidLocalPort, we'd generate invalid teleterm URIs, as they'd end up being like /clusters/<profile name>/leaves/<root cluster name>.

}
case 'invalidLocalPort': {
return {
title: `Invalid local port for ${publicAddrWithTargetPort(routeToApp)}`,
Copy link
Contributor

Choose a reason for hiding this comment

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

One more change that I'm considering is listing all valid ports in this notification. The problem is that the list is going to get unwieldy to display, so I suppose I could do so only when there's less than 10 port ranges in the app spec I guess?

If it's not too much work, I think it's worth adding. Alternatively, we could say 'Verify available ports for the app in the resources tab' or something like that :)

@ravicious ravicious requested a review from gzdunek December 11, 2024 11:50
@ravicious ravicious added this pull request to the merge queue Dec 11, 2024
Merged via the queue into master with commit 7eb25e4 Dec 11, 2024
45 checks passed
@ravicious ravicious deleted the r7s/vnet-check-port branch December 11, 2024 16:40
@public-teleport-github-review-bot

@ravicious See the table below for backport results.

Branch Result
branch/v17 Failed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
application-access backport/branch/v17 no-changelog Indicates that a PR does not require a changelog entry size/md tsh tsh - Teleport's command line tool for logging into nodes running Teleport. ui
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants