mirror of
https://github.com/OpenNebula/one.git
synced 2026-11-20 20:02:38 +09:00
bug #847: Auth drivers are set in OpenNebula core. Login tokens do not include the driver, so the hash logic needs update, see #911
This commit is contained in:
1 parent
7683ba8998
commit
cbf64ecf1b
12 files changed
+141
-59
No files matched your search
@@ -297,28 +297,28 @@ public:
|
||||
ar.add_auth(AuthRequest::NET,2,1,AuthRequest::USE,2,false);
|
||||
ar.add_auth(AuthRequest::IMAGE,3,1,AuthRequest::USE,4,true);
|
||||
|
||||
CPPUNIT_ASSERT(ar.plain_authorize() == true);
|
||||
CPPUNIT_ASSERT(ar.core_authorize() == true);
|
||||
|
||||
ar1.add_auth(AuthRequest::VM,"dGhpcy",-1,AuthRequest::CREATE,2,false);
|
||||
ar1.add_auth(AuthRequest::NET,2,1,AuthRequest::USE,2,false);
|
||||
ar1.add_auth(AuthRequest::IMAGE,3,1,AuthRequest::USE,4,false);
|
||||
|
||||
CPPUNIT_ASSERT(ar1.plain_authorize() == false);
|
||||
CPPUNIT_ASSERT(ar1.core_authorize() == false);
|
||||
|
||||
ar2.add_auth(AuthRequest::HOST,"dGhpcy",-1,AuthRequest::CREATE,0,false);
|
||||
CPPUNIT_ASSERT(ar2.plain_authorize() == false);
|
||||
CPPUNIT_ASSERT(ar2.core_authorize() == false);
|
||||
|
||||
ar3.add_auth(AuthRequest::VM,5,1,AuthRequest::MANAGE,2,false);
|
||||
CPPUNIT_ASSERT(ar3.plain_authorize() == false);
|
||||
CPPUNIT_ASSERT(ar3.core_authorize() == false);
|
||||
|
||||
ar4.add_auth(AuthRequest::VM,4,1,AuthRequest::MANAGE,2,false);
|
||||
CPPUNIT_ASSERT(ar4.plain_authorize() == true);
|
||||
CPPUNIT_ASSERT(ar4.core_authorize() == true);
|
||||
|
||||
ar5.add_auth(AuthRequest::HOST,4,-1,AuthRequest::MANAGE,0,false);
|
||||
CPPUNIT_ASSERT(ar5.plain_authorize() == true);
|
||||
CPPUNIT_ASSERT(ar5.core_authorize() == true);
|
||||
|
||||
ar6.add_auth(AuthRequest::HOST,4,-1,AuthRequest::CREATE,0,false);
|
||||
CPPUNIT_ASSERT(ar6.plain_authorize() == true);
|
||||
CPPUNIT_ASSERT(ar6.core_authorize() == true);
|
||||
}
|
||||
|
||||
void self_authenticate()
|
||||
@@ -327,10 +327,10 @@ public:
|
||||
AuthRequest ar1(2,2);
|
||||
|
||||
ar.add_authenticate("the_user","the_pass","the_secret");
|
||||
CPPUNIT_ASSERT(ar.plain_authenticate() == false);
|
||||
CPPUNIT_ASSERT(ar.core_authenticate() == false);
|
||||
|
||||
ar1.add_authenticate("the_user","the_pass","the_pass");
|
||||
CPPUNIT_ASSERT(ar1.plain_authenticate() == true);
|
||||
CPPUNIT_ASSERT(ar1.core_authenticate() == true);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -19,7 +19,8 @@
|
||||
# $1 = username
|
||||
# $2 = "-" if user is not registered in opennebula
|
||||
# $3 = password
|
||||
echo $1 $3
|
||||
echo core $1 $3
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -161,10 +161,12 @@ class OneUserHelper < OpenNebulaHelper::OneHelper
|
||||
str_h1="%-80s"
|
||||
|
||||
CLIHelper.print_header(str_h1 % "USER #{user['ID']} INFORMATION")
|
||||
puts str % ["ID", user.id.to_s]
|
||||
puts str % ["NAME", user.name]
|
||||
puts str % ["GROUP", user.gid]
|
||||
puts str % ["PASSWORD", user['PASSWORD']]
|
||||
puts str % ["ID", user.id.to_s]
|
||||
puts str % ["NAME", user.name]
|
||||
puts str % ["GROUP", user.gid]
|
||||
puts str % ["PASSWORD", user['PASSWORD']]
|
||||
puts str % ["AUTH_DRIVER", user['AUTH_DRIVER']]
|
||||
|
||||
puts str % ["ENABLED",
|
||||
OpenNebulaHelper.boolean_to_str(user['ENABLED'])]
|
||||
|
||||
|
||||
+11
-2
@@ -105,7 +105,15 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
:description => "Token duration in seconds, defaults to 3600 (1 h)"
|
||||
}
|
||||
|
||||
create_options = [READ_FILE, PLAIN, SSH, X509, KEY, CERT]
|
||||
DRIVER={
|
||||
:name => "driver",
|
||||
:short => "-d driver_name",
|
||||
:large => "--driver driver_name",
|
||||
:format => String,
|
||||
:description => "Authentication driver to be used with this user"
|
||||
}
|
||||
|
||||
create_options = [READ_FILE, PLAIN, SSH, X509, KEY, CERT, DRIVER]
|
||||
login_options = [SSH, X509, X509_PROXY, KEY, CERT, PROXY, TIME]
|
||||
|
||||
########################################################################
|
||||
@@ -159,7 +167,8 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
end
|
||||
|
||||
helper.create_resource(options) do |user|
|
||||
user.allocate(args[0], pass)
|
||||
driver = options[:driver] || OpenNebula::User::CORE_AUTH
|
||||
user.allocate(args[0], pass, driver)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -32,7 +32,10 @@ module OpenNebula
|
||||
:update => "user.update"
|
||||
}
|
||||
|
||||
SELF = -1
|
||||
SELF = -1
|
||||
|
||||
#Selects core authentication driver
|
||||
CORE_AUTH = "core"
|
||||
|
||||
# Creates a User description with just its identifier
|
||||
# this method should be used to create plain User objects.
|
||||
@@ -72,8 +75,8 @@ module OpenNebula
|
||||
# +username+ Name of the new user.
|
||||
#
|
||||
# +password+ Password for the new user
|
||||
def allocate(username, password)
|
||||
super(USER_METHODS[:allocate], username, password)
|
||||
def allocate(username, password, driver=CORE_AUTH)
|
||||
super(USER_METHODS[:allocate], username, password, driver)
|
||||
end
|
||||
|
||||
# Replaces the template contents
|
||||
|
||||
@@ -230,6 +230,7 @@ int UserAllocate::pool_allocate(xmlrpc_c::paramList const& paramList,
|
||||
{
|
||||
string uname = xmlrpc_c::value_string(paramList.getString(1));
|
||||
string passwd = xmlrpc_c::value_string(paramList.getString(2));
|
||||
string driver = xmlrpc_c::value_string(paramList.getString(3));
|
||||
|
||||
UserPool * upool = static_cast<UserPool *>(pool);
|
||||
|
||||
@@ -242,7 +243,12 @@ int UserAllocate::pool_allocate(xmlrpc_c::paramList const& paramList,
|
||||
ugname = GroupPool::USERS_NAME;
|
||||
}
|
||||
|
||||
return upool->allocate(&id,ugid,uname,ugname,passwd,true,error_str);
|
||||
if (driver.empty())
|
||||
{
|
||||
driver = UserPool::CORE_AUTH;
|
||||
}
|
||||
|
||||
return upool->allocate(&id,ugid,uname,ugname,passwd,driver,true,error_str);
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
+15
-13
@@ -128,13 +128,14 @@ string& User::to_xml(string& xml) const
|
||||
|
||||
oss <<
|
||||
"<USER>"
|
||||
"<ID>" << oid <<"</ID>" <<
|
||||
"<GID>" << gid <<"</GID>" <<
|
||||
"<GNAME>" << gname <<"</GNAME>" <<
|
||||
"<NAME>" << name <<"</NAME>" <<
|
||||
"<PASSWORD>" << password <<"</PASSWORD>"<<
|
||||
"<ENABLED>" << enabled_int <<"</ENABLED>" <<
|
||||
obj_template->to_xml(template_xml) <<
|
||||
"<ID>" << oid <<"</ID>" <<
|
||||
"<GID>" << gid <<"</GID>" <<
|
||||
"<GNAME>" << gname <<"</GNAME>" <<
|
||||
"<NAME>" << name <<"</NAME>" <<
|
||||
"<PASSWORD>" << password <<"</PASSWORD>" <<
|
||||
"<AUTH_DRIVER>" << auth_driver <<"</AUTH_DRIVER>"<<
|
||||
"<ENABLED>" << enabled_int <<"</ENABLED>" <<
|
||||
obj_template->to_xml(template_xml) <<
|
||||
"</USER>";
|
||||
|
||||
xml = oss.str();
|
||||
@@ -154,12 +155,13 @@ int User::from_xml(const string& xml)
|
||||
// Initialize the internal XML object
|
||||
update_from_str(xml);
|
||||
|
||||
rc += xpath(oid, "/USER/ID", -1);
|
||||
rc += xpath(gid, "/USER/GID", -1);
|
||||
rc += xpath(gname, "/USER/GNAME", "not_found");
|
||||
rc += xpath(name, "/USER/NAME", "not_found");
|
||||
rc += xpath(password, "/USER/PASSWORD", "not_found");
|
||||
rc += xpath(int_enabled, "/USER/ENABLED", 0);
|
||||
rc += xpath(oid, "/USER/ID", -1);
|
||||
rc += xpath(gid, "/USER/GID", -1);
|
||||
rc += xpath(gname, "/USER/GNAME", "not_found");
|
||||
rc += xpath(name, "/USER/NAME", "not_found");
|
||||
rc += xpath(password, "/USER/PASSWORD", "not_found");
|
||||
rc += xpath(auth_driver,"/USER/AUTH_DRIVER", UserPool::CORE_AUTH);
|
||||
rc += xpath(int_enabled,"/USER/ENABLED", 0);
|
||||
|
||||
enabled = int_enabled;
|
||||
|
||||
|
||||
+62
-16
@@ -29,6 +29,8 @@
|
||||
#include <pwd.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
const char * UserPool::CORE_AUTH = "core";
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
@@ -93,6 +95,7 @@ UserPool::UserPool(SqlDB * db):PoolSQL(db,User::table)
|
||||
one_name,
|
||||
GroupPool::ONEADMIN_NAME,
|
||||
sha1_pass,
|
||||
UserPool::CORE_AUTH,
|
||||
true,
|
||||
error_str);
|
||||
}
|
||||
@@ -125,6 +128,7 @@ int UserPool::allocate (
|
||||
const string& uname,
|
||||
const string& gname,
|
||||
const string& password,
|
||||
const string& auth,
|
||||
bool enabled,
|
||||
string& error_str)
|
||||
{
|
||||
@@ -134,6 +138,8 @@ int UserPool::allocate (
|
||||
GroupPool * gpool;
|
||||
Group * group;
|
||||
|
||||
string auth_driver = auth;
|
||||
|
||||
ostringstream oss;
|
||||
|
||||
if ( !User::is_valid(password, error_str) )
|
||||
@@ -153,8 +159,13 @@ int UserPool::allocate (
|
||||
goto error_duplicated;
|
||||
}
|
||||
|
||||
if (auth_driver.empty())
|
||||
{
|
||||
auth_driver = UserPool::CORE_AUTH;
|
||||
}
|
||||
|
||||
// Build a new User object
|
||||
user = new User(-1, gid, uname, gname, password, enabled);
|
||||
user = new User(-1, gid, uname, gname, password, auth_driver, enabled);
|
||||
|
||||
// Insert the Object in the pool
|
||||
*oid = PoolSQL::allocate(user, error_str);
|
||||
@@ -213,7 +224,8 @@ bool UserPool::authenticate(const string& session,
|
||||
|
||||
User * user = 0;
|
||||
string username;
|
||||
string secret, u_pass;
|
||||
string secret, u_secret, u_pass;
|
||||
string auth_driver;
|
||||
|
||||
string tuname;
|
||||
string tgname;
|
||||
@@ -231,13 +243,14 @@ bool UserPool::authenticate(const string& session,
|
||||
gname = "";
|
||||
result = false;
|
||||
|
||||
rc = User::split_secret(session,username,secret);
|
||||
rc = User::split_secret(session,username,u_secret);
|
||||
|
||||
if ( rc != 0 )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
user = get(username,true);
|
||||
|
||||
if (user != 0) //User known to OpenNebula
|
||||
@@ -249,38 +262,57 @@ bool UserPool::authenticate(const string& session,
|
||||
tuname = user->name;
|
||||
tgname = user->gname;
|
||||
|
||||
auth_driver = user->auth_driver;
|
||||
|
||||
user->unlock();
|
||||
}
|
||||
else //External User
|
||||
{
|
||||
u_pass = "-";
|
||||
u_pass = "-";
|
||||
auth_driver = "";
|
||||
|
||||
uid = -1;
|
||||
gid = -1;
|
||||
}
|
||||
|
||||
AuthRequest ar(uid, gid);
|
||||
|
||||
ar.add_authenticate(username,u_pass,secret);
|
||||
|
||||
if (authm == 0) //plain auth
|
||||
if ( auth_driver == UserPool::CORE_AUTH )
|
||||
{
|
||||
if ( user != 0 && ar.plain_authenticate()) //no plain for external users
|
||||
if (user != 0) //no core auth for external users
|
||||
{
|
||||
user_id = uid;
|
||||
group_id = gid;
|
||||
ar.add_authenticate(username,u_pass,u_secret);
|
||||
|
||||
uname = tuname;
|
||||
gname = tgname;
|
||||
if (ar.core_authenticate())
|
||||
{
|
||||
user_id = uid;
|
||||
group_id = gid;
|
||||
|
||||
result = true;
|
||||
uname = tuname;
|
||||
gname = tgname;
|
||||
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else //use the driver
|
||||
else if ( authm != 0 ) //use auth driver if it was loaded
|
||||
{
|
||||
//Compose secret for the user driver
|
||||
if (!auth_driver.empty())
|
||||
{
|
||||
secret = auth_driver;
|
||||
secret += ":";
|
||||
}
|
||||
|
||||
secret += u_secret;
|
||||
|
||||
//Initialize authentication request and call the driver
|
||||
ar.add_authenticate(username,u_pass,secret);
|
||||
|
||||
authm->trigger(AuthManager::AUTHENTICATE,&ar);
|
||||
ar.wait();
|
||||
|
||||
if (ar.result==true)
|
||||
if (ar.result==true) //User was authenticated
|
||||
{
|
||||
if ( user != 0 ) //knwon user_id
|
||||
{
|
||||
@@ -294,13 +326,20 @@ bool UserPool::authenticate(const string& session,
|
||||
}
|
||||
else //External user, username & pass in driver message
|
||||
{
|
||||
string driver_name;
|
||||
string mad_name;
|
||||
string mad_pass;
|
||||
|
||||
string error_str;
|
||||
|
||||
istringstream is(ar.message);
|
||||
|
||||
if ( is.good() )
|
||||
{
|
||||
is >> driver_name >> ws;
|
||||
}
|
||||
|
||||
if ( !is.fail() )
|
||||
{
|
||||
is >> mad_name >> ws;
|
||||
}
|
||||
@@ -317,6 +356,7 @@ bool UserPool::authenticate(const string& session,
|
||||
mad_name,
|
||||
GroupPool::USERS_NAME,
|
||||
mad_pass,
|
||||
driver_name,
|
||||
true,
|
||||
error_str);
|
||||
}
|
||||
@@ -349,6 +389,12 @@ bool UserPool::authenticate(const string& session,
|
||||
NebulaLog::log("AuM",Log::ERROR,oss);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
NebulaLog::log("AuM",Log::ERROR,
|
||||
"Auth Error: Authentication driver not enabled. "
|
||||
"Check AUTH_MAD in oned.conf");
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -364,7 +410,7 @@ int UserPool::authorize(AuthRequest& ar)
|
||||
|
||||
if (authm == 0)
|
||||
{
|
||||
if (ar.plain_authorize())
|
||||
if (ar.core_authorize())
|
||||
{
|
||||
rc = 0;
|
||||
}
|
||||
|
||||
@@ -98,7 +98,7 @@ protected:
|
||||
string err;
|
||||
|
||||
return ((UserPool*)pool)->allocate(&oid, 0, usernames[index],"oneadmin",
|
||||
passwords[index], true, err);
|
||||
passwords[index], UserPool::CORE_AUTH, true, err);
|
||||
};
|
||||
|
||||
void check(int index, PoolObjectSQL* obj)
|
||||
@@ -296,17 +296,17 @@ public:
|
||||
UserPool * up = static_cast<UserPool *>(pool);
|
||||
|
||||
// Allocate a user.
|
||||
rc = up->allocate(&oid, 0,usernames[0], "oneadmin",passwords[0], true, err);
|
||||
rc = up->allocate(&oid, 0,usernames[0], "oneadmin",passwords[0], UserPool::CORE_AUTH,true, err);
|
||||
CPPUNIT_ASSERT( oid == 1 );
|
||||
CPPUNIT_ASSERT( oid == rc );
|
||||
|
||||
// Try to allocate twice the same user, should fail
|
||||
rc = up->allocate(&oid, 0,usernames[0], "oneadmin", passwords[0], true, err);
|
||||
rc = up->allocate(&oid, 0,usernames[0], "oneadmin", passwords[0],UserPool::CORE_AUTH,true, err);
|
||||
CPPUNIT_ASSERT( rc == -1 );
|
||||
CPPUNIT_ASSERT( oid == rc );
|
||||
|
||||
// Try again, with different password
|
||||
rc = up->allocate(&oid, 0, usernames[0], "oneadmin", passwords[1], true, err);
|
||||
rc = up->allocate(&oid, 0, usernames[0], "oneadmin", passwords[1],UserPool::CORE_AUTH,true, err);
|
||||
CPPUNIT_ASSERT( rc == -1 );
|
||||
CPPUNIT_ASSERT( oid == rc );
|
||||
}
|
||||
@@ -321,7 +321,7 @@ public:
|
||||
|
||||
for(int i=0; i<5; i++)
|
||||
{
|
||||
((UserPool*)pool)->allocate(&oid, 0, d_names[i], "oneadmin", d_pass[i], true, err);
|
||||
((UserPool*)pool)->allocate(&oid, 0, d_names[i], "oneadmin", d_pass[i],UserPool::CORE_AUTH, true, err);
|
||||
}
|
||||
|
||||
ostringstream oss;
|
||||
@@ -348,7 +348,7 @@ public:
|
||||
|
||||
for(int i=0; i<5; i++)
|
||||
{
|
||||
((UserPool*)pool)->allocate(&oid, 0, d_names[i], "oneadmin",d_pass[i], true, err);
|
||||
((UserPool*)pool)->allocate(&oid, 0, d_names[i], "oneadmin",d_pass[i], UserPool::CORE_AUTH,true, err);
|
||||
}
|
||||
|
||||
// Note: second parameter of dump is the WHERE constraint. The "order
|
||||
|
||||
Reference in new issue
Block a user