English
Checkpoint
What must work
On the server:
bash
ufw statusbash
sudo -u postgres psql -c "\l chatex"bash
ls -l /etc/chatex/chatex.envbash
systemctl status chatex-apibash
nginx -tOn your computer:
powershell
curl.exe -i https://<your domain>/healthCompare the server files of your repository with the reference:
powershell
git diff --no-index --stat Deploy D:\Work\Chatex-Reference\DeployOnly two files may appear: nginx/chatex.conf, because of your server_name, and activate-release.sh, which we write in topic 24.
All files were committed and pushed to dev in their chapters; git status reports a clean working tree.
Common mistakes
Table 23.4. Common mistakes when setting up the server
| Symptom | Cause | Fix |
|---|---|---|
the SSH session freezes after ufw enable | SSH was not allowed before the firewall was switched on | log in through the provider's web console and run ufw allow OpenSSH |
git clone fails with Invalid username or token. Password authentication is not supported for Git operations. | the GitHub account password was entered | enter a personal access token as the password |
ERROR: role "chatex" already exists | the CREATE ROLE command was run a second time | nothing to do; to change the password use ALTER ROLE chatex PASSWORD '…' |
[emerg] open() "/etc/nginx/snippets/chatex-security-headers.conf" failed (2: No such file or directory) | the snippet was not copied | copy it into /etc/nginx/snippets/ and run nginx -t again |
ln: failed to create symbolic link '/etc/nginx/sites-enabled/chatex': Already exists | the install command was repeated | harmless: the link exists and points at the same file |
certbot: Could not automatically find a matching server block for <your domain> | server_name still contains chatex.mvano.com | change it in Deploy/nginx/chatex.conf, copy, nginx -t && systemctl reload nginx, run certbot again |
certbot: DNS problem: NXDOMAIN looking up A for <your domain> | the A record is missing or not yet visible | create or fix the record, wait until nslookup shows the IP address |
| the browser shows the Nginx welcome page instead of an error | the default site is still enabled | rm -f /etc/nginx/sites-enabled/default and reload Nginx |
Self-check questions
- Why does Chatex run on one server, and why must the API run as exactly one process?
- Which ports are open to the internet, and which programs listen only on the loopback address? Why?
- Why is
ufw allow OpenSSHrun beforeufw enable? - What do
--system,--home-dirand--shell /usr/sbin/nologindo for thechatexuser? - Which folders belong to
rootand which tochatex, and why? - Why does the application use its own PostgreSQL role, and how does
sudo -u postgres psqllog in without a password? - Why is the settings file a template in the repository and a real file only on the server? What does
__mean in its keys? - Why does
AllowedHostscontain127.0.0.1? - What happens on
systemctl restart chatex-apiafter/opt/chatex/currenthas been switched to another release? - Name five hardening directives of the unit and the attack each one blocks.
- Why does the
/hubs/location setUpgrade,Connectionand a timeout of one hour? - Why must every location with its own
add_headerinclude the security headers again? - How does certbot prove that you control the domain, and why must port 80 stay open after HTTPS works?
Exercises
- Read the sandbox. Run
systemd-analyze security chatex-apiand pick two lines with a cross. Find the directives in systemd.exec and decide whether Chatex could use them. Try one in a copy of the unit (systemctl edit chatex-apicreates an override file) once the API runs after topic 24, and check that/healthstill answersHealthy. - Grade the headers. After the first deployment, test your site with an online checker of security headers and of the TLS configuration. Which recommendations does it make that the snippet does not follow, and why might Chatex deliberately leave them out?
- Plan a non-root setup. Write down the commands to create an administrator account with
sudo, to switch offrootlogin over SSH, and to create a deploy user that may run only/usr/local/bin/chatex-activatethroughsudo(read the header ofactivate-release.shin topic 24). Which secrets and lines ofdeploy.ymlwould change? - Backups off the server. A backup on the same disk is not a backup. Design a daily job that dumps the database with
pg_dump -Fcand copies the dump and/var/lib/chatex/uploadsto another place. What must the restore procedure look like, and how do you test it?