Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't access collections and data on mongo though userAdmin

I am trying to set security settings to my mongo instance. It's on a single remote Linux server. I followed the tutorial of mongo documentation. That's the steps actions I have executed:

// running mongod with auth 
mongod --auth --config /path-to-conf-file
// connect to mongo with local host exception
mongo
// creating user admin
use admin
db.createUser({
    user:"myadmin",
    pwd:"1234",
    roles: [
        "userAdminAnyDatabase"
    ]})
// logging in with user admin
mongo -u myadmin -p 1234 --authenticationDatabase     admin

I get the warning: 'not authorized on admin to execute command {getLog: "start up warnings"}' I am able to create users and 'show dbs' but can't 'show collections'

I get the other error : 'not authorized for query on admin.system.namespaces'

So I think the user was created not as admin. What can I do in order to log in and be able to make query operations?

like image 365
itaied Avatar asked Jan 28 '26 18:01

itaied


1 Answers

The myadmin user has userAdminAnyDatabase privileges. This means the user can grant any privileges to any user in any database, but it doesn't give the user permissions to do non-user management operations. The solution is to use the myadmin user's user administration privileges to grant itself more privileges. For query operations on any database, grant the readWriteAnyDatabase role. There's lots of built-in roles to choose from.

like image 138
wdberkeley Avatar answered Jan 31 '26 15:01

wdberkeley



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!