Skip to content

armgit / Pulse

Public Imported from GitHub
0

Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.

Preserve trailing pathname bytes in configuration snapshots

pulse-triage[bot]f4808c56b23d
diff --git a/docs/release-control/v6/internal/subsystems/deployment-installability.md b/docs/release-control/v6/internal/subsystems/deployment-installability.md
index dee8b97d79..cbb041ffe1 100644
--- a/docs/release-control/v6/internal/subsystems/deployment-installability.md
+++ b/docs/release-control/v6/internal/subsystems/deployment-installability.md
@@ -9051,6 +9051,15 @@ pre-mutation staging failure names only this invocation's completed snapshot.
All three existing-install update/reinstall entries explicitly stop if the
backup fails, including when their caller suppresses implicit shell `errexit`.
+Snapshot construction and rotation must also preserve trailing newline bytes in
+the configuration name and parent. Capturing `dirname` or `basename` output must
+remove only the utility's output delimiter, not any pathname bytes: otherwise a
+distinct instance's snapshots can be rotated and the new recovery copy published
+in that peer's namespace. Option-shaped relative names are data, and ordinary
+trailing directory slashes retain their existing path meaning. Failure to resolve
+either component stops before allocating, copying or rotating any snapshot, also
+under a conditional caller.
+
`scripts/tests/test_server_config_backups.py` exercises real fixture files,
copy/rename/retention, metadata and links; injected failures cover allocation,
copy, privacy admission and publication, including exit-zero late collisions.
@@ -9058,6 +9067,11 @@ It observes the real copy before publication with mode-0755 source configuration
and requires a private installer-owned ancestor, then checks the completed root
and unchanged ownership/nested metadata/source permissions. Mode-setting failure
also runs under a conditional caller so implicit shell `errexit` cannot admit it.
+Trailing-newline controls cover one and two newline bytes in the final name,
+parent and both, at zero, one and five retained snapshots; the selected namespace,
+peer recovery copies and both live configurations are checked independently.
+Relative option-shaped names, trailing slashes and both component-resolution
+failures run through the same registered fixture suite.
It checks rapid
retries, clock reversal, another invocation's retention, fallback, owned discard
and the actual three update entries. The discovered Go installer suite executes
diff --git a/install.sh b/install.sh
index e6004dcdff..cff6aa471c 100644
--- a/install.sh
+++ b/install.sh
@@ -3097,8 +3097,21 @@ backup_existing() {
LAST_CONFIG_BACKUP_DIR=""
if [[ -d "$CONFIG_DIR" ]]; then
print_info "Backing up existing configuration..."
- local backup_parent backup_dir backup_stage backup_payload stage_name
- backup_parent="$(dirname "$CONFIG_DIR")"
+ local backup_parent backup_dir backup_stage backup_payload stage_name config_name
+ # Command substitution strips every trailing newline, including bytes
+ # in the configured name or its parent. Keep a sentinel until after
+ # capture, then remove only the utility's one output newline and marker.
+ # The same literal name must select both publication and retention.
+ if ! backup_parent=$(dirname -- "$CONFIG_DIR" && printf '.'); then
+ print_error "Could not resolve configuration backup parent; existing snapshots are unchanged"
+ return 1
+ fi
+ backup_parent="${backup_parent%$'\n.'}"
+ if ! config_name=$(basename -- "$CONFIG_DIR" && printf '.'); then
+ print_error "Could not resolve configuration backup name; existing snapshots are unchanged"
+ return 1
+ fi
+ config_name="${config_name%$'\n.'}"
if [[ ! -w "$backup_parent" ]]; then
# The hardened pulse-update.service unit mounts /etc read-only
# (ProtectSystem=strict; only /opt/pulse, /etc/pulse and /tmp are
@@ -3114,7 +3127,7 @@ backup_existing() {
# Keep a private outer enclosure: cp -a also adopts the source root's
# ownership/permissions, so copying directly into the reserved directory
# can expose a legacy broadly readable config before publication.
- if ! backup_stage=$(mktemp -d -- "$backup_parent/.$(basename "$CONFIG_DIR").backup.$(date +%Y%m%d-%H%M%S).XXXXXX"); then
+ if ! backup_stage=$(mktemp -d -- "$backup_parent/.$config_name.backup.$(date +%Y%m%d-%H%M%S).XXXXXX"); then
print_error "Could not create configuration backup; existing snapshots are unchanged"
return 1
fi
@@ -3144,7 +3157,7 @@ backup_existing() {
fi
rmdir -- "$backup_stage" || print_warn "Could not remove empty configuration backup staging directory"
LAST_CONFIG_BACKUP_DIR="$backup_dir"
- prune_config_backups "$backup_parent" "$(basename "$CONFIG_DIR").backup." "$backup_dir"
+ prune_config_backups "$backup_parent" "$config_name.backup." "$backup_dir"
fi
}
diff --git a/scripts/installtests/root_install_sh_test.go b/scripts/installtests/root_install_sh_test.go
index 16fd10e96d..b526475ddd 100644
--- a/scripts/installtests/root_install_sh_test.go
+++ b/scripts/installtests/root_install_sh_test.go
@@ -2992,6 +2992,9 @@ func TestRootInstallScriptConfigBackupPublicationPreservesPriorSnapshots(t *test
"test_current_snapshot_survives_rotation_even_after_clock_moves_backwards",
"test_rotation_uses_the_literal_config_namespace",
"test_rotation_keeps_embedded_newlines_inside_each_path",
+ "test_snapshot_namespace_preserves_trailing_newlines_in_name_and_parent",
+ "test_relative_option_shaped_name_and_trailing_slashes_keep_their_namespace",
+ "test_path_resolution_failure_stops_before_copy_or_rotation",
"test_rotation_skips_files_links_and_an_empty_inventory",
"test_incomplete_copy_is_not_another_invocations_rotation_candidate",
"test_discard_removes_only_this_invocations_new_snapshot",
diff --git a/scripts/tests/test_server_config_backups.py b/scripts/tests/test_server_config_backups.py
index d45bb66a8d..a0b55c0c2f 100644
--- a/scripts/tests/test_server_config_backups.py
+++ b/scripts/tests/test_server_config_backups.py
@@ -286,6 +286,80 @@ test -z "$LAST_CONFIG_BACKUP_DIR"
self.assertEqual((self.config / "settings.json").read_text(), "current state\n")
self.assert_no_stages()
+ def test_snapshot_namespace_preserves_trailing_newlines_in_name_and_parent(self):
+ for component in ("name", "parent", "both"):
+ for newlines in ("\n", "\n\n"):
+ for keep in (0, 1, 5):
+ with self.subTest(component=component, newlines=len(newlines), keep=keep):
+ namespace = self.root / f"case-{component}-{len(newlines)}-{keep}"
+ parent = namespace / ("parent" + (newlines if component != "name" else ""))
+ name = "config" + (newlines if component != "parent" else "")
+ self.config = parent / name
+ self.config.mkdir(parents=True)
+ (self.config / "settings.json").write_text("selected live state\n")
+ prior = [self.old_snapshot(f"202610{day:02d}-154500") for day in range(1, 7)]
+ # This is the distinct namespace the old command
+ # substitutions selected by stripping pathname bytes.
+ peer = namespace / "parent" / "config"
+ peer.mkdir(parents=True)
+ (peer / "settings.json").write_text("peer live state\n")
+ peers = []
+ for day in range(1, 7):
+ path = peer.parent / f"config.backup.202610{day:02d}-154500"
+ path.mkdir()
+ (path / "settings.json").write_text("peer recovery state\n")
+ peers.append(path)
+ self.shell(r'''
+backup_existing
+printf '%s' "$LAST_CONFIG_BACKUP_DIR" > "$FIXTURE/latest"
+''', CONFIG_BACKUP_KEEP_COUNT=str(keep))
+ latest = Path((self.root / "latest").read_text())
+ self.assertEqual(latest.parent, parent)
+ self.assertTrue(latest.name.startswith(name + ".backup."))
+ for path in peers:
+ self.assertEqual((path / "settings.json").read_text(), "peer recovery state\n")
+ self.assertEqual((peer / "settings.json").read_text(), "peer live state\n")
+ self.assertEqual((self.config / "settings.json").read_text(), "selected live state\n")
+ self.assertEqual(len(self.completed()), keep)
+ self.assertEqual([p for p in prior if p.exists()], prior[7 - keep:])
+ if keep:
+ self.assertEqual((latest / "settings.json").read_text(), "selected live state\n")
+ else:
+ self.assertFalse(latest.exists())
+ self.assert_no_stages()
+
+ def test_relative_option_shaped_name_and_trailing_slashes_keep_their_namespace(self):
+ self.config = self.root / "-n"
+ self.config.mkdir()
+ (self.config / "settings.json").write_text("selected live state\n")
+ self.shell(r'''
+CONFIG_DIR='-n///'
+backup_existing
+test -f "$LAST_CONFIG_BACKUP_DIR/settings.json"
+''')
+ self.assertEqual(len(self.completed()), 1)
+ self.assertEqual((self.completed()[0] / "settings.json").read_text(), "selected live state\n")
+ self.assert_no_stages()
+
+ def test_path_resolution_failure_stops_before_copy_or_rotation(self):
+ old = self.old_snapshot()
+ for utility in ("dirname", "basename"):
+ with self.subTest(utility=utility):
+ result = self.shell(r'''
+case "$UTILITY" in
+ dirname) dirname() { printf 'partial\n'; return 23; } ;;
+ basename) basename() { printf 'partial\n'; return 23; } ;;
+esac
+mktemp() { echo unexpected-allocation > "$FIXTURE/unexpected"; return 90; }
+if backup_existing; then exit 91; fi
+test -z "$LAST_CONFIG_BACKUP_DIR"
+''', UTILITY=utility)
+ self.assertIn("Could not resolve configuration backup", result.stderr)
+ self.assertFalse((self.root / "unexpected").exists())
+ self.assert_prior(old)
+ self.assertEqual(self.completed(), [old])
+ self.assert_no_stages()
+
def test_rotation_skips_files_links_and_an_empty_inventory(self):
prefix = self.config.name + ".backup."
outside = self.root / "other instance"