如何在日志中找到谁删除了 table

How to find who deletes a table in the logs

我有一个数据集 ID,表已创建。哪些被删除了。我需要检查是谁删除的以及何时删除的。

您需要启用 auditlogs 导出。

有多种删除类型:

  • 从 UI/API
  • 中删除
  • 使用 QUERY 删除(覆盖为目标 table)
  • 通过 CREATE OR REPLACE 语法删除
  • 过期完成自动删除

这里解释了常见的删除类型:

类型 1:您发出了 table 删除了 Query/API 调用等。

然后你可以运行这样的查询:

SELECT * FROM `dataset.cloudaudit_googleapis_com_activity_20190919` 
where resource.type='bigquery_resource' 
and protopayload_auditlog.methodName='tableservice.delete'

你得到一张 large table 不能作为漂亮的图片张贴在这里,但作为简化的 JSON 它在这里:

[
  {
    "logName": "projects/editedname/logs/cloudaudit.googleapis.com%2Factivity",
    "resource": {
      "type": "bigquery_resource",
      "labels": {
        "project_id": "editedname",
      }
    },
    "protopayload_auditlog": {
      "serviceName": "bigquery.googleapis.com",
      "methodName": "tableservice.delete",
      "resourceName": "projects/editedname/datasets/dataset/tables/industry2",
      "authenticationInfo": {
        "principalEmail": "something@domain.com",
        "authoritySelector": null,
        "serviceAccountKeyName": null,
        "serviceAccountDelegationInfo": []
      },
      "authorizationInfo": [
        {
          "resource": "projects/editedname/datasets/dataset/tables/industry2",
          "permission": "bigquery.tables.delete",
          "granted": "true",
          "resourceAttributes": null
        }
      ],
      "requestMetadata": {
        "callerIp": "1.2.3.4",
        "callerSuppliedUserAgent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.75 Safari/537.36,gzip(gfe)",
        "callerNetwork": null,
        "requestAttributes": null,
        "destinationAttributes": null
      },
    },
    "timestamp": "2019-09-19 08:47:00.381 UTC",
    "receiveTimestamp": "2019-09-19 08:47:00.590316 UTC",
    "severity": "NOTICE",
  }
]

如您所见,您删除了 table,例如:industry2 在我的示例中,还有用户或服务帐户的电子邮件地址,以及日期,甚至 metadata呼叫者的 IP 和 userAgent。

有关可用信息的更多信息here

类型 2:您发出了 table 覆盖查询或 CREATE OR REPLACE 语法

对于此类 "deletes",您不会找到单独的已删除条目。但是您可以在 metadataJson

中查找 "truncated" 标志

最简单的方法是在 GCP 控制台中单击 "ACTIVITY" 选项卡,通过 "Big Query" 过滤 "Resource Type" 并查找 "Delete Table" 条目。如果您单击该条目,它将展开并显示有关删除的信息,以及执行删除的帐户。