2 # vim:set ts=4 sw=4 expandtab:
7 # NodeManager plugin to create special accounts
10 create/populate accounts/ssh keys for special persons such as root, site_admin, etc.
25 # right after conf_files
29 logger.log("specialaccounts: plugin starting up...")
31 def GetSlivers(data, conf = None, plc = None):
32 if 'accounts' not in data:
33 logger.log_missing_data("specialaccounts.GetSlivers",'accounts')
36 for account in data['accounts']:
37 name = account['name']
38 new_keys = account['keys']
40 logger.log('specialaccounts: dealing with account %s'%name)
42 # look up account name, which must exist
43 pw_info = pwd.getpwnam(name)
48 # populate account's .ssh/authorized_keys file
49 dot_ssh = os.path.join(pw_dir,'.ssh')
50 if not os.access(dot_ssh, os.F_OK): os.mkdir(dot_ssh)
51 auth_keys = os.path.join(dot_ssh,'authorized_keys')
53 # catenate all keys in string, add newlines just in case (looks like keys already have this, but)
54 auth_keys_contents = '\n'.join(new_keys)+'\n'
56 changes = tools.replace_file_with_string(auth_keys,auth_keys_contents)
58 logger.log("specialaccounts: keys file changed: %s" % auth_keys)
60 # always set permissions properly
61 os.chmod(dot_ssh, 0700)
62 os.chown(dot_ssh, uid,gid)
63 os.chmod(auth_keys, 0600)
64 os.chown(auth_keys, uid,gid)
66 logger.log('specialaccounts: installed ssh keys for %s' % name)