From 28773a229ea5c08085605887b6f7dbf94b06fa5f Mon Sep 17 00:00:00 2001 From: Javi Fontan Date: Thu, 20 Dec 2012 04:47:39 -0600 Subject: [PATCH] feature #1700: move auth libraries to OpenNebula module --- install.sh | 10 ++++++++-- src/authm_mad/remotes/ldap/authenticate | 4 ++-- src/authm_mad/remotes/ldap/ldap_auth.rb | 4 +++- src/authm_mad/remotes/server_cipher/authenticate | 6 +++--- .../remotes/server_cipher/server_cipher_auth.rb | 7 +++++-- src/authm_mad/remotes/server_x509/authenticate | 4 ++-- src/authm_mad/remotes/server_x509/server_x509_auth.rb | 10 ++++++---- src/authm_mad/remotes/ssh/authenticate | 4 ++-- src/authm_mad/remotes/ssh/ssh_auth.rb | 4 +++- src/authm_mad/remotes/x509/authenticate | 4 ++-- src/authm_mad/remotes/x509/x509_auth.rb | 4 +++- 11 files changed, 39 insertions(+), 22 deletions(-) diff --git a/install.sh b/install.sh index e419fe066f..835d948197 100755 --- a/install.sh +++ b/install.sh @@ -406,6 +406,7 @@ INSTALL_FILES=( INCLUDE_FILES:$INCLUDE_LOCATION LIB_FILES:$LIB_LOCATION RUBY_LIB_FILES:$LIB_LOCATION/ruby + RUBY_AUTH_LIB_FILES:$LIB_LOCATION/ruby/opennebula RUBY_OPENNEBULA_LIB_FILES:$LIB_LOCATION/ruby/opennebula MAD_RUBY_LIB_FILES:$LIB_LOCATION/ruby MAD_RUBY_LIB_FILES:$VAR_LOCATION/remotes @@ -673,8 +674,13 @@ RUBY_LIB_FILES="src/mad/ruby/ActionManager.rb \ src/mad/ruby/ssh_stream.rb \ src/vnm_mad/one_vnm.rb \ src/mad/ruby/Ganglia.rb \ - src/oca/ruby/opennebula.rb \ - src/authm_mad/remotes/ssh/ssh_auth.rb \ + src/oca/ruby/opennebula.rb" + +#------------------------------------------------------------------------------- +# Ruby auth library files, to be installed under $LIB_LOCATION/ruby/opennebula +#------------------------------------------------------------------------------- + +RUBY_AUTH_LIB_FILES="src/authm_mad/remotes/ssh/ssh_auth.rb \ src/authm_mad/remotes/server_x509/server_x509_auth.rb \ src/authm_mad/remotes/server_cipher/server_cipher_auth.rb \ src/authm_mad/remotes/ldap/ldap_auth.rb \ diff --git a/src/authm_mad/remotes/ldap/authenticate b/src/authm_mad/remotes/ldap/authenticate index 516c3e37b1..137e7a58fc 100755 --- a/src/authm_mad/remotes/ldap/authenticate +++ b/src/authm_mad/remotes/ldap/authenticate @@ -29,7 +29,7 @@ end $: << RUBY_LIB_LOCATION require 'yaml' -require 'ldap_auth' +require 'opennebula/ldap_auth' require 'uri' if defined?(URI::Parser) @@ -66,7 +66,7 @@ order.each do |server_name| end begin - ldap=LdapAuth.new(server_conf) + ldap=OpenNebula::LdapAuth.new(server_conf) user_name=ldap.find_user(user) diff --git a/src/authm_mad/remotes/ldap/ldap_auth.rb b/src/authm_mad/remotes/ldap/ldap_auth.rb index 7f3293c269..3597b12273 100644 --- a/src/authm_mad/remotes/ldap/ldap_auth.rb +++ b/src/authm_mad/remotes/ldap/ldap_auth.rb @@ -17,7 +17,9 @@ require 'rubygems' require 'net/ldap' -class LdapAuth +module OpenNebula; end + +class OpenNebula::LdapAuth def initialize(options) @options={ :host => 'localhost', diff --git a/src/authm_mad/remotes/server_cipher/authenticate b/src/authm_mad/remotes/server_cipher/authenticate index 9973e6e5ba..86dc0831e1 100755 --- a/src/authm_mad/remotes/server_cipher/authenticate +++ b/src/authm_mad/remotes/server_cipher/authenticate @@ -28,7 +28,7 @@ end $: << RUBY_LIB_LOCATION -require 'server_cipher_auth' +require 'opennebula/server_cipher_auth' require 'scripts_common' user = ARGV[0] # username as registered in OpenNebula @@ -38,7 +38,7 @@ secret = ARGV[2] # Base64 encoded secret as obtained from login_token #OpenNebula.log_debug("Authenticating #{user}, with password #{pass} (#{secret})") begin - server_auth = ServerCipherAuth.new_driver + server_auth = OpenNebula::ServerCipherAuth.new_driver rc = server_auth.authenticate(user, pass, secret) rescue => e OpenNebula.error_message e.message @@ -50,4 +50,4 @@ if rc == true else OpenNebula.error_message rc exit -1 -end \ No newline at end of file +end diff --git a/src/authm_mad/remotes/server_cipher/server_cipher_auth.rb b/src/authm_mad/remotes/server_cipher/server_cipher_auth.rb index 22ed7239fd..37cb061e06 100644 --- a/src/authm_mad/remotes/server_cipher/server_cipher_auth.rb +++ b/src/authm_mad/remotes/server_cipher/server_cipher_auth.rb @@ -20,10 +20,12 @@ require 'digest/sha1' require 'base64' require 'fileutils' +module OpenNebula; end + # Server authentication class. This method can be used by OpenNebula services # to let access authenticated users by other means. It is based on OpenSSL # symmetric ciphers -class ServerCipherAuth +class OpenNebula::ServerCipherAuth ########################################################################### #Constants with paths to relevant files and defaults ########################################################################### @@ -142,4 +144,5 @@ class ServerCipherAuth return rc end -end \ No newline at end of file +end + diff --git a/src/authm_mad/remotes/server_x509/authenticate b/src/authm_mad/remotes/server_x509/authenticate index 77be2ea3f5..63bfca8c51 100755 --- a/src/authm_mad/remotes/server_x509/authenticate +++ b/src/authm_mad/remotes/server_x509/authenticate @@ -28,7 +28,7 @@ end $: << RUBY_LIB_LOCATION -require 'server_x509_auth' +require 'opennebula/server_x509_auth' require 'scripts_common' user = ARGV[0] # username as registered in OpenNebula @@ -38,7 +38,7 @@ secret = ARGV[2] # Base64 encoded secret as obtained from login_token #OpenNebula.log_debug("Authenticating #{user}, with password #{pass} (#{secret})") begin - server_auth = ServerX509Auth.new + server_auth = OpenNebula::ServerX509Auth.new dsecret = Base64::decode64(secret) rc = server_auth.authenticate(user, pass, dsecret) diff --git a/src/authm_mad/remotes/server_x509/server_x509_auth.rb b/src/authm_mad/remotes/server_x509/server_x509_auth.rb index 27c1df42ee..2a4fe56ae8 100644 --- a/src/authm_mad/remotes/server_x509/server_x509_auth.rb +++ b/src/authm_mad/remotes/server_x509/server_x509_auth.rb @@ -18,12 +18,14 @@ require 'openssl' require 'base64' require 'fileutils' -require 'x509_auth' +require 'opennebula/x509_auth' + +module OpenNebula; end # Server authentication class. This authmethod can be used by opennebula services # to let access authenticated users by other means. It is based on x509 server # certificates -class ServerX509Auth < X509Auth +class OpenNebula::ServerX509Auth < OpenNebula::X509Auth ########################################################################### #Constants with paths to relevant files and defaults ########################################################################### @@ -61,7 +63,7 @@ class ServerX509Auth < X509Auth ########################################################################### # Creates a ServerCipher for client and driver sage - class << ServerX509Auth + class << OpenNebula::ServerX509Auth alias :new_client :new alias :new_driver :new end @@ -99,4 +101,4 @@ class ServerX509Auth < X509Auth return e.message end end -end \ No newline at end of file +end diff --git a/src/authm_mad/remotes/ssh/authenticate b/src/authm_mad/remotes/ssh/authenticate index d272ec0b57..8bc9ed8dc0 100755 --- a/src/authm_mad/remotes/ssh/authenticate +++ b/src/authm_mad/remotes/ssh/authenticate @@ -28,7 +28,7 @@ end $: << RUBY_LIB_LOCATION -require 'ssh_auth' +require 'opennebula/ssh_auth' require 'scripts_common' user = ARGV[0] @@ -37,7 +37,7 @@ secret = ARGV[2] #OpenNebula.log_debug("Authenticating #{user}, with password #{pass} (#{secret})") begin - ssh_auth = SshAuth.new(:public_key=>pass) + ssh_auth = OpenNebula::SshAuth.new(:public_key=>pass) rescue Exception => e OpenNebula.error_message e.message exit -1 diff --git a/src/authm_mad/remotes/ssh/ssh_auth.rb b/src/authm_mad/remotes/ssh/ssh_auth.rb index 7a322337cf..1b2d3bc90e 100644 --- a/src/authm_mad/remotes/ssh/ssh_auth.rb +++ b/src/authm_mad/remotes/ssh/ssh_auth.rb @@ -20,10 +20,12 @@ require 'openssl' require 'base64' require 'fileutils' +module OpenNebula; end + # SSH key authentication class. It can be used as a driver for auth_mad # as auth method is defined. It also holds some helper methods to be used # by oneauth command -class SshAuth +class OpenNebula::SshAuth LOGIN_PATH = ENV['HOME']+'/.one/one_ssh' # Initialize SshAuth object diff --git a/src/authm_mad/remotes/x509/authenticate b/src/authm_mad/remotes/x509/authenticate index 5722049887..e43aa6a3a3 100755 --- a/src/authm_mad/remotes/x509/authenticate +++ b/src/authm_mad/remotes/x509/authenticate @@ -28,7 +28,7 @@ end $: << RUBY_LIB_LOCATION -require 'x509_auth' +require 'opennebula/x509_auth' require 'scripts_common' user = ARGV[0] # username as registered in OpenNebula @@ -44,7 +44,7 @@ begin token = asecret[0] certs = asecret[1..-1] - x509_auth = X509Auth.new(:certs_pem=>certs) + x509_auth = OpenNebula::X509Auth.new(:certs_pem=>certs) rc = x509_auth.authenticate(user, pass, token) rescue => e diff --git a/src/authm_mad/remotes/x509/x509_auth.rb b/src/authm_mad/remotes/x509/x509_auth.rb index cad0ca7f29..73ebc2b49c 100644 --- a/src/authm_mad/remotes/x509/x509_auth.rb +++ b/src/authm_mad/remotes/x509/x509_auth.rb @@ -19,10 +19,12 @@ require 'base64' require 'fileutils' require 'yaml' +module OpenNebula; end + # X509 authentication class. It can be used as a driver for auth_mad # as auth method is defined. It also holds some helper methods to be used # by oneauth command -class X509Auth +class OpenNebula::X509Auth ########################################################################### #Constants with paths to relevant files and defaults ###########################################################################