configpolicy/roles
Dustin e4ecd5d58a websites/proxy: Add reverse proxy configuration
For some time, I have been trying to design a new configuration for the
reverse proxy on port 443 to correctly handle all the types of traffic
on that port.  In the original implementation, all traffic on port 443
was forwarded by the gateway to HAProxy.  HAproxy then used TLS SNI to
route connections to the correct backend server based the requested host
name.  This allowed both HTTPS and OpenVPN-over-TLS to use the same
port, however it was not without issues.  A layer 4 (TCP) proxy like
this "hides" the real source address of clients connecting to the
backend, which makes IP-based security (e.g. rate limiting, blacklists,
etc.) impossible at the application level.  In particular, Nextcloud,
which implements rate limiting was constantly imposing login delays on
all users, because legitimate traffic was indistinguishable from
Internet background noise.

To alleviate these issues, I needed to change the proxy to operate in
layer 7 (HTTP) mode, so that headers like *X-Forwarded-For* and
*X-Forwarded-Host* could be added.  Unfortunately, this was not easy,
because of the simultaneous requirement to forward OpenVPN traffic.
HAProxy can only do SNI inspection in TCP mode.  So, I began looking for
an alternate way to proxy both HTTP and non-HTTP traffic on the same
port.

The HTTP protocol defines the `CONNECT` method, which is used by forward
proxies to tunnel HTTPS over plain HTTP.  OpenVPN clients support
tunneling OpenVPN over HTTP using this method as well.  HAProxy has
limited support for the CONNECT method (i.e. it doesn't do DNS
resolution, and I could find no way of restricting the destination) with
the `http_proxy` option, so I looked for alternate proxy servers that
had more complete support.  Unsurprisingly, Apache HTTPD has the most
complete implementation of the `CONNECT` method (Nginx doesn't support
it at all).  Using a name-based virtual host on port 443, Apache will
accept requests for *vpn.pyrocufflink.net* (using TLS SNI) and allow the
clients to use the `CONNECT` method to create a tunnel to the OpenVPN
server.  This requires OpenVPN clients to a) use *stunnel* to wrap plain
HTTP proxy connections in TLS and b) configure OpenVPN to use the
TLS-wrapped HTTP proxy.

With Apache accepting all incoming connections, it was trivial to also
configure it as a layer 7 forward proxy for Bitwarden, Gitea, Jenkins,
and Nextcloud.  Unfortunately, proxying for the other websites
(darkchestofwonders.us, chmod777.sh, dustin.hatch.name) was not quite as
straightforward.  These websites would need to have an internal name
that differed from their external name, and thus a certificate valid for
that name.  Rather than reconfigure all of these sites and set all of
that up, I decided to just move the responsibility for handling direct
connections from outside to the *web0* and eliminate the dedicated
reverse proxy.  This was not possible before, because Apache could not
forward the OpenVPN traffic directly, but now with the forward proxy
configuration, there is no reason to have a separate server for these
connections.

Overall, I am pleased with how this turned out.  It makes the OpenVPN
configuration simpler (*stunnel* no longer needs to run on the OpenVPN
server itself, since Apache is handling TLS termination), eliminates a
network hop for the websites, makes the reverse proxy configuration for
the other web applications much easier to understand, and resolves the
original issue of losing client connection information.
2020-03-16 14:19:08 -05:00
..
ansible/tasks roles/ansible: Install python-netaddr 2018-04-08 12:33:54 -05:00
apache hosts: git0: Switch to Lego wildcard cert 2020-02-22 16:43:46 -06:00
aria2 aria2: Deploy aria2 download manager 2018-08-19 14:17:48 -05:00
base roles/base: Basic config management support 2018-01-29 15:02:10 -06:00
bitwarden_rs roles/bitwarden_rs: Install sqlite 2019-09-19 19:27:30 -05:00
burp-client burp-client: Use burp.p.b name 2020-01-18 12:10:53 -06:00
burp-server roles/burp-server: switch to version_compare test 2020-01-25 13:54:42 -06:00
cert/tasks roles/cert: Common role for installing certs 2020-03-09 20:17:47 -05:00
certbot roles/certbot: Ensure certbot is configured first 2019-09-19 19:50:35 -05:00
cronie/tasks roles/cronie: Install cronie 2018-08-08 21:38:56 -05:00
dch-gw dch-gw: Restrict traffic from Management network 2018-07-15 12:16:43 -05:00
dch-openvpn-server dch-openvpn: Support road-warrior clients 2018-10-07 21:42:18 -05:00
dch-proxy websites: Add chmod777.sh 2020-03-09 20:29:52 -05:00
dch-storage-net roles/dch-storage-net: Add After device dependency 2018-07-29 10:14:00 -05:00
dch-vpn-server roles/dch-vpn-server: Update remote access DNS 2018-08-08 21:37:30 -05:00
dhcpcd roles/dhcpcd: Always send FQDN 2018-07-23 17:35:10 -05:00
dhcpd roles/dhcpd: Support UniFi DHCP option 43 2019-03-22 09:29:56 -05:00
docker roles/docker: Install and set up Docker daemon 2019-09-19 19:27:12 -05:00
fileserver roles/fileserver: Deploy Samba file server 2018-08-01 22:04:07 -05:00
freeradius roles/freeradius: Set dhparam permissions 2019-09-19 19:50:35 -05:00
gitea roles/gitea: Install from upstream binary 2020-02-22 16:43:46 -06:00
haproxy roles/haproxy: Fix undefined var on Fedora hosts 2020-03-03 19:27:19 -06:00
hass-dhcp roles/hass-dhcp: Enable DNS query logging 2019-09-19 19:50:35 -05:00
homeassistant roles/homeassistant: Deploy Home Assistant 2019-03-05 18:30:29 -06:00
hostname hostname: Also write /etc/hosts 2018-04-08 10:11:43 -05:00
jenkins-slave jenkins-slave: Allow Jenkins to connect to Docker 2019-09-19 19:50:35 -05:00
kerberos roles/kerberos: Configure mit-krb5 2018-01-29 15:05:51 -06:00
koji-builder roles/koji-builder: Deploy the Koji builder 2018-08-12 10:14:25 -05:00
koji-client roles/koji-client: Configure the koji client 2018-08-12 10:05:56 -05:00
koji-gc roles/koji-gc: Deploy the Koji garbage collector 2018-08-12 09:58:56 -05:00
koji-hub roles/koji-hub: Deploy the Koji Hub 2018-08-12 09:33:08 -05:00
koji-web roles/koji-web: Deploy the Koji Web UI 2018-08-12 10:08:01 -05:00
kojira roles/kojira: Deploy the Koji repository agent 2018-08-12 10:04:23 -05:00
named roles/named: Provide default for named_keys 2018-08-12 18:06:14 -05:00
net-ifaces roles/net-ifaces: Create bridges for mgmt and hass 2019-03-22 09:29:56 -05:00
nextcloud nextcloud: Deploy Nextcloud w/ Apache+PHP-FPM 2020-03-09 20:18:07 -05:00
nftables roles/nftables: Basic nftables configuration 2018-03-27 20:44:43 -05:00
nsswitch roles/nsswitch: Configure glibc name service 2018-03-11 18:16:17 -05:00
ntpd ntp: Initial PB and role to set up ntpd 2018-04-22 11:19:22 -05:00
postfix roles/postfix: Vary shlib directory by arch 2018-08-07 19:51:09 -05:00
postgresql-server roles/postgresql-server: Deploy PostgreSQL 2018-04-14 15:23:44 -05:00
rabbitmq/tasks roles/rabbitmq: Deploy RabbitMQ 2019-03-07 13:29:29 -06:00
radvd roles/radvd: Support multiple prefixes per network 2018-04-06 20:16:02 -05:00
rhel-network roles/rhel-network: Add static route support 2018-03-27 20:44:43 -05:00
samba roles/samba: Support selecting interfaces 2018-06-23 14:42:45 -05:00
samba-dc roles/samba: Manage LDAP TLS certificates 2019-03-22 09:31:19 -05:00
squid squid: Add role and PB to deploy Squid 2018-08-12 16:00:32 -05:00
ssh-hostkeys nextcloud: Deploy Nextcloud w/ Apache+PHP-FPM 2020-03-09 20:18:07 -05:00
sshd roles/sshd: Configure OpenSSH daemon 2018-06-06 21:44:28 -05:00
strongswan roles/strongswan: Base role for strongSwan setup 2018-05-20 12:56:27 -05:00
sudo roles/sudo: Configure sudo and policy 2018-03-11 18:16:17 -05:00
system-auth roles/system-auth: Configure PAM system authentication 2018-03-11 18:16:17 -05:00
taiga roles/taiga: Fix HTTP->HTTPS redirect 2019-03-22 09:29:56 -05:00
trustca roles/trustca: Generic role for adding CA certs 2018-06-04 20:03:55 -05:00
vmhost roles/vmhost: Enable KSM 2019-03-22 09:29:56 -05:00
websites websites/proxy: Add reverse proxy configuration 2020-03-16 14:19:08 -05:00
wheelhost wheelhost: Publish wheels built by Jenkins 2019-03-22 10:19:27 -05:00
winbind roles/winbind: Fix error handling in ads_member 2019-03-22 09:29:56 -05:00
zabbix-agent roles/zabbix: Add support for Debian 2019-03-22 09:29:56 -05:00
zabbix-server roles/zabbix-server: Redirect HTTP -> HTTPS 2018-06-09 14:35:22 -05:00