nunosempere.com/.secret/how-to.md

411 lines
16 KiB
Markdown
Raw Normal View History

2022-07-06 17:07:18 +00:00
# How to create an autarchic website
2022-05-20 21:17:49 +00:00
> Where to host the blog: Our Recommendation: Use Substack or try out a hosted Ghost website—its a Goldilocks solution of easy-to-use but highly customizable. Ghost makes for a great portfolio site, blog, and newsletter service.
[Effective Ideas: Where to host the blog](https://effectiveideas.org/how-to-start-a-blog/#pt3)
2022-07-06 17:07:18 +00:00
No. Vat do I vant, and in vat order? Uncensorability, ability to ramp up degrees of privacy and paranoia, control over ze whole stack, and finally, ze modern comforts. Vith that in mind, I present my guide to uncensorability.
2022-05-20 21:17:49 +00:00
What is this meant for? Some recent examples:
2022-07-06 17:07:18 +00:00
- The Canadian government [grossly overreached against Canadian truckers' freedom of speech](https://twitter.com/punk6529/status/1494444624630403083).
- [Youtube-dl was banned by Github](https://www.eff.org/deeplinks/2020/11/github-reinstates-youtube-dl-after-riaas-abuse-dmca).
- [EFF Sues Proctorio on Behalf of Student It Falsely Accused of Copyright Infringement to Get Critical Tweets Taken Down](https://www.eff.org/press/releases/eff-sues-proctorio-behalf-student-it-falsely-accused-copyright-infringement-get).
2022-05-20 21:17:49 +00:00
2022-07-06 17:07:18 +00:00
## Index
2022-05-20 21:17:49 +00:00
2022-07-06 17:07:18 +00:00
1. Preliminiaries
2022-05-20 21:17:49 +00:00
2022-07-06 17:07:18 +00:00
- Introduction (^)
- Get a password manager
- Get an email
2022-05-20 21:17:49 +00:00
2022-07-06 17:07:18 +00:00
2. Get a server
- Register a domain
- Get a server
- Point your domain to your server
3. Set up a simple server
- Create and set up users
- Install nginx
- Get nginx working with a simple website
- Install TLS certificates
4. Into the rabbit hole
- Install plan9port
- Install werc
- Configure werc
- Install discount markdown
- Configure nginx to work with werc
- Install fcgi
## 1. Preliminaries
### Get you a password manager for great security
For this, I recommend [pass](https://www.passwordstore.org/) (see also the [archlinux wiki](https://wiki.archlinux.org/title/Pass)). Simple, secure.
To generate a password independent from pass:
2022-05-20 21:17:49 +00:00
```
function newpassword(){
2022-07-06 17:07:18 +00:00
characters="\!#\$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[]^_\abcdefghijklmnopqrstuvwxyz{|}~"
# ^ excludes `
2022-05-20 21:17:49 +00:00
length=25
read -r -n $length new_password < <(LC_ALL=C tr -dc "$characters" < /dev/urandom)
echo $new_password
} ## Taken from pass generate. Maybe save this in your .bashrc
newpassword
pass insert -m autarchy/protonmail ## Then save both the email address and the password.
## You can then recall your password with pass show autarchy/protonmail
```
2022-07-06 17:07:18 +00:00
Personally, I've found it useful to wrap `pass insert -m` into an extension for pass (pass [append]()). I also found it useful to have a utility for [searching passwords](). And, as always, [backup](https://github.com/8go/pass-backup) stuff.
### Get an email
[Protonmail](https://protonmail.com/) is fine.
Mad Eye Moody recommends: Don't give Protonmail a backup email. Instead, make sure to make backups of your passwords. You can access Protonmail over [Tor](https://torproject.org/) [here](https://mail.protonmailrmez3lotccipshtkleegetolb73fuirgj7r4o4vfu7ozyd.onion). For added paranoia, you can register an [XMPP identity](https://www.shad0w.io/) instead of an email address. Also, do your own research on which service providers are the most secure.
2022-05-20 21:17:49 +00:00
2022-07-06 17:07:18 +00:00
## 2. Get a server
### Register a domain
2022-05-20 21:17:49 +00:00
For zis, ve will use, of course, [njal.la](https://njal.la/). The're the non-evil twin brother of [Epik domains](https://www.epik.com/). From their [FAQ](https://njal.la/faq/):
> We're a team of committed internet activists and we're also involved in other privacy projects such as the IPredator VPN service. Some of us have also been involved in projects like The Pirate Bay and Piratbyrån to mention a few things.
> We support signing up for our service using email or XMPP (and yes, we use OTR). For email we also support PGP so all of our outgoing email will be signed and encrypted.
> We accept payments via Bitcoin, Litecoin, Monero, ZCash, DASH, Bitcoin Cash, Ethereum and Paypal.
2022-07-06 17:07:18 +00:00
They also have [a blog](https://njal.la/blog/) vere they record takedown requests. All in all, zis is ze good stuff.
2022-05-20 21:17:49 +00:00
For this, you will need to setup an account on njal.la, using the email you previously created
```
newpassword
pass insert -m autarchy/njalla-account ## save both password and user
2022-07-06 17:07:18 +00:00
## You can later recall this with pass show autarchy/njalla,
## or with pass reveal njalla if you installed that extension
2022-05-20 21:17:49 +00:00
```
2022-07-06 17:07:18 +00:00
Mad Eye Moody recommends: Use [tornado cash](https://tornado.cash/) to anonymize your transaction history before paying njalla. Check which top-level domain names are [more uncensorable](https://www.eff.org/files/2017/08/02/domain_registry_whitepaper.pdf) (from casual reading, I would go with .br, .cr , .is, .org, .ru, of which njalla supports only .org and .ru). If if we wanted further anonymity and uncensorability, [set up an onion service](https://community.torproject.org/onion-services/setup/).
2022-05-20 21:17:49 +00:00
2022-07-06 17:07:18 +00:00
### Get a server
2022-05-20 21:17:49 +00:00
2022-07-06 17:07:18 +00:00
Previously, I had been using an Ubuntu server on [Digital Ocean](digitalocean.com), which offers servers from $5/month ($6/month including backups). But I have grown to dislike my system having 1GB worth of stuff that I don't understand. I also dislike wrangling with systemd services.
2022-05-20 21:17:49 +00:00
So I thought it would be fun to try Alpine Linux on [Njal.la's own servers](https://njal.la/servers/add/). This costs $15/month instead.
When buying a server from Njalla, we need to name it. And we will name it [`ramiel`](https://en.wikipedia.org/wiki/Ramiel) [^1]. We will also need to generate an ssh key to connect to it. The command to do this is `ssh-keygen -t ed25519`. After paying for our server, we'll want to set up payment to autorenew.
[^1]: Why Ramiel? Because Uriel is dead
2022-07-06 17:07:18 +00:00
### Point from your domain to your server.
2022-05-20 21:17:49 +00:00
2022-07-06 17:07:18 +00:00
Add a DNS record pointing from your domain to your server. In particular, you want an A record. Note that it might take a while for it to propagate, so at this point, you can either:
2022-05-20 21:17:49 +00:00
2022-07-06 17:07:18 +00:00
- Wait for ~24 until your server and domain name are connected
- Set up your users and a minimal nginx installation. This requires some additional fiddling, and I will not document it here.
## Step 3: Set up the server
### Set up a new user
2022-05-20 21:17:49 +00:00
We can connect to our server with
```
ssh root@your_ip
```
Then add some essential tooling:
```
apk add vim
apk add sudo
apk add git
```
2022-07-06 17:07:18 +00:00
Strictly speaking you could do everything as root, but this feels dirty. Instead, we will create two new users, one root user for admin tasks, called `ramiel`, and one user for normal operation of web assets, named `www`. The below process probably contains some bugs, which stackoverflow or the alpine and arch linux wikis should solve.
2022-05-20 21:17:49 +00:00
2022-07-06 17:07:18 +00:00
To create a new root user:
2022-05-20 21:17:49 +00:00
```
adduser ramiel
apk add doas
adduser ramiel wheel
mkdir -p /home/ramiel
mkdir /home/ramiel/.ssh
```
2022-07-06 17:07:18 +00:00
Then, add `permit persist :wheel` to `/etc/doas.d/doas.conf`
2022-05-20 21:17:49 +00:00
2022-07-06 17:07:18 +00:00
Then use [visudo](https://unix.stackexchange.com/questions/27594/why-do-we-need-to-use-visudo-instead-of-directly-modifying-the-sudoers-file) to add `ramiel ALL=(ALL) ALL` to `/etc/sudoers`.
2022-05-20 21:17:49 +00:00
2022-07-06 17:07:18 +00:00
Lastly, allow yourself to log into the server as this new user using ssh.
2022-05-20 21:17:49 +00:00
```
cp /root/.ssh/authorized_keys /home/ramiel/.ssh/authorized_keys
chown ramiel /home/ramiel/.ssh/authorized_keys
```
2022-07-06 17:07:18 +00:00
Then, in `/etc/ssh/sshd_config`, change:
2022-05-20 21:17:49 +00:00
```
PasswordAuthentication no
PermitRootLogin prohibit-password
```
to:
```
PasswordAuthentication no
PermitRootLogin yes
```
Then restart the ssh service
```
service sshd restart
exit
```
2022-07-06 17:07:18 +00:00
And connect with your new user
2022-05-20 21:17:49 +00:00
```
ssh ramiel@your_ip
```
2022-07-06 17:07:18 +00:00
### Install nginx
Here we make our first—of many—compromises with the [suckless](https://suckless.org/) philosophy. Unlike simpler web servers, nginx—pronounced "engine x"—is not suckless. However, I do have a job, and I'm choosing nginx because it is well documented, widely used, and has good integration with certbot, the certificates bot from the Electronic Freedom Foundation which allows me to have https (also perhaps not suckless).
2022-05-20 21:17:49 +00:00
2022-07-06 17:07:18 +00:00
To install nginx, follow instructions from [here](https://wiki.alpinelinux.org/wiki/Nginx). Digital Ocean has a few good tutorials on how to get nginx up and running, e.g., [How To Install Nginx on Ubuntu 20.04](https://www.digitalocean.com/community/tutorials/how-to-install-nginx-on-ubuntu-20-04). Steps are very similar on Alpine. Though Alpine doesn't have the `ufw` firewall, the package manager is called `apk`, not `apt`, and so on.
2022-05-20 21:17:49 +00:00
2022-07-06 17:07:18 +00:00
In this case, I chose to create a folder in the `/home/www` directory, rather than directly in `/www`. This is probably some residual scaredness from when I didn't want to play around too much with directories outside the home directory.
In any case, the commands I used to set up nginx were:
2022-05-20 21:17:49 +00:00
```
apk update
apk add nginx
adduser -D -g 'www' www
2022-07-06 17:07:18 +00:00
chown -R www:www /var/lib/nginx ## This is important!!
2022-05-20 21:17:49 +00:00
mkdir /home/www
chown -R www:www /home/www
```
We also want nginx to boot up at startup
```
rc-update add nginx default
2022-07-06 17:07:18 +00:00
rc-service nginx status
```
At this point, we can get a minimal website working. Create an `index.html` file somewhere, and use a nginx setup such as [this](https://github.com/NunoSempere/werc-1.5.0-tweaks/blob/master/etc/contrib/nginx/sites-available/nunosempere.com-simple) to check everything is working out ok. This is an important step, because it lets you check your work so far.
After some debugging, you should have a very simple yet fairly hard to censor website. Congratulations!
### Set up TLS
At this point, one might as well add TLS working, by following instructions such as those in [How To Secure Nginx with Let's Encrypt on Ubuntu 20.04](https://www.digitalocean.com/community/tutorials/how-to-secure-nginx-with-let-s-encrypt-on-ubuntu-20-04).
Before you install SSL, you will need a DNS record, and in particular, an A record, pointing from your domain to your server. It might take a while for the DNS record to be updated; around 24 to 48 hours.
The commands for installing certificates are pretty trivial:
```
apk add --update python3 py3-pip
apk add certbot
pip install certbot-nginx
rc-service nginx stop
sudo certbot --nginx -d your-site.org
```
## 4. Into the rabbit hole
Our setup will looks as follows:
![](https://i.imgur.com/69cnAw2.png)
And the steps we will use to get this working are:
- Install plan9port
- Install werc
- Configure werc
- Install discount markdown
- Configure nginx to work with werc
- Install fcgi
Why am I using werc in Alpine linux rather than, I don't know, [Pelican](https://blog.getpelican.com/) on Debian, or [Jekyll](https://jekyllrb.com/) on Github Pages or [Gatsby](https://www.gatsbyjs.com/) on netlify? Because I am a sadomasochist, that's why. Proba
### Install plan9port
Plan9port is werc's key dependency. I might be able to get werc working with musl. But I can't be arsed. Instead, I am installing plan9port side by side with musl.
To install plan9port, add the following line:
```
https://dl-cdn.alpinelinux.org/alpine/v3.15/community/
```
to the `/etc/apk/repositories` file, to get access to community packages.
Then install plan9port
```
apk install plan9port
## https://pkgs.alpinelinux.org/package/v3.15/community/x86_64/plan9port
```
By default, plan9port gets installed to `/usr/lib/plan9/bin`. But we want the `rc` shell to be easily available:
```
cp /usr/lib/plan9/bin/rc /bin/rc
2022-05-20 21:17:49 +00:00
```
## Install werc
[Werc](https://werc.cat-v.org/) is a work of genius by the mad architect Uriel. It describes itself as a "a minimalist web anti-framework built following the Unix and Plan 9 tool philosophy of software design". It is a more hardcore version of Jekyll, Pelican, Blogger, or Wordpress.
```
cd /home/www
mkdir werc
cd werc
wget --no-check-certificate https://werc.cat-v.org/download/werc-1.5.0.tar.gz
sha512sum werc-1.5.0.tar.gz
## 06695bf0798d28821500d84339f873a712ceb53cec6dc5bc641a47945a811515657e749c1d8c6cfeba42432ec8557397db9231ff4b5d2eec581a5ff063ab6648 werc-1.5.0.tar.gz
tar x -f werc-1.5.0.tar.gz
cd werc-1.5.0
```
Initialize a git repository
```
git init
git add .
git commit -m "feat: start keeping track of atomic changes on top of werc-1.5.0"
git remote add
```
It's good discipline to keep track of changes which are more or less atomic. This facilitates you remembering what changes you've done, and allows you to contribute back.
2022-07-06 17:07:18 +00:00
Alternatively, pull in _my own personal tweaks_:
2022-05-20 21:17:49 +00:00
```
git init
git add .
git remote add tweaks https://github.com/NunoSempere/werc-1.5.0-tweaks.git
git pull tweaks master
```
2022-07-06 17:07:18 +00:00
These tweaks are a bit opinionated (e.g., they assume that you have set-up https). But they also make daily work more pleasant. Proceed at your own caution.
2022-05-20 21:17:49 +00:00
Mad Eye Moody recommends: Go through the [commit history](https://github.com/NunoSempere/werc-1.5.0-tweaks/commits/master) and pick and choose instead.
### Configure werc
There are several important configurations:
- Point to your plan9 binaries
2022-07-06 17:07:18 +00:00
- Decide whether to have a blog or not
2022-05-20 21:17:49 +00:00
- Whether to use http or https
- Whether to use [discount markdown](https://www.pell.portland.or.us/~orc/Code/discount/) or not, in which case you will have to install it
Of these, the more important is the first one. To let werc know where your plan9 binaries are installed
```
cd /home/www/werc/werc-1.5.0/etc/
cp initrc initrc.local
vim initrc.local
## Change one of the first lines to:
## plan9port=/usr/lib/plan9
```
2022-07-06 17:07:18 +00:00
To enable blog functionality, follow instructions [here](https://werc.cat-v.org/apps/blagh/)
2022-05-20 21:17:49 +00:00
2022-07-06 17:07:18 +00:00
To use https instead of http, grep for http and change it all to https. Find the necessary files using `grep http -R bin/`, or have a look at [this git commit](https://github.com/NunoSempere/werc-1.5.0-tweaks/commit/18893f3192721144e82497dce751864faa4437e4)
2022-05-20 21:17:49 +00:00
2022-07-06 17:07:18 +00:00
Personally, I'm a fan of discount markdown, because it has a few more features than the default awk markdown parser. To install discount markdown, run
2022-05-20 21:17:49 +00:00
```
2022-07-06 17:07:18 +00:00
apk install discount
2022-05-20 21:17:49 +00:00
```
2022-07-06 17:07:18 +00:00
And then have a look at [this commit](https://github.com/NunoSempere/werc-1.5.0-tweaks/commit/f492aa962b4c0627dd013f074c0d01000f6e70fe) for the necessary changes.
2022-05-20 21:17:49 +00:00
2022-07-06 17:07:18 +00:00
## Configure nginx to work with werc
2022-05-20 21:17:49 +00:00
2022-07-06 17:07:18 +00:00
Configuring nginx to work with werc is the tricky part. Luckily, [here](https://github.com/NunoSempere/werc-1.5.0-tweaks/tree/master/etc/contrib/nginx) is an example working configuration, i.e., the contents of my `/etc/nginx`. Best of luck!
One of the key pieces to connect nginx and werc is [fcgi](https://wikiless.org/wiki/FastCGI?lang=en) (fast common gateway interface). It can be installed with
2022-05-20 21:17:49 +00:00
```
sudo apk add spawn-fcgi
sudo apk add fcgiwrap
```
You can then spawn this with
```
/usr/bin/spawn-fcgi -a 127.0.0.1 -p 9000 -f /usr/bin/fcgiwrap
```
Alternatively, and more conveniently, you can set this up so that fcgi is spawned when the system starts. To do so, copy the following:
```
#!/sbin/openrc-run
## move to /etc/init.d/spawn-fcgi2
## Then sudo rc-update add spawn-fcgi2
## test with sudo rc-service spawn-fcgi2 start
## and sudo rc-service spawn-fcgi2 stop
PID_file="/var/tmp/spawn"
depend() {
need net
}
start() {
/usr/bin/spawn-fcgi -a 127.0.0.1 -p 9000 -f /usr/bin/fcgiwrap -P "$PID_file"
}
stop() {
kill -15 "$(cat "$PID_file")"
rm "$PID_file"
}
case $1 in
start|stop) "$1" ;;
esac
```
2022-07-06 17:07:18 +00:00
into a new file, `spawn-fcgi2`, and then:
2022-05-20 21:17:49 +00:00
```
mv spawn-fcgi2 /etc/init.d/spawn-fcgi2
cd /etc/init.d
sudo chmod 755 spawn-fcgi2
sudo rc-update add spawn-fcgi2
```
2022-07-06 17:07:18 +00:00
Installing fcgi, copying [my configuration](https://github.com/NunoSempere/werc-1.5.0-tweaks/tree/master/etc/contrib/nginx) and making the relevant changes probably still requires some tweaking and debugging. For instance, it's necessary that the nginx folder is owned by the `www` user. If someone wants to document this better, I welcome improvements.
## Backups
Backups, and then backups for the backups. For this, I would recommend some combination of:
- [tarsnap](https://www.tarsnap.com/)
- an online git service, like GitHub, GitLab or Codeberg
- a local git repository in a different machine
- [ipfs](https://ipfs.io/)
## Conclusion
2022-05-20 21:17:49 +00:00
2022-07-06 17:07:18 +00:00
We have seen how to create a website which is decently anonymous and hard to attack. This isn't secure enough to support a drug empire (unless?), but it should be secure enough to post slightly edgy content online. We did this the hard way in order to not rely on services like WordPress or Netlify, which would probably buckle under external pressure.