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

Localhost access to server #66

Closed
Aptimex opened this issue Oct 25, 2024 · 2 comments · Fixed by #68
Closed

Localhost access to server #66

Aptimex opened this issue Oct 25, 2024 · 2 comments · Fixed by #68
Labels
enhancement New feature or request planned feature Likely to get implemented in the future

Comments

@Aptimex
Copy link
Collaborator

Aptimex commented Oct 25, 2024

Currently there doesn't seem to be any way to access the localhost interface (127.0.0.1) of a server. It would be really handy to be able to do so, since it's common for some services to only listen on localhost interfaces.

But adding AllowedIP routes for localhost addresses probably isn't a great idea; might mess up the client's networking.

@luker983 would it be possible (with how Wiretap's networking stack works) to let users specify a "localhost" access IP for each server, which the receiving server would then just send to 127.0.0.1 instead? For example:

wiretap configure -e 192.168.1.2:51820 -r 10.0.0.0/8 --localhost-ip 1.2.3.4

This would add something like localhost-ip = 1.2.3.4 to the server config, and 1.2.3.4 to the AllowedIPs of the client config. Then once setup, curl 1.2.3.4 would actually get connected to 127.0.0.1 of the associated server.

It would be up to the user to make sure they pick a mock localhost IP that they don't otherwise need to be able to actually talk to.

@Aptimex Aptimex added enhancement New feature or request planned feature Likely to get implemented in the future labels Nov 8, 2024
@Aptimex
Copy link
Collaborator Author

Aptimex commented Nov 8, 2024

Was able to get a PoC of this working using gvisor's IPTables functionality in the localhost-server branch. PoC only works for TCP, and uses 192.168.137.137 as the hard-coded IP that will redirect to localhost on the server. This has to be manually added as an allowedIP to the wiretap.conf file, so it also will only work on whatever server that allowedIP is assigned to.

Unfortunately gvisor doesn't provide the exported functions needed to do DNAT for a range of ports, so I had to do some unsafe stuff with compiler directives to get access the un-exported function that facilitates the desired behavior.

Might alternatively be able to create 65536 rules for each individual port using a loop, but not sure if that would be better or worse than using an unsafe compiler option.

@Aptimex
Copy link
Collaborator Author

Aptimex commented Nov 8, 2024

Actually support for address-only NAT was added to gvisor in this commit, just need to get our gvisor module import updated to a newer version.

Aptimex added a commit that referenced this issue Nov 9, 2024
@Aptimex Aptimex linked a pull request Nov 19, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request planned feature Likely to get implemented in the future
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant