更新角色用户:未授权管理员执行命令
Update role user: not authorized on admin to execute command
当我尝试获取有关副本的信息时,出现以下错误:
rep0:PRIMARY> rs.printReplicationInfo()
2015-05-19T13:30:29.231+0200 error: {
"$err" : "not authorized for query on local.system.namespaces",
"code" : 13
} at src/mongo/shell/query.js:131
我尝试用以下两个用户执行命令:
[
{
"_id" : "admin.siteRootAdmin",
"user" : "siteRootAdmin",
"db" : "admin",
"roles" : [
{
"role" : "root",
"db" : "admin"
}
]
},
{
"_id" : "admin.mongoadmin",
"user" : "mongoadmin",
"db" : "admin",
"roles" : [
{
"role" : "userAdminAnyDatabase",
"db" : "admin"
},
{
"role" : "dbOwner",
"db" : "admin"
},
{
"role" : "clusterAdmin",
"db" : "admin"
}
]
}
]
虽然我有 clusterAdmin
角色来处理副本,但我尝试更新 mongoadmin 的角色以读取本地数据库(因为所有角色都在 admin db 上授予)但我收到以下错误:
rep0:PRIMARY> db.system.users.update({"user":"mongoadmin"},{$addToSet:{"roles":"readAnyDatabase"}})
WriteResult({
"writeError" : {
"code" : 13,
"errmsg" : "not authorized on admin to execute command { update: \"system.users\", updates: [ { q: { user: \"mongoadmin\" }, u: { $addToSet: { roles: \"readAnyDatabase\" } }, multi: false, upsert: false } ], ordered: true }"
}
})
- 我需要什么才能完全访问所有
replica命令除了
clusterAdmin
的作用?
- 如果两个用户中的任何一个都在 admin db 中有权限(mongoadmin 是 dbOwner),为什么我没有更新命令的权限?
我用错误的命令更新角色这里是正确的命令:
db.grantRolesToUser( "mongoadmin", [{ role: "read", db: "local"}])
现在我可以查看副本信息了:
rep0:PRIMARY> rs.printReplicationInfo()
configured oplog size: 990MB
log length start to end: 617347secs (171.49hrs)
oplog first event time: Thu May 14 2015 14:25:04 GMT+0200 (CEST)
oplog last event time: Thu May 21 2015 17:54:11 GMT+0200 (CEST)
now: Thu May 21 2015 17:54:24 GMT+0200 (CEST)
当我尝试获取有关副本的信息时,出现以下错误:
rep0:PRIMARY> rs.printReplicationInfo()
2015-05-19T13:30:29.231+0200 error: {
"$err" : "not authorized for query on local.system.namespaces",
"code" : 13
} at src/mongo/shell/query.js:131
我尝试用以下两个用户执行命令:
[
{
"_id" : "admin.siteRootAdmin",
"user" : "siteRootAdmin",
"db" : "admin",
"roles" : [
{
"role" : "root",
"db" : "admin"
}
]
},
{
"_id" : "admin.mongoadmin",
"user" : "mongoadmin",
"db" : "admin",
"roles" : [
{
"role" : "userAdminAnyDatabase",
"db" : "admin"
},
{
"role" : "dbOwner",
"db" : "admin"
},
{
"role" : "clusterAdmin",
"db" : "admin"
}
]
}
]
虽然我有 clusterAdmin
角色来处理副本,但我尝试更新 mongoadmin 的角色以读取本地数据库(因为所有角色都在 admin db 上授予)但我收到以下错误:
rep0:PRIMARY> db.system.users.update({"user":"mongoadmin"},{$addToSet:{"roles":"readAnyDatabase"}})
WriteResult({
"writeError" : {
"code" : 13,
"errmsg" : "not authorized on admin to execute command { update: \"system.users\", updates: [ { q: { user: \"mongoadmin\" }, u: { $addToSet: { roles: \"readAnyDatabase\" } }, multi: false, upsert: false } ], ordered: true }"
}
})
- 我需要什么才能完全访问所有
replica命令除了
clusterAdmin
的作用? - 如果两个用户中的任何一个都在 admin db 中有权限(mongoadmin 是 dbOwner),为什么我没有更新命令的权限?
我用错误的命令更新角色这里是正确的命令:
db.grantRolesToUser( "mongoadmin", [{ role: "read", db: "local"}])
现在我可以查看副本信息了:
rep0:PRIMARY> rs.printReplicationInfo()
configured oplog size: 990MB
log length start to end: 617347secs (171.49hrs)
oplog first event time: Thu May 14 2015 14:25:04 GMT+0200 (CEST)
oplog last event time: Thu May 21 2015 17:54:11 GMT+0200 (CEST)
now: Thu May 21 2015 17:54:24 GMT+0200 (CEST)