Ensure we purge the ssh backup key file in case it was left over by a
previous failed backup run fs.writeFileSync() would fail to overwrite due to restricted file mode for ssh
This commit is contained in:
@@ -210,7 +210,9 @@ async function copyInternal(config, fromPath, toPath, options, progressCallback)
|
||||
|
||||
if (config._provider === mounts.MOUNT_TYPE_SSHFS) {
|
||||
// we use a temporary key file instead of passing it as stdin
|
||||
const identityFilePath = `/tmp/identity_file_${config._managedMountPath.replaceAll('/', '-')}`;
|
||||
const identityFilePath = `/tmp/identity_file${config._managedMountPath.replaceAll('/', '-')}`;
|
||||
// have to unlink first, in case a previous run crash before cleanup. With mode 0c600 we cannot overwrite it
|
||||
safe.fs.unlinkSync(identityFilePath);
|
||||
if (!safe.fs.writeFileSync(identityFilePath, `${config.mountOptions.privateKey}\n`, { mode: 0o600 })) throw new BoxError(BoxError.FS_ERROR, `Could not write temporary private key: ${safe.error.message}`);
|
||||
|
||||
const sshOptions = [ '-o', '"StrictHostKeyChecking no"', '-i', identityFilePath, '-p', config.mountOptions.port, `${config.mountOptions.user}@${config.mountOptions.host}` ];
|
||||
@@ -271,7 +273,9 @@ async function removeDir(config, limits, remotePathPrefix, progressCallback) {
|
||||
|
||||
if (config._provider === mounts.MOUNT_TYPE_SSHFS) {
|
||||
// we use a temporary key file instead of passing it as stdin
|
||||
const identityFilePath = `/tmp/identity_file_${config._managedMountPath.replaceAll('/', '-')}`;
|
||||
const identityFilePath = `/tmp/identity_file${config._managedMountPath.replaceAll('/', '-')}`;
|
||||
// have to unlink first, in case a previous run crash before cleanup. With mode 0c600 we cannot overwrite it
|
||||
safe.fs.unlinkSync(identityFilePath);
|
||||
if (!safe.fs.writeFileSync(identityFilePath, `${config.mountOptions.privateKey}\n`, { mode: 0o600 })) throw new BoxError(BoxError.FS_ERROR, `Could not write temporary private key: ${safe.error.message}`);
|
||||
|
||||
const sshOptions = [ '-o', '"StrictHostKeyChecking no"', '-i', identityFilePath, '-p', config.mountOptions.port, `${config.mountOptions.user}@${config.mountOptions.host}` ];
|
||||
|
||||
Reference in New Issue
Block a user