Skip to content

Backup and Restore Recovery Lab

github-actions[bot] edited this page Nov 29, 2026 · 1 revision

Last reviewed: 2026-11-29 (18 of 18 cases passed in CI run 46244151474; synthetic, illustrative files only)

Prerequisites: Incident Response index ยท Cybersecurity playbooks: ransomware incident ยท Linux with unshare and Python 3.12 for a local run.

Important

Scope & safety: every case runs pinned restic and rest-server releases against synthetic, illustrative files in a temporary sandbox. Both servers listen on 127.0.0.1 only, and the whole run happens inside unshare -rn, a network namespace where only loopback is brought up. The first case checks that a connection to the RFC 5737 address 192.0.2.1 fails there. The "destructive event" is simulate_destructive_event.py: a benign script that overwrites the synthetic files with random bytes and renames them. It is not ransomware: it does no encryption, keeps no key, opens no network connection and refuses to touch anything outside a directory that holds the lab's marker file. Hosts and addresses in the fixtures use example.test and the RFC 5737 ranges. Timings are lab-only numbers.

๐ŸŽฏ Purpose

Show, with observed exit codes and hashes rather than vendor claims, what a ransomware-resilience restore test has to prove:

  • a backup that a compromised client cannot delete (rest-server --append-only);
  • a restore of the snapshot taken before the event, not simply the latest one;
  • a restored file set checked file by file against a known SHA-256 manifest;
  • a repository integrity check that reads the data (restic check --read-data) and a negative control showing it catches corruption;
  • a measured restore duration and data age, recorded in the fields an organization would use to compare a restore test against its own recovery point and recovery time objectives (the lab's numbers are not such a comparison).

โš™๏ธ Function

run_lab.py reads manifest.json, re-executes itself under unshare -rn, brings up loopback, starts two rest-server instances and runs each case with the real tools. It compares exit codes and parsed output with the case's expectation, then writes an evidence manifest. The manifest holds tool versions, the SHA-256 of every input, the expected and observed result per case, the rest-server log tails and the lab-only timings. The runner exits non-zero on any mismatch, tool error, input hash mismatch or tool version that differs from the pin. With --require-complete, a case that did not run also fails.

install_tools.py downloads the two pinned release assets from GitHub, checks each against the SHA-256 in manifest.json before unpacking, and refuses any mismatch. restic ships a bzip2-compressed binary; rest-server ships a tar.gz with the binary inside a top-level directory.

๐Ÿ† Goal

Give the incident-response and playbook guidance one reproducible, CI-checked example of a restore test that ends with a verified file set and a recorded measurement, instead of "backups exist".

๐Ÿ“‹ When To Use

  • Before writing or reviewing the recovery phase of a ransomware playbook, to see the checks a restore test should record.
  • When choosing between an append-only, offline or immutable copy, to see what append-only does and does not stop.
  • As a template for a quarterly restore exercise: replace the synthetic dataset and servers with your own authorized test systems and keep the same evidence fields.

๐Ÿ—‚๏ธ Layout

Path Content
fixtures/dataset/ Nine small synthetic text, CSV, JSON and INI files (invoices, inventory, runbooks) using example.test and RFC 5737 addresses
simulate_destructive_event.py Benign simulator: random overwrite and .pnwc-damaged rename inside a marked sandbox only; exits 2 and changes nothing on any refusal
manifest.json Tool pins with asset SHA-256, the two server definitions, the dataset spec (including one generated 4 MiB file pinned by SHA-256), 18 cases and the input SHA-256 table
run_lab.py Stdlib runner and evidence writer
install_tools.py Stdlib downloader with SHA-256 checks; --from-dir installs from assets you already downloaded
evidence/ci-run-<id>.json Evidence downloaded from a CI run, named by run ID

Pins

Tool Version Asset & SHA-256 Source
restic 0.20.0 restic_0.20.0_linux_amd64.bz2 0ccd9fa7โ€ฆ2107f7 Release asset, matches the release's SHA256SUMS
rest-server 0.15.0 rest-server_0.15.0_linux_amd64.tar.gz 822e3d72โ€ฆe35e007 Release asset, matches the release's SHA256SUMS

Both releases were under 14 days old when pinned (restic 0.20.0 on 2026-11-19, rest-server 0.15.0 on 2026-11-23). They were chosen deliberately:

  • restic 0.20.0 carries two restore security fixes: #22178 (--ownership-by-name could fall back to UID/GID 0) and #22180 (duplicate or out-of-order node names could let restore write through a symlink outside the target). A restore lab should not pin the version before those fixes.
  • The append-only behaviour this lab asserts was read from rest-server's repo/repo.go at the v0.15.0 tag, and 0.15.0 adds the /healthz endpoint (returns 204) used for readiness. Its changelog also lists a security fix for retrying a failed .htpasswd reload.

restic also publishes SHA256SUMS.asc. This lab pins the asset hashes and does not verify the PGP signature.

๐Ÿงช Scenario & Expected Results

These are the expectations in manifest.json, not observations.

Case Kind Expectation
isolation-probe isolation Inside unshare -rn, lo is up, a connect to 192.0.2.1:443 fails with ENETUNREACH and a loopback connect succeeds
servers-start setup Two rest-server instances with --no-auth on 127.0.0.1:18000 (--append-only) and 127.0.0.1:18001 (no --append-only); GET /healthz returns 204 on both
repo-init-append-only backup restic init through the append-only server prints "created restic repository"
backup-baseline backup The staged dataset matches the SHA-256 manifest; restic backup --json writes snapshot 1 with 10 new files
late-write-after-baseline event One file is written after the baseline backup, before the event
simulated-destructive-event event The benign simulator overwrites and renames all 11 sandbox files; none of the original hashes remain
negative-simulator-refuses-outside-sandbox event The simulator exits 2 and changes nothing when --data is outside the sandbox or the sandbox has no marker
backup-post-event backup A scheduled-style backup after the event succeeds, so the damaged state becomes the latest snapshot (2 snapshots)
append-only-forget-refused append-only restic forget <baseline> exits 3 (restic's help text: "error removing one or more snapshots") with "unable to remove snapshot/..." and "failed to remove one or more snapshots"; the baseline is still listed
append-only-forget-prune-refused append-only restic forget --keep-last 1 --prune exits 3 with the same messages; the baseline is still listed
append-only-http-delete-refused append-only Raw DELETE /snapshots/<baseline> and DELETE /config return 403; the listing still holds the baseline
negative-restore-latest-is-damaged restore Restoring the latest snapshot succeeds but gives 0 verified files and 11 damaged ones
restore-pre-event-snapshot restore Restoring the baseline snapshot into a new target gives all 10 files with matching SHA-256, none missing or extra
check-read-data integrity restic check --read-data on the append-only repository prints "no errors were found"
contrast-forget-allowed-without-append-only append-only On the server without --append-only, restic forget of one of two snapshots exits 0 and removes it
negative-corrupted-pack-detected integrity After one byte in the largest pack of the second repository is flipped, restic check --read-data exits 1, reports "ciphertext verification failed" and "The repository contains damaged pack files", and ends with "repository contains errors"
documented-check-without-read-data integrity A plain restic check on the same corrupted repository exits 0 with "no errors were found": it does not read pack contents
measure-restore-and-data-age measure Records restore duration, data age at the event and the lost file (late/written-after-baseline.txt); lab-only numbers

โ–ถ๏ธ Run In CI

.github/workflows/recovery-lab.yml runs on pull requests and pushes that touch this folder, the test module or the workflow, and on workflow_dispatch. It has permissions: contents: read, uses no secrets and requests no id-token. On ubuntu-24.04 with Python 3.12 it does the following:

  1. Run tools/tests/test_recovery_lab.py with PNWC_RECOVERY_PRODUCING_EVIDENCE=1, which skips only the stale-evidence check.
  2. Install the pinned binaries with install_tools.py.
  3. Allow unprivileged user namespaces (Ubuntu 24.04 restricts them through AppArmor) and check that unshare -rn true works.
  4. Run run_lab.py --require-complete, then upload recovery-evidence.json as the artifact recovery-evidence-<run id>.

guide-tests.yml runs the same test module without the skip on every pull request and on pushes under IncidentResponse/Recovery/**, so committed evidence that no longer matches the inputs fails there.

๐Ÿ’ป Run Locally

python3 -B IncidentResponse/Recovery/labs/backup-restore/install_tools.py --dest /tmp/recovery-bin
python3 -B IncidentResponse/Recovery/labs/backup-restore/run_lab.py --bin-dir /tmp/recovery-bin \
  --evidence /tmp/recovery-evidence.json
python3 -B -m unittest tools/tests/test_recovery_lab.py -v

The first command downloads from GitHub. A local run writes evidence_origin: local-observed, and only CI output (ci-observed) is committed. --isolate none skips the namespace; the isolation probe then fails, as it should.

๐Ÿ“Š Observed CI Evidence

Evidence: evidence/ci-run-46244151474.json, downloaded from the recovery-evidence-46244151474 artifact of CI run 46244151474 (commit fc03734). Earlier runs gave the same 18 of 18 result: 46240939395 on commit 7142e39, before the simulator docstring correction, and 46240815742 on commit eea3225, with the looser expectations of that commit; its messages are what the current expectations pin.

  • Runner: Python 3.12.16 on Linux-7.0.0-1018-aws-x86_64-with-glibc2.39, whole run inside unshare -rn with only loopback up.
  • Tools: restic 0.20.0 and rest-server 0.15.0, both matching the pins. install_tools.py found the rest-server binary at rest-server_0.15.0_linux_amd64/rest-server inside the tarball.
  • Summary: 18 of 18 cases passed, with input hashes and tool versions matching the manifest.
Case Kind Observed output Observed
isolation-probe isolation lo up; 192.0.2.1:443 gave ENETUNREACH; loopback connect worked observed pass
servers-start setup /healthz 204 on both; logs show "Append only mode enabled" and "Append only mode disabled" observed pass
repo-init-append-only backup rc 0, created restic repository ... at rest:http://127.0.0.1:18000/ observed pass
backup-baseline backup rc 0, staged dataset 10 of 10 hashes matched, files_new 10, 1 snapshot observed pass
late-write-after-baseline event late/written-after-baseline.txt written observed pass
simulated-destructive-event event rc 0, 11 files damaged and renamed, 0 original hashes left, note file written observed pass
negative-simulator-refuses-outside-sandbox event rc 2 twice: "is not inside the sandbox" and "is not a lab sandbox (no .pnwc-recovery-sandbox marker)"; decoy unchanged observed pass
backup-post-event backup rc 0, files_new 12 (11 damaged files and the note), 2 snapshots observed pass
append-only-forget-refused append-only rc 3, unable to remove snapshot/<id> from the repository, failed to remove one or more snapshots (followed by a Go stack trace); both snapshots still listed observed pass
append-only-forget-prune-refused append-only rc 3, same messages; both snapshots still listed observed pass
append-only-http-delete-refused append-only DELETE /snapshots/<baseline> 403, DELETE /config 403; listing still holds both snapshots observed pass
negative-restore-latest-is-damaged restore rc 0, 0 verified files, 11 damaged files observed pass
restore-pre-event-snapshot restore rc 0, 10 of 10 SHA-256 matches, none missing, mismatched or extra observed pass
check-read-data integrity rc 0, read 4 of 4 packs, no errors were found observed pass
contrast-forget-allowed-without-append-only append-only rc 0, one of two snapshots removed observed pass
negative-corrupted-pack-detected integrity rc 1, ciphertext verification failed in the flipped 4.0 MiB pack, then restic repair packs <id> advice and Fatal: repository contains errors observed pass
documented-check-without-read-data integrity rc 0, no errors were found on the same corrupted repository observed pass
measure-restore-and-data-age measure restore 0.671 s; data age at event 1.404 s; event to restored 5.503 s; 10 files recovered; lost late/written-after-baseline.txt (lab-only) observed pass

๐Ÿ” Evidence Interpretation

Lab check What it maps to Source
Pre-event snapshot chosen, latest shown to be damaged RC.RP-03: "The integrity of backups and other restoration assets is verified before using them for restoration" NIST CSF 2.0 (CSWP 29, 2024-02-26)
SHA-256 check of every restored file RC.RP-05: "The integrity of restored assets is verified, systems and services are restored, and normal operating status is confirmed" NIST CSF 2.0
Restore into a new target directory, not over the damaged data (partial: same host and namespace, not a separate staging environment) IS-SS-R7: restore to an isolated or air-gapped staging environment, not directly to targets NIST SP 800-209 (October 2020)
Measured restore duration and data age RA-SS-R5 "Test restore to ensure required RTO" and RA-SS-R6 "Meeting RPO requirements" NIST SP 800-209
Append-only copy the backup client cannot delete through the API (partial: the client can still read the repository, and there is no offline copy) IR 8374r1 guidance for PR.DS-11: "Backups should have a copy stored offline or otherwise in a manner that prevents access to them by the attacker or compromise by ransomware." NIST IR 8374r1 (June 2026)
Restore test as an exercise (the test part only; the lab's restic-encrypted copy is online, not offline) "Maintain offline, encrypted backups of critical data, and regularly test the availability and integrity of backups in a disaster recovery scenario" CISA #StopRansomware Guide (PDF cover "Publication: October 2023"; its change record lists this as version 3.0)
  • RPO and RTO here use the NIST glossary definitions: the recovery point objective is "the point in time to which data must be recovered after an outage", and the recovery time objective is how long components can be in the recovery phase before the mission is harmed. The lab's data_age_at_event_seconds (baseline snapshot time to event time) is the data-loss window this run would have had; restore_duration_seconds is one restore of 10 files. Neither is an objective for any real system.
  • Append-only is not immutability. rest-server's --append-only refuses deletes through the API (except of lock files); overwriting an existing object is refused with or without the flag. Anyone with shell access on the backup host can still delete the repository directory, and the lab's corrupted-pack case edits a file on disk directly. restic's own documentation says forget and prune need full access and should run from a separate, well-secured client, and that --keep-within should be used because an attacker who can add snapshots can push legitimate ones out of --keep-last/--keep-weekly windows.
  • "Latest" is not "clean". A backup job that keeps running after the event happily stores the damaged files. The negative-restore-latest-is-damaged case is why a restore must name the snapshot taken before the event.
  • A structure check is not a data check. restic check without --read-data checks repository structure; reading and hashing the pack contents needs --read-data (or --read-data-subset), which costs a full read of the repository.
  • 3-2-1 and 3-2-1-1-0. CISA's 3-2-1 rule is three copies, on two different types of storage media, one off-site. The "3-2-1-1-0" extension (one offline, air-gapped or immutable copy; zero errors on a verified restore) is an industry convention from backup vendors, not a NIST or CISA rule. This lab exercises only its "0 errors on a verified restore" part.

โš ๏ธ Limitations

  • Synthetic scale. Ten files and about 4 MiB. Restore time grows with data size, storage and network; the measured seconds say nothing about a real system's RTO.
  • No authentication or TLS. Both servers run with --no-auth on loopback inside a private network namespace. A real deployment needs .htpasswd (or proxy auth), --private-repos and TLS.
  • No offline or object-lock copy. Append-only is one control. Offline media and object-storage retention locks (for example S3 Object Lock compliance mode) were not exercised.
  • No identity or directory recovery. Active Directory forest recovery and cloud identity backups are separate procedures; see the related files below.
  • Single client. The lab does not separate the backup client from an administrative client, which restic's documentation recommends for forget and prune.

Related Files


โฌ…๏ธ Incident Response index | Master Index | ๐ŸŽฏ Role Navigation | Legal Notice


๐Ÿ“„ Source: IncidentResponse/Recovery/labs/backup-restore/README.md | โœ๏ธ Suggest an edit | โฌ…๏ธ Back to Incident Response

Clone this wiki locally