Skip to content

Commit 2e867c5

Browse files
committed
feat: optionally include encryption key in web server backups
1 parent e87a245 commit 2e867c5

8 files changed

Lines changed: 8652 additions & 4 deletions

File tree

‎apps/dokploy/__test__/env/encryption.test.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {
22
decryptValue,
33
encryptValue,
4+
exportEncryptionKey,
45
isEncrypted,
56
} from "@dokploy/server/lib/encryption";
67
import { afterEach, describe, expect, it, vi } from "vitest";
@@ -42,6 +43,10 @@ describe("encryptValue / decryptValue", () => {
4243
const tampered = `${encrypted.slice(0, -4)}AAAA`;
4344
expect(() => decryptValue(tampered)).toThrow(/BETTER_AUTH_SECRET/);
4445
});
46+
47+
it("exports the primary key as 32-byte hex for backups", () => {
48+
expect(exportEncryptionKey()).toMatch(/^[0-9a-f]{64}$/);
49+
});
4550
});
4651

4752
describe("dedicated ENCRYPTION_KEY", () => {

‎apps/dokploy/components/dashboard/database/backups/handle-backup.tsx‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ const Schema = z
7979
schedule: z.string().min(1, "Schedule (Cron) required"),
8080
prefix: z.string().min(1, "Prefix required"),
8181
enabled: z.boolean(),
82+
includeEncryptionKey: z.boolean(),
8283
database: z.string().min(1, "Database required"),
8384
keepLatestCount: z.coerce.number().optional(),
8485
serviceName: z.string().nullable(),
@@ -223,6 +224,7 @@ export const HandleBackup = ({
223224
: "",
224225
destinationId: "",
225226
enabled: true,
227+
includeEncryptionKey: true,
226228
prefix: "/",
227229
schedule: "",
228230
keepLatestCount: undefined,
@@ -262,6 +264,7 @@ export const HandleBackup = ({
262264
: "",
263265
destinationId: backup?.destinationId ?? "",
264266
enabled: backup?.enabled ?? true,
267+
includeEncryptionKey: backup?.includeEncryptionKey ?? true,
265268
prefix: backup?.prefix ?? "/",
266269
schedule: backup?.schedule ?? "",
267270
keepLatestCount: backup?.keepLatestCount ?? undefined,
@@ -309,6 +312,7 @@ export const HandleBackup = ({
309312
prefix: data.prefix,
310313
schedule: data.schedule,
311314
enabled: data.enabled,
315+
includeEncryptionKey: data.includeEncryptionKey,
312316
database: data.database,
313317
keepLatestCount: data.keepLatestCount ?? null,
314318
databaseType: data.databaseType || databaseType,
@@ -665,6 +669,31 @@ export const HandleBackup = ({
665669
</FormItem>
666670
)}
667671
/>
672+
{databaseType === "web-server" && (
673+
<FormField
674+
control={form.control}
675+
name="includeEncryptionKey"
676+
render={({ field }) => (
677+
<FormItem className="flex flex-row items-center justify-between rounded-lg border p-3 ">
678+
<div className="space-y-0.5">
679+
<FormLabel>Include encryption key</FormLabel>
680+
<FormDescription>
681+
Stores the encryption key inside the backup so
682+
environment variables can be restored on a new server.
683+
Anyone with access to the backup file can decrypt
684+
them.
685+
</FormDescription>
686+
</div>
687+
<FormControl>
688+
<Switch
689+
checked={field.value}
690+
onCheckedChange={field.onChange}
691+
/>
692+
</FormControl>
693+
</FormItem>
694+
)}
695+
/>
696+
)}
668697
{backupType === "compose" && (
669698
<>
670699
{form.watch("databaseType") === "postgres" && (
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ALTER TABLE "backup" ADD COLUMN "includeEncryptionKey" boolean DEFAULT true NOT NULL;

0 commit comments

Comments
 (0)