Cloud Firestore 的审计日志包括删除集合?

Cloud Firestore's audit logs includes delete collections?

我了解审核日志默认包括 'delete' 等管理活动,但我在 GCP 日志注册表中找不到与我的 Firestore 项目中创建或删除的集合相关的任何日志。

我使用了以下查询:

resource.type=("datastore_database" OR "datastore_index")
logName=( 
        "projects/PROJECT_ID/logs/cloudaudit.googleapis.com%2Factivity"
        OR "projects/PROJECT_ID/logs/cloudaudit.googleapis.com%2Fdata_access"
        OR "projects/PROJECT_ID/logs/cloudaudit.googleapis.com%2Fsystem_event"
        OR "projects/PROJECT_ID/logs/cloudaudit.googleapis.com%2Fpolicy"
 )

编辑以修复项目路径(感谢 Javier M)

Firestore 的数据访问日志是disabled by default. You need to explicitly enable接收日志的。

另一方面,您错误地查询了日志,因为您在 PROJECT_ID 之前缺少 projects/,如 here 所述。因此,您应该使用:

logName=(
    "projects/PROJECT_ID/logs/cloudaudit.googleapis.com%2Fdata_access"
    OR "projects/PROJECT_ID/logs/cloudaudit.googleapis.com%2Factivity"
    OR "projects/PROJECT_ID/logs/cloudaudit.googleapis.com%2Fsystem_event"
    OR "projects/PROJECT_ID/logs/cloudaudit.googleapis.com%2Fpolicy")

您也可以 query logs from methodName. For instance, everytime you create a new Collection or Field in Firestore, Write 方法将被使用和记录。因此,您可以执行查询:

protoPayload.methodName="google.firestore.v1.Firestore.Write"

编辑: @Troglo 要求的有关删除操作日志的信息

您可以在 Write method, as it holds information on every write operation, such as delete 下查看对字段、文档和集合所做的每次删除的日志。但是,通过 methodName="google.firestore.v1.Firestore.Write" 查询将输出到目前为止完成的所有写操作。

或者,您可以使用 request 对象构建查询,因为它包含有关写入字段的信息,如 updatedelete。因此:

您项目下任何集合的删除日志

protoPayload.request.writes.delete:"projects/[PROJECT-ID]/databases/(default)/documents/"

删除特定集合的日志

protoPayload.request.writes.delete:"projects/[PROJECT-ID]/databases/(default)/documents/[COLLECTION-ID]"

注意使用 :(“有”,匹配任何子字符串)而不是 =(等于)来构建查询。第一个性能比后者低

重要:

请记住,根据今天(2021 年 10 月 26 日),这些 Data Access audit logs are in preview. Please, check the conditions and stage description 以获取更多信息。

删除操作审计日志

此方法见于 ADMIN WRITE audit logs, are related to long running operations, which are API calls that takes a long time to complete. Thus, the method will erase the long-running operation(意味着客户端不再对其结果感兴趣)。 它与删除 Cloud Firestore 实例中的条目无关。

删除Collection

您看不到删除 Collection 的日志,因为 you can't delete a collection. Instead, you need to delete all the documents and sub documents you have under the Collection.

因此,您在日志中看到的删除指的是删除文档删除字段。删除所有文档后,您可以假设 Collection 也被删除。

您可以将 Collection 视为文档的命名空间或容器(documentation 就是这样引用它的)。