

기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.

# Amazon DocumentDB 이벤트 감사
<a name="event-auditing"></a>

Amazon DocumentDB(MongoDB 호환)에서는 클러스터에서 수행된 이벤트를 감사할 수 있습니다. 기록되는 이벤트의 예제로는 성공 또는 실패한 인증 시도, 데이터베이스에서 모음 삭제 또는 인덱스 생성이 있습니다. 기본적으로 Amazon DocumentDB에서 감사는 비활성화되어 있으므로 사용자가 이 기능을 선택해야 합니다.

감사가 활성화되면 Amazon DocumentDB가 데이터 정의 언어(DDL), 데이터 조작 언어(DML), 인증, 권한 부여 및 사용자 관리 이벤트를 Amazon CloudWatch Logs에 기록합니다. 감사가 활성화되면 Amazon DocumentDB가 클러스터의 감사 기록(JSON 문서)을 Amazon CloudWatch Logs로 내보냅니다. Amazon CloudWatch Logs를 사용하여 Amazon DocumentDB 감사 이벤트를 분석, 모니터링 및 보관할 수 있습니다.

Amazon DocumentDB가 감사 활성화에 대해 추가 요금을 부과하지는 않지만 CloudWatch Logs 사용에 따른 표준 요금이 부과됩니다. CloudWatch Logs 요금에 대한 자세한 내용은 [Amazon CloudWatch 요금](https://aws.amazon.com/cloudwatch/pricing/)을 참조하세요.

Amazon DocumentDB 감사 기능은 로 모니터링되는 서비스 리소스 사용과는 분명히 다릅니다 AWS CloudTrail. CloudTrail은 AWS Command Line Interface (AWS CLI) 또는 클러스터, 인스턴스, 파라미터 그룹 및 스냅샷과 같은 리소스 AWS Management Console 에서 수행되는 작업을 기록합니다. CloudTrail을 사용한 리소스에 대한 감사는 기본적으로 활성화되어 있으며 비활성화할 수 없습니다. Amazon DocumentDB 감사 기능은 옵트인 기능입니다. 데이터베이스, 컬렉션, 인덱스 및 사용자와 같은 객체의 클러스터 내에서 발생하는 작업을 기록합니다.

**Topics**
+ [지원되는 이벤트](#auditing-events)
+ [감사 활성화](#event-auditing-enabling-auditing)
+ [감사 비활성화](#event-auditing-disabling-auditing)
+ [감사 이벤트 액세스](#event-auditing-accessing)
+ [DML 감사 이벤트 필터링](#filtering-dml-events)

## 지원되는 이벤트
<a name="auditing-events"></a>

Amazon DocumentDB 감사는 다음 이벤트 카테고리를 지원합니다.
+ **데이터 정의 언어 (DDL)** - 데이터베이스 관리 작업, 연결, 사용자 관리 및 권한 부여를 포함합니다.
+ **데이터 조작 언어 읽기 이벤트(DML 읽기)** - `find()` 및 다양한 집계 연산자, 산술 연산자, 부울 연산자 및 기타 읽기 쿼리 연산자를 포함합니다.
+ **데이터 조작 언어 쓰기 이벤트(DML 쓰기)** - `insert(), update(), delete(),` 및 `bulkWrite()` 연산자를 포함합니다 

이벤트 유형은 다음과 같습니다.

[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/ko_kr/documentdb/latest/developerguide/event-auditing.html)

**참고**  
DML 이벤트 문서 매개 변수 필드의 값에는 1KB 크기 제한이 있습니다. Amazon DocumentDB는 값이 1KB를 초과하는 경우 값을 잘라냅니다.

**참고**  
TTL 삭제 이벤트는 현재 감사되지 않습니다.

## 감사 활성화
<a name="event-auditing-enabling-auditing"></a>

클러스터에서 감사를 활성화하는 절차는 두 단계로 이루어져 있습니다. 두 단계를 모두 완료하지 않으면 감사 로그가 CloudWatch Logs로 전송되지 않습니다.

### 1단계. audit\$1logs 클러스터 파라미터 활성화
<a name="event-auditing-enable-audit_logs"></a>

감사를 활성화하려면 파라미터 그룹에서 `audit_logs` 파라미터를 수정해야 합니다. `audit_logs`는 로깅할 이벤트의 쉼표로 구분된 목록입니다. 이벤트는 모두 소문자로 지정해야 하며 목록 항목 사이에 공백이 없어야 합니다.

이 파라미터 그룹에 대해 다음 값을 지정할 수 있습니다.


| 값 | 설명 | 
| --- | --- | 
| ddl | 이를 설정하면 createDatabase, dropDatabase, createCollection, dropCollection, createIndex, dropIndex, authCheck, authenticate, createUser, dropUser, grantRolesToUser, revokeRolesFromUser, updateUser, dropAllUsersFromDatabase 등과 같은 DDL 이벤트에 대한 감사가 활성화됩니다 | 
| dml\$1read | 이를 설정하면 찾기, 정렬 횟수, 고유, 그룹, 프로젝트, 언와인드, geoNear, geoIntersects, geoWithin 및 기타 MongoDB 읽기 쿼리 연산자와 같은 DML 읽기 이벤트를 감사할 수 있습니다. | 
| dml\$1write | 이를 설정하면 insert(), update(), delete() 및 bulkWrite()와 같은 DML 쓰기 이벤트에 대한 감사가 활성화됩니다. | 
| all | 이를 설정하면 쿼리 읽기, 쿼리 쓰기, 데이터베이스 작업 및 관리자 작업과 같은 데이터베이스 이벤트를 감사할 수 있습니다. | 
| none | 이렇게 설정하면 감사가 비활성화됩니다. | 
| enabled(레거시) | 이는 'ddl'과 동일한 레거시 파라미터 설정입니다. 이를 설정하면 ccreateDatabase, dropDatabase, createCollection, dropCollection, createIndex, dropIndex, authCheck, authenticate, createUser, dropUser, grantRolesToUser, revokeRolesFromUser, updateUser, dropAllUsersFromDatabase 등과 같은 DDL 이벤트에 대한 감사가 활성화됩니다 이것은 레거시 설정이므로 이 설정을 사용하지 않는 것이 좋습니다. | 
| disabled (레거시) | 이는 'none'과 동일한 레거시 파라미터 설정입니다. 이것은 레거시 설정이므로 이 설정을 사용하지 않는 것이 좋습니다. | 

**참고**  
audit\$1logs 클러스터 매개변수의 기본값은 `none`(레거시 ‘`disabled`‘)입니다.

위에서 언급한 값을 조합하여 사용할 수도 있습니다.


| 값 | 설명 | 
| --- | --- | 
| ddl, dml\$1read | 이를 설정하면 DDL 이벤트 및 DML 읽기 이벤트를 감사할 수 있습니다. | 
| ddl, dml\$1write | 이를 설정하면 DDL 이벤트 및 DML 읽기를 감사할 수 있음 | 
| dml\$1read, dml\$1write | 이를 설정하면 모든 DDL 이벤트를 감사할 수 있음 | 

**참고**  
기본 파라미터 그룹은 수정할 수 없습니다.

자세한 내용은 다음을 참조하세요.
+ [Amazon DocumentDB 클러스터 파라미터 그룹 생성](cluster_parameter_groups-create.md)

  사용자 지정 파라미터 그룹을 생성한 후 `audit_logs` 파라미터 값을 `all`로 변경하여 파라미터 그룹을 수정합니다.
+ [Amazon DocumentDB 클러스터 파라미터 그룹 수정](cluster_parameter_groups-modify.md)

  

### 2단계. Amazon CloudWatch Logs 내보내기 활성화
<a name="event-auditing-enable-export"></a>

`audit_logs` 클러스터 파라미터의 값을 `enabled`, `ddl`, `dml_read`, `dml_write`로 설정한 경우 이와 동시에 Amazon DocumentDB가 Amazon CloudWatch로 로그를 내보내도록 활성화해야 합니다. 이들 단계를 하나라도 생략하면 감사 로그가 CloudWatch로 전송되지 않습니다.

클러스터를 생성하거나, 특정 시점 복원을 수행하거나, 스냅샷을 복원할 때 다음 단계에 따라 CloudWatch Logs를 활성화할 수 있습니다.

------
#### [ Using the AWS Management Console ]

콘솔을 사용하여 CloudWatch로 로그를 내보낼 수 있도록 Amazon DocumentDB를 활성화하려면 다음 주제를 참조하세요.
+ **클러스터를 생성하는 경우**, [를 사용하여 클러스터 및 기본 인스턴스 생성 AWS Management Console](db-cluster-create.md#db-cluster-create-con)에서 **클러스터 생성: 추가 구성**(5단계, **로그 내보내기**)을 참조하세요.
+ **기존 클러스터를 수정하는 경우** — [Amazon DocumentDB 클러스터 수정](db-cluster-modify.md)
+ **클러스터 스냅샷 복원을 수행하는 경우** — [클러스터 스냅샷에서 복원](backup_restore-restore_from_snapshot.md)
+ **특정 시점으로 복구를 수행하는 경우** — [특정 시점으로 복원](backup_restore-point_in_time_recovery.md)

------
#### [ Using the AWS CLI ]

**새 클러스터를 생성할 때 감사 로그를 활성화하려면**  
다음 코드는 클러스터 `sample-cluster`을 생성하고 CloudWatch 감사 로그를 활성화합니다.

**Example**  
Linux, macOS, Unix의 경우:  

```
aws docdb create-db-cluster \
    --db-cluster-identifier sample-cluster \
    --port 27017 \
    --engine docdb \
    --master-username master-username \
    --master-user-password password \
    --db-subnet-group-name default \
    --enable-cloudwatch-logs-exports audit
```
Windows의 경우:  

```
aws docdb create-db-cluster ^
    --db-cluster-identifier sample-cluster ^
    --port 27017 ^
    --engine docdb ^
    --master-username master-username ^
    --master-user-password password ^
    --db-subnet-group-name default ^
    --enable-cloudwatch-logs-exports audit
```

**기존 클러스터를 수정할 때 감사 로그를 활성화하려면**  
다음 코드는 클러스터 `sample-cluster`을 수정하고 CloudWatch 감사 로그를 활성화합니다.

**Example**  
Linux, macOS, Unix의 경우:  

```
aws docdb modify-db-cluster \
   --db-cluster-identifier sample-cluster \
   --cloudwatch-logs-export-configuration '{"EnableLogTypes":["audit"]}'
```
Windows의 경우:  

```
aws docdb modify-db-cluster ^
   --db-cluster-identifier sample-cluster ^
   --cloudwatch-logs-export-configuration '{"EnableLogTypes":["audit"]}'
```
이러한 작업의 출력은 다음과 같습니다(JSON 형식).  

```
{
    "DBCluster": {
        "HostedZoneId": "ZNKXH85TT8WVW",
        "StorageEncrypted": false,
        "DBClusterParameterGroup": "default.docdb4.0",
        "MasterUsername": "<user-name>",
        "BackupRetentionPeriod": 1,
        "Port": 27017,
        "VpcSecurityGroups": [
            {
                "Status": "active",
                "VpcSecurityGroupId": "sg-77186e0d"
            }
        ],
        "DBClusterArn": "arn:aws:rds:us-east-1:900083794985:cluster:sample-cluster",
        "Status": "creating",
        "Engine": "docdb",
        "EngineVersion": "4.0.0",
        "MultiAZ": false,
        "AvailabilityZones": [
            "us-east-1a",
            "us-east-1c",
            "us-east-1f"
        ],
        "DBSubnetGroup": "default",
        "DBClusterMembers": [],
        "ReaderEndpoint": "sample-cluster.cluster-ro-corcjozrlsfc.us-east-1.docdb.amazonaws.com",
        "EnabledCloudwatchLogsExports": [
            "audit"
        ],
        "PreferredMaintenanceWindow": "wed:03:08-wed:03:38",
        "AssociatedRoles": [],
        "ClusterCreateTime": "2019-02-13T16:35:04.756Z",
        "DbClusterResourceId": "cluster-YOS52CUXGDTNKDQ7DH72I4LED4",
        "Endpoint": "sample-cluster.cluster-corcjozrlsfc.us-east-1.docdb.amazonaws.com",
        "PreferredBackupWindow": "07:16-07:46",
        "DBClusterIdentifier": "sample-cluster"
    }
}
```

------

## 감사 비활성화
<a name="event-auditing-disabling-auditing"></a>

CloudWatch Logs 내보내기를 비활성화하고 `audit_logs` 파라미터를 비활성화하여 감사를 비활성화할 수 있습니다.

### CloudWatch Logs 내보내기 비활성화
<a name="event-auditing-disabling-logs-export"></a>

 AWS Management Console 또는를 사용하여 감사 로그 내보내기를 비활성화할 수 있습니다 AWS CLI.

------
#### [ Using the AWS Management Console ]

다음 절차에서는를 사용하여 CloudWatch AWS Management Console 로 로그를 내보내는 Amazon DocumentDB를 비활성화합니다.

**감사 로그를 비활성화하려면**

1. 에 로그인 AWS Management Console하고 [https://console.aws.amazon.com/docdb](https://console.aws.amazon.com/docdb) Amazon DocumentDB 콘솔을 엽니다.

1. 탐색 창에서 **클러스터**를 선택합니다. 그런 다음 로그 내보내기를 비활성화할 클러스터의 이름 왼쪽에 있는 버튼을 선택합니다.

1. **작업**을 선택한 후 **수정**을 선택합니다.

1. **로그 내보내기** 섹션으로 아래로 스크롤하여 **비활성**을 선택합니다.

1. **계속**을 선택합니다.

1. 변경 사항을 검토하고 이 변경 사항을 클러스터에 적용할 시기를 선택합니다.
   + **예약된 다음 유지 관리 기간에 적용**
   + **즉시 적용**

1. **클러스터 수정**을 선택합니다.

------
#### [ Using the AWS CLI ]

다음 코드는 클러스터 `sample-cluster`을 수정하고 CloudWatch 감사 로그를 비활성화합니다.

**Example**  
Linux, macOS, Unix의 경우:  

```
aws docdb modify-db-cluster \
   --db-cluster-identifier sample-cluster \
   --cloudwatch-logs-export-configuration '{"DisableLogTypes":["audit"]}'
```
Windows의 경우:  

```
aws docdb modify-db-cluster ^
   --db-cluster-identifier sample-cluster ^
   --cloudwatch-logs-export-configuration '{"DisableLogTypes":["audit"]}'
```
이 작업의 출력은 다음과 같습니다(JSON 형식).  

```
{
    "DBCluster": {
        "DBClusterParameterGroup": "default.docdb4.0",
        "HostedZoneId": "ZNKXH85TT8WVW",
        "MasterUsername": "<user-name>",
        "Status": "available",
        "Engine": "docdb",
        "Port": 27017,
        "AvailabilityZones": [
            "us-east-1a",
            "us-east-1c",
            "us-east-1f"
        ],
        "EarliestRestorableTime": "2019-02-13T16:35:50.387Z",
        "DBSubnetGroup": "default",
        "LatestRestorableTime": "2019-02-13T16:35:50.387Z",
        "DBClusterArn": "arn:aws:rds:us-east-1:900083794985:cluster:sample-cluster2",
        "Endpoint": "sample-cluster2.cluster-corcjozrlsfc.us-east-1.docdb.amazonaws.com",
        "ReaderEndpoint": "sample-cluster2.cluster-ro-corcjozrlsfc.us-east-1.docdb.amazonaws.com",
        "BackupRetentionPeriod": 1,
        "EngineVersion": "4.0.0",
        "MultiAZ": false,
        "ClusterCreateTime": "2019-02-13T16:35:04.756Z",
        "DBClusterIdentifier": "sample-cluster2",
        "AssociatedRoles": [],
        "PreferredBackupWindow": "07:16-07:46",
        "DbClusterResourceId": "cluster-YOS52CUXGDTNKDQ7DH72I4LED4",
        "StorageEncrypted": false,
        "PreferredMaintenanceWindow": "wed:03:08-wed:03:38",
        "DBClusterMembers": [],
        "VpcSecurityGroups": [
            {
                "Status": "active",
                "VpcSecurityGroupId": "sg-77186e0d"
            }
        ]
    }
}
```

------

### audit\$1logs 파라미터 비활성화
<a name="event-auditing-disabling-audit-parameter"></a>

클러스터에 대한 `audit_logs` 파라미터를 비활성화하려면 `audit_logs` 파라미터 값이 `disabled`인 파라미터 그룹을 사용하도록 클러스터를 수정하면 됩니다. 또는 클러스터의 파라미터 그룹에서 `audit_logs` 파라미터 값을 `disabled`로 수정하면 됩니다.

자세한 내용은 다음 항목을 참조하세요.
+ [Amazon DocumentDB 클러스터 수정](db-cluster-modify.md)
+ [Amazon DocumentDB 클러스터 파라미터 그룹 수정](cluster_parameter_groups-modify.md)

## 감사 이벤트 액세스
<a name="event-auditing-accessing"></a>

다음 단계에 따라 Amazon CloudWatch에서 감사 이벤트에 액세스합니다.

1. [https://console.aws.amazon.com/cloudwatch/](https://console.aws.amazon.com/cloudwatch/)에서 CloudWatch 콘솔을 엽니다.

1. 사용자가 Amazon DocumentDB 클러스터와 동일한 리전에 있어야 합니다.

1. 탐색 창에서 **로그**를 선택합니다.

1. 클러스터에 대한 감사 로그를 찾으려면 목록에서 **/aws/docdb/*yourClusterName*/audit**을 찾아 선택합니다.

   각 인스턴스에 대한 감사 이벤트는 해당 인스턴스 이름 아래에서 찾을 수 있습니다.

## DML 감사 이벤트 필터링
<a name="filtering-dml-events"></a>

### DML 감사 필터링 시작하기
<a name="w2aac29c49c21b3"></a>

DML 감사 이벤트는 Amazon CloudWatch에 기록되기 전에 필터링할 수 있습니다. 이 기능을 사용하려면 감사 로그 및 DML 로깅을 활성화해야 합니다. Amazon DocumentDB는 `atype`, `command`, `user`, `namespace` 및 `auditAuthorizationSuccess`에서 필터링을 지원합니다.

**참고**  
DDL 이벤트는 필터링되지 않습니다.

`db.adminCommand( { command } )` 작업에서 `setAuditConfig`, `filter`및 `auditAuthorizationSuccess` 파라미터를 사용해 감사 필터를 지정하여 언제든지 감사 필터링을 활성화할 수 있습니다.

```
db.admin.runCommand(
   {
      setAuditConfig: 1, 
      filter:
         {
            //filter conditions
         },
      auditAuthorizationSuccess: true | false
   }
)
```

다음 명령을 실행하여 감사 필터 설정을 검색할 수도 있습니다.

```
db.admin.runCommand( { getAuditConfig: 1})
```

**보안 요구 사항**

권한이 있는 `auditConfigure` 작업이 있는 데이터베이스 사용자/역할만 DML 감사 필터를 설정하거나 나열할 때 `admindb`에 대한 명령을 실행할 수 있습니다. [`clusterAdmin`, `hostManager`, `root`]에서 기본 제공 역할 중 하나를 사용하거나 `auditConfigure` 권한이 있는 사용자 지정 역할을 생성할 수 있습니다. 다음은 `auditConfigure` 권한과 함께 기존 역할을 사용하는 예제와 사용자 지정 역할을 사용하는 예제입니다.

역할이 내장된 사용자:

```
use admin
db.createUser(
  {
    user: "myClusterAdmin",
    pwd: "password123",
    roles: [ { role: "clusterAdmin", db: "admin" } ]
  }
)
```

사용자 지정 역할이 있는 사용자:

```
use admin
db.createRole(
   {
     role: "myRole",
     privileges: [
       { resource: { cluster: true }, actions: [ "auditConfigure" ] }
     ],
     roles: []
   }
)
db.createUser(
  {
    user: "myUser",
    pwd: "myPassword",
    roles: [ { role: "myRole", db: "admin" } ]
  }
)
```

#### 사용 사례 필터링
<a name="filtering-use-cases"></a>

**예: 명령을 기준으로 이벤트 필터링**

```
db.admin.runCommand(
   {
      setAuditConfig: 1,
      filter: {
        "$and": [
         {
            "param.command":
               {
                  $in: [ "find","count", "insert", "delete", "update", "findandmodify" ]
               }
         }
         ]
      },
      auditAuthorizationSuccess: true
   }
)
```

**예: 사용자 이름으로 이벤트 필터링**

이 예제에서는 사용자 "myUser"만 로깅됩니다.

```
db.admin.runCommand(
   {
      setAuditConfig: 1,
      filter: {
      "$and": [
         {
            "param.user":
               {
                  $in: [ "myUser" ]
               }
         }
         ]},
      auditAuthorizationSuccess: true})
```

**예제: `atype` 항목을 사용해 필터링**

```
db.admin.runCommand(
   {
      setAuditConfig: 1,
      filter: {atype: "authCheck"},
      auditAuthorizationSuccess: true
   })
```

**참고**  
모든 DML 로그의 `authCheck` 항목은 `atype`입니다. DDL의 경우만 `atype` 항목이 다릅니다. `filter`에서 `authCheck` 이외의 값을 입력하면 CloudWatch 에서 DML 로그가 생성되지 않습니다.

**예: 연산자가 조인한 여러 필터를 사용하여 필터링**

```
db.admin.runCommand(
   {
      setAuditConfig: 1,
      filter: {
      "$and": [
         {
            "param.command":
               {
                  $in: [ "find","count", "insert", "delete", "update", "findandmodify" ]
               }
         }
         ],
       "$nor": [
         {
            "param.command":
               {
                  $in: ["count", "insert", "delete", "update", "findandmodify" ]
               }
         }]  
       },
      auditAuthorizationSuccess: true})
```

**참고**  
최상위 수준에서는 `$and`, `$or`, 및 `$nor` 항목만 지원됩니다. 다른 연산자는 지원되지 않으며 오류가 발생합니다.

**예: `auditAuthorizationSuccess`의 이벤트를 기준으로 필터링**

이 필터에서는 권한 부여를 성공적으로 통과한 모든 명령이 로그되지 않습니다.

```
db.admin.runCommand(
   {
      setAuditConfig: 1,
      filter: {},
      auditAuthorizationSuccess: false
   }
)
```

**예: `$in` 및 `$nin` 조건을 사용한 필터링**

`$in` 및 `$nin`에서 둘 다 사용하는 경우 조건 간에 암시적인 'and'가 존재하므로 명령이 로그되지 않습니다. 이 예제에서는 정규식이 `find` 명령을 차단하므로 아무 것도 로그되지 않습니다.

```
db.admin.runCommand(
   {
      setAuditConfig: 1,
      filter: {
      "$and": [
         {
            atype: "authCheck",
            "param.command":
               {
                  $in: [ "find", "insert", "delete", "update", "findandmodify" ],
                  $nin: ["count", "insert", "delete", "update", "findandmodify" ],
                  $not: /^^find.*/
               }
         }, 
         ],
       "$or": [
         {
            "param.command":
               {
                  $nin: ["count", "insert", "delete", "update", "findandmodify" ]
               }
         }]  
       },
      auditAuthorizationSuccess: true})
```

**예제: `namespace` 항목을 사용해 필터링**

```
db.admin.runCommand(
   {
      setAuditConfig: 1,
      filter: {
      "$and": [
         {
            "param.ns":
               {
                  $in: [ "test.foo" ]
               }
         }
         ]},
      auditAuthorizationSuccess: true})
```

**예제: 기본 필터로 재설정**

기본값으로 재설정하면 모든 DML 감사 이벤트가 로그됩니다. 필터링을 기본값으로 재설정하려면 다음 명령을 실행합니다.

```
db.admin.runCommand(
   {
      setAuditConfig: 1,
      filter: {},
      auditAuthorizationSuccess: true
   }
)
```