Skip to content

Commit

Permalink
F #3064: adapt DDC to new secrets handling (#3716)
Browse files Browse the repository at this point in the history
  • Loading branch information
Alejandro Huertas Herrero authored and Ruben S. Montero committed Sep 17, 2019
1 parent d750d06 commit c9b609c
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 123 deletions.
11 changes: 11 additions & 0 deletions share/etc/oned.conf
Original file line number Diff line number Diff line change
Expand Up @@ -1079,6 +1079,17 @@ HOST_ENCRYPTED_ATTR = "ONE_PASSWORD"
# VNET_ENCRYPTED_ATTR = "PROVISION/PACKET_TOKEN
# VNET_ENCRYPTED_ATTR = "PROVISION/PACKET_TOKEN

# DDC encrypted attrs
HOST_ENCRYPTED_ATTR = "PROVISION/PACKET_TOKEN"
HOST_ENCRYPTED_ATTR = "PROVISION/EC2_ACCESS"
HOST_ENCRYPTED_ATTR = "PROVISION/EC2_SECRET"

VNET_ENCRYPTED_ATTR = "AR/PACKET_TOKEN"

DS_ENCRYPTED_ATTR = "AR/PACKET_TOKEN"

CLUSTER_ENCRYPTED_ATTR = "AR/PACKET_TOKEN"

#*******************************************************************************
# Inherited Attributes Configuration
#*******************************************************************************
Expand Down
18 changes: 3 additions & 15 deletions share/hooks/alias_ip/alias_ip.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def log_error(msg)

def one_fetch(client, type, id)
object = type.new_with_id(id, client)
rc = object.info
rc = object.info(true)

if OpenNebula.is_error?(rc)
STDERR.puts(rc.message)
Expand Down Expand Up @@ -112,22 +112,10 @@ def device_has_ip?(packet_client, device_id, ip_id)
end

def manage_packet(host, ip, address_range, assign = true)
cidr = "#{ip}/32"

system = OpenNebula::System.new(OpenNebula::Client.new)
config = system.get_configuration

if OpenNebula.is_error?(config)
STDERR.puts("Error getting oned configuration : #{config.message}")
exit(-1)
end

token = config['ONE_KEY']
ar_token = OpenNebula.decrypt({ :value => address_range['PACKET_TOKEN'] },
token)[:value]
cidr = "#{ip}/32"
ar_deploy_id = address_range['DEPLOY_ID']

packet_client = Packet::Client.new(ar_token)
packet_client = Packet::Client.new(address_range['PACKET_TOKEN'])
packet_ip = find_packet_ip_assignment(packet_client, ar_deploy_id, cidr)

if assign == true
Expand Down
11 changes: 0 additions & 11 deletions src/ipamm_mad/remotes/packet/allocate_address
Original file line number Diff line number Diff line change
Expand Up @@ -81,17 +81,6 @@ if ar_size.to_i != 1
exit(-1)
end

system = OpenNebula::System.new(OpenNebula::Client.new)
config = system.get_configuration

if OpenNebula.is_error?(config)
STDERR.puts("Error getting oned configuration : #{config.message}")
exit(-1)
end

token = config['ONE_KEY']
ar_token = OpenNebula.decrypt({ :value => ar_token }, token)[:value]

packet = Packet::Client.new
packet.auth_token = ar_token

Expand Down
11 changes: 0 additions & 11 deletions src/ipamm_mad/remotes/packet/free_address
Original file line number Diff line number Diff line change
Expand Up @@ -93,17 +93,6 @@ if ar_size.to_i != 1
exit(-1)
end

system = OpenNebula::System.new(OpenNebula::Client.new)
config = system.get_configuration

if OpenNebula.is_error?(config)
STDERR.puts("Error getting oned configuration : #{config.message}")
exit(-1)
end

token = config['ONE_KEY']
ar_token = OpenNebula.decrypt({ :value => ar_token }, token)[:value]

packet = Packet::Client.new
packet.auth_token = ar_token

Expand Down
11 changes: 0 additions & 11 deletions src/ipamm_mad/remotes/packet/get_address
Original file line number Diff line number Diff line change
Expand Up @@ -87,17 +87,6 @@ if ar_size.to_i != 1
exit(-1)
end

system = OpenNebula::System.new(OpenNebula::Client.new)
config = system.get_configuration

if OpenNebula.is_error?(config)
STDERR.puts("Error getting oned configuration : #{config.message}")
exit(-1)
end

token = config['ONE_KEY']
ar_token = OpenNebula.decrypt({ :value => ar_token }, token)[:value]

packet = Packet::Client.new
packet.auth_token = ar_token

Expand Down
14 changes: 1 addition & 13 deletions src/ipamm_mad/remotes/packet/register_address_range
Original file line number Diff line number Diff line change
Expand Up @@ -94,20 +94,8 @@ require 'opennebula'

data = Nokogiri::XML(Base64.decode64(STDIN.read))

ar_token = data.xpath('//AR/PACKET_TOKEN').text

system = OpenNebula::System.new(OpenNebula::Client.new)
config = system.get_configuration

if OpenNebula.is_error?(config)
STDERR.puts("Error getting oned configuration : #{config.message}")
exit(-1)
end

token = config['ONE_KEY']

packet = Packet::Client.new
packet.auth_token = OpenNebula.decrypt({ :value => ar_token }, token)[:value]
packet.auth_token = data.xpath('//AR/PACKET_TOKEN').text

ip = Packet::Ip.new
ip.project_id = data.xpath('//AR/PACKET_PROJECT').text
Expand Down
11 changes: 0 additions & 11 deletions src/ipamm_mad/remotes/packet/unregister_address_range
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,6 @@ data = Nokogiri::XML(Base64.decode64(STDIN.read))
ar_token = data.xpath('//AR/PACKET_TOKEN').text
deploy_id = data.xpath('//AR/DEPLOY_ID').text.to_s

system = OpenNebula::System.new(OpenNebula::Client.new)
config = system.get_configuration

if OpenNebula.is_error?(config)
STDERR.puts("Error getting oned configuration : #{config.message}")
exit(-1)
end

token = config['ONE_KEY']
ar_token = OpenNebula.decrypt({ :value => ar_token }, token)[:value]

begin
packet = Packet::Client.new
packet.auth_token = ar_token
Expand Down
32 changes: 4 additions & 28 deletions src/oneprovision/lib/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
require 'highline'
require 'highline/import'

ENCRYPT_VALUES = %w[PACKET_TOKEN EC2_SECRET EC2_ACCESS]

# Cleanup Exception
class OneProvisionCleanupException < RuntimeError
end
Expand Down Expand Up @@ -325,8 +323,7 @@ def create_deployment_file(host, provision_id, provision_name)
xml.PROVISION do
host['provision'].each do |key, value|
if key != 'driver'
encrypt = encrypt(key.upcase, value)
xml.send(key.upcase, encrypt)
xml.send(key.upcase, value)
end
end
xml.send('PROVISION_ID', provision_id)
Expand Down Expand Up @@ -417,8 +414,7 @@ def template_like_str(attributes, indent = true)
str = ind_tab + key3.to_s.upcase + '='

if value3
str += "\"#{encrypt(key3.to_s.upcase,
value3.to_s)}\""
str += "\"#{value3}\""
end

str
Expand All @@ -434,8 +430,7 @@ def template_like_str(attributes, indent = true)
str = ind_tab + key3.to_s.upcase + '='

if value3
str += "\"#{encrypt(key3.to_s.upcase,
value3.to_s)}\""
str += "\"#{value3}\""
end

str
Expand All @@ -444,33 +439,14 @@ def template_like_str(attributes, indent = true)
str_line << "\n]\n"

else
str_line << key.to_s.upcase << '=' \
"\"#{encrypt(key.to_s.upcase, value.to_s)}\""
str_line << key.to_s.upcase << '=' << "\"#{value}\""
end
str_line
end.compact.join("\n")

str
end

# Encrypts a value
#
# @param key [String] Key to encrypt
# @param value [String] Value to encrypt
#
# @return [String] Encrypted value
def encrypt(key, value)
if ENCRYPT_VALUES.include? key
system = OpenNebula::System.new(OpenNebula::Client.new)
config = system.get_configuration
token = config['ONE_KEY']

OpenNebula.encrypt({ :value => value }, token)[:value]
else
value
end
end

end

end
Expand Down
36 changes: 13 additions & 23 deletions src/vmm_mad/remotes/packet/packet_driver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,11 @@ def initialize(host, one=OpenNebula::Client.new)
@one = one
@packet = Packet::Client.new

if host.is_a?(String)
@host = get_xhost_by_name(host)
host = host['NAME'] unless host.is_a?(String)

unless @host
raise "Host not found #{host}"
end
else
@host = host
end
@host = get_xhost_by_name(host)

raise "Host not found #{host}" unless @host

@globals = get_globals(@host)
@packet.auth_token = @globals['PACKET_TOKEN']
Expand Down Expand Up @@ -397,40 +393,34 @@ def generate_cc(xobj, xpath_context)
end

def get_globals(xhost)
# get token
system = OpenNebula::System.new(@one)
config = system.get_configuration
raise "Error getting oned configuration : #{config.message}" if OpenNebula.is_error?(config)
token = config["ONE_KEY"]

if xhost["TEMPLATE/PROVISION"]
tmplBase = 'TEMPLATE/PROVISION'
else
tmplBase = 'TEMPLATE'
end

conn_opts = {
'PACKET_TOKEN' => xhost["#{tmplBase}/PACKET_TOKEN"],
}

conn_opts = OpenNebula.decrypt(conn_opts, token)
conn_opts = {}

begin
#conn_opts = OpenNebula.decrypt(conn_opts, token)
conn_opts['PROJECT'] = xhost["#{tmplBase}/PACKET_PROJECT"]
conn_opts['PACKET_TOKEN'] = xhost["#{tmplBase}/PACKET_TOKEN"]
conn_opts['PROJECT'] = xhost["#{tmplBase}/PACKET_PROJECT"]
rescue
raise "HOST: #{xhost['NAME']} must have Packet credentials"
end

return conn_opts
conn_opts
end

def get_xhost_by_name(host)
pool = OpenNebula::HostPool.new(@one)
pool.info

objects = pool.select {|object| object.name == host }
objects.first
host = objects.first

host.info(true)

host
end

# Create a Packet::Device object with parameters
Expand Down

0 comments on commit c9b609c

Please sign in to comment.