A modern, self-hosted backup solution for secure, encrypted backups across local and cloud storage.
fix: incorrect use of encryption keys from env instead of config
towfiqibc7b362b1feb
diff --git a/backend/src/managers/BaseBackupManager.ts b/backend/src/managers/BaseBackupManager.tsindex 3b4463c..7666243 100644--- a/backend/src/managers/BaseBackupManager.ts+++ b/backend/src/managers/BaseBackupManager.ts@@ -8,6 +8,7 @@ import { BackupHandler } from './handlers/BackupHandler';import { PruneHandler } from './handlers/PruneHandler';import { jobQueue } from '../jobs/JobQueue';import { generateUID } from '../utils/helpers';+import { configService } from 'src/services/ConfigService';type ScheduleOptions = (BackupPlanArgs | PlanPrune) & {isActive: boolean;@@ -59,9 +60,15 @@ export class BaseBackupManager extends EventEmitter {): Promise<{ success: boolean; result: string }> {const { storagePath, storage } = options;const { encryption } = options.settings;-+ const encKey = configService.config.ENCRYPTION_KEY;+ if (encryption && (!encKey || encKey.trim() === '')) {+ return {+ success: false,+ result: 'Encryption is enabled but ENCRYPTION_KEY is not set in environment variables.',+ };+ }// Then Create a restic repo based on the provided rclone storage and the backup path- const repoPassword = encryption ? (process.env.ENCRYPTION_KEY as string) : '';+ const repoPassword = encryption ? encKey : '';try {const repoPath = generateResticRepoPath(storage.name, storagePath || '');const repoCommand = ['-r', repoPath, 'init', '--verbose'];@@ -243,6 +250,7 @@ export class BaseBackupManager extends EventEmitter {async unlockRepo(planId: string): Promise<{ success: boolean; result: string }> {const schedules = await this.cronManager.getSchedule(planId);const backupSchedule = schedules?.find(s => s.type === 'backup');+ const encKey = configService.config.ENCRYPTION_KEY;if (!backupSchedule || !backupSchedule.options) {return {@@ -261,9 +269,7 @@ export class BaseBackupManager extends EventEmitter {console.log(`[BaseBackupManager]: Force-unlocking repository for plan: ${planId}`);const repoPath = generateResticRepoPath(options.storage.name, options.storagePath || '');- const repoPassword = options.settings.encryption- ? (process.env.ENCRYPTION_KEY as string)- : '';+ const repoPassword = options.settings.encryption ? encKey : '';// Run the restic unlock commandconst resticArgs = ['unlock', '-r', repoPath, '--json'];const output = await runResticCommand(resticArgs, { RESTIC_PASSWORD: repoPassword });diff --git a/backend/src/managers/BaseSnapshotManager.ts b/backend/src/managers/BaseSnapshotManager.tsindex 040d996..92908e8 100644--- a/backend/src/managers/BaseSnapshotManager.ts+++ b/backend/src/managers/BaseSnapshotManager.ts@@ -84,7 +84,7 @@ export class BaseSnapshotManager extends EventEmitter {}> {try {const { storageName, storagePath, encryption, planId } = options;- const repoPassword = encryption ? (process.env.ENCRYPTION_KEY as string) : '';+ const repoPassword = encryption ? configService.config.ENCRYPTION_KEY : '';const repoPath = generateResticRepoPath(storageName, storagePath || '');let snapshotId = '';const { success, result } = await getSnapshotByTag('backup-' + backupId, options);@@ -125,7 +125,7 @@ export class BaseSnapshotManager extends EventEmitter {return { success: false, result: 'Snapshot not found' };}const { storageName, storagePath, encryption } = options;- const repoPassword = encryption ? (configService.config.ENCRYPTION_KEY as string) : '';+ const repoPassword = encryption ? configService.config.ENCRYPTION_KEY : '';const repoPath = generateResticRepoPath(storageName, storagePath || '');const output = await runResticCommand(['ls', '-r', repoPath, snapshotId, '--json', '--long'],diff --git a/backend/src/managers/handlers/BackupHandler.ts b/backend/src/managers/handlers/BackupHandler.tsindex 4effb63..70f658c 100644--- a/backend/src/managers/handlers/BackupHandler.ts+++ b/backend/src/managers/handlers/BackupHandler.ts@@ -237,7 +237,7 @@ export class BackupHandler {// Update progress: Backup operation startawait this.updateProgress(planId, backupId, 'backup', 'BACKUP_OPERATION_START', false);- const repoPassword = options.settings.encryption ? (process.env.ENCRYPTION_KEY as string) : '';+ const repoPassword = options.settings.encryption ? configService.config.ENCRYPTION_KEY : '';const handlers = this.createHandlers(planId, backupId);const { resticArgs, resticEnv } = resticArgsAndEnv;const resticArgsWithBackupTag: string[] = [...resticArgs, '--tag', `backup-${backupId}`];@@ -416,9 +416,7 @@ export class BackupHandler {console.log(`[BackupHandler]: Unlocking stale locks for plan: ${planId}`);try {const repoPath = generateResticRepoPath(options.storage.name, options.storagePath || '');- const repoPassword = options.settings.encryption- ? (process.env.ENCRYPTION_KEY as string)- : '';+ const repoPassword = options.settings.encryption ? configService.config.ENCRYPTION_KEY : '';await runResticCommand(['unlock', '-r', repoPath], {...resticArgsAndEnv.resticEnv,@@ -449,7 +447,7 @@ export class BackupHandler {}// Check if encryption key is available when encryption is enabled- if (options.settings.encryption && !process.env.ENCRYPTION_KEY) {+ if (options.settings.encryption && !configService.config.ENCRYPTION_KEY) {throw new Error(`Encryption enabled but ENCRYPTION_KEY not found.`);}@@ -571,7 +569,7 @@ export class BackupHandler {const dryRunArgs = [...resticArgs, '--dry-run'];const dryRunEnv = {...resticEnv,- RESTIC_PASSWORD: options.settings.encryption ? (process.env.ENCRYPTION_KEY as string) : '',+ RESTIC_PASSWORD: options.settings.encryption ? configService.config.ENCRYPTION_KEY : '',};if (options.method === 'rescue') {dryRunArgs.push('--one-file-system');diff --git a/backend/src/managers/handlers/DownloadHandler.ts b/backend/src/managers/handlers/DownloadHandler.tsindex 8592ab0..e66ec79 100644--- a/backend/src/managers/handlers/DownloadHandler.ts+++ b/backend/src/managers/handlers/DownloadHandler.ts@@ -8,6 +8,7 @@ import { generateResticRepoPath } from '../../utils/restic/helpers';import { processManager } from '../ProcessManager';import { runCommand } from '../../utils/runCommand';import { appPaths } from '../../utils/AppPaths';+import { configService } from '../../services/ConfigService';export class DownloadHandler {constructor(private emitter: EventEmitter) {}@@ -36,7 +37,7 @@ export class DownloadHandler {return new Promise((resolve, reject) => {const handlers = this.createHandlers(planId, backupId);const { storageName, storagePath, encryption } = options;- const repoPassword = encryption ? (process.env.ENCRYPTION_KEY as string) : '';+ const repoPassword = encryption ? configService.config.ENCRYPTION_KEY : '';const repoPath = generateResticRepoPath(storageName, storagePath || '');runResticCommand(diff --git a/backend/src/managers/handlers/PruneHandler.ts b/backend/src/managers/handlers/PruneHandler.tsindex 52d5816..23133f4 100644--- a/backend/src/managers/handlers/PruneHandler.ts+++ b/backend/src/managers/handlers/PruneHandler.ts@@ -1,6 +1,7 @@import { EventEmitter } from 'events';import { getBackupPlanStats, runResticCommand } from '../../utils/restic/restic';import { generateResticRepoPath } from '../../utils/restic/helpers';+import { configService } from '../../services/ConfigService';export class PruneHandler {constructor(private emitter: EventEmitter) {}@@ -65,7 +66,7 @@ export class PruneHandler {const { prune, encryption = true } = settings;const resticArgs = ['forget', '--prune', '--tag', `plan-${planId}`];const policyArgs: string[] = [];- const resticEnv = { RESTIC_PASSWORD: encryption ? (process.env.ENCRYPTION_KEY as string) : '' };+ const resticEnv = { RESTIC_PASSWORD: encryption ? configService.config.ENCRYPTION_KEY : '' };if (storage.name) {const repoPath = generateResticRepoPath(storage.name, storagePath || '');diff --git a/backend/src/managers/handlers/RestoreHandler.ts b/backend/src/managers/handlers/RestoreHandler.tsindex d7027c1..4e6c7aa 100644--- a/backend/src/managers/handlers/RestoreHandler.ts+++ b/backend/src/managers/handlers/RestoreHandler.ts@@ -12,6 +12,7 @@ import { ProgressManager } from '../ProgressManager';import { appPaths } from '../../utils/AppPaths';import { RestoreOptions } from '../../types/restores';import { RestoreStatsManager } from '../RestoreStatsManager';+import { configService } from '../../services/ConfigService';export class RestoreHandler {private runningRestores = new Set<string>();@@ -430,7 +431,7 @@ export class RestoreHandler {}// Check if encryption key is available when encryption is enabled- if (options.encryption && !process.env.ENCRYPTION_KEY) {+ if (options.encryption && !configService.config.ENCRYPTION_KEY) {throw new Error(`Snapshot encrypted but ENCRYPTION_KEY not found.`);}@@ -470,7 +471,7 @@ export class RestoreHandler {excludes,performanceSettings: performance,} = options;- const repoPassword = encryption ? (process.env.ENCRYPTION_KEY as string) : '';+ const repoPassword = encryption ? configService.config.ENCRYPTION_KEY : '';const repoPath = generateResticRepoPath(storageName, storagePath || '');const overWriteCommand = overwrite == 'always' ? [] : ['--overwrite', overwrite];// Set the target path for the restore operation@@ -627,7 +628,7 @@ export class RestoreHandler {console.log(`[RestoreHandler]: Unlocking stale locks for plan: ${planId}`);try {const repoPath = generateResticRepoPath(options.storageName, options.storagePath || '');- const repoPassword = options.encryption ? (process.env.ENCRYPTION_KEY as string) : '';+ const repoPassword = options.encryption ? configService.config.ENCRYPTION_KEY : '';await runResticCommand(['unlock', '-r', repoPath], {RESTIC_PASSWORD: repoPassword,diff --git a/backend/src/utils/rclone/rclone.ts b/backend/src/utils/rclone/rclone.tsindex 74cf00c..487db6a 100644--- a/backend/src/utils/rclone/rclone.ts+++ b/backend/src/utils/rclone/rclone.ts@@ -2,6 +2,7 @@ import { spawn } from 'child_process';import os from 'os';import { getBinaryPath } from '../binaryPathResolver';import { getRcloneConfigPath } from './helpers';+import { configService } from '../../services/ConfigService';export function runRcloneCommand(args: string[], env?: Record<string, string>): Promise<string> {return new Promise((resolve, reject) => {@@ -12,7 +13,7 @@ export function runRcloneCommand(args: string[], env?: Record<string, string>):// ...process.env,RCLONE_CONFIG: rcloneConfigPath,LOCALAPPDATA: localAppData,- RCLONE_CONFIG_PASS: process.env.ENCRYPTION_KEY,+ RCLONE_CONFIG_PASS: configService.config.ENCRYPTION_KEY,...env,};console.log('rcloneBinary :', rcloneBinary);