【问题标题】:How to find who deletes a table in the logs如何在日志中查找谁删除了表
【发布时间】:2020-01-21 07:51:36
【问题描述】:

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

【问题讨论】:

    标签: google-bigquery google-cloud-logging google-cloud-monitoring


    【解决方案1】:

    您需要启用auditlogs 导出。

    删除的种类很多:

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

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

    类型 1:您发出了删除表的查询/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",
      }
    ]
    

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

    更多关于可用信息here

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

    对于此类“删除”,您不会找到单独的已删除条目。但是您可以在metadataJson 中查找“截断”标志

    【讨论】:

      【解决方案2】:

      最简单的方法是在 GCP 控制台中单击“活动”选项卡,通过“大查询”过滤“资源类型”并查找“删除表”条目。如果您单击该条目,它将展开并显示有关删除的信息,以及执行删除的帐户。

      【讨论】:

        猜你喜欢
        • 2019-04-19
        • 1970-01-01
        • 2016-02-26
        • 2017-05-03
        • 1970-01-01
        • 1970-01-01
        • 2013-05-10
        • 2014-12-09
        • 1970-01-01
        相关资源
        最近更新 更多