From 8471f4c34d793e1e62717dc863a221e3d535a5c9 Mon Sep 17 00:00:00 2001 From: "juvenal.diaz" Date: Sat, 5 Dec 2026 13:53:16 -0600 Subject: [PATCH] Preserve NextPath accounts across redeploys --- apps/nextpath/README.md | 3 +++ lib/jeannie/pipeline.sh | 31 +++++++++++++++++++++++-- tests/jeannie/test_nextpath_pipeline.py | 11 ++++++++- 3 files changed, 42 insertions(+), 3 deletions(-) diff --git a/apps/nextpath/README.md b/apps/nextpath/README.md index 33e493b..c25bda7 100644 --- a/apps/nextpath/README.md +++ b/apps/nextpath/README.md @@ -29,4 +29,7 @@ NextPath is a public work in progress. Deploy it from the Debian control plane: The service runs under systemd, stores private account data in `/data/homelab-nextpath/data`, and exposes only its HTTP port to the tailnet/LAN. The OCI edge supplies public TLS at `https://nextpath.lab2025.duckdns.org/`. +Redeployments never recreate the account store. Jeannie migrates the original +manual-preview file from `/data/homelab-nextpath/accounts.json` when needed and +writes a mode-0600 pre-deploy backup under `/data/homelab-nextpath/backups`. diff --git a/lib/jeannie/pipeline.sh b/lib/jeannie/pipeline.sh index b59ce16..572fd83 100644 --- a/lib/jeannie/pipeline.sh +++ b/lib/jeannie/pipeline.sh @@ -6019,6 +6019,10 @@ deploy_nextpath() { local secure_cookies="${LAB_NEXTPATH_SECURE_COOKIES:-true}" local release_id="" local release_dir="" + local account_store="${install_dir}/data/accounts.json" + local legacy_account_store="${install_dir}/accounts.json" + local backup_dir="${install_dir}/backups" + local backup_timestamp="" local elapsed=0 require_debian_server "deploy-nextpath" @@ -6048,8 +6052,31 @@ deploy_nextpath() { release_id="$(git -C "${REPO_ROOT}" rev-parse --verify HEAD)" release_dir="${install_dir}/releases/${release_id}" sudo install -d -o "${service_user}" -g "${service_user}" -m 0750 \ - "${install_dir}" "${install_dir}/releases" "${install_dir}/data" + "${install_dir}" "${install_dir}/releases" "${install_dir}/data" "${backup_dir}" sudo chmod 0700 "${install_dir}/data" + sudo chmod 0700 "${backup_dir}" + + # The initial manual-preview instructions used the install root. Migrate + # that file once, without ever replacing a store already managed by the + # service. This lets the first Jeannie deployment keep preview accounts. + if sudo test -s "${legacy_account_store}" && ! sudo test -e "${account_store}"; then + echo "Migrating the legacy NextPath account store into the persistent data directory." + sudo mv "${legacy_account_store}" "${account_store}" + sudo chown "${service_user}:${service_user}" "${account_store}" + sudo chmod 0600 "${account_store}" + elif sudo test -e "${legacy_account_store}" && sudo test -e "${account_store}"; then + echo "Warning: both legacy and managed NextPath account stores exist; preserving both and using ${account_store}." >&2 + fi + + # Preserve a private point-in-time copy before every redeploy that has + # account data. The application itself atomically replaces its live file. + if sudo test -s "${account_store}"; then + backup_timestamp="$(date -u +%Y%m%dT%H%M%SZ)" + sudo cp -p "${account_store}" "${backup_dir}/accounts-${backup_timestamp}-${release_id:0:12}.json" + sudo chown "${service_user}:${service_user}" "${backup_dir}/accounts-${backup_timestamp}-${release_id:0:12}.json" + sudo chmod 0600 "${backup_dir}/accounts-${backup_timestamp}-${release_id:0:12}.json" + echo "Preserved a private pre-deploy NextPath account backup in ${backup_dir}." + fi sudo -u "${service_user}" install -d -m 0750 "${release_dir}" ( cd "${REPO_ROOT}" @@ -6070,7 +6097,7 @@ User=${service_user} Group=${service_user} WorkingDirectory=${install_dir}/current Environment=NEXTPATH_ADDRESS=${bind_ip}:${http_port} -Environment=NEXTPATH_ACCOUNT_STORE=${install_dir}/data/accounts.json +Environment=NEXTPATH_ACCOUNT_STORE=${account_store} Environment=NEXTPATH_SECURE_COOKIES=${secure_cookies} ExecStart=${install_dir}/current/nextpath Restart=on-failure diff --git a/tests/jeannie/test_nextpath_pipeline.py b/tests/jeannie/test_nextpath_pipeline.py index e31d674..a2748aa 100644 --- a/tests/jeannie/test_nextpath_pipeline.py +++ b/tests/jeannie/test_nextpath_pipeline.py @@ -14,9 +14,18 @@ class NextPathPipelineTests(unittest.TestCase): self.assertIn("deploy_nextpath()", pipeline) self.assertIn('require_debian_server "deploy-nextpath"', pipeline) self.assertIn("GOTOOLCHAIN=local go test ./cmd/nextpath/...", pipeline) - self.assertIn("NEXTPATH_ACCOUNT_STORE=${install_dir}/data/accounts.json", pipeline) + self.assertIn("NEXTPATH_ACCOUNT_STORE=${account_store}", pipeline) self.assertIn("ReadWritePaths=${install_dir}/data", pipeline) self.assertIn("sudo chmod 0700", pipeline) + self.assertIn('legacy_account_store="${install_dir}/accounts.json"', pipeline) + self.assertIn('! sudo test -e "${account_store}"', pipeline) + self.assertIn('sudo mv "${legacy_account_store}" "${account_store}"', pipeline) + self.assertIn('sudo cp -p "${account_store}"', pipeline) + self.assertIn('"${backup_dir}/accounts-${backup_timestamp}-${release_id:0:12}.json"', pipeline) + self.assertLess( + pipeline.index('sudo cp -p "${account_store}"'), + pipeline.index('sudo systemctl restart nextpath.service'), + ) self.assertIn('curl -fsS --connect-timeout 3 "http://127.0.0.1:${http_port}/healthz"', pipeline) self.assertIn("nextpath.service", pipeline) self.assertIn("deploy-nextpath)", command)