|
| 1 | +.. _auditConfig: |
| 2 | + |
| 3 | +=========== |
| 4 | +auditConfig |
| 5 | +=========== |
| 6 | + |
| 7 | +.. default-domain:: mongodb |
| 8 | + |
| 9 | +.. contents:: On this page |
| 10 | + :local: |
| 11 | + :backlinks: none |
| 12 | + :depth: 2 |
| 13 | + :class: singlecol |
| 14 | + |
| 15 | +.. |both| replace:: Available for both :binary:`~bin.mongod` and :binary:`~bin.mongos`. |
| 16 | + |
| 17 | +Definition |
| 18 | +---------- |
| 19 | + |
| 20 | +.. parameter:: auditConfig |
| 21 | + |
| 22 | + .. versionadded:: 7.1 |
| 23 | + |
| 24 | + |both| |
| 25 | + |
| 26 | + .. include:: /includes/fact-auditConfig.rst |
| 27 | + |
| 28 | +Syntax |
| 29 | +------ |
| 30 | + |
| 31 | +To set ``auditConfig`` for your deployment, run the following command on |
| 32 | +the ``admin`` database: |
| 33 | + |
| 34 | +.. code-block:: javascript |
| 35 | + |
| 36 | + db.adminCommand( { setClusterParameter: { auditConfig: <value> } } ) |
| 37 | + |
| 38 | +To view current values for the ``auditConfig`` cluster parameter, run |
| 39 | +the following command on the ``admin`` database: |
| 40 | + |
| 41 | +.. code-block:: javascript |
| 42 | + |
| 43 | + db.adminCommand( { getClusterParameter: "auditConfig" } ) |
| 44 | + |
| 45 | +Parameter Fields |
| 46 | +---------------- |
| 47 | + |
| 48 | +.. parameter:: auditConfig.auditAuthorizationSuccess |
| 49 | + |
| 50 | + *Type*: boolean |
| 51 | + |
| 52 | + *Default*: false |
| 53 | + |
| 54 | + Enables the :ref:`auditing <auditing>` of authorization |
| 55 | + successes for the :ref:`authCheck <audit-action-details-results>` |
| 56 | + action. |
| 57 | + |
| 58 | + To audit read and write operations, ``auditConfig.auditAuthorizationSuccess`` |
| 59 | + must be set to ``true``. |
| 60 | + |
| 61 | + When ``auditConfig.auditAuthorizationSuccess`` is ``false``, the |
| 62 | + audit system only logs the authorization failures for ``authCheck``. When |
| 63 | + :parameter:`auditAuthorizationSuccess` is ``false``, auditing has less |
| 64 | + performance impact because the audit system only logs authorization failures. |
| 65 | + |
| 66 | +.. parameter:: auditConfig.filter |
| 67 | + |
| 68 | + *Type*: document |
| 69 | + |
| 70 | + *Default*: none |
| 71 | + |
| 72 | + Filter expression that controls which :ref:`types of operations |
| 73 | + <audit-action-details-results>` that the :ref:`audit system <auditing>` |
| 74 | + records. |
| 75 | + |
| 76 | + The document fields can be :ref:`any field in the audit message |
| 77 | + <audit-message>`, including fields returned in the |
| 78 | + :ref:`param <audit-action-details-results>` document. The field values are |
| 79 | + :ref:`query condition expressions <query-selectors>`. |
| 80 | + |
| 81 | + To view a sample filter document, see the :ref:`Examples section |
| 82 | + <auditconfig-example>`. |
| 83 | + |
| 84 | +Behavior |
| 85 | +-------- |
| 86 | + |
| 87 | +Auditing must be enabled to use ``auditConfig``. |
| 88 | + |
| 89 | +Retrieving Audit Configurations |
| 90 | +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 91 | + |
| 92 | +If :ref:`runtime audit configuration <configure-audit-filters-at-runtime>` |
| 93 | +is enabled, the ``auditAuthorizationSuccess`` parameter doesn't appear in the |
| 94 | +``mongod`` or ``mongos`` configuration file. The server will fail to start if |
| 95 | +the parameter is present. |
| 96 | + |
| 97 | +If you run ``getClusterParameter`` on ``auditConfig``, nodes that do not |
| 98 | +participate in a runtime audit configuration return their current configuration |
| 99 | +file settings for ``auditLog.filter`` and |
| 100 | +``setParameter.auditAuthorizationSuccess``. |
| 101 | + |
| 102 | +Setting Audit Configurations |
| 103 | +~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 104 | + |
| 105 | +When you set audit configurations with :dbcommand:`setClusterParameter`, changes |
| 106 | +immediately take effect on all :ref:`config servers <sharding-config-server>` |
| 107 | +and shards in a sharded cluster. |
| 108 | + |
| 109 | +Setting too wide of an audit filter or enabling |
| 110 | +``auditConfig.auditAuthorizationSuccess`` can degrade performance. |
| 111 | + |
| 112 | +.. _auditconfig-example: |
| 113 | + |
| 114 | +Example |
| 115 | +------- |
| 116 | + |
| 117 | +The following example uses the ``setClusterParameter`` command to enable |
| 118 | +auditing when a collection is created or deleted. The audit messages have been |
| 119 | +reformatted. They appear on a single line in the log file. |
| 120 | + |
| 121 | +.. code-block:: javascript |
| 122 | + |
| 123 | + db.adminCommand( |
| 124 | + { |
| 125 | + setClusterParameter: { |
| 126 | + auditConfig: { |
| 127 | + filter: { |
| 128 | + atype: { |
| 129 | + $in: [ "createCollection", "dropCollection" ] |
| 130 | + } |
| 131 | + }, |
| 132 | + auditAuthorizationSuccess: false |
| 133 | + } |
| 134 | + } |
| 135 | + } |
| 136 | + ) |
| 137 | + |
| 138 | +After setting the ``auditConfig`` parameter, if you create an ``inventory`` |
| 139 | +collection in the ``sales`` database, the audit system logs a message that |
| 140 | +resembles the following: |
| 141 | + |
| 142 | +.. code-block:: javascript |
| 143 | + .. copyable: false |
| 144 | + |
| 145 | + { |
| 146 | + "atype" : "createCollection", |
| 147 | + "ts" : { "$date" : "2021-08-09T13:45:05.372+00:00" }, |
| 148 | + "uuid" : { "$binary" : "RKU/YLizS6K9se2GUU7ZVQ==", "$type" : "04" }, |
| 149 | + "local" : { "ip" : "127.0.0.1", "port" : 27502 }, |
| 150 | + "remote" : { "ip" : "127.0.0.1", "port" : 51918 }, |
| 151 | + "users" : [], |
| 152 | + "roles" : [], |
| 153 | + "param" : { "ns" : "sales.inventory" }, |
| 154 | + "result" : 0 |
| 155 | + } |
| 156 | + |
| 157 | +If the ``inventory`` collection is dropped from the ``sales`` database, the |
| 158 | +audit system logs a message similar to the following: |
| 159 | + |
| 160 | +.. code-block:: javascript |
| 161 | + .. copyable: false |
| 162 | + |
| 163 | + { |
| 164 | + "atype" : "dropCollection", |
| 165 | + "ts" : { "$date" : "2021-08-09T13:45:00.661+00:00" }, |
| 166 | + "uuid" : { "$binary" : "0gle4/pSQli+LUcz43ykag==", "$type" : "04" }, |
| 167 | + "local" : { "ip" : "127.0.0.1", "port" : 27502 }, |
| 168 | + "remote" : { "ip" : "127.0.0.1", "port" : 51928 }, |
| 169 | + "users" : [], |
| 170 | + "roles" : [], |
| 171 | + "param" : { "ns" : "sales.inventory" }, |
| 172 | + "result" : 0 |
| 173 | + } |
| 174 | + |
| 175 | +Learn More |
| 176 | +---------- |
| 177 | + |
| 178 | +- :ref:`auditing` |
| 179 | +- :ref:`audit-action-details-results` |
| 180 | +- :ref:`cluster-parameters` |
| 181 | +- :ref:`configure-audit-filters-at-runtime` |
| 182 | +- :ref:`audit-message` |
0 commit comments