vagrant-keymanager 1.0.6 → 1.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/Gemfile.lock +1 -1
- data/lib/vagrant-keymanager/config.rb +12 -13
- data/lib/vagrant-keymanager/hosts_file.rb +131 -99
- data/lib/vagrant-keymanager/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f86ecb2c469be75655708a7b2f8297984df16779
|
4
|
+
data.tar.gz: a592b2082ac1fb8623ce285f505914128e216e4a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eddd74a862aedbeb8bef62c204cbccc84ff40c92120008bbbb1ac45d3c52a3ed0fab12e7090dc0c900cd707cc1cdbb2590cb5c782b7ad1d00f34e6bbe52dff5b
|
7
|
+
data.tar.gz: 5ed4769a76a9114c969f56ee3ceb47c45fab49475dbf243dc7e7d52f8f43b4afe98b896268bf8c4e3459b7d98397cb12c14e6b9afe2766f9f0e3d1d950970ffc
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,17 +1,17 @@
|
|
1
1
|
module VagrantPlugins
|
2
2
|
module KeyManager
|
3
3
|
class Config < Vagrant.plugin('2', :config)
|
4
|
-
attr_accessor :extra_params
|
5
4
|
attr_accessor :extra_steps
|
5
|
+
attr_accessor :user_list
|
6
6
|
|
7
7
|
def initialize
|
8
|
-
@extra_params = []
|
9
|
-
@extra_params = Array.new
|
10
8
|
@extra_steps = nil
|
9
|
+
@user_list = UNSET_VALUE
|
11
10
|
end
|
12
11
|
|
13
12
|
def finalize!
|
14
|
-
@
|
13
|
+
@user_list = [] if @user_list == UNSET_VALUE
|
14
|
+
@user_list = [ "root", @user_list ].flatten.uniq
|
15
15
|
end
|
16
16
|
|
17
17
|
def validate(machine)
|
@@ -19,15 +19,6 @@ module VagrantPlugins
|
|
19
19
|
# errors << validate_bool('keymanager.enabled', @enabled)
|
20
20
|
errors.compact!
|
21
21
|
|
22
|
-
# check if extra_params option is an Array
|
23
|
-
if !machine.config.keymanager.extra_params.kind_of?(Array) &&
|
24
|
-
!machine.config.keymanager.extra_params.kind_of?(String)
|
25
|
-
errors << I18n.t('vagrant_keymanager.config.not_an_array_or_string', {
|
26
|
-
:config_key => 'keymanager.extra_params',
|
27
|
-
:is_class => extra_params.class.to_s,
|
28
|
-
})
|
29
|
-
end
|
30
|
-
|
31
22
|
if !machine.config.keymanager.extra_steps.nil? &&
|
32
23
|
!machine.config.keymanager.extra_steps.kind_of?(Proc)
|
33
24
|
errors << I18n.t('vagrant_keymanager.config.not_a_proc', {
|
@@ -36,6 +27,14 @@ module VagrantPlugins
|
|
36
27
|
})
|
37
28
|
end
|
38
29
|
|
30
|
+
if !machine.config.keymanager.user_list.kind_of?(Array) &&
|
31
|
+
!machine.config.keymanager.user_list.kind_of?(String)
|
32
|
+
errors << I18n.t('vagrant_keymanager.config.not_an_array_or_string', {
|
33
|
+
:config_key => 'keymanager.user_list',
|
34
|
+
:is_class => user_list.class.to_s,
|
35
|
+
})
|
36
|
+
end
|
37
|
+
|
39
38
|
errors.compact!
|
40
39
|
{ "KeyManager configuration" => errors }
|
41
40
|
end
|
@@ -2,103 +2,135 @@ require 'tempfile'
|
|
2
2
|
require 'pp'
|
3
3
|
|
4
4
|
module VagrantPlugins
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
5
|
+
module KeyManager
|
6
|
+
module HostsFile
|
7
|
+
def get_guest_keys(machine)
|
8
|
+
machines = get_machines
|
9
|
+
#running_machines = machines.reject {|m| m.state.short_description.to_s != "running"}
|
10
|
+
running_machines = machines.select {|m| m.communicate.ready? }
|
11
|
+
|
12
|
+
machines.each do |curr_machine|
|
13
|
+
#if curr_machine.state.short_description.to_s != "running"
|
14
|
+
if ! curr_machine.communicate.ready?
|
15
|
+
puts "Skipping machine "+curr_machine.name.to_s+ ". It's not in running state"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
sshkeys = Hash.new
|
20
|
+
required_users = machine.config.keymanager.user_list
|
21
|
+
|
22
|
+
puts "REQUIRED USERS:"
|
23
|
+
pp required_users
|
24
|
+
|
25
|
+
running_machines.each do |curr_machine|
|
26
|
+
curr_machine.communicate.sudo("rm -f /tmp/add_ssh_keys.sh /tmp/get_user_keys.sh")
|
27
|
+
# TODO: save these 2 bash script with curr_machine.communicate.upload
|
28
|
+
# We must save locally a bash script that computes and applies diff and always exits with 0 or vagrant plugin will exit with an error
|
29
|
+
curr_machine.communicate.execute("echo -e 'diff --changed-group-format=\"%>\" --unchanged-group-format=\"\" ~/.ssh/authorized_keys $1 >>~/.ssh/authorized_keys\nexit 0' >/tmp/add_ssh_keys.sh")
|
30
|
+
# We must save locally a bash script that gets ssh keys from any user (will passed as a aparameter)
|
31
|
+
curr_machine.communicate.execute("echo -e 'if [ ! -e ~/.ssh/id_rsa ] || [ ! -e ~/.ssh/id_rsa.pub ]; then\n\tssh-keygen -q -f ~/.ssh/id_rsa -P \"\"\nfi\ncat ~/.ssh/id_rsa.pub' >/tmp/get_user_keys.sh")
|
32
|
+
|
33
|
+
curr_machine_name=curr_machine.name.to_s
|
34
|
+
puts "Getting SSH keys from "+curr_machine_name
|
35
|
+
|
36
|
+
required_users.each do |curr_user|
|
37
|
+
if !check_user_existence(curr_machine, curr_user)
|
38
|
+
create_user(curr_machine, curr_user)
|
39
|
+
end
|
40
|
+
|
41
|
+
if !sshkeys[curr_user]
|
42
|
+
sshkeys[curr_user] = Hash.new
|
43
|
+
end
|
44
|
+
sshkey=get_user_key(curr_machine, curr_user)
|
45
|
+
#puts "SSH key for "+curr_user+": "+sshkey
|
46
|
+
sshkeys[curr_user][curr_machine_name] = sshkey
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
#pp sshkeys
|
51
|
+
|
52
|
+
running_machines.each do |curr_machine|
|
53
|
+
curr_machine_name=curr_machine.name.to_s
|
54
|
+
|
55
|
+
puts "Saving public SSH keys to "+curr_machine_name
|
56
|
+
|
57
|
+
required_users.each do |curr_user|
|
58
|
+
curr_machine.communicate.sudo("rm -f /tmp/.all_"+curr_user+"_keys.txt")
|
59
|
+
|
60
|
+
ssh_keys_to_save=sshkeys[curr_user].reject{|k,v| k == curr_machine_name}.values.join.gsub("\n\n", '\n')
|
61
|
+
curr_machine.communicate.execute("sudo -u "+curr_user+" -H echo '"+ssh_keys_to_save+"' >/tmp/.all_"+curr_user+"_keys.txt")
|
62
|
+
#puts "Saved /tmp/.all_"+curr_user+"_keys.txt"
|
63
|
+
end
|
64
|
+
|
65
|
+
required_users.each do |curr_user|
|
66
|
+
required_users.each do |source_user|
|
67
|
+
curr_machine.communicate.execute("sudo -u "+curr_user+" -H sh /tmp/add_ssh_keys.sh /tmp/.all_"+source_user+"_keys.txt")
|
68
|
+
end
|
69
|
+
#puts "Saved user "+curr_user+"keys"
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
running_machines.each do |curr_machine|
|
74
|
+
call_extra_user_steps(curr_machine)
|
75
|
+
end
|
76
|
+
|
77
|
+
running_machines.each do |curr_machine|
|
78
|
+
curr_machine.communicate.sudo("rm -f /tmp/add_ssh_keys.sh /tmp/get_user_keys.sh")
|
79
|
+
required_users.each do |curr_user|
|
80
|
+
curr_machine.communicate.sudo("rm -f /tmp/.all_"+curr_user+"_keys.txt")
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
private
|
86
|
+
|
87
|
+
def check_user_existence(machine, username)
|
88
|
+
if username != "root"
|
89
|
+
user_id = ""
|
90
|
+
machine.communicate.execute("id -u "+username+" 2>/dev/null; exit 0") do |type, data|
|
91
|
+
user_id << data if type == :stdout
|
92
|
+
end
|
93
|
+
return user_id != ""
|
94
|
+
else
|
95
|
+
return true
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
def create_user(machine, username)
|
100
|
+
puts "Creating user "+username+" on "+machine.name.to_s
|
101
|
+
machine.communicate.sudo("adduser "+username)
|
102
|
+
end
|
103
|
+
|
104
|
+
def get_user_key(machine, username)
|
105
|
+
sshresult=""
|
106
|
+
machine.communicate.execute("sudo -u "+username+" -H sh /tmp/get_user_keys.sh") do |type, data|
|
107
|
+
sshresult << data if type == :stdout
|
108
|
+
end
|
109
|
+
return sshresult
|
110
|
+
end
|
111
|
+
|
112
|
+
def call_extra_user_steps(resolving_machine)
|
113
|
+
extra_user_steps = machine.config.keymanager.extra_steps
|
114
|
+
if extra_user_steps
|
115
|
+
machines = @global_env.machine_names
|
116
|
+
machines.map { |machine| extra_user_steps.call(machine, resolving_machine) }
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
def get_machines
|
121
|
+
machines = @global_env.machine_names
|
122
|
+
# Collect only machines that exist for the current provider
|
123
|
+
machines.collect do |name|
|
124
|
+
begin
|
125
|
+
machine = @global_env.machine(name, @provider)
|
126
|
+
rescue Vagrant::Errors::MachineNotFound
|
127
|
+
# ignore
|
128
|
+
end
|
129
|
+
machine
|
130
|
+
end
|
131
|
+
.reject(&:nil?)
|
132
|
+
end
|
133
|
+
|
134
|
+
end
|
135
|
+
end
|
104
136
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vagrant-keymanager
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Giorgio Baldaccini
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-06-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|