审核日志系统表引用

重要

此功能目前以公共预览版提供。

本文概述了审核日志表架构,并提供了可用于审核日志系统表的示例查询,以回答常见的帐户使用问题。 有关审核日志事件的信息,请参阅诊断日志参考

可在 system.access.audit 找到审核日志系统表。

审核日志注意事项

  • 大多数审核日志仅在工作区的区域中可用。
  • 仅 Unity Catalog 帐户级日志在所有区域可用。
  • 帐户级审核日志将 workspace_id 记录为 0

审核日志系统表架构

审核日志系统表使用以下架构:

列名称 数据类型 说明 示例
version 字符串 审核日志架构版本 2.0
event_time timestamp 时间戳 2023-01-01T01:01:01.123
event_date date 操作发生的日历日期 2023-01-01
workspace_id long 工作区的 ID 1234567890123456
source_ip_address string 请求的来源 IP 地址 10.30.0.242
user_agent string 请求的来源 Apache-HttpClient/4.5.13 (Java/1.8.0_345)
session_id string 请求源自的会话的 ID 123456789
user_identity string 发起请求的用户的标识 {"email": "user@domain.com", "subjectName": null}
service_name string 发起请求的服务名称 unityCatalog
action_name string 审核日志中捕获的事件类别 getTable
request_id string 请求 ID ServiceMain-4529754264
request_params map 包含所有请求参数的键值的映射。 取决于请求类型 [["full_name_arg", "user.chat.messages"],
["workspace_id", "123456789"],
["metastore_id", "123456789"]]
response struct 响应返回值的结构 {"statusCode": 200, "errorMessage": null, "result": null}
audit_level string 工作区或帐户级别事件 ACCOUNT_LEVEL
account_id string 帐户 ID 23e22ba4-87b9-4cc2-9770-d10b894bxx
event_id string 事件的 ID 34ac703c772f3549dcc8671f654950f0

示例查询

以下部分包括可用于获取审核日志系统表的见解的示例查询。 若要使这些查询正常工作,请将大括号 {{}} 中的值替换为你自己的参数。

注意

其中一些示例包括默认情况下未启用的详细审核日志事件。 若要在工作区中启用详细审核日志,请参阅启用详细审核日志

本文包括以下示例查询:

谁访问了此表?

此查询使用 information_schema

SELECT DISTINCT(grantee) AS `ACCESSIBLE BY`
FROM system.information_schema.table_privileges
WHERE table_schema = '{{schema_name}}' AND table_name = '{{table_name}}'
  UNION
    SELECT table_owner
    FROM system.information_schema.tables
    WHERE table_schema = '{{schema_name}}' AND table_name = '{{table}}'
  UNION
    SELECT DISTINCT(grantee)
    FROM system.information_schema.schema_privileges
    WHERE schema_name = '{{schema_name}}'

哪些用户在过去一天内访问了表?

注意

不会在 DML 操作的日志中捕获全名。 包括架构和简单名称以捕获所有内容。

SELECT
  user_identity.email as `User`,
  IFNULL(request_params.full_name_arg,
    request_params.name)
    AS `Table`,
    action_name AS `Type of Access`,
    event_time AS `Time of Access`
FROM system.access.audit
WHERE (request_params.full_name_arg = '{{catalog.schema.table}}'
  OR (request_params.name = '{{table_name}}'
  AND request_params.schema_name = '{{schema_name}}'))
  AND action_name
    IN ('createTable','getTable','deleteTable')
  AND event_date > now() - interval '1 day'
ORDER BY event_date DESC

用户访问了哪些表?

注意

若要按日期范围筛选,请在查询底部取消注释日期子句。

SELECT
        action_name as `EVENT`,
        event_time as `WHEN`,
        IFNULL(request_params.full_name_arg, 'Non-specific') AS `TABLE ACCESSED`,
        IFNULL(request_params.commandText,'GET table') AS `QUERY TEXT`
FROM system.access.audit
WHERE user_identity.email = '{{User}}'
        AND action_name IN ('createTable',
'commandSubmit','getTable','deleteTable')
        -- AND datediff(now(), event_date) < 1
        -- ORDER BY event_date DESC

示例结果

EVENT WHEN TABLE ACCESSED QUERY TEXT
getTable 2023-05-31 system.access.audit GET table
getTable 2023-05-31 system.access.table_lineage GET table
commandSubmit 2023-05-31 Non-specific show functions;
commandSubmit 2023-05-31 Non-specific SELECT

request_params

FROM

system.access.audit

WHERE

service_name = "notebook"

AND action_name = "moveFolder"

LIMIT

5

查看所有安全对象的权限更改

此查询将为帐户中发生的每个权限更改返回一个事件。 此查询将返回进行更改的用户、安全对象类型和名称以及所做的特定更改。

SELECT event_time, user_identity.email, request_params.securable_type, request_params.securable_full_name, request_params.changes
FROM system.access.audit
WHERE service_name = 'unityCatalog'
  AND action_name = 'updatePermissions'
ORDER BY 1 DESC

查看最近运行的笔记本命令

此查询返回最近运行的笔记本命令以及运行该命令的用户。

注意

仅当启用了详细审核日志时,才会发出 runCommand 操作。 若要启用详细审核日志,请参阅启用详细审核日志

SELECT event_time, user_identity.email, request_params.commandText
FROM system.access.audit
WHERE action_name = `runCommand`
ORDER BY event_time DESC
LIMIT 100