20210815-Re_GSoC Port Forwarding-1108.html 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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>15/08/2021, 17:35</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 you fast reply.
  11. <br>
  12. <br>Il 14/08/2021 23:43, Marek Marczykowski-Górecki ha scritto:
  13. <br><blockquote type=cite style="color: #007cff;">
  14. <br>As for the nft syntax, I think iptables-translate tool can help you
  15. <br>(part of the iptables-nft package).
  16. <br>See <a class="moz-txt-link-freetext" href="https://wiki.nftables.org/wiki-nftables/index.php/Moving_from_iptables_to_nftables">https://wiki.nftables.org/wiki-nftables/index.php/Moving_from_iptables_to_nftables</a>
  17. <br>
  18. <br><blockquote type=cite style="color: #007cff;">You can see in [4] how I organized the forwarding mechanism. All the
  19. <br>necessary information, as well as ipv4/ipv6 support should already be in
  20. <br>the 'prepare_forward_rules' function meaning that only the actual
  21. <br>building syntax is left.
  22. <br></blockquote>
  23. <br></blockquote>
  24. <br>I have tried to write the external nft rules as well the extarnal ones,
  25. with the exception of the destination domain.
  26. <br>
  27. <br>Assume the following setup:
  28. <br>sys-net - 10.137.0.5 (ens6 phy with 192.168.10.20)
  29. <br>sys-firewall - 10.137.0.6
  30. <br>personal - 10.137.0.7
  31. <br>
  32. <br>All of them are running fedora-32.
  33. <br>
  34. <br>And assume the following rule added via qvm-firewall:
  35. <br># qvm-firewall personal add action=forward forwardtype=external
  36. scrports=22-22 proto=tcp dstports=2222-2222 srchost=192.168.10.0/24
  37. <br>.
  38. <br>First, a table for the forwarding rules is created:
  39. <br>
  40. <br>flush chain {family} qubes-firewall-forward prerouting
  41. <br>flush chain {family} qubes-firewall-forward postrouting
  42. <br>table {family} qubes-firewall-forward {
  43. <br>&nbsp;&nbsp;&nbsp;&nbsp;chain postrouting {
  44. <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; type nat hook postrouting priority srcnat; policy accept;
  45. <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; masquerade
  46. <br>&nbsp;&nbsp;&nbsp;&nbsp;}
  47. <br>&nbsp;&nbsp;&nbsp;&nbsp;chain prerouting {
  48. <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; type nat hook prerouting priority dstnat; policy accept;
  49. <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }
  50. <br>}
  51. <br>
  52. <br>Then, if the qube is marked as 'last', meaning that it is the external
  53. qube with the physical interface the following rules are added:
  54. <br>
  55. <br>table {family} qubes-firewall-forward {
  56. <br>&nbsp;&nbsp;&nbsp;&nbsp;chain prerouting {
  57. <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; meta iifname "ens6" {family} saddr 192.168.10.0/24 tcp dport {{ 22 }}
  58. dnat to 10.137.0.6:2222
  59. <br>&nbsp;&nbsp;&nbsp;&nbsp;}
  60. <br>}
  61. <br>
  62. <br>table {family} qubes-firewall {
  63. <br>&nbsp;&nbsp;&nbsp;&nbsp;chain forward {
  64. <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; meta iifname "eth0" {family} daddr 10.137.0.6 tcp dport 2222 ct state
  65. new counter accept
  66. <br>&nbsp;&nbsp;&nbsp;&nbsp;}
  67. <br>}
  68. <br>
  69. <br>And that is all for sys-net.
  70. <br>
  71. <br>In sys-firewall, since it is an 'internal' qube, the following rules are
  72. added instead:
  73. <br>
  74. <br>table {family} qubes-firewall-forward {
  75. <br>&nbsp;&nbsp;&nbsp;&nbsp;chain prerouting {
  76. <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; meta iifname "eth0" {family} saddr 120.137.0.5 tcp dport {{ 2222 }}
  77. dnat to 10.137.0.7:2222
  78. <br>&nbsp;&nbsp;&nbsp;&nbsp;}
  79. <br>}
  80. <br>
  81. <br>table {family} qubes-firewall {
  82. <br>&nbsp;&nbsp;&nbsp;&nbsp;chain forward {
  83. <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; meta iifname "eth0" {family} daddr 10.137.0.7 tcp dport 2222 ct state
  84. new counter accept
  85. <br>&nbsp;&nbsp;&nbsp;&nbsp;}
  86. <br>}
  87. <br>
  88. <br>Lastly, the appropriate rules allowing incoming traffic on the selected
  89. port from the previous hop should be added directly yo the 'personal'
  90. domain. However I see that there the nft ruleset is empty, while
  91. iptables seems indeed to be in use. I guess that those rules are the
  92. ones specified in qubes-core-agent-linux/network/iptables, however I am
  93. wondering how we should proceed on this one?
  94. <br>
  95. <br>Also are you able to spot errors or something missing in the
  96. aforedescribed rule flow? When testing I can see the incoming connection
  97. on port 22 of the physical interface of sys-net, but then I am losing
  98. track of the connection after that...
  99. <br>
  100. <br>
  101. <br><blockquote type=cite style="color: #007cff;">In both cases, the code will need some tests of course.
  102. <br>
  103. <br></blockquote>
  104. <br>As soon as everything seems to work with my manual test, I will start
  105. progressively writing the automated tests.
  106. <br>
  107. <br>Cheers
  108. <br>Giulio
  109. <br></div></body>
  110. </html>
  111. </table></div>