Skip to main content

Backups an intruder cannot wipe: append-only mode

Security · · 5 min read

Why an ordinary backup does not help

A copy the server itself can delete is no protection against a break-in. Once an attacker has root, they do exactly what your script does: take the key from /root or the environment and talk to the storage. Only the command is not create but delete. That is the moment you learn the copies are gone — not because a disk failed, but because the server was allowed to erase them.

Ransomware operators do this deliberately and first: while the copies are intact, there is no reason to pay. So the question is not whether backups run, but whether a compromised server can reach them.

Three properties a copy needs

  1. Separate access. The key the server writes copies with must not grant the right to delete them.
  2. Append-only. The storage accepts new data and refuses deletion or modification of what is already there.
  3. A tested restore. A copy nobody has ever restored from is an assumption, not a copy.

Tools give you the first two properties; only discipline gives the third.

restic: append-only on the storage server

In restic the refusal to delete lives not in the client but in rest-server, the service on the storage side. Its own documentation describes the flag this way: append-only mode allows creation of new backups but prevents deletion and modification of existing backups. The ban sits where a compromised server has no authority.

rest-server --path /srv/restic --append-only \
  --htpasswd-file /srv/restic/.htpasswd --listen 127.0.0.1:8000

The client behaves as usual until deletion is involved:

restic -r rest:http://backup.example.net:8000/host1 backup /var /etc /home
restic -r rest:http://backup.example.net:8000/host1 forget --keep-daily 7
# forget and prune are rejected on an append-only server

Hence a consequence that is easy to miss: the retention policy cannot be applied from the same server. Old snapshots are removed separately — from the storage host or from a trusted machine the intruder does not reach.

BorgBackup: append-only and its honest limit

In Borg the mode is enabled on the side accepting the connection, through a forced command in authorized_keys:

command="borg serve --append-only --restrict-to-path /srv/borg/host1",restrict ssh-ed25519 AAAA... host1-backup

Read the documentation literally here rather than by the sense of the name. Borg states that --append-only only allows appending to repository segment files, and adds that this affects only the low-level structure, while running delete or prune and reading from the repository are still allowed. The delete command is not refused — it goes through, the data stays on disk, and an administrator can roll the state back. This is protection with a rollback, not a refusal to act.

The practical difference: with Borg you must notice the intrusion before someone compacts the repository, whereas an append-only restic server rejects the deletion outright.

Immutability on the storage side

The sturdiest option does not depend on the backup tool at all: the ban on deletion is set in the object storage. On S3-compatible storage this is object locking, where a version of a file cannot be deleted until its term expires — not even by the owner of the key. The policy is written in the storage console, not on the server being backed up.

Where the ban livesWhat it givesWhat it does not
Key without delete rightsSimple, works anywhereLifted by whoever reaches the storage account
append-only in the serviceDeletion refused on receiptNeeds a separate machine for retention
Object lockingEven the owner cannot bypass itYou pay for the data until the lock expires

How many copies, and where

The 3-2-1 rule means 3 copies of the data, 2 different media, 1 copy off site. Against ransomware one more condition is added: at least 1 copy must be immutable or offline. A copy "in another directory on the same server" counts as none of the three.

Restore drills

An integrity check and a trial restore are different things. The first reads checksums; the second answers whether the site starts.

restic -r rest:http://backup.example.net:8000/host1 check --read-data-subset=10%
restic -r rest:http://backup.example.net:8000/host1 restore latest --target /tmp/drill
diff -r --brief /tmp/drill/etc/nginx /etc/nginx | head

Do it on a schedule and write down the date. The question "when did you last restore from a copy" should have an answer with a number in it.

What append-only does not do

It does not hide the contents of the copies: encryption protects them from being read, and that is configured separately — see GPG for files and backups. It does not settle the choice of tool: deduplication in restic and Borg is compared in restic and BorgBackup. And it does not replace a plan for after the break-in — the order of the first steps is in the incident response plan.

Was this article helpful?
Back to Knowledge Base Ask Support