MongoDB University M310
Auditing is an enterprise feature in MongoDB.
Why do we audit our database
Auditing Capabilities
{
atype: <String>,
ts: {
"$date":: <timestamp>
},
local: {
ip: <String>, port: <int>
},
remote: {
ip: <String>, port: <int>
},
users: [
{ user: <String>, db: <String> }
],
roles: [
{ roles: <String>, db: <String> }
],
param: <document>,
result: <int>
}
mongod --dbpath /data/db --logpath /data/db/mongo.log --fork auditDestination <args>
args can only be passed:
mongod --dbpath /data/db --logpath /data/db/mongo.log --fork --auditDestination file --auditFormat JSON --auditPath /data/db/auditLog.json
systemLog:
destination: file
path: /data/db/mongo.log
storage:
dbpath: /data/db
auditLog:
destination: file
format: JSON
path: /data/db/auditLog.json
By default only 3 catergories be audited
Because once we audit CRUD operation, there will be too many log.
That makes us lose performance and hard to read the logs.
for example:
{ "atype": { "$in": { "createCollection", "dropCollection" } } }
With command line
mongod --auditFilter <filterStr>
Add in config file
systemLog:
destination: file
path: /data/db/mongo.log
storage:
dbpath: /data/db
auditLog:
destination: file
format: JSON
path: /data/db/auditLog.json
filter: '{ "atype": { "$in": { "createCollection", "dropCollection" } } }'
Most of auditing action are actually related to DDL rather than DML operations, EXCEPT 'authCheck'. Becuase for the most part, auditing within MongoDB is designed to monitor changes made to the configuration of database
Simple example for createIndex operation in my-app database
{ "atype": "createIndex", "param.ns": { "ns": "/^my-app\./" } }
The action type of CRUD is authCheck!
This is because CRUD operations are passed as parameters to the authCheck event.
Every time that you try to create, read, update or destroy data within your database, authCheck is going to be the action type that's actually firing from an auditing perspective.
To enable the auditing of DML operations, actually we want to do is enable the auditing of authorization success
systemLog:
destination: file
path: /data/db/mongo.log
storage:
dbpath: /data/db
auditLog:
destination: file
format: JSON
path: /data/db/auditLog.json
setParameter: { auditAuthorizationSuccess: true }
By setting auditAuthorizationSuccess to true we can effectively audit CRUD operations as an authCheck is required for all CRUD operations.
MongoDB provides a further strengthening protection by redact data from the system log
To capture every signle CRUD instruction into our logs.
Set the slow ms value to -1.
db.setProfilingLevel(0, -1)
mongod --redactClientLogData
storage:
dbPath: /data/redaction
systemLog:
destination: file
path: /data/redaction.log
security:
redactionClientLogData: true
Once the server reboots, we need to make sure to set it up again
db.adminCommand({setParameter:1, redactionClientLogData: 1})
mongos | mongod
The flag should be set on Mongos and Mongod. make sure to redact the log message of all individual mongos and all individual mongod. Otherwise, might get a leak!
Disable server-side scripting
mongod --noscripting
**Reporting a Vulnerability in MongoDB