정의
setAuditConfig버전 5.0의 신규 항목입니다.
setAuditConfigis an administrative command that sets new audit configurations formongodandmongosserver instances at runtime.Use the
db.adminCommand( { command } )method to runsetAuditConfigagainst theadmindatabase.
호환성
이 명령은 다음 환경에서 호스팅되는 배포에서 사용할 수 있습니다.
MongoDB Enterprise: MongoDB의 구독 기반 자체 관리 버전
MongoDB Community: MongoDB의 소스 사용 가능 무료 자체 관리 버전
중요
이 명령은 MongoDB Atlas 클러스터에서 지원되지 않습니다. 모든 명령에 대한 Atlas 지원에 관해 자세히 알아보려면 지원되지 않는 명령을 참조하세요.
구문
명령은 다음과 같은 구문을 가집니다:
db.adminCommand( { setAuditConfig: 1, filter: <Filter Document>, auditAuthorizationSuccess: <Boolean> } )
명령 필드
명령에는 다음과 같은 필드가 있습니다.
필드 | 유형 | 설명 |
|---|---|---|
| integer | |
| 문서 | |
| 부울 | 모든 권한 부여 또는 실패한 액세스 권한만 기록 |
행동
Enable auditing to use setAuditConfig at runtime.
auditAuthorizationSuccess 는 authCheck 조치 에 대한 권한 부여 성공 감사를 활성화합니다. 읽기 및 쓰기 (write) 작업을 감사 하려면 매개 변수 값이 true 여야 합니다. 그러나 auditAuthorizationSuccess false 인 경우 감사 시스템은 권한 부여 실패만 기록하므로 성능 영향 이 적습니다.
Configuration updates are distributed via the oplog mechanism which means updates on mongod nodes are distributed to secondary nodes very quickly. There is a different distribution mechanism on mongos nodes. mongos nodes have to poll the primary server at regular intervals for configuration updates. You may see stale data due to polling delay if you run setAuditConfig on the primary server and getAuditConfig on a shard before the shard has polled the primary server for updated configuration details.
예시
이 예에서는 감사 메시지의 형식이 다시 지정되었습니다. 로그 파일에서 한 줄에 표시됩니다.
컬렉션 생성 및 삭제 감사
컬렉션이 생성되거나 삭제될 때 감사를 활성화합니다.
db.admin.runCommand( { setAuditConfig: 1, filter: { atype: { $in: [ "createCollection", "dropCollection" ] } }, auditAuthorizationSuccess: false } )
inventory 컬렉션이 sales 데이터베이스에 생성되면 감사 시스템은 다음과 같은 메시지를 기록합니다.
{ "atype" : "createCollection", "ts" : { "$date" : "2021-08-09T13:45:05.372+00:00" }, "uuid" : { "$binary" : "RKU/YLizS6K9se2GUU7ZVQ==", "$type" : "04" }, "local" : { "ip" : "127.0.0.1", "port" : 27502 }, "remote" : { "ip" : "127.0.0.1", "port" : 51918 }, "users" : [], "roles" : [], "param" : { "ns" : "sales.inventory" }, "result" : 0 }
inventory 컬렉션이 sales 데이터베이스에서 제거되면 감사 시스템은 다음과 같은 메시지를 기록합니다.
{ "atype" : "dropCollection", "ts" : { "$date" : "2021-08-09T13:45:00.661+00:00" }, "uuid" : { "$binary" : "0gle4/pSQli+LUcz43ykag==", "$type" : "04" }, "local" : { "ip" : "127.0.0.1", "port" : 27502 }, "remote" : { "ip" : "127.0.0.1", "port" : 51928 }, "users" : [], "roles" : [], "param" : { "ns" : "sales.inventory" }, "result" : 0 }
문서 상호 작용 감사
auditAuthorizationSuccess 를 true 로 설정하고 읽기 및 쓰기 작업을 감사할 관심 있는 작업을 포함하는 필터를 만듭니다.
db.admin.runCommand( { setAuditConfig: 1, filter: { atype: "authCheck", "param.command": { $in: [ "find", "insert", "delete", "update", "findandmodify" ] } }, auditAuthorizationSuccess: true } )
find 명령을 사용하여 sales 데이터베이스에서 inventory 컬렉션을 검색하여 다음과 같은 감사 로그 항목을 생성합니다.
{ "atype" : "authCheck", "ts" : { "$date" : "2021-08-09T15:28:10.788+00:00" }, "uuid" : { "$binary" : "ngwRt5CRTZqgE4TsfleoqQ==", "$type" : "04" }, "local" : { "ip" : "127.0.0.1", "port" : 27502 }, "remote" : { "ip" : "127.0.0.1", "port" : 51930 }, "users" : [], "roles" : [], "param" : { "command" : "find", "ns" : "sales.inventory", "args" : { "find" : "inventory", "filter" : { "widget" : 1 }, "lsid" : { "id" : { "$binary" : "FNWNxiitQ8GHKrHx8eJSbg==", "$type" : "04" } }, "$clusterTime" : { "clusterTime" : { "$timestamp" : { "t" : 1628521381, "i" : 1 } }, "signature" : { "hash" : { "$binary" : "AAAAAAAAAAAAAAAAAAAAAAAAAAA=", "$type" : "00" }, "keyId" : { "$numberLong" : "0" } } }, "$db" : "sales" } }, "result" : 0 }