Ejemplo n.º 1
0
  def testAddingExistingKeyWithSomeMoreSpaces(self):
    utils.AddAuthorizedKey(self.tmpname,
      "ssh-dss  AAAAB3NzaC1w5256closdj32mZaQU   root@key-a")
    utils.AddAuthorizedKey(self.tmpname,
      "ssh-dss AAAAB3NzaC1w520smc01ms0jfJs22")

    self.assertFileContent(self.tmpname,
      "ssh-dss AAAAB3NzaC1w5256closdj32mZaQU root@key-a\n"
      'command="/usr/bin/fooserver -t --verbose",from="198.51.100.4"'
      " ssh-dss AAAAB3NzaC1w520smc01ms0jfJs22 root@key-b\n"
      "ssh-dss AAAAB3NzaC1w520smc01ms0jfJs22\n")
Ejemplo n.º 2
0
def UpdateSshRoot(data, dry_run, _homedir_fn=None):
    """Updates root's SSH keys.

  Root's C{authorized_keys} file is also updated with new public keys.

  @type data: dict
  @param data: Input data
  @type dry_run: boolean
  @param dry_run: Whether to perform a dry run

  """
    keys = data.get(constants.SSHS_SSH_ROOT_KEY)
    if not keys:
        return

    (auth_keys_file, keyfiles) = \
      ssh.GetAllUserFiles(constants.SSH_LOGIN_USER, mkdir=True,
                          _homedir_fn=_homedir_fn)

    _UpdateKeyFiles(keys, dry_run, keyfiles)

    if dry_run:
        logging.info("This is a dry run, not modifying %s", auth_keys_file)
    else:
        for (_, _, public_key) in keys:
            utils.AddAuthorizedKey(auth_keys_file, public_key)
Ejemplo n.º 3
0
  def testAddingNewKey(self):
    utils.AddAuthorizedKey(self.tmpname,
                           "ssh-dss AAAAB3NzaC1kc3MAAACB root@test")

    self.assertFileContent(self.tmpname,
      "ssh-dss AAAAB3NzaC1w5256closdj32mZaQU root@key-a\n"
      'command="/usr/bin/fooserver -t --verbose",from="198.51.100.4"'
      " ssh-dss AAAAB3NzaC1w520smc01ms0jfJs22 root@key-b\n"
      "ssh-dss AAAAB3NzaC1kc3MAAACB root@test\n")
Ejemplo n.º 4
0
  def testAddingAlmostButNotCompletelyTheSameKey(self):
    utils.AddAuthorizedKey(self.tmpname,
        "ssh-dss AAAAB3NzaC1w5256closdj32mZaQU root@test")

    # Only significant fields are compared, therefore the key won't be
    # updated/added
    self.assertFileContent(self.tmpname,
      "ssh-dss AAAAB3NzaC1w5256closdj32mZaQU root@key-a\n"
      'command="/usr/bin/fooserver -t --verbose",from="198.51.100.4"'
      " ssh-dss AAAAB3NzaC1w520smc01ms0jfJs22 root@key-b\n")
Ejemplo n.º 5
0
def _InitSSHSetup():
    """Setup the SSH configuration for the cluster.

  This generates a dsa keypair for root, adds the pub key to the
  permitted hosts and adds the hostkey to its own known hosts.

  """
    priv_key, pub_key, auth_keys = ssh.GetUserFiles(constants.SSH_LOGIN_USER)

    for name in priv_key, pub_key:
        if os.path.exists(name):
            utils.CreateBackup(name)
        utils.RemoveFile(name)

    result = utils.RunCmd(
        ["ssh-keygen", "-t", "dsa", "-f", priv_key, "-q", "-N", ""])
    if result.failed:
        raise errors.OpExecError("Could not generate ssh keypair, error %s" %
                                 result.output)

    utils.AddAuthorizedKey(auth_keys, utils.ReadFile(pub_key))