Revision 7900ed01

b/lib/backend.py
80 80

  
81 81

  
82 82
def AddNode(dsa, dsapub, rsa, rsapub, sshkey, sshpub):
83
  """ adds the node to the cluster
84
      - updates the hostkey
85
      - adds the ssh-key
86
      - sets the node id
87
      - sets the node status to installed
83
  """Joins this node to the cluster.
88 84

  
89
  """
90
  f = open("/etc/ssh/ssh_host_rsa_key", 'w')
91
  f.write(rsa)
92
  f.close()
85
  This does the following:
86
      - updates the hostkeys of the machine (rsa and dsa)
87
      - adds the ssh private key to the user
88
      - adds the ssh public key to the users' authorized_keys file
93 89

  
94
  f = open("/etc/ssh/ssh_host_rsa_key.pub", 'w')
95
  f.write(rsapub)
96
  f.close()
90
  """
91
  user_dir = utils.GetHomeDir(constants.GANETI_RUNAS)
92
  if not user_dir:
93
    logger.Error("Cannot find home of run-as user %s" % constants.GANETI_RUNAS)
94
    return False
97 95

  
98
  f = open("/etc/ssh/ssh_host_dsa_key", 'w')
99
  f.write(dsa)
100
  f.close()
96
  sshd_keys =  [("ssh_host_rsa_key", rsa, 0600),
97
                ("ssh_host_rsa_key.pub", rsapub, 0644),
98
                ("ssh_host_dsa_key", dsa, 0600),
99
                ("ssh_host_dsa_key.pub",  dsapub, 0644)]
100
  for name, content, mode in sshd_keys:
101
    utils.WriteFile(os.path.join(constants.SSH_CONFIG_DIR, name),
102
                    data=content, mode=mode)
101 103

  
102
  f = open("/etc/ssh/ssh_host_dsa_key.pub", 'w')
103
  f.write(dsapub)
104
  f.close()
104
  user_ssh_dir = os.path.join(user_dir, ".ssh")
105 105

  
106
  if not os.path.isdir("/root/.ssh"):
107
    os.mkdir("/root/.ssh")
106
  if not os.path.isdir(user_ssh_dir):
107
    os.mkdir(user_ssh_dir)
108 108

  
109
  f = open("/root/.ssh/id_dsa", 'w')
110
  f.write(sshkey)
111
  f.close()
109
  for name, content in [("id_dsa", sshkey), ("id_dsa.pub", sshpub)]:
110
    utils.WriteFile(os.path.join(user_ssh_dir, name), data=content, mode=0600)
112 111

  
113
  f = open("/root/.ssh/id_dsa.pub", 'w')
114
  f.write(sshpub)
115
  f.close()
116

  
117
  f = open('/root/.ssh/id_dsa.pub', 'r')
118
  try:
119
    utils.AddAuthorizedKey('/root/.ssh/authorized_keys', f.read(8192))
120
  finally:
121
    f.close()
112
  utils.AddAuthorizedKey(os.path.join(user_ssh_dir, "authorized_keys"), sshpub)
122 113

  
123 114
  utils.RunCmd([constants.SSH_INITD_SCRIPT, "restart"])
124 115

  
......
135 126
      if os.path.isfile(full_name) and not os.path.islink(full_name):
136 127
        utils.RemoveFile(full_name)
137 128

  
138
  f = open('/root/.ssh/id_dsa.pub', 'r')
129
  user_dir = utils.GetHomeDir(constants.GANETI_RUNAS)
130
  if not user_dir:
131
    logger.Error("Cannot find home of run-as user %s" % constants.GANETI_RUNAS)
132
    return
133

  
134
  user_ssh_dir = os.path.join(user_dir, ".ssh")
135

  
136
  if not os.path.isdir(user_ssh_dir):
137
    logger.Error("User's ssh dir '%s' does not exist?!" % user_ssh_dir)
138
    return
139

  
140
  f = open(os.path.join(user_ssh_dir, "id_dsa.pub"), 'r')
139 141
  try:
140
    utils.RemoveAuthorizedKey('/root/.ssh/authorized_keys', f.read(8192))
142
    utils.RemoveAuthorizedKey(os.path.join(user_ssh_dir, "authorized_keys"),
143
                              f.read(8192))
141 144
  finally:
142 145
    f.close()
143 146

  
144
  utils.RemoveFile('/root/.ssh/id_dsa')
145
  utils.RemoveFile('/root/.ssh/id_dsa.pub')
147

  
148
  utils.RemoveFile(os.path.join(user_ssh_dir, "id_dsa"))
149
  utils.RemoveFile(os.path.join(user_ssh_dir, "id_dsa.pub"))
146 150

  
147 151

  
148 152
def GetNodeInfo(vgname):
......
1120 1124

  
1121 1125
  destcmd = utils.BuildShellCmd("mkdir -p %s && cat > %s/%s",
1122 1126
                                destdir, destdir, destfile)
1123
  remotecmd = ssh.BuildSSHCmd(dest_node, 'root', destcmd)
1127
  remotecmd = ssh.BuildSSHCmd(dest_node, constants.GANETI_RUNAS, destcmd)
1124 1128

  
1125 1129

  
1126 1130

  
......
1262 1266
    os.mkdir(constants.LOG_OS_DIR, 0750)
1263 1267

  
1264 1268
  destcmd = utils.BuildShellCmd('cat %s', src_image)
1265
  remotecmd = ssh.BuildSSHCmd(src_node, 'root', destcmd)
1269
  remotecmd = ssh.BuildSSHCmd(src_node, constants.GANETI_RUNAS, destcmd)
1266 1270

  
1267 1271
  comprcmd = "gunzip"
1268 1272
  impcmd = utils.BuildShellCmd("(cd %s; %s -i %s -b %s -s %s &>%s)",
b/lib/constants.py
39 39
SSH_KNOWN_HOSTS_FILE = DATA_DIR + "/known_hosts"
40 40

  
41 41
NODE_INITD_SCRIPT = _autoconf.SYSCONFDIR + "/init.d/ganeti"
42
SSH_INITD_SCRIPT = _autoconf.SSH_INITD_SCRIPT
43 42
DEFAULT_NODED_PORT = 1811
44 43
FIRST_DRBD_PORT = 11000
45 44
LAST_DRBD_PORT = 14999
......
109 108
SYNC_SPEED = 30 * 1024
110 109
LOCALHOST_IP_ADDRESS="127.0.0.1"
111 110
TCP_PING_TIMEOUT = 10
111
GANETI_RUNAS = "root"
112

  
113
# external utilities
114
SSH_INITD_SCRIPT = _autoconf.SSH_INITD_SCRIPT
115
SSH_CONFIG_DIR = "/etc/ssh"

Also available in: Unified diff