Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save sarjarapu/b8e25e8279e1c71b82f09fca00a013d7 to your computer and use it in GitHub Desktop.
Save sarjarapu/b8e25e8279e1c71b82f09fca00a013d7 to your computer and use it in GitHub Desktop.
Set of bash & JavaScript to show that user with user-defined role, readWriteMinusDropRole role cannot drop a collection
mongo social --port 28000 -u human_user -p password --authenticationDatabase admin
# output of above command
# MongoDB shell version v3.6.2
# connecting to: mongodb://127.0.0.1:28000/social
# MongoDB server version: 3.6.2
# replset:PRIMARY>
# create a document in person collection
db.person.insert({"fname": "Shyam", "lname": "Arjarapu"})
# output of above command
# WriteResult({ "nInserted" : 1 })
db.getCollectionNames()
# The output of above command
# [ "person" ]
# drop the collection
db.person.drop()
# The output of above command
# 2018-05-14T17:01:38.830-0500 E QUERY [thread1] Error: drop failed: {
# "operationTime" : Timestamp(1526335298, 1),
# "ok" : 0,
# "errmsg" : "not authorized on social to execute command { drop: \"person\", $clusterTime: { clusterTime: Timestamp(1526335285, 1), signature: { hash: BinData(0, 7EE640BEC21303BD6514D6791A9F50D6DEB45CC5), keyId: 6555423603385434113 } }, $db: \"social\" }",
# "code" : 13,
# "codeName" : "Unauthorized",
# "$clusterTime" : {
# "clusterTime" : Timestamp(1526335298, 1),
# "signature" : {
# "hash" : BinData(0,"lh/gXN9yKwcrV4asUPFVV8kLAxA="),
# "keyId" : NumberLong("6555423603385434113")
# }
# }
# } :
# _getErrorWithCode@src/mongo/shell/utils.js:25:13
# DBCollection.prototype.drop@src/mongo/shell/collection.js:695:1
# @(shell):1:1
db.getCollectionNames()
# The output of above command
# [ "person" ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment