/
configure-audit-filters.txt
309 lines (213 loc) · 10.5 KB
/
configure-audit-filters.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
.. _audit-filter:
=======================
Configure Audit Filters
=======================
.. default-domain:: mongodb
.. contents:: On this page
:local:
:backlinks: none
:depth: 1
:class: singlecol
.. admonition:: Auditing in MongoDB Atlas
:class: note
MongoDB Atlas supports auditing for all ``M10`` and larger
clusters. Atlas supports specifying a JSON-formatted audit
filter as documented below and using the Atlas audit filter
builder for simplified auditing configuration. To learn more, see
the Atlas documentation for
:atlas:`Set Up Database Auditing </database-auditing>`
and
:atlas:`Configure a Custom Auditing Filter </tutorial/auditing-custom-filter>`.
:products:`MongoDB Enterprise </mongodb-enterprise-advanced?jmp=docs>`
supports :ref:`auditing <auditing>` of various operations. When
:doc:`enabled </tutorial/configure-auditing>`, the audit facility, by
default, records all auditable operations as detailed in
:ref:`audit-action-details-results`. To specify which events to record,
the audit feature includes the ``--auditFilter`` option.
.. note::
.. include:: /includes/extracts/default-bind-ip-security.rst
Before you bind to other ip addresses, consider :ref:`enabling
access control <checklist-auth>` and other security measures listed
in :doc:`/administration/security-checklist` to prevent unauthorized
access.
``--auditFilter`` Option
------------------------
The ``--auditFilter`` option takes a string representation of a
query document of the form:
.. code-block:: javascript
{ <field1>: <expression1>, ... }
- The ``<field>`` can be :doc:`any field in the audit message
</reference/audit-message>`, including fields returned in the
:ref:`param <audit-action-details-results>` document.
- The ``<expression>`` is a :ref:`query condition expression
<query-selectors>`.
.. include:: /includes/fact-audit-filter-single-quotes.rst
.. include:: /includes/fact-audit-filter-yaml-configuration.rst
Examples
--------
Filter for Multiple Operation Types
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The following example audits only the :authaction:`createCollection`
and :authaction:`dropCollection` actions by using the filter:
.. code-block:: sh
{ atype: { $in: [ "createCollection", "dropCollection" ] } }
.. include:: /includes/fact-audit-filter-single-quotes.rst
.. code-block:: javascript
mongod --dbpath data/db --auditDestination file --auditFilter '{ atype: { $in: [ "createCollection", "dropCollection" ] } }' --auditFormat BSON --auditPath data/db/auditLog.bson
.. include:: /includes/extracts/default-bind-ip-security-additional-command-line.rst
.. include:: /includes/fact-audit-filter-yaml-configuration.rst
.. code-block:: yaml
storage:
dbPath: data/db
auditLog:
destination: file
format: BSON
path: data/db/auditLog.bson
filter: '{ atype: { $in: [ "createCollection", "dropCollection" ] } }'
Filter on Authentication Operations on a Single Database
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The ``<field>`` can include :doc:`any field in the audit message
</reference/audit-message>`. For authentication operations (i.e.
``atype: "authenticate"``), the audit messages include a ``db`` field
in the ``param`` document.
The following example audits only the ``authenticate`` operations
that occur against the ``test`` database by using the filter:
.. code-block:: sh
{ atype: "authenticate", "param.db": "test" }
.. include:: /includes/fact-audit-filter-single-quotes.rst
.. code-block:: javascript
mongod --dbpath data/db --auth --auditDestination file --auditFilter '{ atype: "authenticate", "param.db": "test" }' --auditFormat BSON --auditPath data/db/auditLog.bson
.. include:: /includes/extracts/default-bind-ip-security-additional-command-line.rst
.. include:: /includes/fact-audit-filter-yaml-configuration.rst
.. code-block:: yaml
storage:
dbPath: data/db
security:
authorization: enabled
auditLog:
destination: file
format: BSON
path: data/db/auditLog.bson
filter: '{ atype: "authenticate", "param.db": "test" }'
To filter on all :authaction:`authenticate` operations across
databases, use the filter ``{ atype: "authenticate" }``.
Filter on Collection Creation and Drop Operations for a Single Database
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The ``<field>`` can include :doc:`any field in the audit message
</reference/audit-message>`. For collection creation and drop
operations (i.e. ``atype: "createCollection"`` and ``atype:
"dropCollection"``), the audit messages include a namespace ``ns``
field in the ``param`` document.
The following example audits only the ``createCollection`` and
``dropCollection`` operations that occur against the ``test`` database
by using the filter:
.. note::
The regular expression requires two backslashes (``\\``) to escape
the dot (``.``).
.. code-block:: sh
{ atype: { $in: [ "createCollection", "dropCollection" ] }, "param.ns": /^test\\./ } }
.. include:: /includes/fact-audit-filter-single-quotes.rst
.. code-block:: javascript
mongod --dbpath data/db --auth --auditDestination file --auditFilter '{ atype: { $in: [ "createCollection", "dropCollection" ] }, "param.ns": /^test\\./ } }' --auditFormat BSON --auditPath data/db/auditLog.bson
.. include:: /includes/extracts/default-bind-ip-security-additional-command-line.rst
.. include:: /includes/fact-audit-filter-yaml-configuration.rst
.. code-block:: yaml
storage:
dbPath: data/db
security:
authorization: enabled
auditLog:
destination: file
format: BSON
path: data/db/auditLog.bson
filter: '{ atype: { $in: [ "createCollection", "dropCollection" ] }, "param.ns": /^test\\./ } }'
Filter by Authorization Role
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The following example audits operations by users with
:authrole:`readWrite` role on the ``test`` database, including users
with roles that inherit from :authrole:`readWrite`, by using the filter:
.. code-block:: sh
{ roles: { role: "readWrite", db: "test" } }
.. include:: /includes/fact-audit-filter-single-quotes.rst
.. code-block:: javascript
mongod --dbpath data/db --auth --auditDestination file --auditFilter '{ roles: { role: "readWrite", db: "test" } }' --auditFormat BSON --auditPath data/db/auditLog.bson
.. include:: /includes/extracts/default-bind-ip-security-additional-command-line.rst
.. include:: /includes/fact-audit-filter-yaml-configuration.rst
.. code-block:: yaml
storage:
dbPath: data/db
security:
authorization: enabled
auditLog:
destination: file
format: BSON
path: data/db/auditLog.bson
filter: '{ roles: { role: "readWrite", db: "test" } }'
Filter on Read and Write Operations
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
To capture :authaction:`read` and :authaction:`write` operations in the
audit, you must also enable the audit system to log authorization
successes using the :parameter:`auditAuthorizationSuccess` parameter.
[#authorization-agnostic]_
.. note::
.. include:: /includes/fact-auditAuthorizationSuccess-performance-impact.rst
The following example audits the :method:`~db.collection.find()`,
:method:`~db.collection.insert()`, :method:`~db.collection.remove()`,
:method:`~db.collection.update()`, :method:`~db.collection.save()`, and
:method:`~db.collection.findAndModify()` operations by using the filter:
.. code-block:: sh
{ atype: "authCheck", "param.command": { $in: [ "find", "insert", "delete", "update", "findandmodify" ] } }
.. include:: /includes/fact-audit-filter-single-quotes.rst
.. code-block:: javascript
mongod --dbpath data/db --auth --setParameter auditAuthorizationSuccess=true --auditDestination file --auditFilter '{ atype: "authCheck", "param.command": { $in: [ "find", "insert", "delete", "update", "findandmodify" ] } }' --auditFormat BSON --auditPath data/db/auditLog.bson
.. include:: /includes/extracts/default-bind-ip-security-additional-command-line.rst
.. include:: /includes/fact-audit-filter-yaml-configuration.rst
.. code-block:: yaml
storage:
dbPath: data/db
security:
authorization: enabled
auditLog:
destination: file
format: BSON
path: data/db/auditLog.bson
filter: '{ atype: "authCheck", "param.command": { $in: [ "find", "insert", "delete", "update", "findandmodify" ] } }'
setParameter: { auditAuthorizationSuccess: true }
Filter on Read and Write Operations for a Collection
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
To capture :authaction:`read` and :authaction:`write` operations in the
audit, you must also enable the audit system to log authorization
successes using the :parameter:`auditAuthorizationSuccess` parameter.
[#authorization-agnostic]_
.. note::
.. include:: /includes/fact-auditAuthorizationSuccess-performance-impact.rst
The following example audits the :method:`~db.collection.find()`,
:method:`~db.collection.insert()`, :method:`~db.collection.remove()`,
:method:`~db.collection.update()`, :method:`~db.collection.save()`, and
:method:`~db.collection.findAndModify()` operations for the collection
``orders`` in the database ``test`` by using the filter:
.. code-block:: sh
{ atype: "authCheck", "param.ns": "test.orders", "param.command": { $in: [ "find", "insert", "delete", "update", "findandmodify" ] } }
.. include:: /includes/fact-audit-filter-single-quotes.rst
.. code-block:: javascript
mongod --dbpath data/db --auth --setParameter auditAuthorizationSuccess=true --auditDestination file --auditFilter '{ atype: "authCheck", "param.ns": "test.orders", "param.command": { $in: [ "find", "insert", "delete", "update", "findandmodify" ] } }' --auditFormat BSON --auditPath data/db/auditLog.bson
.. include:: /includes/extracts/default-bind-ip-security-additional-command-line.rst
.. include:: /includes/fact-audit-filter-yaml-configuration.rst
.. code-block:: yaml
storage:
dbPath: data/db
security:
authorization: enabled
auditLog:
destination: file
format: BSON
path: data/db/auditLog.bson
filter: '{ atype: "authCheck", "param.ns": "test.orders", "param.command": { $in: [ "find", "insert", "delete", "update", "findandmodify" ] } }'
setParameter: { auditAuthorizationSuccess: true }
.. seealso::
:doc:`/tutorial/configure-auditing`,
:doc:`/core/auditing`,
:doc:`/reference/audit-message`
.. [#authorization-agnostic] You can enable :parameter:`auditAuthorizationSuccess`
parameter without enabling ``--auth``; however, all operations will
return success for authorization checks.