diff --git a/blog/site-to-site-wireguard-part-4-2019-04-16.markdown b/blog/site-to-site-wireguard-part-4-2019-04-16.markdown index ee0156a..c7b1578 100644 --- a/blog/site-to-site-wireguard-part-4-2019-04-16.markdown +++ b/blog/site-to-site-wireguard-part-4-2019-04-16.markdown @@ -43,6 +43,14 @@ chown root:root /usr/local/bin/caddy chmod 755 /usr/local/bin/caddy ``` +These permissions are set as such: + +| Facet | Read | Write | Directory Listing | +| :--------------- | :--- | :---- | :---------------- | +| User (www-data) | Yes | Yes | Yes | +| Group (www-data) | Yes | No | Yes | +| Others | Yes | No | Yes | + In order for Caddy to bind to the standard HTTP and HTTPS ports as non-root (this is a workaround for the fact that [Go can't currently drop permissions with suid() cleanly](https://github.com/golang/go/issues/1435)), run the following: ```console diff --git a/blog/site-to-site-wireguard-part-4-2019-04-19.markdown b/blog/site-to-site-wireguard-part-4-2019-04-19.markdown deleted file mode 100644 index c7b1578..0000000 --- a/blog/site-to-site-wireguard-part-4-2019-04-19.markdown +++ /dev/null @@ -1,346 +0,0 @@ ---- -title: "Site to Site WireGuard: Part 4 - HTTPS" -date: 2019-04-16 -series: site-to-site-wireguard ---- - -# Site to Site WireGuard: Part 4 - HTTPS - -This is the fourth post in my Site to Site WireGuard VPN series. You can read the other articles here: - -- [Part 1 - Names and Numbers](https://christine.website/blog/site-to-site-wireguard-part-1-2019-04-02) -- [Part 2 - DNS](https://christine.website/blog/site-to-site-wireguard-part-2-2019-04-07) -- [Part 3 - Custom TLS Certificate Authority](https://christine.website/blog/site-to-site-wireguard-part-3-2019-04-11) -- Part 4 - HTTPS (this post) -- Setting up additional iOS, macOS, Android and Linux clients -- Other future fun things (seamless tor2web routing, etc) - -In this article, we are going to install [Caddy](https://caddyserver.com) and set up the following: - -- A plaintext markdown site to demonstrate the process -- A URL shortener at https://g.o/ (with DNS and TLS certificates too) - -## HTTPS and Caddy - -[Caddy](https://caddyserver.com) is a general-purpose HTTP server. One of its main features is automatic [Let's Encrypt](https://letsencrypt.org) support. We are using it here to serve HTTPS because it has a very, very simple configuration file format. - -Caddy doesn't have a stable package in Ubuntu yet, but it is fairly simple to install it by hand. - -## Installing Caddy - -One of the first things you should do when installing Caddy is picking the list of extra plugins you want in addition to the core ones. I generally suggest the following plugins: - -- [`http.cors`](https://caddyserver.com/docs/http.cors) - [Cross-Origin Resource Sharing](https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS), because we can't trust browsers -- [`http.git`](https://caddyserver.com/docs/http.git) - it facilitates automatic deployment -- [`http.supervisor`](https://caddyserver.com/docs/http.supervisor) - run background processes - -First we are going to need to download Caddy (please do this as root): - -```console -curl https://getcaddy.com > install_caddy.sh -bash install_caddy.sh -s personal http.cors,http.git,http.supervisor -chown root:root /usr/local/bin/caddy -chmod 755 /usr/local/bin/caddy -``` - -These permissions are set as such: - -| Facet | Read | Write | Directory Listing | -| :--------------- | :--- | :---- | :---------------- | -| User (www-data) | Yes | Yes | Yes | -| Group (www-data) | Yes | No | Yes | -| Others | Yes | No | Yes | - -In order for Caddy to bind to the standard HTTP and HTTPS ports as non-root (this is a workaround for the fact that [Go can't currently drop permissions with suid() cleanly](https://github.com/golang/go/issues/1435)), run the following: - -```console -setcap 'cap_net_bind_service=+eip' /usr/local/bin/caddy -``` - -Caddy expects configuration file/s to exist at `/etc/caddy`, so let's create the folders for them: - -```console -mkdir -p /etc/caddy -touch /etc/caddy/Caddyfile -chown -R root:www-data /etc/caddy -``` - -### Let's Encrypt Certificate Permissions - -Caddy's systemd unit expects to be able to create new certificates at `/etc/ssl/caddy`: - -```console -mkdir -p /etc/ssl/caddy -chown -R www-data:root /etc/ssl/caddy -chmod 770 /etc/ssl/caddy -``` - -These permissions are set as such: - -| Facet | Read | Write | Directory Listing | -| :--------------- | :--- | :---- | :---------------- | -| User (www-data) | Yes | Yes | Yes | -| Group (root) | Yes | Yes | Yes | -| Others | No | No | No | - -This will allow only Caddy and root to manage certificates in that folder. - -### Custom CA Certificate Permissions - -In the [last post](https://christine.website/blog/site-to-site-wireguard-part-3-2019-04-11), custom certificates were created at `/srv/within/certs`. Caddy is going to need to have the correct permissions in order to be able to read them. - -```shell -#!/bin/sh -chmod -R 750 . -chown -R root:www-data . -chmod 600 minica-key.pem -``` - -Then mark it executable: - -``` -chmod +x fixperms.sh -``` - -These permissions are set as such: - -| Facet | Read | Write | Execute/Directory Listing | -| :--------------- | :--- | :---- | :------------------------ | -| User (root) | Yes | Yes | Yes | -| Group (www-data) | Yes | No | Yes | -| Others | No | No | No | - -This will allow Caddy to be able to read the certificates later in the post. Run this after certificates are created. - -``` -cd /srv/within/certs -./fixperms.sh -``` - -### HTTP Root Permissions - -I dypically store all of my websites under `/srv/http/domain.name.here`. To create a folder like this: - -```console -mkdir -p /srv/http -chown www-data:www-data /srv/http -chmod 755 /srv/http -``` - -These permissions are set as such: - -| Facet | Read | Write | Directory Listing | -| :--------------- | :--- | :---- | :---------------- | -| User (www-data) | Yes | Yes | Yes | -| Group (www-data) | Yes | No | Yes | -| Others | Yes | No | Yes | - -### Systemd - -To install the [upstream systemd unit](https://github.com/mholt/caddy/blob/master/dist/init/linux-systemd/caddy.service), run the following: - -```console -curl -L https://github.com/mholt/caddy/raw/master/dist/init/linux-systemd/caddy.service \ - | sed "s/;CapabilityBoundingSet/CapabilityBoundingSet/" \ - | sed "s/;AmbientCapabilities/AmbientCapabilities/" \ - | sed "s/;NoNewPrivileges/NoNewPrivileges/" \ - | tee /etc/systemd/system/caddy.service -chown root:root /etc/systemd/system/caddy.service -chmod 744 /etc/systemd/system/caddy.service -systemctl daemon-reload -systemctl enable caddy.service -``` - -These permissions are set as such: - -| Facet | Read | Write | Execute | -| :----------- | :--- | :---- | :------ | -| User (root) | Yes | Yes | Yes | -| Group (root) | Yes | No | No | -| Others | Yes | No | No | - -This will also configure Caddy to start on boot. - - * Configure Caddy for static file serving for aloha.pele - * root directive - * browse directive - * Link to Caddy documentation - -## Configure aloha.pele - -In the last post, we created the domain and TLS certificates for `aloha.pele`. Let's create a website for it. - -Open `/etc/caddy/Caddyfile` and add the following: - -``` -# /etc/caddy/Caddyfile - -aloha.pele:80 { - tls off - redir / https://aloha.pele:443 -} - -aloha.pele:443 { - tls /srv/within/certs/aloha.pele/cert.pem /srv/within/certs/aloha.pele/key.pem - - internal /templates - - markdown / { - template templates/page.html - } - - ext .md - browse / - - root /srv/http/aloha.pele -} -``` - -And create `/srv/http/aloha.pele/templates`: - -```console -mkdir -p /srv/http/aloha.pele/templates -chown -R www-data:www-data /srv/http/aloha.pele/templates -``` - -And open `/srv/http/aloha.pele/templates/page.html`: - -```html - - - -
-