1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2026-12-03 17:36:05 +00:00

feat: an installation's own settings in data/local_settings.py; settings.py is part of the code

Every update rebuilt settings.py from the template, and the operator put
back their own values by reading a diff: a forgotten DATABASES started
the panel on a new, empty sqlite database. Docker users who needed an
option only settings.py has (LDAP, OTP_ENABLED, LOGIN_TRUSTED_PROXIES)
mounted their own copy and kept it up to date by hand.

webvirtcloud/settings.py is now the tracked file (no template, no copy
in the installer, the image, the container's start or CI), and it runs
data/local_settings.py last: the installation's own values, which an
update does not touch, kept in Docker's data volume, in the panel's
backups and readable by the panel's user only. The installer writes the
time zone, the noVNC port (now checked to be a number), ALLOWED_HOSTS
and CSRF_TRUSTED_ORIGINS there instead of editing settings.py with sed.
LDAP is set up there too; settings.py keeps only python-ldap's
timeouts. The README's update steps move an older version's own
settings.py into the backup before git pull and have its values moved
into the local file once.
This commit is contained in:
catborise 2026-11-20 17:22:49 +03:00
parent 0fb0b61a1a
commit 29a1cbcace
15 changed files with 221 additions and 180 deletions

View file

@ -15,7 +15,7 @@ PREFIX = "webvirtcloud-backup-"
class Command(BaseCommand):
help = ("Copy the database, secret key, worker id, settings and the SSH keys and TLS certificates of the "
help = ("Copy the database, secret key, worker id, local settings and the SSH keys and TLS certificates of the "
"panel's user into a new directory in backups/, then delete all but the newest --keep backups.")
def add_arguments(self, parser):
@ -70,7 +70,7 @@ class Command(BaseCommand):
# 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 / "node_id", settings.BASE_DIR / "webvirtcloud" / "settings.py"):
for source in (data / "node_id", data / "local_settings.py"):
if source.is_file():
shutil.copyfile(source, to / source.name)
ssh = Path.home() / ".ssh"

View file

@ -30,7 +30,7 @@ class BackupTests(SimpleTestCase):
self.addCleanup(shutil.rmtree, self.base)
self.addCleanup(os.umask, os.umask(0o022)) # the command sets its own
for path, text in (("data/secret_key", "key"), ("data/node_id", "a1b2c3"),
("webvirtcloud/settings.py", "DEBUG = False"), ("home/.ssh/id_ed25519", "private")):
("data/local_settings.py", "DEBUG = False"), ("home/.ssh/id_ed25519", "private")):
(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")
@ -66,7 +66,7 @@ class BackupTests(SimpleTestCase):
backup = self.backup()
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(sorted(p.name for p in backup.iterdir()), ["db.sqlite3", "local_settings.py", "node_id", "secret_key", "ssh"])
# 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")