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.

Keep installer configuration snapshots private during copying

pulse-triage[bot]2100b5bdea6c
diff --git a/docs/release-control/v6/internal/subsystems/deployment-installability.md b/docs/release-control/v6/internal/subsystems/deployment-installability.md
index dfdbbdf69d..546c59f428 100644
--- a/docs/release-control/v6/internal/subsystems/deployment-installability.md
+++ b/docs/release-control/v6/internal/subsystems/deployment-installability.md
@@ -8993,6 +8993,17 @@ directory or dangling link at the final path stops the update, even when GNU
`mv -n` returns zero after skipping. Copy/allocation/publication failure removes
only the invocation's incomplete stage and never rotates earlier snapshots.
+The incomplete copy stays inside an installer-owned mode-0700 outer enclosure.
+`cp -a` may adopt the source directory's owner and permissions, including a
+legacy broadly traversable mode, only on the enclosed payload. Before that
+payload can be published, its root must have mode 0700. Source ownership,
+including the root directory's owner/group, stays preserved for direct recovery;
+so do nested modes, hidden entries, empty directories and links. The live
+configuration is not changed. Failure to set the private mode removes only the
+incomplete copy, leaves the recorded
+completed-snapshot path empty and never rotates previous recovery copies. The
+completed snapshot retains the existing flat recovery layout and private root.
+
Incomplete hidden stages are not retention candidates. After publication,
rotation still keeps the configured number of snapshots (five by default),
including the current invocation's completed copy for positive retention counts
@@ -9006,7 +9017,12 @@ backup fails, including when their caller suppresses implicit shell `errexit`.
`scripts/tests/test_server_config_backups.py` exercises real fixture files,
copy/rename/retention, metadata and links; injected failures cover allocation,
-copy and publication, including exit-zero late collisions. It checks rapid
+copy, privacy admission and publication, including exit-zero late collisions.
+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.
+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
it on the existing repository test routes. These are disposable filesystem
diff --git a/install.sh b/install.sh
index 6c8093b453..8a7813393e 100644
--- a/install.sh
+++ b/install.sh
@@ -3090,7 +3090,7 @@ backup_existing() {
LAST_CONFIG_BACKUP_DIR=""
if [[ -d "$CONFIG_DIR" ]]; then
print_info "Backing up existing configuration..."
- local backup_parent backup_dir backup_stage stage_name
+ local backup_parent backup_dir backup_stage backup_payload stage_name
backup_parent="$(dirname "$CONFIG_DIR")"
if [[ ! -w "$backup_parent" ]]; then
# The hardened pulse-update.service unit mounts /etc read-only
@@ -3104,25 +3104,38 @@ backup_existing() {
# can already be another run's recovery copy: cp would nest into it,
# and failed-copy cleanup would then erase that earlier snapshot.
# Hidden, incomplete copies are not candidates for snapshot rotation.
+ # 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
print_error "Could not create configuration backup; existing snapshots are unchanged"
return 1
fi
stage_name="${backup_stage##*/}"
backup_dir="$backup_parent/${stage_name#.}"
- if ! cp -a -- "$CONFIG_DIR/." "$backup_stage/"; then
+ backup_payload="$backup_stage/snapshot"
+ if ! mkdir -- "$backup_payload" || ! cp -a -- "$CONFIG_DIR/." "$backup_payload/"; then
rm -rf -- "$backup_stage"
print_error "Configuration backup failed; existing snapshots are unchanged"
return 1
fi
+ # Retain the source ownership for direct recovery, including the root
+ # directory. Only its mode is tightened before leaving the private outer
+ # enclosure; nested file modes, hidden entries and links stay unchanged.
+ if ! chmod 700 -- "$backup_payload"; then
+ rm -rf -- "$backup_stage"
+ print_error "Could not protect configuration backup; existing snapshots are unchanged"
+ return 1
+ fi
# GNU mv -n can return zero without moving anything. Admit publication
# only when our stage actually disappeared; never merge or overwrite a
# file, directory or link that appeared at the final path.
- if ! mv -T -n -- "$backup_stage" "$backup_dir" || [[ -e "$backup_stage" || -L "$backup_stage" ]]; then
+ if ! mv -T -n -- "$backup_payload" "$backup_dir" || [[ -e "$backup_payload" || -L "$backup_payload" ]]; then
rm -rf -- "$backup_stage"
print_error "Could not publish configuration backup; existing snapshots are unchanged"
return 1
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"
fi
diff --git a/scripts/installtests/root_install_sh_test.go b/scripts/installtests/root_install_sh_test.go
index 37ce9e0974..75c4851660 100644
--- a/scripts/installtests/root_install_sh_test.go
+++ b/scripts/installtests/root_install_sh_test.go
@@ -2983,6 +2983,8 @@ func TestRootInstallScriptConfigBackupPublicationPreservesPriorSnapshots(t *test
runPythonFixtureControls(t, repoFile("scripts", "tests", "test_server_config_backups.py"), "ConfigBackupPublication", []string{
"test_two_successful_same_second_copies_are_separate_complete_snapshots",
"test_failed_partial_copy_does_not_mutate_or_delete_a_previous_snapshot",
+ "test_copy_and_published_snapshot_remain_private_with_broad_source_permissions",
+ "test_snapshot_privacy_failure_preserves_prior_snapshots_without_rotation",
"test_allocation_failure_stops_before_copy_or_rotation",
"test_headroom_failure_creates_no_stage_and_preserves_prior_snapshot",
"test_failed_publication_does_not_rotate_or_publish_a_snapshot",
diff --git a/scripts/tests/test_server_config_backups.py b/scripts/tests/test_server_config_backups.py
index 179e208e23..fcf14b8dfc 100644
--- a/scripts/tests/test_server_config_backups.py
+++ b/scripts/tests/test_server_config_backups.py
@@ -107,6 +107,61 @@ test -z "$LAST_CONFIG_BACKUP_DIR"
self.assertEqual(self.completed(), [old])
self.assert_no_stages()
+ def test_copy_and_published_snapshot_remain_private_with_broad_source_permissions(self):
+ # Older or manually managed configs can be traversable by other users.
+ # cp -a copies the source directory's owner/mode too, not just its files.
+ # Inspect the completed copy before publication, not just a later chmod.
+ self.config.chmod(0o755)
+ self.config.parent.chmod(0o755)
+ self.shell(r'''
+cp() {
+ command cp "$@" || return
+ python3 - "${@: -1}" "$(dirname "$CONFIG_DIR")" <<'PY'
+import os
+from pathlib import Path
+import stat
+import sys
+
+path, parent = (Path(arg).resolve() for arg in sys.argv[1:])
+while path != parent:
+ observed = path.stat()
+ if observed.st_uid == os.geteuid() and stat.S_IMODE(observed.st_mode) & 0o077 == 0:
+ break
+ path = path.parent
+else:
+ sys.exit("configuration copy exposed source permissions before publication")
+PY
+}
+backup_existing
+printf '%s\n' "$LAST_CONFIG_BACKUP_DIR" > "$FIXTURE/latest"
+''')
+ snapshot = Path((self.root / "latest").read_text().strip())
+ self.assertEqual(stat.S_IMODE(snapshot.stat().st_mode), 0o700)
+ self.assertEqual(snapshot.stat().st_uid, self.config.stat().st_uid)
+ self.assertEqual(snapshot.stat().st_gid, self.config.stat().st_gid)
+ self.assertEqual((snapshot / ".env").read_bytes(), (self.config / ".env").read_bytes())
+ self.assertEqual(stat.S_IMODE((snapshot / ".env").stat().st_mode), 0o600)
+ self.assertEqual(stat.S_IMODE((snapshot / "settings.json").stat().st_mode),
+ stat.S_IMODE((self.config / "settings.json").stat().st_mode))
+ self.assertTrue((snapshot / "empty").is_dir())
+ self.assertEqual(os.readlink(snapshot / "setting-link"), "settings.json")
+ self.assertEqual(stat.S_IMODE(self.config.stat().st_mode), 0o755)
+ self.assert_no_stages()
+
+ def test_snapshot_privacy_failure_preserves_prior_snapshots_without_rotation(self):
+ old = self.old_snapshot("privacy-mode")
+ result = self.shell(r'''
+chmod() { return 23; }
+prune_config_backups() { echo unexpected-prune > "$FIXTURE/unexpected"; }
+if backup_existing; then exit 90; fi
+test -z "$LAST_CONFIG_BACKUP_DIR"
+''')
+ self.assertIn("Could not protect configuration backup", result.stderr)
+ self.assertFalse((self.root / "unexpected").exists())
+ self.assert_prior(old)
+ self.assert_no_stages()
+ self.assertEqual(self.completed(), [old])
+
def test_allocation_failure_stops_before_copy_or_rotation(self):
old = self.old_snapshot()
self.shell(r'''