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 option to map (force) port use on the server for reverse tunnels #274

Merged
merged 1 commit into from
May 22, 2024

Conversation

siepkes
Copy link
Contributor

@siepkes siepkes commented May 16, 2024

This change adds a port_mapping option to the ReverseTunnel definition in the (YAML) restriction file.

It maps ports on the server side from X to Y (X:Y). Where X is the originally requested port by the client and Y is the port which will be used to listen on server-side.

For example with 10001:8080 configured and a client which connects using -R tcp://10001:localhost:80 the server will listen on port 8080 instead of 10001. The originally requested ports (NOT the mapped ports) still needs to be allowed via the ports directive.

This is for example useful when dealing with lots of clients and you don't want to coordinate port use on all the clients but centrally on the server.

Let me know if this works for you and the project or if you have (other) ideas on it!

@siepkes siepkes changed the title Add option to map (force) port use on the server for reverse tunnels. Add option to map (force) port use on the server for reverse tunnels May 16, 2024
.iter()
.find_map(|allow| {
if let AllowConfig::ReverseTunnel(allow) = allow {
if remote.protocol.is_reverse_tunnel() {
Copy link
Owner

Choose a reason for hiding this comment

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

No need of this check, as you already know at this point that a ReverseTcp has been requested.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!

.find_map(|allow| {
if let AllowConfig::ReverseTunnel(allow) = allow {
if remote.protocol.is_reverse_tunnel() {
return allow.port_mapping.get(&remote.port).cloned();
Copy link
Owner

Choose a reason for hiding this comment

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

.clone() is enough i would say

@erebe
Copy link
Owner

erebe commented May 18, 2024

Hello,

I am not against the idea of it, but it should be supported for all reverse tunnels :)
The PR only introduce it for ReverseTcp at the moment.

This change adds a `port_mapping` option to the `ReverseTunnel` definition in the (YAML) restriction file.

It maps ports on the server side from X to Y (X:Y). Where X is the originally requested port by the client and Y is the port which will be used to listen on server-side.

For example with `10001:8080` configured and a client which connects using `-R tcp://10001:localhost:80` the server will listen on port 8080 instead of 10001. The originally requested ports (NOT the mapped ports) still needs to be allowed via the `ports` directive.

This is for example useful when dealing with lots of clients and you don't want to coordinate port use on all the clients but centrally on the server.
@siepkes
Copy link
Contributor Author

siepkes commented May 20, 2024

I am not against the idea of it, but it should be supported for all reverse tunnels :)

Yes, definitely! Sorry, should have been clear about that it was merely a first proof on concept to iterate on and to get a feel about how you thought about such a feature. Since your open to it I've also implemented the other ones but I still need to test the thing (so hold yer horses with any merging 😉 )

.clone() is enough i would say

I'm still new to Rust and I'm struggling a bit with this one. Simply changing to .clone() does not work since cloned() returns a borrowed value. I've also moved the logic to a separate method so that probably also compounds a bit to my lifetime issues. I assume the advantage in this context of clone() vs cloned() is about preventing adding a new integer on the stack?

@siepkes
Copy link
Contributor Author

siepkes commented May 22, 2024

I did some basic testing ( TCP port with forced mapping, Client which has TCP forced mappings but not for the requested port, etc.) and functionally it all seems to work.

@erebe
Copy link
Owner

erebe commented May 22, 2024

Alright, thank you for the PR ;}

For the clone vs cloned, cloned should be only available for iterator. But essentially it does the same thing than clone.
It is just that now, Option can be considered an iterator that contains a single element. like a list with only 1 item

@erebe erebe merged commit 6c4576b into erebe:main May 22, 2024
10 checks passed
erebe pushed a commit that referenced this pull request May 22, 2024
…#274)

This change adds a `port_mapping` option to the `ReverseTunnel` definition in the (YAML) restriction file.

It maps ports on the server side from X to Y (X:Y). Where X is the originally requested port by the client and Y is the port which will be used to listen on server-side.

For example with `10001:8080` configured and a client which connects using `-R tcp://10001:localhost:80` the server will listen on port 8080 instead of 10001. The originally requested ports (NOT the mapped ports) still needs to be allowed via the `ports` directive.

This is for example useful when dealing with lots of clients and you don't want to coordinate port use on all the clients but centrally on the server.
erebe pushed a commit that referenced this pull request May 22, 2024
…#274)

This change adds a `port_mapping` option to the `ReverseTunnel` definition in the (YAML) restriction file.

It maps ports on the server side from X to Y (X:Y). Where X is the originally requested port by the client and Y is the port which will be used to listen on server-side.

For example with `10001:8080` configured and a client which connects using `-R tcp://10001:localhost:80` the server will listen on port 8080 instead of 10001. The originally requested ports (NOT the mapped ports) still needs to be allowed via the `ports` directive.

This is for example useful when dealing with lots of clients and you don't want to coordinate port use on all the clients but centrally on the server.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants