Пример #1
0
    def vm_host_ssh_setup(self, ssh_config_dir, filename, username,
                          builder_access_ssh_public_key,
                          builder_access_ssh_private_key):
        'Setup ssh config inside a vm host instance'
        check.check_string(ssh_config_dir)
        check.check_string(filename)
        check.check_string(username)
        check.check_string(builder_access_ssh_public_key)
        check.check_string(builder_access_ssh_private_key)

        self.log.log_d(
            'vm_host_ssh_setup: ssh_config_dir={} filename={} username={}'.
            format(ssh_config_dir, filename, username))

        cm = ssh_config_manager(ssh_config_dir)

        # Install inbound keys to ssh into the vm builder from the vm host
        builder_access_ssh_public_key_content = file_util.read(
            builder_access_ssh_public_key, codec='utf-8')
        builder_access_ssh_private_key_content = file_util.read(
            builder_access_ssh_private_key, codec='utf-8')
        installed = cm.install_key_pair(
            builder_access_ssh_public_key_content,
            builder_access_ssh_private_key_content, filename)
        self.log.log_d(
            'vm_builder_ssh_setup: access installed={}'.format(installed))
        return 0
Пример #2
0
  def _do_download_with_temp_ssh(clazz, address, revision, output_filename,
                                 base_name, download_options, parsed_address,
                                 ssh_credentials):
    domain_name = parsed_address.service
    clazz._log.log_d('_do_download_with_temp_ssh: domain_name={}'.format(domain_name))

    temp_home = temp_file.make_temp_dir(delete = not download_options.debug)
    if download_options.debug:
      print('temp_home={}'.format(temp_home))
    temp_ssh_dir = path.join(temp_home, '.ssh')
    clazz._log.log_d('_do_download_with_temp_ssh: temp_ssh_dir={}'.format(temp_ssh_dir))
    cm = ssh_config_manager(temp_ssh_dir)

    installed = cm.install_key_pair_for_host(ssh_credentials.public_key,
                                             ssh_credentials.private_key,
                                             domain_name,
                                             username = ssh_credentials.username,
                                             host_key_type = ssh_credentials.host_key_type,
                                             include_ip_address = True,
                                             include_comment = True)
    # use a temporary HOME with custom git and ssh config just for this download
    with env_override.temp_home(use_temp_home = temp_home) as env:
      git_config.set_identity('test', '*****@*****.**')
      ssh_config_file = path.join(temp_ssh_dir, 'config')
      ssh_command = 'ssh -F {}'.format(ssh_config_file)
      git_config.set_value('core.sshCommand', ssh_command)
      clazz._do_download(address, revision, output_filename, base_name, download_options)
      file_util.remove(temp_home)
Пример #3
0
    def test_add_authorized_key_clean_slate(self):
        tmp_dir = self.make_temp_dir(suffix='.ssh')
        cm = ssh_config_manager(tmp_dir)
        cm.add_authorized_key('ssh-rsa', 'key1', 'fred@bedrock')
        files = file_find.find(tmp_dir, relative=True)
        self.assertEqual([
            'authorized_keys',
        ], files)

        expected_authorized_keys = '''
ssh-rsa key1 fred@bedrock
'''
        self.assertMultiLineEqual(
            expected_authorized_keys.strip(),
            file_util.read(path.join(tmp_dir, 'authorized_keys'),
                           codec='utf-8').strip())
Пример #4
0
    def test_add_known_host_clean_slate(self):
        tmp_dir = self.make_temp_dir(suffix='.ssh')
        cm = ssh_config_manager(tmp_dir)
        cm.add_known_host(['example.com'], 'ssh-rsa', 'key1')
        files = file_find.find(tmp_dir, relative=True)
        self.assertEqual([
            'known_hosts',
        ], files)

        expected_known_hosts = '''
example.com ssh-rsa key1
'''
        self.assertMultiLineEqual(
            expected_known_hosts.strip(),
            file_util.read(path.join(tmp_dir, 'known_hosts'),
                           codec='utf-8').strip())
Пример #5
0
    def test_install_key_pair_for_host(self):
        tmp_dir = self.make_temp_dir(suffix='.ssh')
        cm = ssh_config_manager(tmp_dir)
        tmp_public_key = 'publickey'
        tmp_private_key = 'privatekey'
        tmp_hostname = 'bitbucket.org'

        installed = cm.install_key_pair_for_host('publickey',
                                                 'privatekey',
                                                 'bitbucket.org',
                                                 username='******',
                                                 include_ip_address=False,
                                                 include_comment=False)

        files = file_find.find(tmp_dir, relative=True)
        self.assertEqual([
            'config',
            'id_rsa_bitbucket_org',
            'id_rsa_bitbucket_org.pub',
            'known_hosts',
        ], files)

        expected_config = '''
Host bitbucket.org
  Hostname bitbucket.org
  IdentityFile {private_key}
  User fred
'''.format(private_key=installed.private_key_filename)
        self.assertMultiLineEqual(
            expected_config.strip(),
            file_util.read(path.join(tmp_dir, 'config'),
                           codec='utf-8').strip())

        expected_known_hosts = '''
bitbucket.org ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAubiN81eDcafrgMeLzaFPsw2kNvEcqTKl/VqLat/MaB33pZy0y3rJZtnqwR2qOOvbwKZYKiEO1O6VqNEBxKvJJelCq0dTXWT5pbO2gDXC6h6QDXCaHo6pOHGPUy+YBaGQRGuSusMEASYiWunYN0vCAI8QaXnWMXNMdFP3jHAJH0eDsoiGnLPBlBp4TNm6rYI74nMzgz3B9IikW4WVK+dc8KZJZWYjAuORU3jc1c/NPskD2ASinf8v3xnfXeukU0sJ5N6m5E8VLjObPEO+mN2t/FZTMZLiFqPWc/ALSqnMnnhwrNi2rbfg/rd/IpL8Le3pSBne8+seeFVBoGqzHM9yXw==
'''
        self.assertMultiLineEqual(
            expected_known_hosts.strip(),
            file_util.read(path.join(tmp_dir, 'known_hosts'),
                           codec='utf-8').strip())

        abs_files = [path.join(tmp_dir, f) for f in files]
        for filename in abs_files:
            self.assertEqual(0o0600, file_util.mode(filename))
Пример #6
0
    def test_add_config_host_clean_slate(self):
        tmp_dir = self.make_temp_dir(suffix='.ssh')
        cm = ssh_config_manager(tmp_dir)
        cm.add_config_host(
            'foo', 'Hostname=192.168.1.2 IdentityFile=/tmp/id_rsa User=fred')
        files = file_find.find(tmp_dir, relative=True)
        self.assertEqual([
            'config',
        ], files)

        expected_config = '''
Host foo
  Hostname 192.168.1.2
  IdentityFile /tmp/id_rsa
  User fred
'''
        self.assertMultiLineEqual(
            expected_config.strip(),
            file_util.read(path.join(tmp_dir, 'config'),
                           codec='utf-8').strip())
Пример #7
0
    def vm_builder_ssh_setup(self, ssh_config_dir, username, ssh_public_key,
                             ssh_private_key, domain_name,
                             builder_access_ssh_public_key):
        'Setup ssh config inside a vm builder instance'
        check.check_string(ssh_config_dir)
        check.check_string(username)
        check.check_string(ssh_public_key)
        check.check_string(ssh_private_key)
        check.check_string(domain_name)
        check.check_string(builder_access_ssh_public_key)

        self.log.log_d(
            'vm_builder_ssh_setup: ssh_config_dir={} username={}'.format(
                ssh_config_dir, username))
        cm = ssh_config_manager(ssh_config_dir)

        # Install outbound keys needed for git push and pull from domain_name
        ssh_public_key_content = file_util.read(ssh_public_key, codec='utf-8')
        ssh_private_key_content = file_util.read(ssh_private_key,
                                                 codec='utf-8')
        installed = cm.install_key_pair_for_host(
            ssh_public_key_content,
            ssh_private_key_content,
            domain_name,
            username=username,
            include_ip_address=not self.options.dont_include_ip_address,
            include_comment=not self.options.dont_include_comment)
        self.log.log_d(
            'vm_builder_ssh_setup: bitbucket installed={}'.format(installed))

        # Install inbound keys to ssh into the vm builder from the vm host
        builder_access_ssh_public_key_content = file_util.read(
            builder_access_ssh_public_key, codec='utf-8')
        installed = cm.install_public_key(
            builder_access_ssh_public_key_content, 'vm_builder_access_key',
            True)
        self.log.log_d(
            'vm_builder_ssh_setup: access installed={}'.format(installed))
        return 0
Пример #8
0
 def test_nothing(self):
     tmp_dir = self.make_temp_dir(suffix='.ssh')
     cm = ssh_config_manager(tmp_dir)
     self.assertEqual([], file_find.find(tmp_dir, relative=True))