These are instructions for setting up a Snowflake broker on Debian 10.
#### Debian Base System Setup
Set up APT and etckeeper.
Install etckeeper.
<pre>
...
...
@@ -46,83 +50,463 @@ root# service sshd restart
root# etckeeper commit "Add users."
</pre>
Set up a firewall.
<pre>
root# apt install ferm # Enable ferm on bootup? Yes
root# vi /etc/ferm/ferm.conf
Set a password for root for console recovery
```
root# passwd # Set a random password
```
This root password cannot be used for SSH login, instead, it is created to allow recovery from system that cannot finish boot to muti-user run level.
#### Setup IPv6
IPv6 Address for the VPS we are using can be chosen by customer. It sounds scary but we have the CAA record to reject request from unknown accounts.
To generate a random postfix for the given address range:
```
python3 -c 'import os; print(":".join(os.urandom(2).hex() for _ in range(3)))'
```
And then add generated IP address to system configuration `/etc/network/interfaces`:
```
iface eth0 inet6 static
address 2a00:c6c0:0:151:4:ae99:c0a9:d585
netmask 64
gateway 2a00:c6c0:0:151::1
```
It may takes a restart to apply the change.
#### probetest(NAT Test Assist Tool) Installation
This `probetest` tool is installed and setup first as it is more likely to cause a system failure that requires reinstallation than others. Plus, its setup is coupled with the setup of firewalls.
Create `/var/lib/probenattest/init-netns.sh` file, with instruction to setup network namespace for probetest.
```
#!/bin/bash
ip netns add net0
ip link add veth-a type veth peer name veth-b
ip link set veth-a netns net0
ip netns exec net0 ip link set lo up
ip netns exec net0 ip address add 10.0.0.2/24 dev veth-a
ip netns exec net0 ip address add fc00::2/7 dev veth-a
ip netns exec net0 ip link set veth-a up
ip address add 10.0.0.1/24 dev veth-b
ip address add fc00::1/7 dev veth-b
ip link set veth-b up
ip netns exec net0 ip route add default via 10.0.0.1 dev veth-a
ip netns exec net0 ip route add default via fc00::1 dev veth-a
mkdir-p /etc/netns/net0/
ln-sf /etc/resolv.conf /etc/netns/net0/
ln-sf /etc/hosts /etc/netns/net0/
echo 1 > /proc/sys/net/ipv4/ip_forward
sysctl -w net.ipv6.conf.all.forwarding=1
```
Create `/etc/systemd/system/probeNatTestSetup.service` file to run the script above at system startup.
```
[Unit]
Description=Probe NAT Test Setup
Before=ferm.service
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=%S/probenattest/init-netns.sh
[Install]
WantedBy=default.target
WantedBy=ferm.service
```
Disable whatever firewall that are already installed and install ferm instead:
```
apt install ferm
apt remove iptables-persistent
```
And modify the ferm configuration file `/etc/ferm/ferm.conf` to
Finally enable the firewall. Be sure to check that recovery option is present before go ahead with enable it.
```
systemctl start ferm.service
# Test everything still works
systemctl enable ferm.service
```
Tip: to inspect the rules derived from the ferm configuration file above use `iptables-legacy -vL $tableName`
Build and then copy the binary for [probetest](https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/-/tree/main/probetest) to `/var/lib/probenattestd/probenattestd`.
Allow probetest binary to be executed:
```
chmod +x /var/lib/probenattestd/probenattestd
```
Then create `/etc/systemd/system/probeNatTestd.service` file, to run `probetest` as a system unit:
```
[Unit]
Description=Snowflake Nat Type Test Daemon
After=probeNatTestSetup.service
[Service]
# --addr 10.0.0.2:8081 is added to ensure should NetworkNamespacePath failed to apply the unit will fail. Do NOT remove it unless the the reason to add it is understood.
and then enable and start it with `systemctl enable probeNatTestd.service` and `systemctl start probeNatTestd.service`.
**WARNING**: in systemd, the failure to apply `NetworkNamespacePath=/var/run/netns/net0` is silent, and the service will run anyway without it being applied if systemd was unable to apply it without even a line of warning. This behaviour is against the best practice, and should be aware of when operating it. `--addr 10.0.0.2:8081` is there to make sure the service will fail and make a noise when the `NetworkNamespacePath` is not applied, be considerate of this when changing it.
# Although we only selected tor-geoipdb, a tor daemon is also installed at the same time. Let's disable it
systemctl disable tor.service
systemctl mask tor.service
```
Then find out location for these geoip files:
```
dpkg -S geoip
tor-geoipdb: /usr/share/tor/geoip6
tor-geoipdb: /usr/share/tor/geoip
```
Setup broker service
```
# Create a user just for webapps
useradd -m webapp
# install additional packages required for the environment; if a different slim installion was used, it may require different set of packages to be installed manually. Please do not lost hope when systemd failed in wired way and the error message yield no result with search engine
apt install systemd-container libpam-systemd
# sudo is not sufficient here as we are interacting systemd and there is many environment varibles needs to be set correctly
WARNING: this setup is used to work with tls-alpn-01 domain validiation, which is currently not supported by certbot. Currently HTTP based validation was used.