Edge routing with HardenedBSD

This work would not have been possible without the help of Shawn (from HardenedBSD), the determination of Jordan, Christian, Yawnbox, and the patience of the Seattle Internet Exchange.

History

Emerald Onion set out to maximize the use of free/libre open source software for our compute environment, especially for the routing infrastructure (routing is actually all that we do). Before our partnership with HardenedBSD, we chose pfSense because we were most experienced with it. We had considered OPNSense but decided to move directly to HardenedBSD.

As part of our ongoing research and development for the enhancement of privacy infrastructure, we’re actively working on identifying and testing open source hardware.

Why did we move from pfSense to HardenedBSD?

  • Misplaced ARPs in pfSense were occurring, for unknown reasons, and could not be mitigated
  • Overall software minimization and attack surface reduction
  • A “common operating environment” — to have the same OS and application stack as our Tor router
  • Flexibility, like being able to use the most up-to-date software packages and latest features
  • Overall greater diversity and security for the Tor network

HardenedBSD – base operating system configuration

For our current configuration, we are using stock HBSD 11-stable.

rc.conf
ipv6_gateway_enable="YES"
gateway_enable="YES"
clear_tmp_enable="YES"
syslogd_flags="-ss"
sendmail_enable="NONE"
hostname="eo-pf-01.emeraldonion.org"
unbound_enable="YES"
sshd_enable="YES"
ntpd_enable="YES"
openbgpd_enable="YES"
powerd_enable="YES"
vnstat_enable="YES"
# Set dumpdev to "AUTO" to enable crash dumps, "NO" to disable
dumpdev="NO"
zfs_enable="YES"

ipv6_activate_all_interfaces="YES"
ifconfig_ix0="inet 23.129.64.1/24"
ifconfig_ix0_ipv6="inet6 2620:18c::1 prefixlen 36"

pf_enable="YES"
pf_rules="/usr/local/emeraldonion/etc/pf.rules"
pflog_enable="NO"

# Unused
ifconfig_igb0="down"
ifconfig_igb1="down"

# SIX
ifconfig_ix1="inet 206.81.81.158/23 group eo_egress"
ifconfig_ix1_ipv6="inet6 2001:504:16::6:cdb prefixlen 64 accept_rtadv"
sysctl.conf
# $FreeBSD$
#
# This file is read when going to multi-user and its contents piped thru
# ``sysctl'' to adjust kernel values. ``man 5 sysctl.conf'' for details.
#

# Uncomment this to prevent users from seeing information about processes that
# are being run under another UID.
#security.bsd.see_other_uids=0
security.bsd.see_other_uids=0
security.bsd.see_other_gids=0
security.bsd.unprivileged_read_msgbuf=0
security.bsd.unprivileged_proc_debug=0
security.bsd.stack_guard_page=1

# SIX requirement
net.link.ether.inet.max_age=14400

# Allow router solicitations whilst being a router
net.inet6.ip6.rfc6204w3=1
loader.conf
aesni_load="YES"
geom_eli_load="YES"
geli_nvd0p5_keyfile0_load="YES"
geli_nvd0p5_keyfile0_type="nvd0p5:geli_keyfile0"
geli_nvd0p5_keyfile0_name="/boot/encryption.key"
vfs.root.mountfrom="zfs:zroot/ROOT/default"
kern.geom.label.disk_ident.enable="0"
kern.geom.label.gptid.enable="0"
vfs.zfs.min_auto_ashift=12
zpool_cache_load="YES"
zpool_cache_type="/boot/zfs/zpool.cache"
zpool_cache_name="/boot/zfs/zpool.cache"
geom_eli_passphrase_prompt="YES"
zfs_load="YES"

PF – routing and firewall configuration

#########
#
# Emerald Onion 
#
#########
#
###### Variables and data used throughout this document:
#
### Dynamic tables
table <hardened_updates> persist
table <hardened_updates6> persist
table <ssh_permitted_hosts> { } persist
table <tor_instances> const { 23.129.64.0/24, !23.129.64.1 } persist
table <tor_instances6> const { 2620:18c::0/36, !2620:18c::1 } persist

# SIX BGP sources
h4_six_bgp="{ 206.81.80.0/23 }"
h6_six_bgp="{ 2001:504:16::0/64 }"
h4_six_bgp_nonat="206.81.80.0/23"
h6_six_bgp_nonat="2001:504:16::0/64"

# Private addresses
h_tor_relay="23.129.64.10"

### Ports of note
p_ssh = "22"
p_dns = "53"
p_hbsd_update = "{ 80 443 }"
p_tor = "{ 80 443 }"
p_ntp = "123"
p_bgp = "179"
p_internal_permitted = "{" $p_ntp $p_dns "}"

### Interfaces - Outside
i_six = "ix1"
# functionally equivalent to eo_egress interface group - need to collapse rules using this alias
i_wan = "{" $i_six "}"
a_wan = "23.129.64.1" 
a6_wan = "2620:18c::1"

### Interfaces - Inside
i_lan = "{" ix0 "}"

### Permissible ICMP
icmp_types = "{ echoreq unreach }"
icmp6_types = "{ toobig echoreq neighbrsol neighbradv }"
i_wan_icmp6_types="{ echoreq listendone routeradv neighbrsol neighbradv redir }"

#
###### Options section
# Do not process loopback traffic
set skip on lo0
set limit { states 200000, frags 40000, src-nodes 50000 }

# Scrub (normalize) packets to ensure consistent rule assignment
scrub in all

#
###### NAT/RDR
#
### NAT Rules
# Anything sent out by the host to a BGP peer should use the native address. Everything else should NAT to the advertised address
nat on $i_six inet from ($i_six) to ! $h4_six_bgp_nonat -> $a_wan
nat on $i_six inet6 from ($i_six) to ! $h6_six_bgp_nonat -> $a6_wan

#
### Port Forwarding (RDR)
# Remember your filter rules below! These rules only translate incoming traffic, the filter rules decide what is allowed....
# These two rules should be collapsed to use eo_egress...
rdr on $i_six inet proto tcp from any to $a_wan port $p_ssh -> $h_tor_relay port $p_ssh
rdr on $i_six inet proto tcp from any to $a_wan port = 2222 -> $a_wan port $p_ssh

#
###### Filter
#
# Strict default policy
block all

# Block spurious emissions
block quick on $i_six inet6 from 2620:18c::1/128 to any

# Permit DNS requests from anything - interface group eo_egress includes $i_wow and $i_six
pass out quick on eo_egress inet proto { tcp udp } to any port = $p_dns keep state 
pass out quick on eo_egress inet6 proto { tcp udp } to any port = $p_dns keep state

# Permit openBGPd
pass out quick on $i_six inet proto tcp from ($i_six) to $h4_six_bgp port = $p_bgp keep state
pass out quick on $i_six inet6 proto tcp from ($i_six) to $h6_six_bgp port = $p_bgp keep state
pass in quick on $i_six inet proto tcp from $h4_six_bgp to ($i_six) port = $p_bgp keep state
pass in quick on $i_six inet6 proto tcp from $h6_six_bgp to ($i_six) port = $p_bgp keep state

# Permit SSH from authorized...
pass in quick on eo_egress inet proto tcp from <ssh_permitted_hosts> to $h_tor_relay port $p_ssh keep state
pass in quick on eo_egress inet proto tcp from <ssh_permitted_hosts> to $a_wan port $p_ssh keep state
pass out quick on ix0 inet proto tcp from <ssh_permitted_hosts> to $h_tor_relay port $p_ssh keep state
# ...and block from anyone else
block in quick on eo_egress inet proto tcp from any to any port $p_ssh 
block in quick on eo_egress inet6 proto tcp from any to any port $p_ssh

# Permit anything to the Tor servers
pass in quick on eo_egress inet from any to <tor_instances> 
pass out quick on ix0 inet from any to <tor_instances> 
pass in quick on ix0 inet from <tor_instances> to !(ix0) 
pass out quick on eo_egress inet from <tor_instances> to any 
pass in quick on eo_egress inet6 from any to <tor_instances6> 
pass out quick on ix0 inet6 from any to <tor_instances6> 
pass in quick on ix0 inet6 from <tor_instances6> to !(ix0) 
pass out quick on eo_egress inet6 from <tor_instances6> to any

# Allow Tor traffic to transit the router but do not allow it towards our management network
#pass in quick on ix0 from ix0:network to !(ix0) 
#pass out quick on eo_egress from ix0:network to any 
## IPv6 address hasn't been configured on this interface yet
#pass in quick on ix0 inet6 from ix0:network to !(ix0) 
#pass out quick on $i_wan inet6 from ix0:network to any

## Permitted egress traffic
# Hardened BSD Updates
# Script provided to update <hardened_updates> and <hardened_updates6> tables on-demand although the addresses should be relatively stable
# Any host is allowed to these servers on 80/443
pass out quick on eo_egress inet proto tcp from $a_wan to <hardened_updates> port $p_hbsd_update keep state
#pass out quick on eo_egress inet6 proto tcp from $a_wan to <hardened_updates6> port $p_hbsd_update keep state

# Permit ICMP facilities
pass out quick on eo_egress inet proto icmp all icmp-type $icmp_types keep state
pass out quick on eo_egress inet6 proto ipv6-icmp all icmp6-type $icmp6_types keep state
pass in quick on eo_egress inet proto icmp all icmp-type $icmp_types keep state
pass in quick on eo_egress inet6 proto ipv6-icmp icmp6-type $icmp6_types keep state
pass in quick on $i_six inet6 proto ipv6-icmp from any to { ($i_six) ff02::1/16 } icmp6-type $i_wan_icmp6_types keep state
# And for internal services...
pass quick on $i_lan inet proto icmp all icmp-type $icmp_types keep state
pass quick on $i_lan inet6 proto ipv6-icmp all icmp6-type $icmp6_types keep state

# Permit DNS and NTP requests to us from our internal interfaces
pass in quick on $i_lan inet proto { tcp udp } from ix0:network to (ix0) port $p_internal_permitted keep state

# Protect the router from internal users - block everything else (not DNS or NTP requests)
block in quick on ix0 from ix0:network to (ix0)

Unbound – DNS configuration

#
# See unbound.conf(5) man page, version 1.7.0.
#

# The server clause sets the main parameters.
server:
# whitespace is not necessary, but looks cleaner.

# verbosity number, 0 is least verbose. 1 is default.
verbosity: 1

# number of threads to create. 1 disables threading.
num-threads: 16

# specify the interfaces to answer queries from by ip-address.
# The default is to listen to localhost (127.0.0.1 and ::1).
# specify 0.0.0.0 and ::0 to bind to all available interfaces.
# specify every interface[@port] on a new 'interface:' labelled line.
# The listen interfaces are not changed on reload, only on restart.
interface: 0.0.0.0

# control which clients are allowed to make (recursive) queries
# to this server. Specify classless netblocks with /size and action.
# By default everything is refused, except for localhost.
access-control: 23.129.64.1/24 allow

# file to read root hints from.
# get one from https://www.internic.net/domain/named.cache
root-hints: "/usr/local/etc/unbound/root.hints"

# enable to not answer id.server and hostname.bind queries.
hide-identity: yes

# enable to not answer version.server and version.bind queries.
hide-version: yes

# Sent minimum amount of information to upstream servers to enhance
# privacy. Only sent minimum required labels of the QNAME and set QTYPE
# to A when possible.
qname-minimisation: yes

# Use 0x20-encoded random bits in the query to foil spoof attempts.
# This feature is an experimental implementation of draft dns-0x20.
use-caps-for-id: yes

# if yes, Unbound rotates RRSet order in response.
rrset-roundrobin: yes

# Python config section. To enable:
# o use --with-pythonmodule to configure before compiling.
# o list python in the module-config string (above) to enable.
# o and give a python-script to run.
python:

# Remote control config section.
remote-control:

OpenBGPD – BGP configuration

AS 396507

fib-update yes
holdtime 90

router-id 206.81.81.158

# IPv4 network
network 23.129.64.0/24
# IPv6 network
network 2620:18C::/36

#### IPv4 neighbors ####
group "AS-SIXRSv4" {
remote-as 33108
neighbor 206.81.80.2 {
descr "SIXRS_rs2v4"
announce self
local-address 206.81.81.158
enforce neighbor-as no
max-prefix 200000
}
neighbor 206.81.80.3 {
descr "SIXRS_rs3v4"
announce self
local-address 206.81.81.158
enforce neighbor-as no
max-prefix 200000
}
}
group "AS-HURRICANE-Transit-v4" {
remote-as 6939
neighbor 206.81.80.40 {
descr "HE_transit_rs1v4"
announce self
local-address 206.81.81.158
max-prefix 100000000
}
}
group "AS-ALTOPIAv4" {
remote-as 6456
neighbor 206.81.80.10 {
descr "ALT_rs1v4"
announce self
local-address 206.81.81.158
max-prefix 20 restart 30
}
neighbor 206.81.81.41 {
descr "ALT_rs2v4"
announce self
local-address 206.81.81.158
max-prefix 20 restart 30
}
}
group "AS-POCKETINETv4" {
remote-as 23265
neighbor 206.81.80.88 {
descr "POK_rs1v4"
announce self
local-address 206.81.81.158
max-prefix 600
}
}
group "AS-DOOFv4" {
remote-as 395823
neighbor 206.81.81.125 {
descr "DOOF_rs1v4"
announce self
local-address 206.81.81.158
max-prefix 5
}
}
group "AS-PCHv4" {
remote-as 3856
neighbor 206.81.80.81 {
descr "PCH_rs1v4"
announce self
local-address 206.81.81.158
max-prefix 600
}
}
group "AS-PCHWNv4" {
remote-as 42
neighbor 206.81.80.80 {
descr "PCHWN_rs1v4"
announce self
local-address 206.81.81.158
max-prefix 600
}
}
group "AS-WOBv4" {
remote-as 64241
neighbor 206.81.81.87 {
descr "WOB_rs1v4"
announce self
local-address 206.81.81.158
max-prefix 5
}
}
group "AS-MISAKAv4" {
remote-as 57695
neighbor 206.81.81.161 {
descr "MISAKA_rs1v4"
announce self
local-address 206.81.81.158
max-prefix 300
}
}
group "AS-RISUPv4" {
remote-as 16652
neighbor 206.81.81.74 {
descr "RISUP_rs1v4"
announce self
local-address 206.81.81.158
max-prefix 20
}
}
group "AS-CLDFLRv4" {
remote-as 13335
neighbor 206.81.81.10 {
descr "CLDFLR_rs1v4"
announce self
local-address 206.81.81.158
max-prefix 1000
}
}
group "AS-GITHUBv4" {
remote-as 36459
neighbor 206.81.81.89 {
descr "GITHUB_rs1v4"
announce self
local-address 206.81.81.158
max-prefix 100
}
neighbor 206.81.81.90 {
descr "GITHUB_rs2v4"
announce self
local-address 206.81.81.158
max-prefix 100
}
}
group "AS-YAHOOv4" {
remote-as 10310
neighbor 206.81.80.98 {
descr "YAHOO_rs1v4"
announce self
local-address 206.81.81.158
max-prefix 2000
}
neighbor 206.81.81.50 {
descr "YAHOO_rs2v4"
announce self
local-address 206.81.81.158
max-prefix 2000
}
}
group "AS-SYMTECv4" {
remote-as 27471
neighbor 206.81.81.169 {
descr "SYMTEC_rs1v4"
announce self
local-address 206.81.81.158
max-prefix 40
}
neighbor 206.81.81.170 {
descr "SYMTEC_rs2v4"
announce self
local-address 206.81.81.158
max-prefix 40
}
}
group "AS-AKAMAIv4" {
remote-as 20940
neighbor 206.81.80.113 {
descr "AKAMAI_rs1v4"
announce self
local-address 206.81.81.158
max-prefix 200
}
}
group "AS-WAVEv4" {
remote-as 11404
neighbor 206.81.80.56 {
descr "WAVE_rs1v4"
announce self
local-address 206.81.81.158
max-prefix 3000
}
}


group "AS-GOOGLEv4" {
remote-as 15169
neighbor 206.81.80.17 {
descr "GOOGLE_rs1v4"
announce self
local-address 206.81.81.158
max-prefix 15000
}
}


#### IPv6 neighbors ####
group "AS-SIXRSv6" {
remote-as 33108
neighbor 2001:504:16::2 {
descr "SIXRS_rs2v6"
announce self
local-address 2001:504:16::6:cdb
enforce neighbor-as no
max-prefix 60000
}
neighbor 2001:504:16::3 {
descr "SIXRS_rs3v6"
announce self
local-address 2001:504:16::6:cdb
enforce neighbor-as no
max-prefix 60000
}
}
group "AS-HURRICANE-Transit-v6" {
remote-as 6939
neighbor 2001:504:16::1b1b {
descr "HE_transit_rs1v6"
announce self
local-address 2001:504:16::6:cdb
max-prefix 100000000
}
}
group "AS-ALTOPIAv6" {
remote-as 6456
neighbor 2001:504:16::1938 {
descr "ALT_rs1v6"
announce self
local-address 2001:504:16::6:cdb
max-prefix 20 restart 30
}
neighbor 2001:504:16::297:0:1938 {
descr "ALT_rs2v6"
announce self
local-address 2001:504:16::6:cdb
max-prefix 20 restart 30
}
}
group "AS-POCKETINETv6" {
remote-as 23265
neighbor 2001:504:16::5ae1 {
descr "POK_rs1v6"
announce self
local-address 2001:504:16::6:cdb
max-prefix 600
}
}
group "AS-DOOFv6" {
remote-as 395823
neighbor 2001:504:16::6:a2f {
descr "DOOF_rs1v6"
announce self
local-address 2001:504:16::6:cdb
max-prefix 5
}
}
group "AS-PCHv6" {
remote-as 3856
neighbor 2001:504:16::f10 {
descr "PCH_rs1v6"
announce self
local-address 2001:504:16::6:cdb
max-prefix 600
}
}
group "AS-PCHWNv6" {
remote-as 42
neighbor 2001:504:16::2a {
descr "PCHWN_rs1v6"
announce self
local-address 2001:504:16::6:cdb
max-prefix 600
}
}
group "AS-WOBv6" {
remote-as 64241
neighbor 2001:504:16::faf1 {
descr "WOB_rs1v6"
announce self
local-address 2001:504:16::6:cdb
max-prefix 5
}
}
group "AS-MISAKAv6" {
remote-as 57695
neighbor 2001:504:16::e15f {
descr "MISAKA_rs1v6"
announce self
local-address 2001:504:16::6:cdb
max-prefix 300
}
}
group "AS-RISUPv6" {
remote-as 16652
neighbor 2001:504:16::410c {
descr "RISUP_rs1v6"
announce self
local-address 2001:504:16::6:cdb
max-prefix 10
}
}
group "AS-CLDFLRv6" {
remote-as 13335
neighbor 2001:504:16::3417 {
descr "CLDFLR_rs1v6"
announce self
local-address 2001:504:16::6:cdb
max-prefix 200
}
}
group "AS-GITHUBv6" {
remote-as 36459
neighbor 2001:504:16::8e6b {
descr "GITHUB_rs1v6"
announce self
local-address 2001:504:16::6:cdb
max-prefix 20
}
neighbor 2001:504:16::346:0:8e6b {
descr "GITHUB_rs2v6"
announce self
local-address 2001:504:16::6:cdb
max-prefix 20
}
}
group "AS-YAHOOv6" {
remote-as 10310
neighbor 2001:504:16::2846 {
descr "YAHOO_rs1v6"
announce self
local-address 2001:504:16::6:cdb
max-prefix 200
}
neighbor 2001:504:16::306:0:2846 {
descr "YAHOO_rs2v6"
announce self
local-address 2001:504:16::6:cdb
max-prefix 200
}
}
group "AS-AKAMAIv6" {
remote-as 20940
neighbor 2001:504:16::51cc {
descr "AKAMAI_rs1v6"
announce self
local-address 2001:504:16::6:cdb
max-prefix 40
}
}
group "AS-WAVEv6" {
remote-as 11404
neighbor 2001:504:16::2c8c {
descr "WAVE_rs1v6"
announce self
local-address 2001:504:16::6:cdb
max-prefix 250
}
}


group "AS-GOOGLEv6" {
remote-as 15169
neighbor 2001:504:16::3b41 {
descr "GOOGLE_rs1v6"
announce self
local-address 2001:504:16::6:cdb
max-prefix 1000
}
}

#### Filtering Rules ####

deny from any
deny to any

# https://www.arin.net/announcements/2014/20140130.html
# This block will be subject to a minimum size allocation of /28 and a
# maximum size allocation of /24. ARIN should use sparse allocation when
# possible within that /10 block.
allow from any prefix 23.128.0.0/10 prefixlen 24 - 28 # ARIN IPv6 transition

## IPv4 ##
# SIXRS_rs2v4
allow from 206.81.80.2 inet prefixlen 8 - 24
allow to 206.81.80.2 inet prefixlen 8 - 24
# SIXRS_rs3v4
allow from 206.81.80.3 inet prefixlen 8 - 24
allow to 206.81.80.3 inet prefixlen 8 - 24
# HE_transit_rs1v4
allow from 206.81.80.40
allow to 206.81.80.40
# ALT_rs1v4
allow from 206.81.80.10 inet prefixlen 8 - 24
allow to 206.81.80.10 inet prefixlen 8 - 24
# ALT_rs2v4
allow from 206.81.81.41 inet prefixlen 8 - 24
allow to 206.81.81.41 inet prefixlen 8 - 24
# POK_rs1v4
allow from 206.81.80.88 inet prefixlen 8 - 24
allow to 206.81.80.88 inet prefixlen 8 - 24
# DOOF_rs1v4
allow from 206.81.81.125 inet prefixlen 8 - 24
allow to 206.81.81.125 inet prefixlen 8 - 24
# PCH_rs1v4
allow from 206.81.80.81 inet prefixlen 8 - 24
allow to 206.81.80.81 inet prefixlen 8 - 24
# PCHWN_rs1v4
allow from 206.81.80.80 inet prefixlen 8 - 24
allow to 206.81.80.80 inet prefixlen 8 - 24
# WOB_rs1v4
allow from 206.81.81.87 inet prefixlen 8 - 24
allow to 206.81.81.87 inet prefixlen 8 - 24
# MISAKA_rs1v4
allow from 206.81.81.161 inet prefixlen 8 - 24
allow to 206.81.81.161 inet prefixlen 8 - 24
# RISUP_rs1v4
allow from 206.81.81.74 inet prefixlen 8 - 24
allow to 206.81.81.74 inet prefixlen 8 - 24
# CLDFLR_rs1v4
allow from 206.81.81.10 inet prefixlen 8 - 24
allow to 206.81.81.10 inet prefixlen 8 - 24
# GITHUB_rs1v4
allow from 206.81.81.89 inet prefixlen 8 - 24
allow to 206.81.81.89 inet prefixlen 8 - 24
# GITHUB_rs2v4
allow from 206.81.81.90 inet prefixlen 8 - 24
allow to 206.81.81.90 inet prefixlen 8 - 24
# YAHOO_rs1v4
allow from 206.81.80.98 inet prefixlen 8 - 24
allow to 206.81.80.98 inet prefixlen 8 - 24
# YAHOO_rs2v4
allow from 206.81.81.50 inet prefixlen 8 - 24
allow to 206.81.81.50 inet prefixlen 8 - 24
# SYMTEC_rs1v4
allow from 206.81.81.169 inet prefixlen 8 - 24
allow to 206.81.81.169 inet prefixlen 8 - 24
# SYMTEC_rs2v4
allow from 206.81.81.170 inet prefixlen 8 - 24
allow to 206.81.81.170 inet prefixlen 8 - 24
# AKAMAI_rs1v4
allow from 206.81.80.113 inet prefixlen 8 - 24
allow to 206.81.80.113 inet prefixlen 8 - 24
# WAVE_rs1v4
allow from 206.81.80.56 inet prefixlen 8 - 24
allow to 206.81.80.56 inet prefixlen 8 - 24
# GOOG_rs1v4
allow from 206.81.80.17
allow to 206.81.80.17

## IPv6 ##
# SIXRS_rs2v6
allow from 2001:504:16::2 inet6 prefixlen 16 - 48
allow to 2001:504:16::2 inet6 prefixlen 16 - 48
# SIXRS_rs3v6
allow from 2001:504:16::3 inet6 prefixlen 16 - 48
allow to 2001:504:16::3 inet6 prefixlen 16 - 48
# HE_transit_rs1v6
allow from 2001:504:16::1b1b
allow to 2001:504:16::1b1b
# ALT_rs1v6
allow from 2001:504:16::1938 inet6 prefixlen 16 - 48
allow to 2001:504:16::1938 inet6 prefixlen 16 - 48
# ALT_rs2v6
allow from 2001:504:16::297:0:1938 inet6 prefixlen 16 - 48
allow to 2001:504:16::297:0:1938 inet6 prefixlen 16 - 48
# POK_rs1v6
allow from 2001:504:16::5ae1 inet6 prefixlen 16 - 48
allow to 2001:504:16::5ae1 inet6 prefixlen 16 - 48
# DOOF_rs1v6
allow from 2001:504:16::6:a2f inet6 prefixlen 16 - 48
allow to 2001:504:16::6:a2f inet6 prefixlen 16 - 48
# PCH_rs1v6
allow from 2001:504:16::f10 inet6 prefixlen 16 - 48
allow to 2001:504:16::f10 inet6 prefixlen 16 - 48
# PCHWN_rs1v6
allow from 2001:504:16::2a inet6 prefixlen 16 - 48
allow to 2001:504:16::2a inet6 prefixlen 16 - 48
# WOB_rs1v6
allow from 2001:504:16::faf1 inet6 prefixlen 16 - 48
allow to 2001:504:16::faf1 inet6 prefixlen 16 - 48
# MISAKA_rs1v6
allow from 2001:504:16::e15f inet6 prefixlen 16 - 48
allow to 2001:504:16::e15f inet6 prefixlen 16 - 48
# RISUP_rs1v6
allow from 2001:504:16::410c inet6 prefixlen 16 - 48
allow to 2001:504:16::410c inet6 prefixlen 16 - 48
# CLDFLR_rs1v6
allow from 2001:504:16::3417 inet6 prefixlen 16 - 48
allow to 2001:504:16::3417 inet6 prefixlen 16 - 48
# GITHUB_rs1v6
allow from 2001:504:16::8e6b inet6 prefixlen 16 - 48
allow to 2001:504:16::8e6b inet6 prefixlen 16 - 48
# GITHUB_rs2v6
allow from 2001:504:16::346:0:8e6b inet6 prefixlen 16 - 48
allow to 2001:504:16::346:0:8e6b inet6 prefixlen 16 - 48
# YAHOO_rs1v6
allow from 2001:504:16::2846 inet6 prefixlen 16 - 48
allow to 2001:504:16::2846 inet6 prefixlen 16 - 48
# YAHOO_rs2v6
allow from 2001:504:16::306:0:2846 inet6 prefixlen 16 - 48
allow to 2001:504:16::306:0:2846 inet6 prefixlen 16 - 48
# AKAMAI_rs1v6
allow from 2001:504:16::51cc inet6 prefixlen 16 - 48
allow to 2001:504:16::51cc inet6 prefixlen 16 - 48
# WAVE_rs1v6
allow from 2001:504:16::2c8c inet6 prefixlen 16 - 48
allow to 2001:504:16::2c8c inet6 prefixlen 16 - 48
# GOOG_rs1v6
allow from 2001:504:16::3b41
allow to 2001:504:16::3b41

# filter bogus networks according to RFC5735
deny from any prefix 0.0.0.0/8 prefixlen >= 8 # 'this' network [RFC1122]
deny from any prefix 10.0.0.0/8 prefixlen >= 8 # private space [RFC1918]
deny from any prefix 100.64.0.0/10 prefixlen >= 10 # CGN Shared [RFC6598]
deny from any prefix 127.0.0.0/8 prefixlen >= 8 # localhost [RFC1122]
deny from any prefix 169.254.0.0/16 prefixlen >= 16 # link local [RFC3927]
deny from any prefix 172.16.0.0/12 prefixlen >= 12 # private space [RFC1918]
deny from any prefix 192.0.2.0/24 prefixlen >= 24 # TEST-NET-1 [RFC5737]
deny from any prefix 192.168.0.0/16 prefixlen >= 16 # private space [RFC1918]
deny from any prefix 198.18.0.0/15 prefixlen >= 15 # benchmarking [RFC2544]
deny from any prefix 198.51.100.0/24 prefixlen >= 24 # TEST-NET-2 [RFC5737]
deny from any prefix 203.0.113.0/24 prefixlen >= 24 # TEST-NET-3 [RFC5737]
deny from any prefix 224.0.0.0/4 prefixlen >= 4 # multicast
deny from any prefix 240.0.0.0/4 prefixlen >= 4 # reserved

# filter bogus IPv6 networks according to IANA
deny from any prefix ::/8 prefixlen >= 8
deny from any prefix 0100::/64 prefixlen >= 64 # Discard-Only [RFC6666]
deny from any prefix 2001:2::/48 prefixlen >= 48 # BMWG [RFC5180]
deny from any prefix 2001:10::/28 prefixlen >= 28 # ORCHID [RFC4843]
deny from any prefix 2001:db8::/32 prefixlen >= 32 # docu range [RFC3849]
deny from any prefix 3ffe::/16 prefixlen >= 16 # old 6bone
deny from any prefix fc00::/7 prefixlen >= 7 # unique local unicast
deny from any prefix fe80::/10 prefixlen >= 10 # link local unicast
deny from any prefix fec0::/10 prefixlen >= 10 # old site local unicast
deny from any prefix ff00::/8 prefixlen >= 8 # multicast

vnStat – statistics gathering configuration

# vnStat 1.15 config file
##

# default interface
Interface "eth0"

# location of the database directory
DatabaseDir "/var/lib/vnstat"

# locale (LC_ALL) ("-" = use system locale)
Locale "-"

# on which day should months change
MonthRotate 1

# date output formats for -d, -m, -t and -w
# see 'man date' for control codes
DayFormat "%x"
MonthFormat "%b '%y"
TopFormat "%x"

# characters used for visuals
RXCharacter "%"
TXCharacter ":"
RXHourCharacter "r"
TXHourCharacter "t"

# how units are prefixed when traffic is shown
# 0 = IEC standard prefixes (KiB/MiB/GiB/TiB)
# 1 = old style binary prefixes (KB/MB/GB/TB)
UnitMode 0

# output style
# 0 = minimal & narrow, 1 = bar column visible
# 2 = same as 1 except rate in summary and weekly
# 3 = rate column visible
OutputStyle 3

# used rate unit (0 = bytes, 1 = bits)
RateUnit 1

# try to detect interface maximum bandwidth, 0 = disable feature
# MaxBandwidth will be used as fallback value when enabled
BandwidthDetection 1

# maximum bandwidth (Mbit) for all interfaces, 0 = disable feature
# (unless interface specific limit is given)
MaxBandwidth 1000

# interface specific limits
# example 8Mbit limit for 'ethnone':
MaxBWethnone 8

# how many seconds should sampling for -tr take by default
Sampletime 5

# default query mode
# 0 = normal, 1 = days, 2 = months, 3 = top10
# 4 = exportdb, 5 = short, 6 = weeks, 7 = hours
QueryMode 0

# filesystem disk space check (1 = enabled, 0 = disabled)
CheckDiskSpace 1

# database file locking (1 = enabled, 0 = disabled)
UseFileLocking 1

# how much the boot time can variate between updates (seconds)
BootVariation 15

# log days without traffic to daily list (1 = enabled, 0 = disabled)
TrafficlessDays 1


# vnstatd
##

# switch to given user when started as root (leave empty to disable)
DaemonUser ""

# switch to given user when started as root (leave empty to disable)
DaemonGroup ""

# how often (in seconds) interface data is updated
UpdateInterval 30

# how often (in seconds) interface status changes are checked
PollInterval 5

# how often (in minutes) data is saved to file
SaveInterval 5

# how often (in minutes) data is saved when all interface are offline
OfflineSaveInterval 30

# how often (in minutes) bandwidth detection is redone when
# BandwidthDetection is enabled (0 = disabled)
BandwidthDetectionInterval 5

# force data save when interface status changes (1 = enabled, 0 = disabled)
SaveOnStatusChange 1

# enable / disable logging (0 = disabled, 1 = logfile, 2 = syslog)
UseLogging 2

# create dirs if needed (1 = enabled, 0 = disabled)
CreateDirs 1

# update ownership of files if needed (1 = enabled, 0 = disabled)
UpdateFileOwner 1

# file used for logging if UseLogging is set to 1
LogFile "/var/log/vnstat/vnstat.log"

# file used as daemon pid / lock file
PidFile "/var/run/vnstat/vnstat.pid"


# vnstati
##

# title timestamp format
HeaderFormat "%x %H:%M"

# show hours with rate (1 = enabled, 0 = disabled)
HourlyRate 1

# show rate in summary (1 = enabled, 0 = disabled)
SummaryRate 1

# layout of summary (1 = with monthly, 0 = without monthly)
SummaryLayout 1

# transparent background (1 = enabled, 0 = disabled)
TransparentBg 0

# image colors
CBackground "FFFFFF"
CEdge "AEAEAE"
CHeader "606060"
CHeaderTitle "FFFFFF"
CHeaderDate "FFFFFF"
CText "000000"
CLine "B0B0B0"
CLineL "-"
CRx "92CF00"
CTx "606060"
CRxD "-"
CTxD "-"

OpenNTPD – network time protocol for system clock synchronization

# Upstream Servers
servers pool.ntp.org

 

Introducing gibson

Artwork by Mike Finch (CC BY 4.0)

 

As you may know, Emerald Onion systems run HardenedBSD. BSD systems in general, and HBSD in particular, provide numerous advantages to our team in operating secure and highly performant Tor relays. But BSD systems make up only a very small percentage of the Tor network. There are many similarities between BSD and Linux, with which many users may be more familiar, but the differences can be intimidating. We’re addressing this by launching gibson, a project to develop a suite of tools to address the needs of Tor service operators. The Tor network is more robust when it is diverse, and this is one way that we can encourage a more diverse Tor network and enhance our community.

It is important to say that while our initial focus is on BSD systems, our plan is to extend gibson to serve the Tor community regardless of platform. We’re starting with HBSD because it’s an obvious and natural choice for us; we believe in “dogfood“, and we want you to be assured that the code we share is used by our team in real deployments. In our mind it isn’t enough to make running Tor services easy, our tools must also help make services secure and reliable. At Emerald Onion, we do this by example.

What is gibson?

A generous description is that gibson is a no-dependency suite of cross-functional tools for creating and maintaining secure and robust Tor services. We currently support HardenedBSD systems, but plan to extend our support to FreeBSD, OpenBSD, and Linux in future releases.

We say that this is a generous description because we want our tools to take as light a touch as possible. To an experienced user, gibson may not appear to do much of anything at all. This is an intentional design decision. An experienced user might say, “Using gibson to do an update achieves the same outcome as just running these three commands I already know”. Truly, nothing would make us happier than this outcome. We want for everyone in the Tor community to be an expert of the tools that make the network operate, from Tor itself to the operating system, hardware, and everything in between. That said, we hope that experienced users will continue to use gibson, and that they will propose new solutions and new functionality.

The goal of gibson isn’t to make difficult Tor management tasks trivial. Rather, the goal of gibson is to make Tor management tasks consistent. We believe that secure systems are built around reproducible, auditable processes. Most of our maintenance is simple and mundane, but a small configuration error or a missed security patch could be catastrophic to the anonymity and security of Tor users. We want to eliminate possible sources of human error and to share our best practices with the community.

We also believe that users should be able to adopt gibson on existing systems without onerous effort, and should also be able to walk away from it whenever they wish without any lock-in. We want our tools to promote the adoption of correct processes and best practices. We also hope that they will be educational. Users new to BSD systems, new to Linux, and new to Tor should be able to look at our code and with minimal effort be able to understand what it does and why.

Finally, we say that gibson is cross-functional because our solution space is defined by the needs of a secure and robust Tor deployment. We do not seek to replace virtualization and jail tools (for instance, bhyve, virtualbox, ezjail, iocell, etc.). We do not seek to replace disk encryption tools (geli, LUKS, etc.). We’re not replacing any web servers, either (nginx, Apache, Caddy, etc.). What we are doing is providing tools to streamline the implementation of these other projects into a complete solution which addresses the needs of Tor administrators.

What does gibson do now?

Currently, gibson updates and controls Tor services running in HBSD jails. A simple and mundane task, but one that we want to make sure is done consistently during each of our maintenance windows. Our initial release of gibson is version 0.1, which is derived from a handful of scripts currently used in maintenance of Emerald Onion systems.

  • 0.0.1 Initial scripts used for EmeraldOnion system maintenance
  • 0.1.0 First version 0.0.1 scripts refactored into gibson: apply system and package updates in jails; start, stop, restart tor services in jails;

Where can I get gibson?

We’re working on getting gibson into the HardenedBSD ports repository, and it should land there shortly.  It will take a little more time for binary packages to become available for users who prefer to use pkg.

In the meantime, gibson is available at our GitHub, as is the files you need to sideload it as a port.  Detailed installation instructions are available there.

Roadmap (or: what will gibson do in the future?)

0.2 -> 0.5

  • Create and maintain template jail(s); clone templates into new jails and deploy tor services:
    • middle relays
    • exit relays
    • bridges
    • onion services (with nginix, initially)
  • Create and manage geli-encrypted ZFS pools
  • Initial creation of encrypted providers and pool members from specified devices
  • Replacement of devices due to failure or capacity expansion
  • Good ideas suggested (or implemented and submitted) by our community!

0.6 -> 0.9

  • Support for FreeBSD systems
  • Good ideas suggested (or implemented and submitted) by our community!

1.5+

  • Support for Linux systems
  • Support for non-geli encrypted filesystems
  • Support for non-ZFS storage pools
  • Good ideas suggested (or implemented and submitted) by our community!

House Style

gibson is always written in all-lowercase.

Logo

The gibson logo was generously donated by Mike Finch and is licensed by Emerald Onion as Creative Commons Attribution 4.0 International.

Tor on HardenedBSD

In this post, we’ll detail how we set up Tor on HardenedBSD. Because of HardenedBSD’s innovative approach to security, including the adoption of strong next-gen exploit mitigations like SafeStack and CFI. We’ll use HardenedBSD 11-STABLE. The vast majority of Tor infrastructure nodes run Linux and OpenSSL. Emerald Onion believes running HardenedBSD will help improve the diversity and resiliency of the Tor network. Additionally, running HardenedBSD gives us peace of mind due to its expertly crafted, robust, and scalable exploit mitigations. Together, Emerald Onion and HardenedBSD are working towards a safer and more secure Tor network.

This article should be considered a living document. We’ll keep it up-to-date as HardenedBSD and Emerald Onion evolve.

02 Sep 2018: This page is being updated to better reflect our ever-evolving setup. Please note that this update may take days. Sections of this page may be incomplete. We will update with another note once the documentation update is complete.

Initial Steps

Downloading and installing HardenedBSD 11-STABLE is simple. Navigate to the latest build and download the installation media that suits your needs. The memstick image is suited for USB flash drives. Boot the installation media.

Installing HardenedBSD is simple. Follow the prompts. Sample screenshots are provided below:

  1. Select Install:
  2. Select your keymap. If you use a standard US English keyboard, the default is fine:
  3. Choose a hostname:
  4. Select the distribution sets to install:
  5. Choose your filesystem. For purposes of this article, we’ll use ZFS for full-disk encryption:
  6. Selecting the Pool Type will allow you to configure your ZFS pool the way you want. We will just use a single disk in this article:
  7. Since we’re using a single disk, we’ll select the Stripe option:
  8. Select the disks to use in the pool. Only a single disk for us:
  9. After selecting the disks, you’ll go back to the original ZFS setup menu. We’ve made a few changes (Encrypt Disks, Swap Size, Encrypt Swap):
  10. Review the changes:
  11. Set the password on your encrypted ZFS pool:
  12. Validate the password:
  13. Encrypted ZFS will initialize itself:
  14. HardenedBSD will now install distribution sets:
  15. Set the root password:
  16. If you want to set up networking, select the network device to configure. In this article, we’ll set up a dynamic (DHCP) network configuration:
  17. We want to use IPv4:
  18. We want to use DHCP:
  19. It will try to acquire a DHCP lease:
  20. At Emerald Onion, we put IPv6 first. However, in this example article, we won’t use IPv6 as it’s not currently available. So we’ll choose no when prompted to set up IPv6:
  21. Ensure the DNS information is correct and make any changes if needed:
  22. It’s now time to choose the system timezone. Select the region:
  23. We chose America. We’ll choose United States for the country next:
  24. Finally we’ll chose the actual timezone:
  25. Confirm the timezone:
  26. Because we use NTP, we’ll skip setting the date:
  27. We’ll also skip setting the time:
  28. Select the services to start at boot:
  29. Select the system hardening options. HardenedBSD sets options one through five by default, so there’s no need to set them here.
  30. We will go ahead and add an unprivileged user. Make sure to add the user to the “wheel” group for access to use the su program:
  31. Set the user’s details:
  32. HardenedBSD is now installed! Exit the installer. The installer will do things in the background so there may be some delay between exiting and the next prompt:
  33. We don’t want to make further modifications to the installation prior to rebooting:
  34. Go ahead and reboot:

The installation is now complete!

Creating the Template Jail

02 Sep 2018: This section is not complete

We want to run multiple instances of Tor in the safest and most organized fashion available. Since we use ZFS, we’ll create a template jail, take a snapshot of the template, then clone the snapshot for our production Tor instances.

# zfs create -omountpoint=/usr/jails zroot/jails
# zfs create zroot/jails/templates/tor-exit
# hbsd-update -V -r /usr/jails/templates/tor-exit
# zfs snapshot zroot/jails/templates/tor-exit@baseinstall
# pkg -r /usr/jails/templates/tor-exit install tor
# pkg -r /usr/jails/templates/tor-exit install py27-nyx
# sysrc -R /usr/jails/templates/tor-exit tor_enable=YES

Now, we need to add additional IP addresses to the interface that we want these jails on. In our case, we’re using ix2.

# sysrc ifconfig_ix2_alias0="inet 23.129.64.103 netmask 255.255.255.0 alias"
# ifconfig ix2 inet 23.129.64.103 netmask 255.255.255.0 alias

Now, let’s set up our /etc/jail.conf file:

# cat <<EOF > /etc/jail.conf
exec.start = "/bin/sh /etc/rc";
exec.stop = "/bin/sh /etc/rc.shutdown";
exec.clean;
mount.devfs;
mount.fstab = "/etc/jail.fstab.$name";

path = "/usr/jails/$name";

template-tor-exit {
	path = "/usr/jails/templates/tor-exit";
        host.hostname = "template-tor-exit";
        ip4 = "inherit";
}
EOF
# touch /etc/jail.fstab.template-tor-exit

The Tor package on HardenedBSD, and its upstream FreeBSD, currently does not ship with a modified Tor configuration file, which can be found at /usr/local/etc/tor/torrc. Tor isn’t set up to log outside of initial startup messages. You will need to edit the Tor configuration file to suit your needs. Take a look at the tor(1) manpage for all the available configuration options.

We’ll populate our template Tor jail with a sample torrc that contains special replacement fields:

cat <<EOF > /usr/jails/templates/tor-exit/usr/local/etc/tor/torrc
Nickname 		%%NICKNAME%%
Address 		%%ADDRESS%%
ContactInfo		%%CONTACTINFO%%
Log notice file		%%LOG_NOTICES%%
OutboundBindAddressExit	%%IP4ADDR%%
OutboundBindAddressOR	%%IP4ADDR%%
DirPort			%%IP4ADDR%%:80
ORPort			%%IP4ADDR%%:443
ORPort			[%%IP6ADDR%%]:443
RelayBandwidthRate	%%BANDWIDTHRATE%%
RelayBandwidthBurst	%%BANDWIDTHBURST%%
MyFamily		%%FAMILY%%
IPv6Exit		%%IP6EXIT%%
SOCKSPort		%%SOCKSPORT%%

# TODO: parameter-ize these bits
ExitPolicy accept *:*
ExitPolicy accept6 *:*
EOF

Now that our template jail is set up, we need to snapshot it:

# zfs snapshot zroot/jails/templates/tor-exit@`date '+%F'`_01

Creating the Production Jail

Now that we have a template jail, we need to create the production jail:

# /bin/sh
# template=`zfs list -t snapshot -r -H -o name zroot/jails/templates/tor-exit | tail -n 1`
# zfs clone ${template} zroot/jails/tor-exit-001

The following script will allow you to modify the template torrc in the production jail:

#!/bin/sh

configpath=""

# Defaults
address="tor.emeraldonion.org"
bandwidthburst="1000 MBytes"
bandwidthrate="120 MBytes"
contactinfo="abuse_at_emeraldonion_dot_org"
ip6exit="1"
log_notices="/var/log/tor/notices.log"
nickname="EmeraldOnion"
socksport="0"

family=""
ip4addr=""
ip6addr=""

SED="/usr/bin/sed"

usage() {
	echo "USAGE: ${0} DOCUMENT ME, FOOLS!" >&2
}

while getopts "4:6:a:b:C:c:e:f:l:n:r:s:" o; do
	case "${o}" in
		4)
			ip4addr="${OPTARG}"
			;;
		6)
			ip6addr="${OPTARG}"
			;;
		a)
			address="${OPTARG}"
			;;
		b)
			bandwidthburst="${OPTARG}"
			;;
		C)
			contactinfo="${OPTARG}"
			;;
		c)
			configpath="${OPTARG}"
			;;
		e)
			ip6exit="${OPTARG}"
			;;
		f)
			family="${OPTARG}"
			;;
		l)
			log_notices="${OPTARG}"
			;;
		n)
			nickname="${OPTARG}"
			;;
		r)
			bandwidthrate="${OPTARG}"
			;;
		s)
			socksport="${OPTARG}"
			;;
		*)
			usage
			;;

	esac
done

if [ -z "${configpath}" ]; then
	echo "[-] Specify the path to the torrc config file." >&2
	exit 1
fi

if [ ! -f "${configpath}" ]; then
	echo "[-] Template torrc at ${configpath} does not exist." >&2
	exit 1
fi

if [ -z "${ip4addr}" ] && [ -z "${ip6addr}" ]; then
	echo "[-] At least one IPv4 or IPv6 address is required." >&2
	exit 1
fi

tmpfile=$(mktemp)
if [ -z "${tmpfile}" ]; then
	echo "[-] Could not create a temporary file." >&2
	exit 1
fi

${SED} \
    -e "s/%%ADDRESS%%/${address}/g" \
    -e "s/%%BANDWIDTHBURST%%/${bandwidthburst}/g" \
    -e "s/%%BANDWIDTHRATE%%/${bandwidthrate}/g" \
    -e "s/%%CONTACTINFO%%/${contactinfo}/g" \
    -e "s/%%FAMILY%%/${family}/g" \
    -e "s/%%IP4ADDR%%/${ip4addr}/g" \
    -e "s/%%IP6ADDR%%/${ip6addr}/g" \
    -e "s/%%IP6EXIT%%/${ip6exit}/g" \
    -e "s,%%LOG_NOTICES%%,${log_notices},g" \
    -e "s/%%NICKNAME%%/${nickname}/g" \
    -e "s/%%SOCKSPORT%%/${socksport}/g" \
    ${configpath} > ${tmpfile}

res=${?}
if [ ${res} -gt 0 ]; then
	echo "[-] Parsing the template torrc failed." >&2
	exit 1
fi

mv ${tmpfile} ${configpath}

Run the script with the proper parameters. Now you can add the new jail to /etc/jail.conf

# cat <<EOF >> /etc/jail.conf
tor-exit-001 {
        host.hostname = "tor-exit-001";
        ip4.addr = 23.129.64.103;
}
EOF

And now we can start up the jail:

# service jail start

Tor should now be running inside the jail!

Keeping HardenedBSD and Tor Up-To-Date

Updating HardenedBSD is simple with hbsd-update. We publish updates for base periodically. Feel free to use hbsd-update as often as you’d like to check for updates to the base operating system.

For example:

# hbsd-update
# shutdown -r now

To update your packages, including Tor, use:

# pkg upgrade

Tor Service Management Basics

The tor rc script uses SIGINT when shutting Tor down. This causes Tor to shutdown in an ungraceful manner, immediately halting connections from clients. Instead of using the traditional service tor stop command, directly issue SIGTERM to the instance you wish to stop.

# service tor status instance-01
tor is running as pid 70918.
# kill -SIGTERM 70918

If you’d like to stop all instances in a graceful way at the same time:

# killall -SIGTERM tor

In a multi-jail setup, you can tell the service command which instance you want to control by specifying the jail name with the -j option. For example, to reload the config file for tor-exit-001, issue the following command:

# service -j tor-exit-001 tor reload

If you want to reload the config file for all instances, simply remove the instance name from the above command. The rc script will issue the reload command across all instances.

If you’d like to look at an instance’s log file, you can use the tail command:

# tail -f /usr/jails/tor-exit-001/var/log/tor/notices.log

Future Work

We plan to switch to our own builds of HardenedBSD. This would allow us to create custom builds specifically tailored for use as a Tor relay. We will also maintain our own minimal package repo.