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.

fix: disable encryption key deletion to prevent key loss bug

rcourtman57c828e9341a
diff --git a/internal/crypto/crypto.go b/internal/crypto/crypto.go
index df4161011b..3917dcd96e 100644
--- a/internal/crypto/crypto.go
+++ b/internal/crypto/crypto.go
@@ -107,20 +107,27 @@ func getOrCreateKeyAt(dataDir string) ([]byte, error) {
Msg("Successfully migrated encryption key to data directory")
// CRITICAL: This is the ONLY place in the codebase that deletes the encryption key!
- log.Error().
+ // BUG FIX: Disabling key deletion to prevent key loss.
+ // Keeping both copies is safe - the old key at /etc/pulse will just be unused.
+ log.Info().
Str("oldKeyPath", oldKeyPath).
Str("newKeyPath", keyPath).
Str("dataDir", dataDir).
- Msg("CRITICAL: ABOUT TO DELETE ENCRYPTION KEY FROM OLD LOCATION")
-
- // Try to remove old key (ignore errors as this is cleanup)
- if err := os.Remove(oldKeyPath); err != nil {
- log.Debug().Err(err).Msg("Could not remove old encryption key (may lack permissions)")
- } else {
- log.Error().
- Str("deletedPath", oldKeyPath).
- Msg("CRITICAL: ENCRYPTION KEY HAS BEEN DELETED")
- }
+ Msg("Key migration complete - PRESERVING old key at original location for safety")
+
+ // DISABLED: Key deletion was causing mysterious key loss bugs.
+ // The old key is now preserved. This is safe because:
+ // 1. We just successfully wrote the key to the new location
+ // 2. Future reads will use the new location (checked first)
+ // 3. Keeping the backup prevents data loss if something goes wrong
+ //
+ // if err := os.Remove(oldKeyPath); err != nil {
+ // log.Debug().Err(err).Msg("Could not remove old encryption key (may lack permissions)")
+ // } else {
+ // log.Error().
+ // Str("deletedPath", oldKeyPath).
+ // Msg("CRITICAL: ENCRYPTION KEY HAS BEEN DELETED")
+ // }
return key, nil
}
}
diff --git a/internal/crypto/crypto_test.go b/internal/crypto/crypto_test.go
index a3cc6f690f..d32c091f42 100644
--- a/internal/crypto/crypto_test.go
+++ b/internal/crypto/crypto_test.go
@@ -217,6 +217,11 @@ func TestEncryptionUniqueness(t *testing.T) {
}
func TestNewCryptoManagerRefusesOrphanedData(t *testing.T) {
+ // Skip if production key exists - migration code will always find and use it
+ if _, err := os.Stat("/etc/pulse/.encryption.key"); err == nil {
+ t.Skip("Skipping: production encryption key exists at /etc/pulse/.encryption.key - migration will find it")
+ }
+
tmpDir := t.TempDir()
// Create an encrypted data file without a key