diff --git a/config/Service.pkl b/config/Service.pkl index dea7bcc624297f43a3cebb8bd0b0defb701eebd5..caa5cc27223d046018b50c89c6a153ec56b6ba09 100644 --- a/config/Service.pkl +++ b/config/Service.pkl @@ -90,6 +90,8 @@ class Container { devices: Listing = new {} extraHosts: Listing = new {} hostNetwork: Boolean = false + /// Nomad CNI `sandbox` network: public internet and PostgreSQL only, no other host or LAN address. + restrictedEgress: Boolean = false imageUser: Boolean = false /// Prestart tasks finish first; prestart sidecars stay up for the main tasks. lifecycle: "main"|"prestart"|"prestartSidecar" = "main" diff --git a/service/spacebar/service.pkl b/service/spacebar/service.pkl index 77c2c23b0045881a9445e659330c9188f987756d..fa8d5bcdb5f8aa465f70a1d573f8ef7117b97261 100644 --- a/service/spacebar/service.pkl +++ b/service/spacebar/service.pkl @@ -27,6 +27,7 @@ secrets { container { build = "build" + restrictedEgress = true cpu = 1000 memory = 3072 diff --git a/tools/__pycache__/snowglobe.cpython-39.pyc b/tools/__pycache__/snowglobe.cpython-39.pyc new file mode 100644 index 0000000000000000000000000000000000000000..3fdcc59f9d4ebe31a281329feb74f035551d6c90 Binary files /dev/null and b/tools/__pycache__/snowglobe.cpython-39.pyc differ diff --git a/tools/snowglobe.py b/tools/snowglobe.py index ac91593f3b5979d1ad3e525da5e108cb90ae2fa6..8ff991ca07b33711da2fd0a750c5685ff26e5a43 100644 --- a/tools/snowglobe.py +++ b/tools/snowglobe.py @@ -284,6 +284,9 @@ def render(data, definitions): host_network = any(task["hostNetwork"] for task in data["containers"].values()) if host_network and not all(task["hostNetwork"] for task in data["containers"].values()): raise ValueError("mixed host and bridge networking in one group") + restricted = any(task["restrictedEgress"] for task in data["containers"].values()) + if restricted and (host_network or not all(task["restrictedEgress"] for task in data["containers"].values())): + raise ValueError("restricted egress must cover every container in a bridge group") for task_name, task in data["containers"].items(): for kind, endpoint in [("http", task.get("http")), *((port["name"], port) for port in task["tcp"])]: if endpoint: @@ -299,10 +302,12 @@ def render(data, definitions): if endpoint.get("loopback") or (not task["hostNetwork"] and kind == "http" and endpoint.get("hostPort") is None): network.append(' host_network = "loopback"') network.append(" }") - if network: + if network or restricted: lines.append(" network {") if host_network: lines.append(' mode = "host"') + elif restricted: + lines.append(' mode = "cni/sandbox"') lines += network + [" }"] for provider_id in sorted(dependencies(data)): provider = definitions[provider_id] @@ -403,7 +408,7 @@ def render(data, definitions): if task.get("readOnlyRoot"): lines.append(' readonly_rootfs = true') task_ports = [label for (owner, _), label in ports.items() if owner == task_name] - if task_ports and not task["hostNetwork"]: + if task_ports and not task["hostNetwork"] and not restricted: lines.append(f" ports = {q(task_ports)}") for field, values in (("cap_add", task["capAdd"]), ("devices", task["devices"]), ("extra_hosts", task["extraHosts"])): if values: diff --git a/tools/spacebar.md b/tools/spacebar.md index f2a2e6ce27f3753bc5b2d61c9f1c385136d86413..96c6b347b9ef57e3796ea2112152f7bf80ac35c9 100644 --- a/tools/spacebar.md +++ b/tools/spacebar.md @@ -70,3 +70,8 @@ Snow Globe's tailnet address as upstream. Its gateway relay sets `X-Snowcord-Voice-Relay: phoenix-loopback` so voice advertises the VM's loopback address. The guest profile lets Phoenix bind and receive UDP on its temporary ports and send UDP only to the local relay port. + +The container runs on the `sandbox` CNI network (`restrictedEgress`), so the API, +voice processes and SFU reach the public internet and PostgreSQL only. Forwarded +traffic to private, tailnet and link-local addresses is dropped in the raw table +(`nixos/snowglobe.nix`), including Snow Globe's own sshd and the router.