mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-03-11 09:04:54 +00:00
Backups: allow using keyfile as credentials for sshfs mounts
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
parent
b2f5d68ca6
commit
fc9e406bf8
@ -58,7 +58,7 @@ def parse_arguments():
|
||||
|
||||
|
||||
def subcommand_mount(arguments):
|
||||
"""Show repository information."""
|
||||
"""Mount a remote ssh path via sshfs."""
|
||||
try:
|
||||
validate_mountpoint(arguments.mountpoint)
|
||||
except AlreadyMountedError:
|
||||
@ -72,7 +72,7 @@ def subcommand_mount(arguments):
|
||||
'UserKnownHostsFile=/dev/null', '-o',
|
||||
'StrictHostKeyChecking=no']
|
||||
if arguments.ssh_keyfile:
|
||||
cmd += ['-o', 'IdentityFile=$SSHKEY']
|
||||
cmd += ['-o', 'IdentityFile=' + arguments.ssh_keyfile]
|
||||
else:
|
||||
password = read_password()
|
||||
if not password:
|
||||
@ -84,7 +84,7 @@ def subcommand_mount(arguments):
|
||||
|
||||
def subcommand_umount(arguments):
|
||||
"""Unmount a mountpoint."""
|
||||
run(['umount', arguments.mountpoint])
|
||||
subprocess.run(['umount', arguments.mountpoint], check=True)
|
||||
|
||||
|
||||
def validate_mountpoint(mountpoint):
|
||||
@ -123,12 +123,6 @@ def read_password():
|
||||
return ''.join(sys.stdin)
|
||||
|
||||
|
||||
def run(cmd, env=None, check=True):
|
||||
"""Wrap the command with ssh password or keyfile authentication"""
|
||||
# Set a timeout to not get stuck if the remote server asks for a password.
|
||||
subprocess.run(cmd, check=check, env=env, timeout=TIMEOUT)
|
||||
|
||||
|
||||
def main():
|
||||
"""Parse arguments and perform all duties."""
|
||||
arguments = parse_arguments()
|
||||
|
||||
@ -116,9 +116,27 @@ class TestBackups(unittest.TestCase):
|
||||
self.assertEquals(len(content), 0)
|
||||
|
||||
@unittest.skipUnless(euid == 0 and test_config.backups_ssh_path,
|
||||
'Needs to be root and ssh credentials provided')
|
||||
def test_ssh_mount(self):
|
||||
"""Test (un)mounting if credentials for a remote location are given"""
|
||||
'Needs to be root and ssh password provided')
|
||||
def test_sshfs_mount_password(self):
|
||||
"""Test (un)mounting if password for a remote location is given"""
|
||||
credentials = self.get_credentials()
|
||||
if not credentials:
|
||||
return
|
||||
ssh_path = test_config.backups_ssh_path
|
||||
|
||||
repository = SshBorgRepository(uuid=str(uuid.uuid1()),
|
||||
path=ssh_path,
|
||||
credentials=credentials,
|
||||
automount=False)
|
||||
repository.mount()
|
||||
self.assertTrue(repository.is_mounted)
|
||||
repository.umount()
|
||||
self.assertFalse(repository.is_mounted)
|
||||
|
||||
@unittest.skipUnless(euid == 0 and test_config.backups_ssh_keyfile,
|
||||
'Needs to be root and ssh keyfile provided')
|
||||
def test_sshfs_mount_keyfile(self):
|
||||
"""Test (un)mounting if keyfile for a remote location is given"""
|
||||
credentials = self.get_credentials()
|
||||
if not credentials:
|
||||
return
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user