opennebula-oca 3.9.0.beta → 3.9.90.rc
Sign up to get free protection for your applications and to get access to all the features.
- data/README +1 -0
- metadata +35 -108
- data/LICENSE +0 -202
- data/NOTICE +0 -48
- data/lib/opennebula/acl.rb +0 -259
- data/lib/opennebula/acl_pool.rb +0 -53
- data/lib/opennebula/client.rb +0 -102
- data/lib/opennebula/cluster.rb +0 -247
- data/lib/opennebula/cluster_pool.rb +0 -56
- data/lib/opennebula/datastore.rb +0 -169
- data/lib/opennebula/datastore_pool.rb +0 -53
- data/lib/opennebula/document.rb +0 -259
- data/lib/opennebula/document_json.rb +0 -129
- data/lib/opennebula/document_pool.rb +0 -97
- data/lib/opennebula/document_pool_json.rb +0 -58
- data/lib/opennebula/error.rb +0 -52
- data/lib/opennebula/group.rb +0 -161
- data/lib/opennebula/group_pool.rb +0 -54
- data/lib/opennebula/host.rb +0 -199
- data/lib/opennebula/host_pool.rb +0 -91
- data/lib/opennebula/image.rb +0 -293
- data/lib/opennebula/image_pool.rb +0 -74
- data/lib/opennebula/ldap_auth.rb +0 -99
- data/lib/opennebula/ldap_auth_spec.rb +0 -70
- data/lib/opennebula/pool.rb +0 -157
- data/lib/opennebula/pool_element.rb +0 -269
- data/lib/opennebula/server_cipher_auth.rb +0 -148
- data/lib/opennebula/server_x509_auth.rb +0 -104
- data/lib/opennebula/ssh_auth.rb +0 -139
- data/lib/opennebula/system.rb +0 -141
- data/lib/opennebula/template.rb +0 -201
- data/lib/opennebula/template_pool.rb +0 -74
- data/lib/opennebula/user.rb +0 -172
- data/lib/opennebula/user_pool.rb +0 -53
- data/lib/opennebula/virtual_machine.rb +0 -426
- data/lib/opennebula/virtual_machine_pool.rb +0 -318
- data/lib/opennebula/virtual_network.rb +0 -247
- data/lib/opennebula/virtual_network_pool.rb +0 -74
- data/lib/opennebula/x509_auth.rb +0 -241
- data/lib/opennebula/xml_element.rb +0 -427
- data/lib/opennebula/xml_pool.rb +0 -45
- data/lib/opennebula/xml_utils.rb +0 -34
- data/lib/opennebula.rb +0 -58
@@ -1,269 +0,0 @@
|
|
1
|
-
# -------------------------------------------------------------------------- #
|
2
|
-
# Copyright 2002-2012, OpenNebula Project Leads (OpenNebula.org) #
|
3
|
-
# #
|
4
|
-
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
5
|
-
# not use this file except in compliance with the License. You may obtain #
|
6
|
-
# a copy of the License at #
|
7
|
-
# #
|
8
|
-
# http://www.apache.org/licenses/LICENSE-2.0 #
|
9
|
-
# #
|
10
|
-
# Unless required by applicable law or agreed to in writing, software #
|
11
|
-
# distributed under the License is distributed on an "AS IS" BASIS, #
|
12
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
|
13
|
-
# See the License for the specific language governing permissions and #
|
14
|
-
# limitations under the License. #
|
15
|
-
#--------------------------------------------------------------------------- #
|
16
|
-
|
17
|
-
require 'opennebula/pool'
|
18
|
-
|
19
|
-
module OpenNebula
|
20
|
-
# The PoolElement Class represents a generic element of a Pool in
|
21
|
-
# XML format
|
22
|
-
class PoolElement < XMLElement
|
23
|
-
|
24
|
-
protected
|
25
|
-
# node:: _XML_is a XML element that represents the Pool element
|
26
|
-
# client:: _Client_ represents a XML-RPC connection
|
27
|
-
def initialize(node, client)
|
28
|
-
@xml = node
|
29
|
-
@client = client
|
30
|
-
|
31
|
-
if self['ID']
|
32
|
-
@pe_id = self['ID'].to_i
|
33
|
-
else
|
34
|
-
@pe_id = nil
|
35
|
-
end
|
36
|
-
@name = self['NAME'] if self['NAME']
|
37
|
-
end
|
38
|
-
|
39
|
-
#######################################################################
|
40
|
-
# Common XML-RPC Methods for all the Pool Element Types
|
41
|
-
#######################################################################
|
42
|
-
|
43
|
-
# Common client call wrapper. Checks that @pe_id is defined, and
|
44
|
-
# returns nil instead of the response if it is successful
|
45
|
-
#
|
46
|
-
# @param [String] xml_method xml-rpc method
|
47
|
-
# @param [Array] args any arguments for the xml-rpc method
|
48
|
-
#
|
49
|
-
# @return [nil, OpenNebula::Error] nil in case of success, Error
|
50
|
-
# otherwise
|
51
|
-
def call(xml_method, *args)
|
52
|
-
return Error.new('ID not defined') if !@pe_id
|
53
|
-
|
54
|
-
rc = @client.call(xml_method, *args)
|
55
|
-
rc = nil if !OpenNebula.is_error?(rc)
|
56
|
-
|
57
|
-
return rc
|
58
|
-
end
|
59
|
-
|
60
|
-
# Calls to the corresponding info method to retreive the element
|
61
|
-
# detailed information in XML format
|
62
|
-
#
|
63
|
-
# @param [String] xml_method the name of the XML-RPC method
|
64
|
-
# @param [String] root_element Base XML element name
|
65
|
-
# @param [Array] args additional arguments
|
66
|
-
#
|
67
|
-
# @return [nil, OpenNebula::Error] nil in case of success, Error
|
68
|
-
# otherwise
|
69
|
-
def info(xml_method, root_element)
|
70
|
-
return Error.new('ID not defined') if !@pe_id
|
71
|
-
|
72
|
-
rc = @client.call(xml_method, @pe_id)
|
73
|
-
|
74
|
-
if !OpenNebula.is_error?(rc)
|
75
|
-
initialize_xml(rc, root_element)
|
76
|
-
rc = nil
|
77
|
-
|
78
|
-
@pe_id = self['ID'].to_i if self['ID']
|
79
|
-
@name = self['NAME'] if self['NAME']
|
80
|
-
end
|
81
|
-
|
82
|
-
return rc
|
83
|
-
end
|
84
|
-
|
85
|
-
# Calls to the corresponding allocate method to create a new element
|
86
|
-
# in the OpenNebula core
|
87
|
-
#
|
88
|
-
# @param [String] xml_method the name of the XML-RPC method
|
89
|
-
# @param [Array] args any extra arguments for the xml-rpc method
|
90
|
-
#
|
91
|
-
# @return [nil, OpenNebula::Error] nil in case of success, Error
|
92
|
-
# otherwise
|
93
|
-
def allocate(xml_method, *args)
|
94
|
-
rc = @client.call(xml_method, *args)
|
95
|
-
|
96
|
-
if !OpenNebula.is_error?(rc)
|
97
|
-
@pe_id = rc
|
98
|
-
rc = nil
|
99
|
-
end
|
100
|
-
|
101
|
-
return rc
|
102
|
-
end
|
103
|
-
|
104
|
-
# Calls to the corresponding update method to modify
|
105
|
-
# the object's template
|
106
|
-
#
|
107
|
-
# @param [String] xml_method the name of the XML-RPC method
|
108
|
-
# @param [String] new_template the new template contents
|
109
|
-
# @param [Array] args any extra arguments for the xml-rpc method
|
110
|
-
#
|
111
|
-
# @return [nil, OpenNebula::Error] nil in case of success, Error
|
112
|
-
# otherwise
|
113
|
-
def update(xml_method, new_template, *args)
|
114
|
-
new_template ||= template_xml
|
115
|
-
|
116
|
-
return call(xml_method, @pe_id, new_template, *args)
|
117
|
-
end
|
118
|
-
|
119
|
-
# Calls to the corresponding delete method to remove this element
|
120
|
-
# from the OpenNebula core
|
121
|
-
#
|
122
|
-
# @param [String] xml_method the name of the XML-RPC method
|
123
|
-
#
|
124
|
-
# @return [nil, OpenNebula::Error] nil in case of success, Error
|
125
|
-
# otherwise
|
126
|
-
def delete(xml_method)
|
127
|
-
return call(xml_method,@pe_id)
|
128
|
-
end
|
129
|
-
|
130
|
-
# Calls to the corresponding chown method to modify
|
131
|
-
# the object's owner and group
|
132
|
-
#
|
133
|
-
# @param [String] xml_method the name of the XML-RPC method
|
134
|
-
# @param [Integer] uid the new owner id. Set to -1 to leave the current one
|
135
|
-
# @param [Integer] gid the new goup id. Set to -1 to leave the current one
|
136
|
-
#
|
137
|
-
# @return [nil, OpenNebula::Error] nil in case of success, Error
|
138
|
-
# otherwise
|
139
|
-
def chown(xml_method, uid, gid)
|
140
|
-
return call(xml_method, @pe_id, uid, gid)
|
141
|
-
end
|
142
|
-
|
143
|
-
# Calls to the corresponding chmod method to modify
|
144
|
-
# the object's permission bits
|
145
|
-
#
|
146
|
-
# @param xml_method [String] the name of the XML-RPC method
|
147
|
-
# @param octet [String] Permissions octed , e.g. 640
|
148
|
-
#
|
149
|
-
# @return [nil, OpenNebula::Error] nil in case of success, Error
|
150
|
-
# otherwise
|
151
|
-
def chmod_octet(xml_method, octet)
|
152
|
-
owner_u = octet[0..0].to_i & 4 != 0 ? 1 : 0
|
153
|
-
owner_m = octet[0..0].to_i & 2 != 0 ? 1 : 0
|
154
|
-
owner_a = octet[0..0].to_i & 1 != 0 ? 1 : 0
|
155
|
-
group_u = octet[1..1].to_i & 4 != 0 ? 1 : 0
|
156
|
-
group_m = octet[1..1].to_i & 2 != 0 ? 1 : 0
|
157
|
-
group_a = octet[1..1].to_i & 1 != 0 ? 1 : 0
|
158
|
-
other_u = octet[2..2].to_i & 4 != 0 ? 1 : 0
|
159
|
-
other_m = octet[2..2].to_i & 2 != 0 ? 1 : 0
|
160
|
-
other_a = octet[2..2].to_i & 1 != 0 ? 1 : 0
|
161
|
-
|
162
|
-
chmod(owner_u, owner_m, owner_a, group_u, group_m, group_a, other_u,
|
163
|
-
other_m, other_a)
|
164
|
-
end
|
165
|
-
|
166
|
-
# Calls to the corresponding chmod method to modify
|
167
|
-
# the object's permission bits
|
168
|
-
# Each [Integer] parameter must be 1 to allow, 0 deny, -1 do not change
|
169
|
-
#
|
170
|
-
# @param xml_method [String] the name of the XML-RPC method
|
171
|
-
#
|
172
|
-
# @return [nil, OpenNebula::Error] nil in case of success, Error
|
173
|
-
# otherwise
|
174
|
-
def chmod(xml_method, owner_u, owner_m, owner_a, group_u, group_m, group_a, other_u,
|
175
|
-
other_m, other_a)
|
176
|
-
return call(xml_method, @pe_id, owner_u, owner_m,
|
177
|
-
owner_a, group_u, group_m, group_a, other_u,
|
178
|
-
other_m, other_a)
|
179
|
-
end
|
180
|
-
|
181
|
-
|
182
|
-
# Retrieves this Element's monitoring data from OpenNebula
|
183
|
-
#
|
184
|
-
# @param [String] xml_method the name of the XML-RPC method
|
185
|
-
# @param [String] root_elem Root for each individual PoolElement
|
186
|
-
# @param [String] timestamp_elem Name of the XML element with the last
|
187
|
-
# monitorization timestamp
|
188
|
-
# @param xpath_expressions [Array<String>] Xpath expressions for the
|
189
|
-
# elements to retrieve.
|
190
|
-
#
|
191
|
-
# @return [Hash<String, Array<Array<int>>, OpenNebula::Error] Hash with
|
192
|
-
# the requested xpath expressions, and an Array of [timestamp, value].
|
193
|
-
def monitoring(xml_method, root_elem, timestamp_elem, xpath_expressions)
|
194
|
-
return Error.new('ID not defined') if !@pe_id
|
195
|
-
|
196
|
-
rc = @client.call(xml_method, @pe_id)
|
197
|
-
|
198
|
-
if ( OpenNebula.is_error?(rc) )
|
199
|
-
return rc
|
200
|
-
end
|
201
|
-
|
202
|
-
xmldoc = XMLElement.new
|
203
|
-
xmldoc.initialize_xml(rc, 'MONITORING_DATA')
|
204
|
-
|
205
|
-
|
206
|
-
return OpenNebula.process_monitoring(
|
207
|
-
xmldoc, root_elem, timestamp_elem, @pe_id, xpath_expressions)
|
208
|
-
end
|
209
|
-
|
210
|
-
public
|
211
|
-
|
212
|
-
# Creates new element specifying its id
|
213
|
-
# id:: identifyier of the element
|
214
|
-
# client:: initialized OpenNebula::Client object
|
215
|
-
def self.new_with_id(id, client=nil)
|
216
|
-
self.new(self.build_xml(id), client)
|
217
|
-
end
|
218
|
-
|
219
|
-
# Returns element identifier
|
220
|
-
# [return] _Integer_ the PoolElement ID
|
221
|
-
def id
|
222
|
-
@pe_id
|
223
|
-
end
|
224
|
-
|
225
|
-
# Gets element name
|
226
|
-
# [return] _String_ the PoolElement name
|
227
|
-
def name
|
228
|
-
@name
|
229
|
-
end
|
230
|
-
|
231
|
-
# DO NOT USE - ONLY REXML BACKEND
|
232
|
-
def to_str
|
233
|
-
str = ""
|
234
|
-
REXML::Formatters::Pretty.new(1).write(@xml,str)
|
235
|
-
|
236
|
-
return str
|
237
|
-
end
|
238
|
-
end
|
239
|
-
|
240
|
-
# Processes the monitoring data in XML returned by OpenNebula
|
241
|
-
#
|
242
|
-
# @param [XMLElement] xmldoc monitoring data returned by OpenNebula
|
243
|
-
# @param [String] root_elem Root for each individual PoolElement
|
244
|
-
# @param [String] timestamp_elem Name of the XML element with the last
|
245
|
-
# monitorization timestamp
|
246
|
-
# @param [Integer] Id of the object to process
|
247
|
-
# @param [Array<String>] xpath_expressions Elements to retrieve.
|
248
|
-
# @param args arguemnts for the xml_method call
|
249
|
-
#
|
250
|
-
# @return [Hash<String, Array<Array<int>>, OpenNebula::Error] Hash with
|
251
|
-
# the requested xpath expressions, and an Array of [timestamp, value].
|
252
|
-
def self.process_monitoring(xmldoc, root_elem, timestamp_elem, oid, xpath_expressions)
|
253
|
-
hash = {}
|
254
|
-
timestamps = xmldoc.retrieve_elements(
|
255
|
-
"#{root_elem}[ID=#{oid}]/#{timestamp_elem}")
|
256
|
-
|
257
|
-
xpath_expressions.each { |xpath|
|
258
|
-
xpath_values = xmldoc.retrieve_elements("#{root_elem}[ID=#{oid}]/#{xpath}")
|
259
|
-
|
260
|
-
if ( xpath_values.nil? )
|
261
|
-
hash[xpath] = []
|
262
|
-
else
|
263
|
-
hash[xpath] = timestamps.zip(xpath_values)
|
264
|
-
end
|
265
|
-
}
|
266
|
-
|
267
|
-
return hash
|
268
|
-
end
|
269
|
-
end
|
@@ -1,148 +0,0 @@
|
|
1
|
-
# -------------------------------------------------------------------------- #
|
2
|
-
# Copyright 2002-2012, OpenNebula Project Leads (OpenNebula.org) #
|
3
|
-
# #
|
4
|
-
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
5
|
-
# not use this file except in compliance with the License. You may obtain #
|
6
|
-
# a copy of the License at #
|
7
|
-
# #
|
8
|
-
# http://www.apache.org/licenses/LICENSE-2.0 #
|
9
|
-
# #
|
10
|
-
# Unless required by applicable law or agreed to in writing, software #
|
11
|
-
# distributed under the License is distributed on an "AS IS" BASIS, #
|
12
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
|
13
|
-
# See the License for the specific language governing permissions and #
|
14
|
-
# limitations under the License. #
|
15
|
-
#--------------------------------------------------------------------------- #
|
16
|
-
|
17
|
-
require 'openssl'
|
18
|
-
require 'digest/sha1'
|
19
|
-
|
20
|
-
require 'base64'
|
21
|
-
require 'fileutils'
|
22
|
-
|
23
|
-
module OpenNebula; end
|
24
|
-
|
25
|
-
# Server authentication class. This method can be used by OpenNebula services
|
26
|
-
# to let access authenticated users by other means. It is based on OpenSSL
|
27
|
-
# symmetric ciphers
|
28
|
-
class OpenNebula::ServerCipherAuth
|
29
|
-
###########################################################################
|
30
|
-
#Constants with paths to relevant files and defaults
|
31
|
-
###########################################################################
|
32
|
-
|
33
|
-
CIPHER = "aes-256-cbc"
|
34
|
-
|
35
|
-
###########################################################################
|
36
|
-
|
37
|
-
def initialize(srv_user, srv_passwd)
|
38
|
-
@srv_user = srv_user
|
39
|
-
@srv_passwd = srv_passwd
|
40
|
-
|
41
|
-
if !srv_passwd.empty?
|
42
|
-
@key = Digest::SHA1.hexdigest(@srv_passwd)
|
43
|
-
else
|
44
|
-
@key = ""
|
45
|
-
end
|
46
|
-
|
47
|
-
@cipher = OpenSSL::Cipher::Cipher.new(CIPHER)
|
48
|
-
end
|
49
|
-
|
50
|
-
###########################################################################
|
51
|
-
# Client side
|
52
|
-
###########################################################################
|
53
|
-
|
54
|
-
# Creates a ServerCipher for client usage
|
55
|
-
def self.new_client(srv_user=nil, srv_passwd=nil)
|
56
|
-
if ( srv_user == nil || srv_passwd == nil )
|
57
|
-
begin
|
58
|
-
if ENV["ONE_CIPHER_AUTH"] and !ENV["ONE_CIPHER_AUTH"].empty?
|
59
|
-
one_auth = File.read(ENV["ONE_CIPHER_AUTH"])
|
60
|
-
else
|
61
|
-
raise "ONE_CIPHER_AUTH environment variable not set"
|
62
|
-
end
|
63
|
-
|
64
|
-
one_auth.rstrip!
|
65
|
-
|
66
|
-
rc = one_auth.match(/(.*?):(.*)/)
|
67
|
-
|
68
|
-
if rc.nil?
|
69
|
-
raise "Bad format for one_auth token (<user>:<passwd>)"
|
70
|
-
else
|
71
|
-
srv_user = rc[1]
|
72
|
-
srv_passwd = rc[2]
|
73
|
-
end
|
74
|
-
rescue => e
|
75
|
-
raise e.message
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
self.new(srv_user, srv_passwd)
|
80
|
-
end
|
81
|
-
|
82
|
-
# Generates a login token in the form:
|
83
|
-
# - server_user:target_user:time_expires
|
84
|
-
# The token is then encrypted with the contents of one_auth
|
85
|
-
def login_token(expire, target_user=nil)
|
86
|
-
target_user ||= @srv_user
|
87
|
-
token_txt = "#{@srv_user}:#{target_user}:#{expire}"
|
88
|
-
|
89
|
-
token = encrypt(token_txt)
|
90
|
-
token64 = Base64::encode64(token).strip.delete("\n")
|
91
|
-
|
92
|
-
return "#{@srv_user}:#{target_user}:#{token64}"
|
93
|
-
end
|
94
|
-
|
95
|
-
# Returns a valid password string to create a user using this auth driver
|
96
|
-
def password
|
97
|
-
return @srv_passwd
|
98
|
-
end
|
99
|
-
|
100
|
-
###########################################################################
|
101
|
-
# Driver side
|
102
|
-
###########################################################################
|
103
|
-
|
104
|
-
# Creates a ServerCipher for driver usage
|
105
|
-
def self.new_driver()
|
106
|
-
self.new("","")
|
107
|
-
end
|
108
|
-
|
109
|
-
# auth method for auth_mad
|
110
|
-
def authenticate(srv_user,srv_pass, signed_text)
|
111
|
-
begin
|
112
|
-
@key = srv_pass
|
113
|
-
|
114
|
-
s_user, t_user, expires = decrypt(signed_text).split(':')
|
115
|
-
|
116
|
-
return "User name missmatch" if s_user != srv_user
|
117
|
-
|
118
|
-
return "login token expired" if Time.now.to_i >= expires.to_i
|
119
|
-
|
120
|
-
return true
|
121
|
-
rescue => e
|
122
|
-
return e.message
|
123
|
-
end
|
124
|
-
end
|
125
|
-
|
126
|
-
private
|
127
|
-
|
128
|
-
def encrypt(data)
|
129
|
-
@cipher.encrypt
|
130
|
-
@cipher.key = @key
|
131
|
-
|
132
|
-
rc = @cipher.update(data)
|
133
|
-
rc << @cipher.final
|
134
|
-
|
135
|
-
return rc
|
136
|
-
end
|
137
|
-
|
138
|
-
def decrypt(data)
|
139
|
-
@cipher.decrypt
|
140
|
-
@cipher.key = @key
|
141
|
-
|
142
|
-
rc = @cipher.update(Base64::decode64(data))
|
143
|
-
rc << @cipher.final
|
144
|
-
|
145
|
-
return rc
|
146
|
-
end
|
147
|
-
end
|
148
|
-
|
@@ -1,104 +0,0 @@
|
|
1
|
-
# -------------------------------------------------------------------------- #
|
2
|
-
# Copyright 2002-2012, OpenNebula Project Leads (OpenNebula.org) #
|
3
|
-
# #
|
4
|
-
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
5
|
-
# not use this file except in compliance with the License. You may obtain #
|
6
|
-
# a copy of the License at #
|
7
|
-
# #
|
8
|
-
# http://www.apache.org/licenses/LICENSE-2.0 #
|
9
|
-
# #
|
10
|
-
# Unless required by applicable law or agreed to in writing, software #
|
11
|
-
# distributed under the License is distributed on an "AS IS" BASIS, #
|
12
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
|
13
|
-
# See the License for the specific language governing permissions and #
|
14
|
-
# limitations under the License. #
|
15
|
-
#--------------------------------------------------------------------------- #
|
16
|
-
|
17
|
-
require 'openssl'
|
18
|
-
require 'base64'
|
19
|
-
require 'fileutils'
|
20
|
-
|
21
|
-
require 'opennebula/x509_auth'
|
22
|
-
|
23
|
-
module OpenNebula; end
|
24
|
-
|
25
|
-
# Server authentication class. This authmethod can be used by opennebula services
|
26
|
-
# to let access authenticated users by other means. It is based on x509 server
|
27
|
-
# certificates
|
28
|
-
class OpenNebula::ServerX509Auth < OpenNebula::X509Auth
|
29
|
-
###########################################################################
|
30
|
-
#Constants with paths to relevant files and defaults
|
31
|
-
###########################################################################
|
32
|
-
|
33
|
-
SERVER_AUTH_CONF_PATH = ETC_LOCATION + "/auth/server_x509_auth.conf"
|
34
|
-
|
35
|
-
SERVER_DEFAULTS = {
|
36
|
-
:one_cert => ETC_LOCATION + "/auth/cert.pem",
|
37
|
-
:one_key => ETC_LOCATION + "/auth/key.pem"
|
38
|
-
}
|
39
|
-
|
40
|
-
###########################################################################
|
41
|
-
|
42
|
-
def initialize()
|
43
|
-
@options = SERVER_DEFAULTS
|
44
|
-
|
45
|
-
load_options(SERVER_AUTH_CONF_PATH)
|
46
|
-
|
47
|
-
begin
|
48
|
-
certs = [ File.read(@options[:one_cert]) ]
|
49
|
-
key = File.read(@options[:one_key])
|
50
|
-
|
51
|
-
super(:certs_pem => certs, :key_pem => key)
|
52
|
-
rescue
|
53
|
-
raise
|
54
|
-
end
|
55
|
-
|
56
|
-
if @options[:srv_user] == nil || @options[:srv_user].empty?
|
57
|
-
raise "User for x509 server not defined"
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
###########################################################################
|
62
|
-
# Client side
|
63
|
-
###########################################################################
|
64
|
-
|
65
|
-
# Creates a ServerCipher for client and driver sage
|
66
|
-
class << OpenNebula::ServerX509Auth
|
67
|
-
alias :new_client :new
|
68
|
-
alias :new_driver :new
|
69
|
-
end
|
70
|
-
|
71
|
-
# Generates a login token in the form:
|
72
|
-
# - server_user:target_user:time_expires
|
73
|
-
def login_token(expire, target_user=nil)
|
74
|
-
target_user ||= @options[:srv_user]
|
75
|
-
token_txt = "#{@options[:srv_user]}:#{target_user}:#{expire}"
|
76
|
-
|
77
|
-
token = encrypt(token_txt)
|
78
|
-
token64 = Base64::encode64(token).strip.delete("\n")
|
79
|
-
|
80
|
-
return "#{@options[:srv_user]}:#{target_user}:#{token64}"
|
81
|
-
end
|
82
|
-
|
83
|
-
###########################################################################
|
84
|
-
# Server side
|
85
|
-
###########################################################################
|
86
|
-
|
87
|
-
# auth method for auth_mad
|
88
|
-
def authenticate(server_user, server_pass, signed_text)
|
89
|
-
begin
|
90
|
-
s_user, t_user, expires = decrypt(signed_text).split(':')
|
91
|
-
|
92
|
-
return "Server password missmatch" if server_pass != password
|
93
|
-
|
94
|
-
return "User name missmatch" if ( s_user != server_user ||
|
95
|
-
s_user != @options[:srv_user] )
|
96
|
-
|
97
|
-
return "login token expired" if Time.now.to_i >= expires.to_i
|
98
|
-
|
99
|
-
return true
|
100
|
-
rescue => e
|
101
|
-
return e.message
|
102
|
-
end
|
103
|
-
end
|
104
|
-
end
|
data/lib/opennebula/ssh_auth.rb
DELETED
@@ -1,139 +0,0 @@
|
|
1
|
-
# -------------------------------------------------------------------------- #
|
2
|
-
# Copyright 2002-2012, OpenNebula Project Leads (OpenNebula.org) #
|
3
|
-
# #
|
4
|
-
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
5
|
-
# not use this file except in compliance with the License. You may obtain #
|
6
|
-
# a copy of the License at #
|
7
|
-
# #
|
8
|
-
# http://www.apache.org/licenses/LICENSE-2.0 #
|
9
|
-
# #
|
10
|
-
# Unless required by applicable law or agreed to in writing, software #
|
11
|
-
# distributed under the License is distributed on an "AS IS" BASIS, #
|
12
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
|
13
|
-
# See the License for the specific language governing permissions and #
|
14
|
-
# limitations under the License. #
|
15
|
-
#--------------------------------------------------------------------------- #
|
16
|
-
|
17
|
-
|
18
|
-
require 'pp'
|
19
|
-
require 'openssl'
|
20
|
-
require 'base64'
|
21
|
-
require 'fileutils'
|
22
|
-
|
23
|
-
module OpenNebula; end
|
24
|
-
|
25
|
-
# SSH key authentication class. It can be used as a driver for auth_mad
|
26
|
-
# as auth method is defined. It also holds some helper methods to be used
|
27
|
-
# by oneauth command
|
28
|
-
class OpenNebula::SshAuth
|
29
|
-
LOGIN_PATH = ENV['HOME']+'/.one/one_ssh'
|
30
|
-
|
31
|
-
# Initialize SshAuth object
|
32
|
-
#
|
33
|
-
# @param [Hash] default options for path
|
34
|
-
# @option options [String] :public_key public key for the user
|
35
|
-
# @option options [String] :private_key key private key for the user.
|
36
|
-
def initialize(options={})
|
37
|
-
@private_key = nil
|
38
|
-
@public_key = nil
|
39
|
-
|
40
|
-
if options[:private_key]
|
41
|
-
begin
|
42
|
-
@private_key = File.read(options[:private_key])
|
43
|
-
rescue Exception => e
|
44
|
-
raise "Cannot read #{options[:private_key]}"
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
if options[:public_key]
|
49
|
-
@public_key = options[:public_key]
|
50
|
-
elsif @private_key != nil
|
51
|
-
# Init ssh keys using private key. public key is extracted in a
|
52
|
-
# format compatible with openssl. The public key does not contain
|
53
|
-
# "---- BEGIN/END RSA PUBLIC KEY ----" and is in a single line
|
54
|
-
key = OpenSSL::PKey::RSA.new(@private_key)
|
55
|
-
|
56
|
-
@public_key = key.public_key.to_pem.split("\n")
|
57
|
-
@public_key = @public_key.reject {|l| l.match(/RSA PUBLIC KEY/) }.join('')
|
58
|
-
end
|
59
|
-
|
60
|
-
if @private_key.nil? && @public_key.nil?
|
61
|
-
raise "You have to define at least one of the keys"
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
# Creates the login file for ssh authentication at ~/.one/one_ssh.
|
66
|
-
# By default it is valid for 1 hour but it can be changed to any number
|
67
|
-
# of seconds with expire parameter (in seconds)
|
68
|
-
def login(user, expire=3600)
|
69
|
-
expire ||= 3600
|
70
|
-
|
71
|
-
# Init proxy file path and creates ~/.one directory if needed
|
72
|
-
proxy_dir = File.dirname(LOGIN_PATH)
|
73
|
-
|
74
|
-
begin
|
75
|
-
FileUtils.mkdir_p(proxy_dir)
|
76
|
-
rescue Errno::EEXIST
|
77
|
-
end
|
78
|
-
|
79
|
-
# Generate security token
|
80
|
-
time = Time.now.to_i + expire.to_i
|
81
|
-
|
82
|
-
secret_plain = "#{user}:#{time}"
|
83
|
-
secret_crypted = encrypt(secret_plain)
|
84
|
-
|
85
|
-
proxy = "#{user}:#{secret_crypted}"
|
86
|
-
|
87
|
-
file = File.open(LOGIN_PATH, "w")
|
88
|
-
file.write(proxy)
|
89
|
-
file.close
|
90
|
-
|
91
|
-
File.chmod(0600,LOGIN_PATH)
|
92
|
-
|
93
|
-
secret_crypted
|
94
|
-
end
|
95
|
-
|
96
|
-
# Returns a valid password string to create a user using this auth driver.
|
97
|
-
# In this case the ssh public key.
|
98
|
-
def password
|
99
|
-
@public_key
|
100
|
-
end
|
101
|
-
|
102
|
-
# Checks the proxy created with the login method
|
103
|
-
def authenticate(user, token)
|
104
|
-
begin
|
105
|
-
token_plain = decrypt(token)
|
106
|
-
_user, time = token_plain.split(':')
|
107
|
-
|
108
|
-
if user == _user
|
109
|
-
if Time.now.to_i >= time.to_i
|
110
|
-
return "ssh proxy expired, login again to renew it"
|
111
|
-
else
|
112
|
-
return true
|
113
|
-
end
|
114
|
-
else
|
115
|
-
return "invalid credentials"
|
116
|
-
end
|
117
|
-
rescue
|
118
|
-
return "error"
|
119
|
-
end
|
120
|
-
end
|
121
|
-
|
122
|
-
private
|
123
|
-
|
124
|
-
###########################################################################
|
125
|
-
# Methods to handle ssh keys
|
126
|
-
###########################################################################
|
127
|
-
# Encrypts data with the private key of the user and returns
|
128
|
-
# base 64 encoded output in a single line
|
129
|
-
def encrypt(data)
|
130
|
-
rsa=OpenSSL::PKey::RSA.new(@private_key)
|
131
|
-
Base64::encode64(rsa.private_encrypt(data)).gsub!(/\n/, '').strip
|
132
|
-
end
|
133
|
-
|
134
|
-
# Decrypts base 64 encoded data with pub_key (public key)
|
135
|
-
def decrypt(data)
|
136
|
-
rsa=OpenSSL::PKey::RSA.new(Base64::decode64(@public_key))
|
137
|
-
rsa.public_decrypt(Base64::decode64(data))
|
138
|
-
end
|
139
|
-
end
|