20210622-Re_GSoC Port Forwarding-1053.html 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. <html>
  2. <head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  3. <title>Re: GSoC Port Forwarding</title>
  4. <link rel="important stylesheet" href="">
  5. <style>div.headerdisplayname {font-weight:bold;}
  6. </style></head>
  7. <body>
  8. <table border=0 cellspacing=0 cellpadding=0 width="100%" class="header-part1"><tr><td><div class="headerdisplayname" style="display:inline;">Oggetto: </div>Re: GSoC Port Forwarding</td></tr><tr><td><div class="headerdisplayname" style="display:inline;">Mittente: </div>Giulio <giulio@gmx.com></td></tr><tr><td><div class="headerdisplayname" style="display:inline;">Data: </div>22/06/2021, 14:28</td></tr></table><table border=0 cellspacing=0 cellpadding=0 width="100%" class="header-part2"><tr><td><div class="headerdisplayname" style="display:inline;">A: </div>Marek Marczykowski-Górecki &lt;marmarek@invisiblethingslab.com&gt;</td></tr><tr><td><div class="headerdisplayname" style="display:inline;">CC: </div>Frédéric Pierret &lt;frederic.pierret@qubes-os.org&gt;</td></tr></table><br>
  9. <div class="moz-text-flowed" style="font-family: -moz-fixed; font-size: 14px;" lang="x-unicode">Hello,
  10. <br>thank you for the detailed response.
  11. <br>
  12. <br>Il 22/06/2021 04:43, Marek Marczykowski-Górecki ha scritto:
  13. <br><blockquote type=cite style="color: #007cff;">Hi, I'm replying to both emails at once:
  14. <br>
  15. <br>On Sun, Jun 20, 2021 at 10:50:04PM +0200, Giulio wrote:
  16. <br><blockquote type=cite style="color: #007cff;">Questions:
  17. <br>
  18. <br>1) Should we both support internal port forwarding and external port
  19. <br>forwarding? Such as exposing a port for another domain or exposing a
  20. <br>port through the public network interface? I would say yes.
  21. <br></blockquote>
  22. <br>Yes, I think so. Technically, those two cases should be quite similar.
  23. <br>See also the case of sys-vpn much lower in the email.
  24. <br>
  25. <br></blockquote>
  26. <br>I think that I'm actually failing to picture all the possible internal
  27. scenarios.
  28. <br>
  29. <br>1) In the case of external port forwarding &lt;sys-net&gt; should forward to
  30. &lt;sys-firewall&gt; and &lt;sys-firewall&gt; then to the &lt;appvm&gt;.
  31. <br>In this case the port gets forwarded on the external interface ie: a LAN
  32. or a public ip address depending on the network environment.
  33. <br>2) In the case of internal port forwarding, the port is forwarded only
  34. from &lt;sys-firewall&gt; to &lt;appvm&gt;. In that case, another &lt;appvm2&gt; can visit
  35. the &lt;appvm&gt; service using &lt;sys-firewall&gt; ip address and the chosen port.
  36. <br>In this case, the ports get exposed on &lt;sys-firewall&gt; and thus depending
  37. on how the rules are implemented, may be available to all the AppVMs
  38. that share the same &lt;sys-firewall&gt;.
  39. <br>
  40. <br>In both cases may be important to allow to specify access rules for the
  41. forwarded port, such as the lan/public ip addresses ranges allowed for
  42. case 1 and the appvm name for case 2.
  43. <br>
  44. <br><blockquote type=cite style="color: #007cff;"><blockquote type=cite style="color: #007cff;">3) Since the expire= feature seems to be already implemented (and
  45. <br>limited for the expiring full outgoing access) would it be useful to be
  46. <br>implemented in gui and cli for every rule? I would say yes since the
  47. <br>admin and agent code seems to be already there. The same goes for the
  48. <br>"comment=" field.
  49. <br></blockquote>
  50. <br>Per-rule expire may be tricky to handle at the GUI level, I have no idea
  51. <br>how to make the UI for this not very confusing...
  52. <br>But the comment field is definitely useful to use.
  53. <br>
  54. <br></blockquote>
  55. <br>How do you see the same checkbox that actually allows full internet
  56. access with the 5 minutes expiration time, displayed also on the window
  57. for adding a rule?
  58. <br>However I think there is time to think more through this as the UI will
  59. be the last component.
  60. <br>
  61. <br><blockquote type=cite style="color: #007cff;"><blockquote type=cite style="color: #007cff;">4) How would you implement the management of forwarding rules in the
  62. <br>network providing domain (sys-net)? Shall the user add a rule both in
  63. <br>the target domain (ie the one with webserver and another one in sys-net)
  64. <br>or should it be fully automatic from the first?
  65. <br></blockquote>
  66. <br>From the user point of view, I think it should be automated as much as
  67. <br>possible. Like, let the user choose which port in which VM redirect to
  68. <br>where. There may be cases when such redirection won't be possible - if
  69. <br>there is no network path between the two points.
  70. <br>
  71. <br></blockquote>
  72. <br>I agree with you. We might just check when the user adds an internal
  73. forwarding rule if both the source and the destination shares the same
  74. &lt;firewallvm&gt;, don't we?
  75. <br>
  76. <br>
  77. <br><blockquote type=cite style="color: #007cff;"><blockquote type=cite style="color: #007cff;">5) Users should be able to set forward rules using domain names and not
  78. <br>static ip addresses. In this case, the actual ip addresses of the dst
  79. <br>domains should be collected in a similr way as currently DNS are
  80. <br>resolved in `/core-agent-linux/qubesagent/firewall.py`, would this be good?
  81. <br></blockquote>
  82. <br>But here we are mostly talking about IP addresses of different VMs,
  83. <br>right? Those can (and should) be resolved at core-admin side, so the VM
  84. <br>applying the rules will have all the IP given. In fact VM may not be
  85. <br>able to resolve IP of another VM at all.
  86. <br>
  87. <br></blockquote>
  88. <br>Thanks for the insight, it totally makes sense.
  89. <br>
  90. <br><blockquote type=cite style="color: #007cff;"><blockquote type=cite style="color: #007cff;">Proposed XML Syntax:
  91. <br>&lt;rule&gt;
  92. <br>&nbsp;&nbsp;&nbsp;&nbsp;&lt;properties&gt;
  93. <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;property name="action"&gt;forward&lt;/property&gt;
  94. <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;property name="proto"&gt;udp&lt;/property&gt;
  95. <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;property name="dstports"&gt;443-8080-5555&lt;/property&gt;
  96. <br>&nbsp;&nbsp;&nbsp;&nbsp;&lt;/properties&gt;
  97. <br>&lt;rule&gt;
  98. <br></blockquote>
  99. <br>I don't see an important information here: forward to <span class="moz-txt-underscore"><span class="moz-txt-tag">_</span>where<span class="moz-txt-tag">_</span></span>.
  100. <br>
  101. <br><blockquote type=cite style="color: #007cff;">Proposed Admin API Syntax:
  102. <br>action=forward proto=udp dstports=443-8080-5555 [expire=&lt;unix
  103. <br>timestamp&gt;] [comment=random text]
  104. <br></blockquote>
  105. <br>Similar here, there needs to be a forward target (IP, and possibly a
  106. <br>port)
  107. <br>
  108. <br>On Tue, Jun 22, 2021 at 01:49:15AM +0200, Giulio wrote:
  109. <br><blockquote type=cite style="color: #007cff;">Since in the case of port forwarding the target ip address would always be the &lt;vmname&gt; IP address,
  110. <br></blockquote>
  111. <br>This is very true. But there needs to be an information where to forward
  112. <br>the traffic to (as noted earlier). Plus, possibly a second set of ports
  113. <br>(if you want to redirect to a different port).
  114. <br>
  115. <br></blockquote>
  116. <br>I am still failing to understand something here, could you give me a an
  117. example on when the dsthosts would different rather than the &lt;appvm&gt; or
  118. &lt;firewallvm&gt; ip?
  119. <br>
  120. <br>
  121. <br><blockquote type=cite style="color: #007cff;"><blockquote type=cite style="color: #007cff;">I think my main concern now is the question 4 from the aforementioned
  122. <br>email. Shall the rules be automatically implemented in all 3 involved
  123. <br>vms? (&lt;netvm,firewallvm,appvm&gt;). I think yes, because otherwise it would
  124. <br>be counterintuitive to be a partially manual and partially automatic
  125. <br>operation. But since it actually 'automatically' exposes more attack
  126. <br>surface, by loosening up all 3 vms network rules, I guess that maybe
  127. <br>more reasoning on it would be helpful.
  128. <br></blockquote>
  129. <br>Yes, but you need to pass the traffic somehow. The direct connection can
  130. <br>be achieved with qvm-connnect-tcp (connecting to the target directly
  131. <br>using qrexec, bypassing intermediate VMs), but it has its limits (low
  132. <br>performance, TCP only). To keep it as actual IP traffic, you need to
  133. <br>change firewall rules at all intermediate VMs too.
  134. <br>
  135. <br>Lets have a specific example: in default setup, redirect TCP port 80
  136. <br>from the outside, to 'work' VM port 8080.
  137. <br>
  138. <br>The setup looks like this:
  139. <br>&nbsp;&nbsp;
  140. &nbsp;&nbsp; sys-net -&gt; sys-firewall -&gt; work
  141. <br>
  142. <br>For this, you will need those rules:
  143. <br>
  144. <br>1. In sys-net: forward TCP port 80 to sys-firewall
  145. <br>2. In sys-firewall: forward TCP port 80 to work, port 8080
  146. <br>3. In work: allow TCP port 8080
  147. <br>
  148. <br>Now is the important design question: how to store those rules? If you
  149. <br>store them at all three places separately, it
  150. <br>will be easier to apply them at runtime, but it will be harder to
  151. <br>correlate them in UI. Plus, if any of them get modified/removed, it may
  152. <br>be non-trivial to troubleshoot the issue.
  153. <br>The other approach is to store the forward rules only in one place (the
  154. <br>target, 'work' in this example? or the source, 'sys-net' here?). This
  155. <br>way, it's harder to mess thing up. But when applying the rules (building
  156. <br>rule sets for qubes-firewall service in all the involved VMs), you need
  157. <br>to check several places.
  158. <br>Plus, the UI should clearly show such redirected ports at all involved
  159. <br>places, because it does affect system security - it must be easy to spot
  160. <br>if any redirects are enabled.
  161. <br>
  162. <br>
  163. <br>To make things more complex (sorry...), there may be a VPN or other
  164. <br>proxy service (Tor?) involved. For example:
  165. <br>
  166. <br>sys-net -&gt; sys-firewall -&gt; sys-vpn -&gt; work
  167. <br>
  168. <br>In such a case, the "external" VM for 'work' is not really sys-net, but
  169. <br>rather sys-vpn. And actually you need to be careful to not accidentally
  170. <br>bypass VPN either by allowing 'work' to communicate outside of the VPN,
  171. <br>or (maybe even worse) systems on the LAN (via sys-net) reach inside VPN.
  172. <br>
  173. <br>This case is not easy to solve, because currently core-admin has no idea
  174. <br>whether sys-vpn (or other such VM) do any of such tunnelling. Maybe we
  175. <br>need to (finally) introduce some flag to mark such VMs?
  176. <br>
  177. <br>
  178. <br>And another question: what should happen if you change netvm of 'work'.
  179. <br>For example switch to something like:
  180. <br>
  181. <br>&nbsp;&nbsp;&nbsp;&nbsp; sys-net -&gt; sys-firewall -&gt; (other VMs, but not 'work')
  182. <br>
  183. <br>&nbsp;&nbsp;&nbsp;&nbsp; sys-wifi -&gt; work
  184. <br>
  185. <br>Should the redirection stay active via sys-wifi? I think it should not,
  186. <br>at least not automatically (maybe have an option for that?).
  187. <br>
  188. <br></blockquote>
  189. <br>I understand all of your points and consequently it is hard to figure
  190. out a catch-all solution.
  191. <br>
  192. <br>I tried charting the flow of the possible solution.
  193. <br><a class="moz-txt-link-freetext" href="https://git.lsd.cat/Qubes/gsoc/src/master/assets/implementation.png">https://git.lsd.cat/Qubes/gsoc/src/master/assets/implementation.png</a>
  194. <br>
  195. <br>As a sum up:
  196. <br>1) Rules are stored only in &lt;appvm&gt;/firewall.xml
  197. <br>2) Rules can either be internal or exteranl (ie: they are applied only
  198. to &lt;firewallvm&gt; or both to &lt;firewallvm&gt; and its &lt;netvm&gt;)
  199. <br>3) Forwarding rules should be purged if &lt;appvm&gt; changes &lt;firewall&gt;
  200. (maybe also if &lt;firewallvm&gt; changes &lt;netvm&gt;? But that would be harde to
  201. detect I guess)
  202. <br>4) Users should be able to specify both the forwarded port and
  203. destination port as you were saying
  204. <br>5) Users should be able to eventually restrict forwarding to designated
  205. networks (with 0.0.0.0/0 being the wildcard instead of being a wildcard
  206. by default)
  207. <br>
  208. <br>However, in this case it will surely be harder to display the rules in
  209. all the affected vms.
  210. <br>The other approach, as you were suggesting, of adding each specific rule
  211. in each vm conf does make sense, but I think then it would necessary
  212. something to keep track of the rule dependencies (such as a unique
  213. identifier). Furthermore there is a higher risk of having orphaned rules
  214. or a inconsistent state.
  215. <br>
  216. <br>Furthermore, in the "internal" vpn case that I have in mind, the idea is
  217. to forward the local port via the VPN interface or Tor (but in the Tor
  218. case users should just stick to Whonix). Some providers, such as
  219. Mullvad, AirVPN, PIA etc allows port forwarding this way and I think
  220. that's the most relevant case since it allows exposing a service on the
  221. internet while maintaining a bit of privacy/anonimity and whithout
  222. needing to bypass the local network NAT. Is this the same case you are
  223. referring to?
  224. <br>
  225. <br><blockquote type=cite style="color: #007cff;">And finally, don't forget IPv6 exists. Which means you can have the same
  226. <br>port on IPv4 and IPv6. And theoretically they could be redirected to
  227. <br>different places (but I'm not sure if that's a good idea...).
  228. <br>
  229. <br></blockquote>
  230. <br>I think that once we have figured out the overall logic to implement, it
  231. should not be hard to duplicate it for ipv4/ipv6. I think the main
  232. problem to think about is to insert proper checks to prevent users from
  233. adding mixed rules.
  234. <br>
  235. <br>Cheers
  236. <br>Giulio
  237. <br></div></body>
  238. </html>
  239. </table></div>