Skip to content

Commit

Permalink
fix read only user support with sharding for basic queries SERVER-4156
Browse files Browse the repository at this point in the history
  • Loading branch information
erh committed Oct 26, 2011
1 parent c0773ef commit 5a03de8
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 6 deletions.
3 changes: 3 additions & 0 deletions s/commands_admin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1002,6 +1002,8 @@ namespace mongo {
class CmdShardingGetPrevError : public Command {
public:
virtual LockType locktype() const { return NONE; }
virtual bool requiresAuth() { return false; }

virtual bool slaveOk() const {
return true;
}
Expand All @@ -1018,6 +1020,7 @@ namespace mongo {
class CmdShardingGetLastError : public Command {
public:
virtual LockType locktype() const { return NONE; }
virtual bool requiresAuth() { return false; }
virtual bool slaveOk() const {
return true;
}
Expand Down
1 change: 1 addition & 0 deletions s/commands_public.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1346,6 +1346,7 @@ namespace mongo {
if( c->requiresAuth() && !ai->isAuthorized(cl)) {
ok = false;
errmsg = "unauthorized";
anObjBuilder.append( "note" , str::stream() << "need to authorized on db: " << cl << " for command: " << e.fieldName() );
}
else if( c->adminOnly() && c->localHostOnlyIfNoAuth( jsobj ) && noauth && !ai->isLocalHost ) {
ok = false;
Expand Down
9 changes: 6 additions & 3 deletions s/request.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,12 @@ namespace mongo {
_clientInfo->newRequest( p );
}

void Request::checkAuth() const {
void Request::checkAuth( Auth::Level levelNeeded ) const {
char cl[256];
nsToDatabase(getns(), cl);
uassert(15845, "unauthorized", _clientInfo->getAuthenticationInfo()->isAuthorized(cl));
uassert( 15845 ,
str::stream() << "unauthorized for db:" << cl << " level: " << levelNeeded ,
_clientInfo->getAuthenticationInfo()->isAuthorizedForLevel(cl,levelNeeded) );
}

void Request::init() {
Expand Down Expand Up @@ -144,10 +146,11 @@ namespace mongo {
}
}
else if ( op == dbGetMore ) {
checkAuth( Auth::READ ); // this is important so someone can't steal a cursor
s->getMore( *this );
}
else {
checkAuth();
checkAuth( Auth::WRITE );
s->writeOp( op, *this );
}

Expand Down
2 changes: 1 addition & 1 deletion s/request.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ namespace mongo {
return _clientInfo;
}

void checkAuth() const;
void checkAuth( Auth::Level levelNeeded ) const;

// ---- remote location info -----

Expand Down
2 changes: 1 addition & 1 deletion s/strategy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ namespace mongo {

void Strategy::doQuery( Request& r , const Shard& shard ) {

r.checkAuth();
r.checkAuth( Auth::READ );

ShardConnection dbcon( shard , r.getns() );
DBClientBase &c = dbcon.conn();
Expand Down
2 changes: 1 addition & 1 deletion s/strategy_shard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ namespace mongo {
virtual void queryOp( Request& r ) {
QueryMessage q( r.d() );

r.checkAuth();
r.checkAuth( Auth::READ );

LOG(3) << "shard query: " << q.ns << " " << q.query << endl;

Expand Down

0 comments on commit 5a03de8

Please sign in to comment.