Articles / Security

  • security
  • threat-modelling
  • self-hosting
  • backups
  • restic
  • linux

Your Threat Model Should Include the Admin Who Is You

Most home-grown threat models have an attacker on the internet, maybe a burglar, and then a trusted figure called "admin" who is outside the diagram. On a one-person setup that figure is you, holding root, the backups, the logs, the DNS account and the recovery codes. Anything that can act as you gets the lot.

You may well be entirely trustworthy. I'm sure you're lovely. The question is what happens when your hands, laptop or session do something you would not choose to do.

"You" is at least four different attackers

Model each version of you separately, because they fail in different ways:

  • Tired you runs the right command in the wrong terminal.
  • Compromised you is malware or a stranger using your SSH agent, browser session or password vault.
  • Curious or cross you can read other people's mail, photos or messages if the box hosts them.
  • Absent you is ill, locked out or on a train with no signal while something needs doing.

A confirmation prompt helps with tired you and does nothing against compromised you, who is very happy to type "yes". File permissions that root can change stop neither of them once they are root.

Ask what one session can destroy

Start with your laptop, unlocked, in someone else's hands. Write down what they can reach without learning a new secret. Include cached sudo, loaded SSH keys, logged-in browser tabs and tokens sitting in dotfiles.

Then mark every item where the same session can damage both a thing and the means of recovering or noticing it:

  • the server and its backups
  • the service and its logs
  • the domain and the email address that resets the domain's password
  • the encrypted data and the only copy of its key

Those pairs are your real findings. You do not need to solve all of them this weekend. Backups and logs usually give the most for the least effort.

Take delete away from the machine being backed up

If a server can prune its own backups, then root on that server can erase its history. restic can instead talk over SSH to an rclone process on the backup host, and that process can refuse deletion.

On the backup host, give the server's key one permitted command in the backup user's ~/.ssh/authorized_keys (all on one line):

restrict,command="rclone serve restic --stdio --append-only /srv/restic/web1" ssh-ed25519 AAAA... web1-backup

restrict turns off forwarding, PTY allocation and the other extras. command= means the client gets that program, whatever it asks to run. On the server being backed up:

export RESTIC_PASSWORD_FILE=/root/restic.pass
repo_opts=(-o rclone.program="ssh -i /root/.ssh/backup backup@backuphost" -r rclone:web1)

restic "${repo_opts[@]}" init      # first time only
restic "${repo_opts[@]}" backup /etc /srv

The name after rclone: is ignored here, because the path is fixed at the far end. Now test that deletion fails, since an untested restriction is just a comment with ambitions:

restic "${repo_opts[@]}" snapshots
restic "${repo_opts[@]}" forget SNAPSHOT_ID   # use a throwaway snapshot; must be refused
restic "${repo_opts[@]}" snapshots            # it must still be listed

This has limits. A compromised server still holds the repository password, so it can read its own old backups, including secrets you have since removed. It can also fill the disk. And if your laptop has an ordinary shell on the backup host, compromised you walks round the whole arrangement.

Quick detour: append-only can still trick your pruning

This bit is clever. An attacker who cannot delete anything can still add junk snapshots with chosen timestamps. A later count-based policy such as --keep-daily 7, run by you with full access, may keep the junk and discard the real ones. You become the delete button.

The restic documentation on forgetting snapshots recommends the --keep-within family for append-only repositories. Run it from a trusted machine, preview first, and look for odd entries:

restic -r /srv/restic/web1 forget --dry-run \
  --keep-within-daily 14d \
  --keep-within-weekly 2m \
  --keep-within-monthly 1y

This has a limit too. Leave a broken or hostile client unnoticed for longer than the window and good history can still age out.

Put the evidence somewhere you aren't root

A log that root can rewrite is weak evidence about root. chattr +a makes a file append-only, but a sufficiently privileged user can simply remove the attribute.

Send logs to another machine as they happen, using an authenticated, encrypted transport. Use separate credentials there, and do not let the sending host log in to it. A compromised machine can stop sending or start lying, but it should not be able to edit what already arrived.

systemd also offers Forward Secure Sealing. journalctl --setup-keys creates a sealing key, kept on the host, and a verification key to store elsewhere. journalctl --verify --verify-key=... can then check authenticity. It helps detect tampering; it does not stop anyone deleting the files.

Remember what sudo records, too. After sudo -i, its log shows that you opened a shell, but not every command you then typed in it.

Make the dangerous identity a deliberate one

Your everyday session should not be your destroy-everything session. Some cheap separations:

  • Use a different key for administering backups, ideally on a hardware token that needs a touch, and do not leave it loaded in an agent.
  • Check sudo -l for NOPASSWD rules you added at 1am and forgot.
  • Consider Defaults timestamp_timeout=0, edited with visudo, so sudo does not cache authentication.
  • Keep DNS, hosting and recovery email behind MFA, with recovery codes stored away from the laptop.

A second account on the same compromised laptop is a weaker boundary than it looks. Malware can wait for you to use it. The separations that count involve another device, a physical action, or a server-side rule your current session cannot change.

Other people's data needs a rule before you're curious

If friends, family or a club use your server, root can probably read their data. Say so plainly. Decide when you will look (a restore they asked for, an abuse report), what you will record, and who gets told.

A written rule will not technically stop you, but it turns "just having a quick look while debugging" into something you can recognise as a choice. Where you can avoid holding readable content at all, with client-side encryption for instance, that is stronger than a promise.

Don't lock out future you

Every restriction above can become a self-inflicted outage. Write the recovery route down and rehearse it from a machine that is not your usual one. You should be able to answer:

  • Where is the backup password if the server and laptop both vanish?
  • How do you get administrative access if the hardware token breaks?
  • Who can keep things running, or shut them down cleanly, if you cannot?

An offline envelope is unfashionable and rather good. It also adds a burglar-shaped risk, so choose where it lives and what it can open on its own.

For a first pass, pick one thing you would hate to lose and ask: "Can the session I have open right now destroy it, and every way of getting it back?" If the answer is yes, you have found your next job. It was probably not on the diagram.