This took me some time to figure out, but it finally clicked! This proxy is one way only, from host into netns!
This proxy opens listener port in "host's" netns (aka netns:0 - let's call it that) and then sends itself into the target netns (aka netns:tgt), so once it accepts "host" connection and forwards it to the connection target, the forwarded connection will appear to originate from within netns:tgt and will use netns:tgt's default route a and routing table.
This is cool and fine, but is something that docker/podman and other container runtimes already implement, and it is akin to "reverse proxying" into the netns's network, like when using nginx or haproxy balancer in front of application nodes.
What I have yet to see and what I am searching for, and that nobody besides perhaps socat implemented (and I haven't had time to try it there yet), would be exactly the reverse situation:
- keep main part of the process running in netns:0 and send listening socket into "container" ie netns:tgt
- then when processes bound to given netns:tgt connects to let's say it's
lo: (127.0.0.1) or dummy: (x.x.x.x)
- the connection from inside netns:tgt would then be forwarded to netns:0, and from outside would appear as if originated from netns:0, following hosts default route and routing table
- but it would be in fact originating in netns:tgt
I am interested into this to safely enclose "lower-trust"/"untrusted" process inside it's own netns, yet allow it to connect outside. Modularly and "unix-composably", i.e. so it plays nicely with tools like netcat, ucspi-tcp protocol tools etc.
Circa 7+ years ago I implemented something like that of FreeBSD using jails and kqueue(), but there, it was relatively straightforward in C. On linux I played around with netns in C and such, but the code required would be much bigger, not mentioning the eventloop core on linux, of which I know only of poll(), and would be well beyond my resources to implement atm.
Would you consider this special use-case as one of valid uses of your tool?
It would allow insides of netns:tgt to chain socks proxies for example wrom within it. But even just single port+connection forwarder would be great achievement for many tasks. In my experience netns separation is 100s times more safer and more secure isolation strategy than, for example, firewall rules, or, god forbid, seccomp.
But maybe you have different aims for this project, I would understand that.
This took me some time to figure out, but it finally clicked! This proxy is one way only, from host into netns!
This proxy opens listener port in "host's" netns (aka netns:0 - let's call it that) and then sends itself into the target netns (aka netns:tgt), so once it accepts "host" connection and forwards it to the connection target, the forwarded connection will appear to originate from within netns:tgt and will use netns:tgt's default route a and routing table.
This is cool and fine, but is something that docker/podman and other container runtimes already implement, and it is akin to "reverse proxying" into the netns's network, like when using nginx or haproxy balancer in front of application nodes.
What I have yet to see and what I am searching for, and that nobody besides perhaps
socatimplemented (and I haven't had time to try it there yet), would be exactly the reverse situation:lo:(127.0.0.1) ordummy:(x.x.x.x)I am interested into this to safely enclose "lower-trust"/"untrusted" process inside it's own netns, yet allow it to connect outside. Modularly and "unix-composably", i.e. so it plays nicely with tools like netcat, ucspi-tcp protocol tools etc.
Circa 7+ years ago I implemented something like that of FreeBSD using jails and
kqueue(), but there, it was relatively straightforward in C. On linux I played around with netns in C and such, but the code required would be much bigger, not mentioning the eventloop core on linux, of which I know only ofpoll(), and would be well beyond my resources to implement atm.Would you consider this special use-case as one of valid uses of your tool?
It would allow insides of netns:tgt to chain socks proxies for example wrom within it. But even just single port+connection forwarder would be great achievement for many tasks. In my experience netns separation is 100s times more safer and more secure isolation strategy than, for example, firewall rules, or, god forbid, seccomp.
But maybe you have different aims for this project, I would understand that.