2424 base
2525)
2626
27+
2728CONF = cloudbaseinit_conf .CONF
2829LOG = oslo_logging .getLogger (__name__ )
2930
31+ # The default Win32-OpenSSH config assumes that the built-in Administrators
32+ # group with SID S-1-5-32-544 does not have an internationalized name.
33+ ADMINISTRATORS = "Administrators"
34+
3035
3136class UsersPlugin (base .BaseCloudConfigPlugin ):
3237 """Creates users given in the cloud-config format."""
@@ -154,6 +159,7 @@ def process(self, data):
154159 "Can't process the type of data %r" % type (data ))
155160
156161 osutils = osutils_factory .get_os_utils ()
162+ administrators_authorized_keys = []
157163 for item in data :
158164 if not isinstance (item , dict ):
159165 continue
@@ -172,4 +178,25 @@ def process(self, data):
172178 LOG .warning ("An error occurred during user '%s' creation: '%s"
173179 % (user_name , ex ))
174180
181+ if ADMINISTRATORS in self ._get_groups (item ):
182+ admin_public_keys = item .get ('ssh_authorized_keys' , [])
183+ administrators_authorized_keys .extend (admin_public_keys )
184+
185+ if osutils .group_exists (ADMINISTRATORS ):
186+ program_data_dir = os .getenv ("PROGRAMDATA" , "C:\ProgramData" )
187+ program_data_ssh_dir = os .path .join (program_data_dir , "ssh" )
188+ if not os .path .exists (program_data_ssh_dir ):
189+ os .makedirs (program_data_ssh_dir )
190+
191+ administrators_authorized_keys_path = os .path .join (
192+ program_data_ssh_dir , "administrators_authorized_keys"
193+ )
194+
195+ LOG .info ("Writing SSH public keys in: %s" ,
196+ administrators_authorized_keys_path )
197+
198+ with open (administrators_authorized_keys_path , 'w' ) as f :
199+ for authorized_key in administrators_authorized_keys :
200+ f .write (authorized_key + "\n " )
201+
175202 return False
0 commit comments