diff --git a/app/server/modules/repositories/repositories.service.ts b/app/server/modules/repositories/repositories.service.ts index f32312f9..cac2af30 100644 --- a/app/server/modules/repositories/repositories.service.ts +++ b/app/server/modules/repositories/repositories.service.ts @@ -120,7 +120,7 @@ const createRepository = async (name: string, config: RepositoryConfig, compress error = result.error; } else { - const initResult = await restic.init(encryptedConfig, organizationId); + const initResult = await restic.init(encryptedConfig, organizationId, { timeoutMs: 20000 }); error = initResult.error; } diff --git a/app/server/utils/restic.ts b/app/server/utils/restic.ts index 6532cbd1..30366f20 100644 --- a/app/server/utils/restic.ts +++ b/app/server/utils/restic.ts @@ -185,11 +185,27 @@ export const buildEnv = async (config: RepositoryConfig, organizationId: string) const sshArgs = [ "-o", - "LogLevel=VERBOSE", + "LogLevel=ERROR", "-o", - "ServerAliveInterval=60", + "BatchMode=yes", "-o", - "ServerAliveCountMax=240", + "NumberOfPasswordPrompts=0", + "-o", + "PreferredAuthentications=publickey", + "-o", + "PasswordAuthentication=no", + "-o", + "KbdInteractiveAuthentication=no", + "-o", + "IdentitiesOnly=yes", + "-o", + "ConnectTimeout=10", + "-o", + "ConnectionAttempts=1", + "-o", + "ServerAliveInterval=10", + "-o", + "ServerAliveCountMax=3", "-i", keyPath, ]; @@ -227,7 +243,7 @@ export const buildEnv = async (config: RepositoryConfig, organizationId: string) return env; }; -const init = async (config: RepositoryConfig, organizationId: string) => { +const init = async (config: RepositoryConfig, organizationId: string, options?: { timeoutMs?: number }) => { const repoUrl = buildRepoUrl(config); logger.info(`Initializing restic repository at ${repoUrl}...`); @@ -237,7 +253,7 @@ const init = async (config: RepositoryConfig, organizationId: string) => { const args = ["init", "--repo", repoUrl]; addCommonArgs(args, env, config); - const res = await exec({ command: "restic", args, env }); + const res = await exec({ command: "restic", args, env, timeout: options?.timeoutMs ?? 20000 }); await cleanupTemporaryKeys(env); if (res.exitCode !== 0) { diff --git a/app/server/utils/spawn.ts b/app/server/utils/spawn.ts index a68f321d..73f06e22 100644 --- a/app/server/utils/spawn.ts +++ b/app/server/utils/spawn.ts @@ -53,6 +53,7 @@ export const safeSpawn = (params: SafeSpawnParams) => { const child = spawn(command, args, { env: { ...process.env, ...env }, signal: signal, + stdio: ["ignore", "pipe", "pipe"], }); child.stdout.setEncoding("utf8");