arvados-login-sync 2.0.4 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/bin/arvados-login-sync +79 -22
  3. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a68f9e7cdad5787087bc8e8b9658b8d935e0c45e805b4a2e9cd4f7991d12523b
4
- data.tar.gz: b179bdfdd8a8d171d0922935418f3ee5418340b1c8f1f9af87080803c301dfa8
3
+ metadata.gz: c1a0c7f1fcb3c928fdbb862b70f72687d7c4a0be16d2fab5cdb6654a0b186637
4
+ data.tar.gz: bb169f64011ed76c08a2fd0f7593fa23f62825faba26ee1bc2a09037f1d8355f
5
5
  SHA512:
6
- metadata.gz: 9bd46ea7cba87a45e905633b3004a39a79153fd2ca7a0a0b7ada29169d7a78979e142ea6048f4c76ae793fbbf5a20e854ad13b479a39e97d121481faace2dc20
7
- data.tar.gz: 316f986a8b493430c7e8de4c172c5bc36e5a8f85961f4b83ee0cd5a2093abe0fd85f45a24d9be444e20d40053b5433a96f6687d348b971d33ccf0fea2a9eb27d
6
+ metadata.gz: f90f358925db86b5a4b7783ec1228bcae0ac8a6220ef7c54f9bdecc8fc08c7c4b134cf0bd288a3fa62bfc063c43433655b4d6f882b1c2e33ab8cafbc211ba4ee
7
+ data.tar.gz: 144925d7685c565fd224bd0c96cd509c988ef364765cbc556cfdf41f504124e39d07e6434a898e142054ee0ac6993f14ce88604ff0fb09ac7a1091f76d612281
@@ -36,7 +36,7 @@ begin
36
36
 
37
37
  logins = arv.virtual_machine.logins(:uuid => vm_uuid)[:items]
38
38
  logins = [] if logins.nil?
39
- logins = logins.reject { |l| l[:username].nil? or l[:hostname].nil? or l[:public_key].nil? or l[:virtual_machine_uuid] != vm_uuid }
39
+ logins = logins.reject { |l| l[:username].nil? or l[:hostname].nil? or l[:virtual_machine_uuid] != vm_uuid }
40
40
 
41
41
  # No system users
42
42
  uid_min = 1000
@@ -79,48 +79,77 @@ begin
79
79
  logins.each do |l|
80
80
  keys[l[:username]] = Array.new() if not keys.has_key?(l[:username])
81
81
  key = l[:public_key]
82
- # Handle putty-style ssh public keys
83
- key.sub!(/^(Comment: "r[^\n]*\n)(.*)$/m,'ssh-rsa \2 \1')
84
- key.sub!(/^(Comment: "d[^\n]*\n)(.*)$/m,'ssh-dss \2 \1')
85
- key.gsub!(/\n/,'')
86
- key.strip
87
-
88
- keys[l[:username]].push(key) if not keys[l[:username]].include?(key)
82
+ if !key.nil?
83
+ # Handle putty-style ssh public keys
84
+ key.sub!(/^(Comment: "r[^\n]*\n)(.*)$/m,'ssh-rsa \2 \1')
85
+ key.sub!(/^(Comment: "d[^\n]*\n)(.*)$/m,'ssh-dss \2 \1')
86
+ key.gsub!(/\n/,'')
87
+ key.strip
88
+
89
+ keys[l[:username]].push(key) if not keys[l[:username]].include?(key)
90
+ end
89
91
  end
90
92
 
91
93
  seen = Hash.new()
92
- devnull = open("/dev/null", "w")
94
+
95
+ current_user_groups = Hash.new
96
+ while (ent = Etc.getgrent()) do
97
+ ent.mem.each do |member|
98
+ current_user_groups[member] ||= Array.new
99
+ current_user_groups[member].push ent.name
100
+ end
101
+ end
102
+ Etc.endgrent()
93
103
 
94
104
  logins.each do |l|
95
105
  next if seen[l[:username]]
96
106
  seen[l[:username]] = true
97
107
 
108
+ username = l[:username]
109
+
98
110
  unless pwnam[l[:username]]
99
111
  STDERR.puts "Creating account #{l[:username]}"
100
- groups = l[:groups] || []
101
- # Adding users to the FUSE group has long been hardcoded behavior.
102
- groups << "fuse"
103
- groups.select! { |g| Etc.getgrnam(g) rescue false }
104
112
  # Create new user
105
113
  unless system("useradd", "-m",
106
- "-c", l[:username],
114
+ "-c", username,
107
115
  "-s", "/bin/bash",
108
- "-G", groups.join(","),
109
- l[:username],
110
- out: devnull)
116
+ username)
111
117
  STDERR.puts "Account creation failed for #{l[:username]}: #{$?}"
112
118
  next
113
119
  end
114
120
  begin
115
- pwnam[l[:username]] = Etc.getpwnam(l[:username])
121
+ pwnam[username] = Etc.getpwnam(username)
116
122
  rescue => e
117
123
  STDERR.puts "Created account but then getpwnam() failed for #{l[:username]}: #{e}"
118
124
  raise
119
125
  end
120
126
  end
121
127
 
122
- @homedir = pwnam[l[:username]].dir
123
- userdotssh = File.join(@homedir, ".ssh")
128
+ existing_groups = current_user_groups[username] || []
129
+ groups = l[:groups] || []
130
+ # Adding users to the FUSE group has long been hardcoded behavior.
131
+ groups << "fuse"
132
+ groups << username
133
+ groups.select! { |g| Etc.getgrnam(g) rescue false }
134
+
135
+ groups.each do |addgroup|
136
+ if existing_groups.index(addgroup).nil?
137
+ # User should be in group, but isn't, so add them.
138
+ STDERR.puts "Add user #{username} to #{addgroup} group"
139
+ system("adduser", username, addgroup)
140
+ end
141
+ end
142
+
143
+ existing_groups.each do |removegroup|
144
+ if groups.index(removegroup).nil?
145
+ # User is in a group, but shouldn't be, so remove them.
146
+ STDERR.puts "Remove user #{username} from #{removegroup} group"
147
+ system("deluser", username, removegroup)
148
+ end
149
+ end
150
+
151
+ homedir = pwnam[l[:username]].dir
152
+ userdotssh = File.join(homedir, ".ssh")
124
153
  Dir.mkdir(userdotssh) if !File.exist?(userdotssh)
125
154
 
126
155
  newkeys = "###\n###\n" + keys[l[:username]].join("\n") + "\n###\n###\n"
@@ -148,13 +177,41 @@ begin
148
177
  f.write(newkeys)
149
178
  f.close()
150
179
  end
180
+
181
+ userdotconfig = File.join(homedir, ".config")
182
+ if !File.exist?(userdotconfig)
183
+ Dir.mkdir(userdotconfig)
184
+ end
185
+
186
+ configarvados = File.join(userdotconfig, "arvados")
187
+ Dir.mkdir(configarvados) if !File.exist?(configarvados)
188
+
189
+ tokenfile = File.join(configarvados, "settings.conf")
190
+
191
+ begin
192
+ if !File.exist?(tokenfile)
193
+ user_token = arv.api_client_authorization.create(api_client_authorization: {owner_uuid: l[:user_uuid], api_client_id: 0})
194
+ f = File.new(tokenfile, 'w')
195
+ f.write("ARVADOS_API_HOST=#{ENV['ARVADOS_API_HOST']}\n")
196
+ f.write("ARVADOS_API_TOKEN=v2/#{user_token[:uuid]}/#{user_token[:api_token]}\n")
197
+ f.close()
198
+ end
199
+ rescue => e
200
+ STDERR.puts "Error setting token for #{l[:username]}: #{e}"
201
+ end
202
+
151
203
  FileUtils.chown_R(l[:username], nil, userdotssh)
204
+ FileUtils.chown_R(l[:username], nil, userdotconfig)
152
205
  File.chmod(0700, userdotssh)
153
- File.chmod(0750, @homedir)
206
+ File.chmod(0700, userdotconfig)
207
+ File.chmod(0700, configarvados)
208
+ File.chmod(0750, homedir)
154
209
  File.chmod(0600, keysfile)
210
+ if File.exist?(tokenfile)
211
+ File.chmod(0600, tokenfile)
212
+ end
155
213
  end
156
214
 
157
- devnull.close
158
215
  rescue Exception => bang
159
216
  puts "Error: " + bang.to_s
160
217
  puts bang.backtrace.join("\n")
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: arvados-login-sync
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.4
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Arvados Authors
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-04-13 00:00:00.000000000 Z
11
+ date: 2020-09-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: arvados
@@ -73,7 +73,7 @@ dependencies:
73
73
  - !ruby/object:Gem::Version
74
74
  version: '0.12'
75
75
  description: Creates and updates local login accounts for Arvados users. Built from
76
- git commit 5f300020c51e8073a9cb6e45ee49991386244510
76
+ git commit 1771152da97200b038378666457d18679f4c8cd7
77
77
  email: gem-dev@curoverse.com
78
78
  executables:
79
79
  - arvados-login-sync