9799: Merge branch 'master' into 9799-nonadmin-logs
[arvados.git] / services / login-sync / bin / arvados-login-sync
index b9cecb686028fff8caffc9bb79a5e57203c4bb44..e1b8c484f0413cb8ff6bfe3ac0be77aebbcd2aa7 100755 (executable)
@@ -25,11 +25,7 @@ begin
 
   vm_uuid = ENV['ARVADOS_VIRTUAL_MACHINE_UUID']
 
-  begin
-    logins = arv.virtual_machine.get_all_logins(limit: 10000, uuid: vm_uuid)[:items]
-  rescue
-    logins = arv.virtual_machine.logins(:uuid => vm_uuid)[:items]
-  end
+  logins = arv.virtual_machine.logins(:uuid => vm_uuid)[:items]
   logins = [] if logins.nil?
   logins = logins.reject { |l| l[:username].nil? or l[:hostname].nil? or l[:public_key].nil? or l[:virtual_machine_uuid] != vm_uuid }
 
@@ -72,7 +68,6 @@ begin
   logins.each do |l|
     next if seen[l[:username]]
     seen[l[:username]] = true if not seen.has_key?(l[:username])
-    @homedir = "/home/#{l[:username]}"
 
     unless uids[l[:username]]
       STDERR.puts "Creating account #{l[:username]}"
@@ -81,7 +76,7 @@ begin
       groups << "fuse"
       groups.select! { |name| gids[name] }
       # Create new user
-      next unless system("/usr/sbin/useradd", "-m",
+      next unless system("useradd", "-m",
                          "-c", l[:username],
                          "-s", "/bin/bash",
                          "-G", groups.join(","),
@@ -89,6 +84,7 @@ begin
                          out: devnull)
     end
     # Create .ssh directory if necessary
+    @homedir = Etc.getpwnam(l[:username]).dir
     userdotssh = File.join(@homedir, ".ssh")
     Dir.mkdir(userdotssh) if !File.exists?(userdotssh)
     @key = "#######################################################################################
@@ -104,6 +100,7 @@ begin
     FileUtils.chown_R(l[:username], l[:username], userdotssh)
     File.chmod(0700, userdotssh)
     File.chmod(0750, @homedir)
+    File.chmod(0600, userauthkeys)
   end
 
   devnull.close
@@ -112,4 +109,3 @@ rescue Exception => bang
   puts bang.backtrace.join("\n")
   exit 1
 end
-