Auditing Amazon DocumentDB Events

With Amazon DocumentDB (with MongoDB compatibility), you can audit events that were performed in your cluster. Examples of logged events include successful and failed authentication attempts, dropping a collection in a database, or creating an index. By default, auditing is disabled on Amazon DocumentDB and requires that you opt in to use this feature.

When auditing is enabled, Amazon DocumentDB records Data Definition Language (DDL), authentication, authorization, and user management events to Amazon CloudWatch Logs. When auditing is enabled, Amazon DocumentDB exports your cluster’s auditing records (JSON documents) to Amazon CloudWatch Logs. You can use Amazon CloudWatch Logs to analyze, monitor, and archive your Amazon DocumentDB auditing events.

Although Amazon DocumentDB does not charge an additional cost to enable auditing, you are charged standard rates for the usage of CloudWatch Logs. For information about CloudWatch Logs pricing, see Amazon CloudWatch pricing.

The Amazon DocumentDB auditing feature is distinctly different from the service resource usage that is monitored with AWS CloudTrail. CloudTrail records operations that are performed with the AWS Command Line Interface (AWS CLI) or AWS Management Console on resources like clusters, instances, parameter groups, and snapshots. Auditing of AWS resources with CloudTrail is on by default and cannot be disabled. The Amazon DocumentDB auditing feature is an opt-in feature. It records operations that take place within your cluster on objects, such as databases, collections, indexes, and users.

Supported Events

Amazon DocumentDB auditing supports the following event categories: connection, data definition language (DDL), user management, and authorization. The event types are as follows.

Event TypeCategoryDescription
authenticateConnectionSuccessful or failed authentication attempts on a new connection.
createDatabaseDDLCreation of a new database.
createCollectionDDLCreation of a new collection within a database.
createIndexDDLCreation of a new index within a collection.
dropCollectionDDLDropping of a collection within a database.
dropDatabaseDDLDropping of a database.
dropIndexDDLDropping of an index within a collection.
createUserUser ManagementCreation of a new user.
dropUserUser ManagementDropping of an existing user.
updateUserUserManagementUpdating of an existing user.
dropAllUsersFromDatabaseUser ManagementDropping of all users within a database.
authCheckAuthorizationUnauthorized attempts to perform an operation.

Enabling Auditing

Enabling auditing on a cluster is a two-step process. Ensure that both steps are completed, or auditing logs will not be sent to CloudWatch Logs.

Step 1. Enable the audit_logs Cluster Parameter

To set the audit_logs parameter to enabled, create a new cluster parameter group or use an existing custom parameter group and modify it by setting audit_logs to enabled. You cannot modify a default parameter group.

For more information, see the following:

Step 2. Enable Amazon CloudWatch Logs Export

When the value of the audit_logs cluster parameter is enabled, you must also enable Amazon DocumentDB to export logs to Amazon CloudWatch. If you omit either of these steps, audit logs will not be sent to CloudWatch.

When creating a cluster, performing a point-in-time-restore, or restoring a snapshot, you can enable CloudWatch Logs by following these steps.

Using the AWS Management Console

To enable Amazon DocumentDB exporting logs to CloudWatch using the console, see the following topics:

Using the AWS CLI

To enable audit logs when creating a new cluster

The following code creates the cluster sample-cluster and enables CloudWatch audit logs.

For Linux, macOS, or Unix:

  1. aws docdb create-db-cluster \
  2. --db-cluster-identifier sample-cluster \
  3. --port 27017 \
  4. --engine docdb \
  5. --master-username master-username \
  6. --master-user-password password \
  7. --db-subnet-group-name default \
  8. --enable-cloudwatch-logs-exports audit

For Windows:

  1. aws docdb create-db-cluster ^
  2. --db-cluster-identifier sample-cluster ^
  3. --port 27017 ^
  4. --engine docdb ^
  5. --master-username master-username ^
  6. --master-user-password password ^
  7. --db-subnet-group-name default ^
  8. --enable-cloudwatch-logs-exports audit

To enable audit logs when modifying an existing cluster

The following code modifies the cluster sample-cluster and enables CloudWatch audit logs.

For Linux, macOS, or Unix:

  1. aws docdb modify-db-cluster \
  2. --db-cluster-identifier sample-cluster \
  3. --cloudwatch-logs-export-configuration '{"EnableLogTypes":["audit"]}'

For Windows:

  1. aws docdb modify-db-cluster ^
  2. --db-cluster-identifier sample-cluster ^
  3. --cloudwatch-logs-export-configuration '{"EnableLogTypes":["audit"]}'

Output from these operations looks something like the following (JSON format).

  1. {
  2. "DBCluster": {
  3. "HostedZoneId": "ZNKXH85TT8WVW",
  4. "StorageEncrypted": false,
  5. "DBClusterParameterGroup": "default.docdb4.0",
  6. "MasterUsername": "<user-name>",
  7. "BackupRetentionPeriod": 1,
  8. "Port": 27017,
  9. "VpcSecurityGroups": [
  10. {
  11. "Status": "active",
  12. "VpcSecurityGroupId": "sg-77186e0d"
  13. }
  14. ],
  15. "DBClusterArn": "arn:aws:rds:us-east-1:900083794985:cluster:sample-cluster",
  16. "Status": "creating",
  17. "Engine": "docdb",
  18. "EngineVersion": "4.0.0",
  19. "MultiAZ": false,
  20. "AvailabilityZones": [
  21. "us-east-1a",
  22. "us-east-1c",
  23. "us-east-1f"
  24. ],
  25. "DBSubnetGroup": "default",
  26. "DBClusterMembers": [],
  27. "ReaderEndpoint": "sample-cluster.cluster-ro-corcjozrlsfc.us-east-1.docdb.amazonaws.com",
  28. "EnabledCloudwatchLogsExports": [
  29. "audit"
  30. ],
  31. "PreferredMaintenanceWindow": "wed:03:08-wed:03:38",
  32. "AssociatedRoles": [],
  33. "ClusterCreateTime": "2019-02-13T16:35:04.756Z",
  34. "DbClusterResourceId": "cluster-YOS52CUXGDTNKDQ7DH72I4LED4",
  35. "Endpoint": "sample-cluster.cluster-corcjozrlsfc.us-east-1.docdb.amazonaws.com",
  36. "PreferredBackupWindow": "07:16-07:46",
  37. "DBClusterIdentifier": "sample-cluster"
  38. }
  39. }

Disabling Auditing

You can disable auditing by disabling CloudWatch Logs export and disabling the audit_logs parameter.

Disabling CloudWatch Logs Export

You can disable exporting audit logs using either the AWS Management Console or the AWS CLI.

Using the AWS Management Console

The following procedure uses the AWS Management Console to disable Amazon DocumentDB exporting logs to CloudWatch.

To disable audit logs

  1. Sign in to the AWS Management Console, and open the Amazon DocumentDB console at https://console.aws.amazon.com/docdb.

  2. In the navigation pane, choose Clusters. Then choose the button to the left of the name of the cluster for which you want to disable exporting logs.

  3. Choose Actions, and then choose Modify.

  4. Scroll down to the Log exports section and choose Disabled.

  5. Choose Continue.

  6. Review your changes, and then choose when you want this change applied to your cluster.

    • Apply during the next scheduled maintenance window

    • Apply immediately

  7. Choose Modify cluster.

Using the AWS CLI

The following code modifies the cluster sample-cluster and disables CloudWatch audit logs.

For Linux, macOS, or Unix:

  1. aws docdb modify-db-cluster \
  2. --db-cluster-identifier sample-cluster \
  3. --cloudwatch-logs-export-configuration '{"DisableLogTypes":["audit"]}'

For Windows:

  1. aws docdb modify-db-cluster ^
  2. --db-cluster-identifier sample-cluster ^
  3. --cloudwatch-logs-export-configuration '{"DisableLogTypes":["audit"]}'

Output from this operation looks something like the following (JSON format).

  1. {
  2. "DBCluster": {
  3. "DBClusterParameterGroup": "default.docdb4.0",
  4. "HostedZoneId": "ZNKXH85TT8WVW",
  5. "MasterUsername": "<user-name>",
  6. "Status": "available",
  7. "Engine": "docdb",
  8. "Port": 27017,
  9. "AvailabilityZones": [
  10. "us-east-1a",
  11. "us-east-1c",
  12. "us-east-1f"
  13. ],
  14. "EarliestRestorableTime": "2019-02-13T16:35:50.387Z",
  15. "DBSubnetGroup": "default",
  16. "LatestRestorableTime": "2019-02-13T16:35:50.387Z",
  17. "DBClusterArn": "arn:aws:rds:us-east-1:900083794985:cluster:sample-cluster2",
  18. "Endpoint": "sample-cluster2.cluster-corcjozrlsfc.us-east-1.docdb.amazonaws.com",
  19. "ReaderEndpoint": "sample-cluster2.cluster-ro-corcjozrlsfc.us-east-1.docdb.amazonaws.com",
  20. "BackupRetentionPeriod": 1,
  21. "EngineVersion": "4.0.0",
  22. "MultiAZ": false,
  23. "ClusterCreateTime": "2019-02-13T16:35:04.756Z",
  24. "DBClusterIdentifier": "sample-cluster2",
  25. "AssociatedRoles": [],
  26. "PreferredBackupWindow": "07:16-07:46",
  27. "DbClusterResourceId": "cluster-YOS52CUXGDTNKDQ7DH72I4LED4",
  28. "StorageEncrypted": false,
  29. "PreferredMaintenanceWindow": "wed:03:08-wed:03:38",
  30. "DBClusterMembers": [],
  31. "VpcSecurityGroups": [
  32. {
  33. "Status": "active",
  34. "VpcSecurityGroupId": "sg-77186e0d"
  35. }
  36. ]
  37. }
  38. }

Disabling the audit_logs Parameter

To disable the audit_logs parameter for your cluster, you can modify the cluster so that it uses a parameter group where the audit_logs parameter value is disabled. Or you can modify the audit_logs parameter value in the cluster’s parameter group so that it is disabled.

For more information, see the following topics:

Accessing Your Audit Events

Use following steps to access your audit events on Amazon CloudWatch.

  1. Open the CloudWatch console at https://console.aws.amazon.com/cloudwatch/.

  2. Make sure that you are in the same Region as your Amazon DocumentDB cluster.

  3. In the navigation pane, choose Logs.

  4. To find the audit logs for your cluster, from the list locate and choose /aws/docdb/`yourClusterName`/audit.

    The auditing events for each of your instances are available under each of the respective instance names.