aboutsummaryrefslogtreecommitdiffstats
path: root/host.nix
diff options
context:
space:
mode:
Diffstat (limited to 'host.nix')
-rw-r--r--host.nix22
1 files changed, 15 insertions, 7 deletions
diff --git a/host.nix b/host.nix
index 7b1f0d5..1907617 100644
--- a/host.nix
+++ b/host.nix
@@ -5,9 +5,11 @@
# same time.
#
# Egress: nothing gets forwarded from fcbr0. The guests' DNS resolves
-# every name to 172.16.0.1, where nginx takes TLS connections on port 443,
-# reads the server name (SNI) from the ClientHello, and if it's one of the
-# domains (or their subdomains) listed in /var/lib/fc-egress/allowed,
+# every name to 172.16.0.1, and their TLS connections (tcp port 443,
+# whatever the address) get redirected to nginx on 172.16.0.1:proxyPort
+# (not 443 itself, as the host may run a web server on 0.0.0.0:443).
+# nginx reads the server name (SNI) from the ClientHello, and if it's one
+# of the domains (or their subdomains) listed in /var/lib/fc-egress/allowed,
# connects to port 443 of that name, as resolved by the host. The guests
# need no proxy settings, and they can only ever reach the real addresses
# of allowed names. The user can change the list at any time with
@@ -16,8 +18,8 @@
# usage (in the host's configuration.nix):
# imports = [ (import ./host.nix { user = "tv"; }) ];
# The host's firewall has to let the guests in on fcbr0: DHCP (udp 67),
-# DNS (udp and tcp 53) and TLS (tcp 443).
-{ user, taps ? 8 }: { lib, pkgs, ... }: let
+# DNS (udp and tcp 53) and the proxy (tcp proxyPort, after the redirect).
+{ user, taps ? 8, proxyPort ? 10443 }: { lib, pkgs, ... }: let
tapNames = map (i: "fctap${toString i}") (lib.range 0 (taps - 1));
dir = "/var/lib/fc-egress";
allowed = "${dir}/allowed";
@@ -127,7 +129,7 @@
}
server {
- listen 172.16.0.1:443;
+ listen 172.16.0.1:${toString proxyPort};
ssl_preread on;
proxy_pass $egress_upstream;
}
@@ -152,11 +154,17 @@ in {
# with scripted networking, which assigns it regardless.)
systemd.network.networks."40-fcbr0".networkConfig.ConfigureWithoutCarrier = true;
- # Only rejects; for anything else the host's own forward chain decides.
+ # forward only rejects; for anything else the host's own forward chain
+ # decides. redirect sends the guests' TLS to nginx, see above.
networking.nftables.enable = true;
networking.nftables.tables.firecracker = {
family = "inet";
content = ''
+ chain prerouting {
+ type nat hook prerouting priority dstnat;
+ iifname "fcbr0" tcp dport 443 redirect to :${toString proxyPort}
+ }
+
chain forward {
type filter hook forward priority filter; policy accept;
iifname "fcbr0" reject with icmpx admin-prohibited