MongoDB - 管理者ユーザーが承認されていません 質問する

MongoDB - 管理者ユーザーが承認されていません 質問する

MongoDB に認証を追加しようとしています。
この作業はすべて Linux の MongoDB 2.6.1 で行っています。mongod.conf
ファイルは古い互換性形式です
(インストール時にこの形式が使用されていました)。

1) ここで説明したように管理者ユーザーを作成しました(3)

http://docs.mongodb.org/manual/tutorial/add-user-administrator/

2) 次に、mongod.confを編集して、この行のコメントを解除しました。

auth = true

3) 最後に、mongod サービスを再起動して、次のようにログインを試みました。

/usr/bin/mongo localhost:27017/admin -u sa -p pwd

4) 接続はできますが、接続時に次のように表示されます。

MongoDB shell version: 2.6.1
connecting to: localhost:27017/admin
Welcome to the MongoDB shell!
The current date/time is: Thu May 29 2014 17:47:16 GMT-0400 (EDT)
Error while trying to show server startup warnings: not authorized on admin to execute command { getLog: "startupWarnings" }

5)sa作成したこのユーザーには権限がまったくないようです。

root@test02:~# mc
MongoDB shell version: 2.6.1
connecting to: localhost:27017/admin
Welcome to the MongoDB shell!
The current date/time is: Thu May 29 2014 17:57:03 GMT-0400 (EDT)
Error while trying to show server startup warnings: not authorized on admin to execute command { getLog: "startupWarnings" }
[admin] 2014-05-29 17:57:03.011 >>> use admin
switched to db admin
[admin] 2014-05-29 17:57:07.889 >>> show collections
2014-05-29T17:57:10.377-0400 error: {
        "$err" : "not authorized for query on admin.system.namespaces",
        "code" : 13
} at src/mongo/shell/query.js:131
[admin] 2014-05-29 17:57:10.378 >>> use test
switched to db test
[test] 2014-05-29 17:57:13.466 >>> show collections
2014-05-29T17:57:15.930-0400 error: {
        "$err" : "not authorized for query on test.system.namespaces",
        "code" : 13
} at src/mongo/shell/query.js:131
[test] 2014-05-29 17:57:15.931 >>>

何が問題なのでしょうか? この手順全体を 3 回繰り返し、
MongoDB ドキュメントで指定されているとおりにすべて実行したと思います。しかし、うまくいきません。このユーザーには何でも実行できる権限が与えられ、他のユーザーを作成してより具体的な権限を付与できると
期待していました。sa

ベストアンサー1

私も同じ問題で頭を悩ませていましたが、最初の管理者ユーザーを追加するときに役割を root に設定した後はすべて機能しました。

use admin
db.createUser(
  {
    user: 'admin',
    pwd: 'password',
    roles: [ { role: 'root', db: 'admin' } ]
  }
);
exit;

すでにadminユーザーを作成している場合は、次のようにロールを変更できます。

use admin;
db.grantRolesToUser('admin', [{ role: 'root', db: 'admin' }])

完全な認証設定リファレンスについては、手順インターネットで何時間も調査してまとめました。

おすすめ記事