diff --git a/src/cli/one_helper.rb b/src/cli/one_helper.rb index af12558800..f56904e090 100644 --- a/src/cli/one_helper.rb +++ b/src/cli/one_helper.rb @@ -504,7 +504,6 @@ EOT cipher.encrypt.key = key_one puts "cifrando #{key}" encrypted = cipher.update(value) + cipher.final - #res.merge!({key => value}) res[key] = Base64::encode64(encrypted) puts "encriptado es: "+encrypted end @@ -512,26 +511,6 @@ EOT return res end - def decrypt(res) - opts = {} - key_one= File.read(VAR_LOCATION+'/.one/one_key') - - res.each do |key, encrypted_value| - decipher = OpenSSL::Cipher::AES.new(256,:CBC) - decipher.decrypt - decipher.key = key_one - puts "desencriptando #{key}" - plain = decipher.update(Base64::decode64(encrypted_value)) + decipher.final - puts "una vez desencriptado es "+plain - opts[key] = plain - end - - return opts - - end - - - def list_pool(options, top=false, filter_flag=nil) if options[:describe] table = format_pool(options) diff --git a/src/cli/onehost b/src/cli/onehost index c53cbbc043..a0ca1f563c 100755 --- a/src/cli/onehost +++ b/src/cli/onehost @@ -126,16 +126,6 @@ cmd=CommandParser::CmdParser.new(ARGV) do ec2_host = !options[:ec2access].nil? && !options[:ec2secret].nil? - if ec2_host - ec2_opts = { - :access => options[:ec2access], - :secret => options[:ec2secret] - } - - encrypt_opts = helper.encrypt(ec2_opts) - helper.decrypt(encrypt_opts) - - end cid = options[:cluster] || ClusterPool::NONE_CLUSTER_ID helper.create_resource(options) do |host| @@ -143,12 +133,19 @@ cmd=CommandParser::CmdParser.new(ARGV) do options[:im], options[:vm], cid) + if ec2_host + ec2_opts = { + :access => options[:ec2access], + :secret => options[:ec2secret] + } - template = "EC2_ACCESS=\"#{encrypt_opts[:access]}\"\n"\ - "EC2_SECRET=\"#{encrypt_opts[:secret]}\"\n"\ + encrypt_opts = helper.encrypt(ec2_opts) + template = "EC2_ACCESS=\"#{encrypt_opts[:access]}\"\n"\ + "EC2_SECRET=\"#{encrypt_opts[:secret]}\"\n"\ - host.update(template, true) + host.update(template, true) + end end end diff --git a/src/vmm_mad/remotes/ec2/ec2_driver.rb b/src/vmm_mad/remotes/ec2/ec2_driver.rb index d582e5db1d..4c268e532e 100755 --- a/src/vmm_mad/remotes/ec2/ec2_driver.rb +++ b/src/vmm_mad/remotes/ec2/ec2_driver.rb @@ -20,9 +20,11 @@ ONE_LOCATION = ENV["ONE_LOCATION"] if !defined?(ONE_LOCATION) if !ONE_LOCATION RUBY_LIB_LOCATION = "/usr/lib/one/ruby" if !defined?(RUBY_LIB_LOCATION) ETC_LOCATION = "/etc/one/" if !defined?(ETC_LOCATION) + VAR_LOCATION = "/var/lib/one/" if !defined?(VAR_LOCATION) else RUBY_LIB_LOCATION = ONE_LOCATION + "/lib/ruby" if !defined?(RUBY_LIB_LOCATION) ETC_LOCATION = ONE_LOCATION + "/etc/" if !defined?(ETC_LOCATION) + VAR_LOCATION = ONE_LOCATION + "/var/" if !defined?(VAR_LOCATION) end EC2_DRIVER_CONF = "#{ETC_LOCATION}/ec2_driver.conf" @@ -242,8 +244,13 @@ class EC2Driver @instance_types = PUBLIC_CLOUD_EC2_CONF['instance_types'] + conn_opts = get_connect_info(host) regions = PUBLIC_CLOUD_EC2_CONF['regions'] + regions["default"]["access_key_id"] = conn_opts[:access] + regions["default"]["secret_access_key"] = conn_opts[:secret] + @region = regions[host] || regions["default"] + #sanitize region data raise "access_key_id not defined for #{host}" if @region['access_key_id'].nil? raise "secret_access_key not defined for #{host}" if @region['secret_access_key'].nil? @@ -254,7 +261,6 @@ class EC2Driver :secret_access_key => @region['secret_access_key'], :region => @region['region_name'] }) - get_connect_info(host) if (proxy_uri = PUBLIC_CLOUD_EC2_CONF['proxy_uri']) Aws.config(:proxy_uri => proxy_uri) @@ -262,6 +268,21 @@ class EC2Driver @ec2 = Aws::EC2::Resource.new end + def decrypt(res) + opts = {} + key_one= File.read(VAR_LOCATION+'/.one/one_key') + + + res.each do |key, encrypted_value| + decipher = OpenSSL::Cipher::AES.new(256,:CBC) + decipher.decrypt + decipher.key = key_one + plain = decipher.update(Base64::decode64(encrypted_value)) + decipher.final + opts[key] = plain + end + return opts + + end def get_connect_info(host) @@ -273,14 +294,17 @@ class EC2Driver objects=pool.select {|object| object.name==host } xmlhost = objects.first - access = xmlhost["TEMPLATE/EC2_ACCESS"] - secret = xmlhost["TEMPLATE/EC2_SECRET"] - - - File.open("/home/semedi/prueba_secret", 'w') {|f| f << "el secreto esta en #{secret}\n" } - File.open("/home/semedi/prueba_acces", 'w') {|f| f << "el acceso esta en #{access}\n" } - + conn_opts = { + :access => xmlhost["TEMPLATE/EC2_ACCESS"], + :secret => xmlhost["TEMPLATE/EC2_SECRET"] + } + begin + conn_opts = decrypt(conn_opts) + rescue + raise "HOST: #{host} must have ec2 credentials in order to work properly" + end + return conn_opts end # DEPLOY action, also sets ports and ip if needed