mirror of
https://github.com/retspen/webvirtcloud
synced 2026-11-11 12:46:49 +00:00
fix(backup): the backup holds the secret key in use
The backup copied data/secret_key, which does not exist when SECRET_KEY comes from the environment (Docker then makes none) and can differ from the key in use: a restored panel signed everyone out and could not read what it had signed. The backup now writes settings.SECRET_KEY. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Kk4h2TcUiaWmU5MUszYSea
This commit is contained in:
parent
d0b08db654
commit
9323d61743
3 changed files with 8 additions and 4 deletions
|
|
@ -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:
|
||||
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -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")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue