diff --git a/install.sh b/install.sh index 5c9ecb41ef..e33d064816 100755 --- a/install.sh +++ b/install.sh @@ -76,7 +76,7 @@ while true ; do -l) LINK="yes" ; shift ;; -c) CLIENT="yes"; INSTALL_ETC="no" ; shift ;; -s) SUNSTONE="yes"; shift ;; - -o) OZONES="yes"; INSTALL_ETC="no" ; shift ;; + -o) OZONES="yes"; shift ;; -u) ONEADMIN_USER="$2" ; shift 2;; -g) ONEADMIN_GROUP="$2"; shift 2;; -d) ROOT="$2" ; shift 2 ;; @@ -107,7 +107,7 @@ if [ -z "$ROOT" ] ; then MAN_LOCATION="/usr/share/man/man1" if [ "$CLIENT" = "yes" ]; then - MAKE_DIRS="$BIN_LOCATION $LIB_LOCATION" + MAKE_DIRS="$BIN_LOCATION $LIB_LOCATION $ETC_LOCATION" DELETE_DIRS="" @@ -120,7 +120,8 @@ if [ -z "$ROOT" ] ; then CHOWN_DIRS="" elif [ "$OZONES" = "yes" ]; then - MAKE_DIRS="$BIN_LOCATION $LIB_LOCATION $VAR_LOCATION $OZONES_LOCATION" + MAKE_DIRS="$BIN_LOCATION $LIB_LOCATION $VAR_LOCATION $OZONES_LOCATION \ + $ETC_LOCATION" DELETE_DIRS="$MAKE_DIRS" @@ -150,7 +151,7 @@ else MAN_LOCATION="$ROOT/share/man/man1" if [ "$CLIENT" = "yes" ]; then - MAKE_DIRS="$BIN_LOCATION $LIB_LOCATION $CONF_LOCATION" + MAKE_DIRS="$BIN_LOCATION $LIB_LOCATION $ETC_LOCATION" DELETE_DIRS="$MAKE_DIRS" elif [ "$SUNSTONE" = "yes" ]; then @@ -286,7 +287,7 @@ LIB_OCA_CLIENT_DIRS="$LIB_LOCATION/ruby \ LIB_CLI_CLIENT_DIRS="$LIB_LOCATION/ruby/cli \ $LIB_LOCATION/ruby/cli/one_helper" -CONF_CLI_DIRS="$CONF_LOCATION/cli" +CONF_CLI_DIRS="$ETC_LOCATION/cli" if [ "$CLIENT" = "yes" ]; then MAKE_DIRS="$MAKE_DIRS $LIB_ECO_CLIENT_DIRS $LIB_OCCI_CLIENT_DIRS \ @@ -374,7 +375,7 @@ INSTALL_CLIENT_FILES=( OZONES_BIN_CLIENT_FILES:$BIN_LOCATION OZONES_LIB_CLIENT_CLI_FILES:$LIB_LOCATION/ruby/cli OZONES_LIB_CLIENT_CLI_HELPER_FILES:$LIB_LOCATION/ruby/cli/ozones_helper - CLI_CONF_FILES:$CONF_LOCATION/cli + CLI_CONF_FILES:$ETC_LOCATION/cli OCA_LIB_FILES:$LIB_LOCATION/ruby RUBY_OPENNEBULA_LIB_FILES:$LIB_LOCATION/ruby/OpenNebula ) @@ -415,7 +416,6 @@ INSTALL_OZONES_RUBY_FILES=( INSTALL_OZONES_FILES=( OZONES_FILES:$OZONES_LOCATION OZONES_BIN_FILES:$BIN_LOCATION - OZONES_ETC_FILES:$ETC_LOCATION OZONES_MODELS_FILES:$OZONES_LOCATION/models OZONES_TEMPLATE_FILES:$OZONES_LOCATION/templates OZONES_LIB_FILES:$OZONES_LOCATION/lib @@ -435,6 +435,10 @@ INSTALL_OZONES_FILES=( OZONES_LIB_CLIENT_CLI_HELPER_FILES:$LIB_LOCATION/ruby/cli/ozones_helper ) +INSTALL_OZONES_ETC_FILES=( + OZONES_ETC_FILES:$ETC_LOCATION +) + INSTALL_ETC_FILES=( ETC_FILES:$ETC_LOCATION VMM_EC2_ETC_FILES:$ETC_LOCATION/vmm_ec2 @@ -1189,9 +1193,12 @@ done if [ "$INSTALL_ETC" = "yes" ] ; then if [ "$SUNSTONE" = "yes" ]; then INSTALL_ETC_SET="${INSTALL_SUNSTONE_ETC_FILES[@]}" + elif [ "$OZONES" = "yes" ]; then + INSTALL_ETC_SET="${INSTALL_OZONES_ETC_FILES[@]}" else INSTALL_ETC_SET="${INSTALL_ETC_FILES[@]} \ - ${INSTALL_SUNSTONE_ETC_FILES[@]}" + ${INSTALL_SUNSTONE_ETC_FILES[@]} \ + ${INSTALL_OZONES_ETC_FILES[@]}" fi for i in ${INSTALL_ETC_SET[@]}; do diff --git a/src/authm/AuthManager.cc b/src/authm/AuthManager.cc index 99d8667825..8ed3a16b9b 100644 --- a/src/authm/AuthManager.cc +++ b/src/authm/AuthManager.cc @@ -117,6 +117,28 @@ void AuthRequest::add_auth(Object ob, self_authorize = self_authorize && auth; auths.push_back(oss.str()); + + if ( auth == false ) + { + ostringstream oss; + + oss << message; + + if ( !message.empty() ) + { + oss << "; "; + } + + oss << "Not authorized to perform " << Operation_to_str(op) + << " " << Object_to_str(ob); + + if ( ob_id_int != -1 ) + { + oss << " [" << ob_id << "]"; + } + + message = oss.str(); + } } /* -------------------------------------------------------------------------- */ @@ -417,7 +439,16 @@ void AuthManager::notify_request(int auth_id,bool result,const string& message) } ar->result = result; - ar->message= message; + + if ( message != "-" ) + { + if ( !ar->message.empty() ) + { + ar->message.append("; "); + } + + ar->message.append(message); + } ar->notify(); } diff --git a/src/authm_mad/one_auth_mad.rb b/src/authm_mad/one_auth_mad.rb index c1b9d6cd06..b1d40bcaf9 100755 --- a/src/authm_mad/one_auth_mad.rb +++ b/src/authm_mad/one_auth_mad.rb @@ -49,7 +49,9 @@ class AuthDriver < OpenNebulaDriver # # @param [String] the authorization method to be used, nil to use the # built-in ACL engine - def initialize(authZ, nthreads) + # @param [Array] authentication modules enabled, nil will use any + # any method existing in remotes directory + def initialize(authZ, authN, nthreads) super( "auth", :concurrency => nthreads, @@ -66,6 +68,20 @@ class AuthDriver < OpenNebulaDriver else @authZ_cmd = nil end + + if authN == nil + # get the directories from remotes dir that have an authenticate + # script + @authN_protocols=Dir[@local_scripts_path+"/*/authenticate"].map do |d| + d.split('/')[-2] + end + else + if authN.class==String + @authN_protocols=[authN] + else + @authN_protocols=authN + end + end end # Authenticate a user based in a string of the form user:secret when using the @@ -88,6 +104,14 @@ class AuthDriver < OpenNebulaDriver secret_attr.shift end + unless @authN_protocols.include?(protocol) + return send_message( + ACTION[:authN], + RESULT[:failure], + request_id, + "Authentication protocol '#{protocol}' not available") + end + #build path for the auth action #/var/lib/one/remotes/auth//authenticate authN_path = File.join(@local_scripts_path, protocol) @@ -133,11 +157,13 @@ end # Auth Driver Main program opts = GetoptLong.new( [ '--threads', '-t', GetoptLong::REQUIRED_ARGUMENT ], - [ '--authz', '-z', GetoptLong::REQUIRED_ARGUMENT ] + [ '--authz', '-z', GetoptLong::REQUIRED_ARGUMENT ], + [ '--authn', '-n', GetoptLong::REQUIRED_ARGUMENT ] ) threads = 15 authz = nil +authn = nil begin opts.each do |opt, arg| @@ -146,12 +172,14 @@ begin threads = arg.to_i when '--authz' authz = arg + when '--authn' + authn = arg.split(',').map {|a| a.strip } end end rescue Exception => e exit(-1) end -auth_driver = AuthDriver.new(authz, threads) +auth_driver = AuthDriver.new(authz, authn, threads) auth_driver.start_driver diff --git a/src/authm_mad/remotes/quota/quota.rb b/src/authm_mad/remotes/quota/quota.rb index 37304120e2..1f13234e45 100644 --- a/src/authm_mad/remotes/quota/quota.rb +++ b/src/authm_mad/remotes/quota/quota.rb @@ -190,6 +190,7 @@ class Quota quota = get_quota(user_id) msg = "" + separator = "" info.each { |qname, quota_requested| unless quota[qname] next @@ -201,10 +202,13 @@ class Quota spent = used + request if spent > limit + msg << separator msg << " #{qname.to_s.upcase} quota exceeded " msg << "(Quota: #{limit}, " msg << "Used: #{used}, " msg << "Requested: #{request})" + + separator = ";" end } diff --git a/src/cli/one_helper.rb b/src/cli/one_helper.rb index 20b649c3bc..f1ce493baa 100644 --- a/src/cli/one_helper.rb +++ b/src/cli/one_helper.rb @@ -65,7 +65,13 @@ EOT class OneHelper def initialize(secret=nil, endpoint=nil, hash=true) - @client = OpenNebula::Client.new(secret,endpoint,hash) + begin + @client = OpenNebula::Client.new(secret,endpoint,hash) + rescue Exception => e + puts e.message + exit -1 + end + @translation_hash = nil end diff --git a/src/cli/one_helper/oneuser_helper.rb b/src/cli/one_helper/oneuser_helper.rb index 6f72e17017..f76ace7cc8 100644 --- a/src/cli/one_helper/oneuser_helper.rb +++ b/src/cli/one_helper/oneuser_helper.rb @@ -84,7 +84,7 @@ class OneUserHelper < OpenNebulaHelper::OneHelper end end - def login(username, options) + def self.login(username, options) if options[:ssh] require 'ssh_auth' diff --git a/src/cli/oneuser b/src/cli/oneuser index e46b8a757b..b866e6e1a9 100755 --- a/src/cli/oneuser +++ b/src/cli/oneuser @@ -34,8 +34,6 @@ cmd=CommandParser::CmdParser.new(ARGV) do usage "`oneuser` [] []" version OpenNebulaHelper::ONE_VERSION - helper = OneUserHelper.new - ######################################################################## # Global Options ######################################################################## @@ -118,10 +116,12 @@ cmd=CommandParser::CmdParser.new(ARGV) do end set :format, :userid, OneUserHelper.to_id_desc do |arg| + helper = OneUserHelper.new helper.to_id(arg) end set :format, :userid_list, OneUserHelper.list_to_id_desc do |arg| + helper = OneUserHelper.new helper.list_to_id(arg) end @@ -145,6 +145,8 @@ cmd=CommandParser::CmdParser.new(ARGV) do command :create, create_desc, :username, [:password, nil], :options=>create_options do + helper = OneUserHelper.new + if args[1] pass = args[1] else @@ -171,9 +173,8 @@ cmd=CommandParser::CmdParser.new(ARGV) do --time 72000 EOT - command :login, login_desc, :username, [:password, nil], - :options=>login_options do - helper.login(args[0], options) + command :login, login_desc, :username, :options=>login_options do + OneUserHelper.login(args[0], options) end key_desc = <<-EOT.unindent @@ -202,6 +203,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do EOT command :delete, delete_desc, [:range, :userid_list] do + helper = OneUserHelper.new helper.perform_actions(args[0],options,"deleted") do |user| user.delete end @@ -213,6 +215,8 @@ cmd=CommandParser::CmdParser.new(ARGV) do command :passwd, passwd_desc, :userid, [:password, nil], :options=>create_options do + helper = OneUserHelper.new + if args[1] pass = args[1] else @@ -234,6 +238,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do EOT command :chgrp, chgrp_desc, [:range, :userid_list], :groupid do + helper = OneUserHelper.new helper.perform_actions(args[0],options,"Group changed") do |user| user.chgrp(args[1].to_i) end @@ -244,6 +249,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do EOT command :list, list_desc, :options=>list_options do + helper = OneUserHelper.new helper.list_pool(options) end @@ -254,6 +260,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do command :show, show_desc, [:userid, nil], :options=>OpenNebulaHelper::XML do user=args[0] || OpenNebula::User::SELF + helper = OneUserHelper.new helper.show_resource(user,options) end diff --git a/src/ozones/Client/bin/onevdc b/src/ozones/Client/bin/onevdc index c15193e244..e93478416e 100755 --- a/src/ozones/Client/bin/onevdc +++ b/src/ozones/Client/bin/onevdc @@ -18,6 +18,10 @@ cmd=CommandParser::CmdParser.new(ARGV) do usage "`onevdc` command [] []" version OpenNebulaHelper::ONE_VERSION + set :format, :vdcid, "VDC ID" do |arg| + arg.match(/^[0123456789]+$/) ? [0,arg] : [-1] + end + ######################################################################## # Global Options ######################################################################## @@ -34,7 +38,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do helper.create_resource(args[0]) end - command :show, 'Show information of a particular VDC', :text do + command :show, 'Show information of a particular VDC', :vdcid do helper.show_resource(args[0],options) end diff --git a/src/ozones/Client/bin/onezone b/src/ozones/Client/bin/onezone index 861dddec88..ff97efa6f7 100755 --- a/src/ozones/Client/bin/onezone +++ b/src/ozones/Client/bin/onezone @@ -17,15 +17,19 @@ require 'ozones_helper/zones_helper.rb' cmd=CommandParser::CmdParser.new(ARGV) do usage "`onezone` [] []" version OpenNebulaHelper::ONE_VERSION - + + set :format, :zoneid, "Zone ID" do |arg| + arg.match(/^[0123456789]+$/) ? [0,arg] : [-1] + end + ######################################################################## # Global Options - ######################################################################## + ######################################################################## set :option, CommandParser::OPTIONS - + begin helper = ZonesHelper.new "zone" - rescue Exception => e + rescue Exception => e warn e.message exit -1 end @@ -33,8 +37,16 @@ cmd=CommandParser::CmdParser.new(ARGV) do command :create, 'Create a new Zone', :file do helper.create_resource(args[0]) end - - command :show, 'Show information of a particular Zone', :text, [:text, nil] do + + show_desc = <<-EOT.unindent + Show information of a particular Zone + Available resources: host, vm, image, vn, template, user + Examples: + onezone show 4 + onezone show 4 host + EOT + + command :show, show_desc, :zoneid, [:resource, nil] do zone=helper.show_resource(args[0],options)[1] case args[1] @@ -44,54 +56,54 @@ cmd=CommandParser::CmdParser.new(ARGV) do zone['endpoint'], false) - aux_helper.list_pool(options) + aux_helper.list_pool(options) when "vm" aux_helper = OneVMHelper.new( zone['onename'] + ":" + zone['onepass'], zone['endpoint'], false) - aux_helper.list_pool(options) + aux_helper.list_pool(options) when "image" aux_helper = OneImageHelper.new( zone['onename'] + ":" + zone['onepass'], zone['endpoint'], false) - aux_helper.list_pool(options) + aux_helper.list_pool(options) when "vn" aux_helper = OneVNetHelper.new( zone['onename'] + ":" + zone['onepass'], zone['endpoint'], false) - aux_helper.list_pool(options) - + aux_helper.list_pool(options) + when "template" aux_helper = OneTemplateHelper.new( zone['onename'] + ":" + zone['onepass'], zone['endpoint'], false) - aux_helper.list_pool(options) - + aux_helper.list_pool(options) + when "user" aux_helper = OneUserHelper.new( zone['onename'] + ":" + zone['onepass'], zone['endpoint'], false) - aux_helper.list_pool(options) + aux_helper.list_pool(options) end 0 end - - command :list, 'Lists Zones in the pool', + + command :list, 'Lists Zones in the pool', :options=>CLIHelper::OPTIONS+OpenNebulaHelper::OPTIONS do helper.list_pool(options) end command :delete, 'Deletes a Zone', :zoneid do - helper.delete_resource(args[0],options) + helper.delete_resource(args[0],options) end end diff --git a/src/rm/Request.cc b/src/rm/Request.cc index 606d5d203d..5a3c2b73be 100644 --- a/src/rm/Request.cc +++ b/src/rm/Request.cc @@ -189,13 +189,16 @@ string Request::authorization_error (const string &message, { ostringstream oss; - oss << "[" << method_name << "]" << " User [" << att.uid << "] not authorized" - << " to perform action on " << object_name(auth_object) << "."; + oss << "[" << method_name << "]" << " User [" << att.uid << "] "; - - if ( !message.empty() ) + if ( message.empty() ) { - oss << message ; + oss << "not authorized to perform action on " + << object_name(auth_object) << "."; + } + else + { + oss << ": " << message << "."; } return oss.str();