diff --git a/README.md b/README.md index 10238422..c305dadd 100644 --- a/README.md +++ b/README.md @@ -749,7 +749,7 @@ A version from before v3.0.0 has no worker: `systemctl disable --now webvirt-wor ### Moving to a new machine -A [backup](#backups) moves the panel to a new machine, or back onto lost volumes: the database, the secret key (signed-in users stay signed in), the worker's id and the SSH keys and TLS certificates the computes accept. Install the panel there first, the same version or a newer one, then copy the backup directory over and set `b` to it. The backup does not hold `docker-compose.override.yml`, the nginx config or `/etc/default/webvirtcloud`: bring your own lines over yourself. Users sign in with their passwords from the backup; the new installation's `data/admin_password` no longer applies. A `SECRET_KEY` set in the compose file has no `secret_key` in the backup: set the same value on the new machine. With PostgreSQL, restore that database yourself and leave out the line below that restores `db.sqlite3` (the backup has none), and stop the old panel before the new one starts: both would run the jobs of the one database. +A [backup](#backups) moves the panel to a new machine, or back onto lost volumes: the database, the secret key (signed-in users stay signed in), the worker's id and the SSH keys and TLS certificates the computes accept. Install the panel there first, the same version or a newer one, then copy the backup directory over and set `b` to it. The backup does not hold `docker-compose.override.yml`, the nginx config or `/etc/default/webvirtcloud`: bring your own lines over yourself. Users sign in with their passwords from the backup; the new installation's `data/admin_password` no longer applies. The backup's `secret_key` is the key in use, also one set as `SECRET_KEY` in the environment. With PostgreSQL, restore that database yourself and leave out the line below that restores `db.sqlite3` (the backup has none), and stop the old panel before the new one starts: both would run the jobs of the one database. Docker, in the directory you installed from: diff --git a/appsettings/management/commands/backup.py b/appsettings/management/commands/backup.py index 6d2d2c46..924d21ff 100644 --- a/appsettings/management/commands/backup.py +++ b/appsettings/management/commands/backup.py @@ -63,8 +63,10 @@ class Command(BaseCommand): raise CommandError(f"The copy of the database is damaged: {result}") else: self.stderr.write("The database is not sqlite and is not in the backup: back it up with its own tools.") + # the key in use: SECRET_KEY from the environment has no data/secret_key + (to / "secret_key").write_text(settings.SECRET_KEY + "\n") data = settings.BASE_DIR / "data" - for source in (data / "secret_key", data / "node_id", settings.BASE_DIR / "webvirtcloud" / "settings.py"): + for source in (data / "node_id", settings.BASE_DIR / "webvirtcloud" / "settings.py"): if source.is_file(): shutil.copyfile(source, to / source.name) ssh = Path.home() / ".ssh" diff --git a/appsettings/tests/test_backup.py b/appsettings/tests/test_backup.py index b11c53e0..6a1d1fe8 100644 --- a/appsettings/tests/test_backup.py +++ b/appsettings/tests/test_backup.py @@ -33,7 +33,7 @@ class BackupTests(SimpleTestCase): (self.base / path).parent.mkdir(parents=True, exist_ok=True) (self.base / path).write_text(text) (self.base / "home/.ssh/agent").symlink_to(self.base / "data/secret_key") - overridden = override_settings(BASE_DIR=self.base) + overridden = override_settings(BASE_DIR=self.base, SECRET_KEY="key in use") overridden.enable() self.addCleanup(overridden.disable) home = patch.object(Path, "home", return_value=self.base / "home") @@ -66,7 +66,9 @@ class BackupTests(SimpleTestCase): with closing(sqlite3.connect(backup / "db.sqlite3")) as db: self.assertEqual(db.execute("SELECT name FROM computes_compute").fetchall(), [("kept",)]) self.assertEqual(sorted(p.name for p in backup.iterdir()), ["db.sqlite3", "node_id", "secret_key", "settings.py", "ssh"]) - self.assertEqual((backup / "secret_key").read_text(), "key") + # the key in use, also when it came from the environment and not data/secret_key + self.assertEqual((backup / "secret_key").read_text(), "key in use\n") + self.assertEqual(oct((backup / "secret_key").stat().st_mode & 0o777), "0o600") self.assertEqual([p.name for p in (backup / "ssh").iterdir()], ["id_ed25519"]) # not what a link points to self.assertEqual(oct(self.backups.stat().st_mode & 0o777), "0o700") self.assertEqual(oct(backup.stat().st_mode & 0o777), "0o700")