AI エージェント向け: ドキュメントインデックスは https://www.mongodb.com/ja-jp/docs/llms.txt で利用できます。すべてのページの markdown バージョンは、いずれかの URL パスに .md を追加することで利用できます。
Docs Menu

setAuditConfig(データベースコマンド)

重要

バージョン 7.1 から非推奨:代わりにauditConfigクラスター パラメータを使用してください。

setAuditConfig

バージョン 5.0 の新機能。

setAuditConfig is an administrative command that sets new audit configurations for mongod and mongos server instances at runtime.

Use the db.adminCommand( { command } ) method to run setAuditConfig against the admin database.

このコマンドは、次の環境でホストされている配置で使用できます。

  • MongoDB Enterprise: サブスクリプションベースの自己管理型 MongoDB バージョン

  • MongoDB Community: ソースが利用可能で、無料で使用できる自己管理型の MongoDB のバージョン

重要

This command is not supported in MongoDB Atlas clusters. For information on Atlas support for all commands, see Unsupported Commands.

このコマンドの構文は、次のとおりです。

db.adminCommand(
{
setAuditConfig: 1,
filter: <Filter Document>,
auditAuthorizationSuccess: <Boolean>
}
)

コマンドには次のフィールドがあります:

フィールド
タイプ
説明

setAuditConfig

integer

実行する setAuditConfig

filter

ドキュメント

auditAuthorizationSuccess

ブール値

アクセス認可のすべてまたは失敗のみをログに記録

Enable auditing to use setAuditConfig at runtime.

auditAuthorizationSuccessは、 authCheckアクションの認可成功の監査を有効にします。 読み取り操作と書込み操作を監査するには、パラメータ値が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.

これらの例では、監査メッセージが再フォーマットされています。 これらはログファイルの 1 行に表示されます。

コレクションが作成または削除されたときに監査を有効にします。

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
}