# Hardening and security checklist

`deploy/install.sh` applies the core hardening on a fresh install. `deploy/harden.sh` is a standalone, re-runnable pass that adds the rest, and it can also retrofit an existing ITFlow-style install.

## Run the hardening pass

Run it once, after installing:

```bash
sudo deploy/install.sh --domain=msp.example.com ...
sudo deploy/harden.sh
```

`install.sh` already applies the PHP-FPM, MariaDB, firewall and fail2ban settings inline from the same template files. `harden.sh` compares content before writing, so it skips what is already in place and picks up the two things the installer does not do: the MariaDB cleanup and unattended security updates.

Preview first on any box you did not just build:

```bash
sudo deploy/harden.sh --dry-run
```

### What it applies

1. **PHP-FPM hardening**, validated with a config test, reloaded only on success and rolled back otherwise.
2. **MariaDB hardening**, with the same validate, restart, roll back pattern.
3. **A `mysql_secure_installation`-equivalent cleanup**: removes anonymous users and the `test` database.
4. **fail2ban** jails for SSH and for the application's sign-in.
5. **ufw**, allowing every port `sshd` actually listens on, plus 80 and 443 (and 8443 in proxy mode), before enabling the firewall.
6. **unattended-upgrades**, limited to security updates, with automatic reboot disabled. A live application rebooting itself unattended is its own outage.
7. **nginx**: the shared rate-limit zone and locations snippet, and a re-rendered virtual host if you pass `--domain`, `--app-root`, `--ssl-cert` and `--ssl-cert-key`.

Every step checks before acting, so running it again is safe. You can skip sections with `--skip-php`, `--skip-mariadb`, `--skip-mysql-secure`, `--skip-fail2ban`, `--skip-ufw`, `--skip-unattended-upgrades` or `--skip-nginx`. None of it will disable SSH access.

## The four things every install should do

1. **Rotate the database password if it was ever visible.** The installer writes it straight into `config.php` without printing it, but if you typed a `--password=` flag yourself or someone saw it on screen, treat it as exposed.
2. **Enable cron in the app's settings** once the instance is configured. The system cron entry fires every five minutes regardless, but nothing happens until the setting is on.
3. **Store the backup passphrase off the server.** See [Backups and disaster recovery](/docs/msp/backups-and-disaster-recovery).
4. **Turn on two-factor sign-in for the admin.** TOTP and passkeys are both supported and neither is on by default.

## Other protections worth knowing

- **Optional login key.** An install-wide shared secret that must be supplied in addition to a user's own credentials, as a perimeter check.
- **Remember me.** A hashed cookie that bypasses two-factor at sign-in and restores the session on later visits. It exists so internet outages do not force everyone to sign in again.
- **Passkeys are agent-only.** Client contacts cannot use them.
- **Reporting a vulnerability.** For issues specific to RivetMSP, open an issue on the repository. Problems in upstream ITFlow itself belong in [its security policy](https://github.com/itflow-org/itflow/security/policy).
