收集 Snowflake 日志
支持的平台:
Google SecOps
SIEM
本文档介绍了如何使用 AWS S3 将 Snowflake 日志注入到 Google Security Operations。解析器使用一系列 Grok 和 KV 模式匹配规则从日志消息中提取字段,这些规则专门用于处理 Snowflake 日志格式。然后,它会将提取的字段映射到统一数据模型 (UDM),通过添加更多上下文信息来丰富数据,并标准化表示形式以供进一步分析。
准备工作
请确保满足以下前提条件:
- Google SecOps 实例
- 对 AWS 的特权访问权限
- 对 Snowflake 的特权访问权限 (ACCOUNTADMIN)
配置 Amazon S3 存储分区
- 按照以下用户指南创建 Amazon S3 存储桶:创建存储桶
- 保存相应存储桶的名称和区域,以供日后参考。
配置 Snowflake AWS IAM 政策
- 登录 AWS 管理控制台。
- 搜索并选择 IAM。
- 选择账号设置。
- 在端点列表中的 Security Token Service (STS) 下,找到您的账号所在的 Snowflake 区域。
- 如果 STS 状态为非活跃,请将切换开关移至活跃。
- 选择政策。
- 选择创建政策。
- 在政策编辑器中,选择 JSON。
复制并粘贴以下政策(采用 JSON 格式),以向 Snowflake 授予使用单个存储桶和文件夹路径加载或卸载数据所需的权限。您还可以使用 PURGE 复制选项清除数据文件。
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "s3:PutObject", "s3:GetObject", "s3:GetObjectVersion", "s3:DeleteObject", "s3:DeleteObjectVersion" ], "Resource": "arn:aws:s3:::<bucket>/<prefix>/*" }, { "Effect": "Allow", "Action": [ "s3:ListBucket", "s3:GetBucketLocation" ], "Resource": "arn:aws:s3:::<bucket>", "Condition": { "StringLike": { "s3:prefix": [ "<prefix>/*" ] } } } ] }点击下一步。
输入政策名称(例如 snowflake_access)和(可选)说明。
点击创建政策。
配置 Snowflake AWS IAM 角色
- 在 AWS Identity and Access Management (IAM) 中,选择 Roles。
- 点击 Create role。
- 选择 AWS account 作为可信实体类型。
- 选择其他 AWS 账号。
- 在“账号 ID”字段中,暂时输入您自己的 AWS 账号 ID。之后,您修改信任关系并向 Snowflake 授予访问权限。
- 选择需要外部 ID 选项。
- 输入占位 ID,例如 0000。在后续步骤中,您将修改 IAM 角色的信任关系,并为存储集成指定外部 ID。
- 点击下一步。
- 选择您之前创建的 IAM 政策。
- 点击下一步。
- 输入角色的名称和说明。
- 点击 Create role。
- 在角色摘要页面上,复制并保存角色 ARN 值。
配置 Snowflake S3 集成
- 连接到 Snowflake 数据库。
替换以下字段,然后运行该命令:
<integration_name>是新集成的名称(例如,s3_integration)。<iam_role>是您之前创建的角色的 Amazon 资源名称 (ARN)。<aws_s3_bucket_path>是您之前创建的存储桶的路径(例如s3://your-log-bucket-name/)。
CREATE OR REPLACE STORAGE INTEGRATION <integration_name> TYPE = EXTERNAL_STAGE STORAGE_PROVIDER = 'S3' ENABLED = TRUE STORAGE_AWS_ROLE_ARN = '<iam_role>' STORAGE_ALLOWED_LOCATIONS = ('<aws_s3_bucket_path>')
配置 AWS IAM 用户权限以访问存储分区
- 检索为您的 Snowflake 账号自动创建的 IAM 用户的 ARN,将
<integration_name>替换为您之前创建的集成项的实际名称:none DESC INTEGRATION <integration_name>;
- 例如:
none DESC INTEGRATION s3_integration; +---------------------------+---------------+--------------------------------------------------------------------------------+------------------+ | property | property_type | property_value | property_default | +---------------------------+---------------+--------------------------------------------------------------------------------+------------------| | ENABLED | Boolean | true | false | | STORAGE_ALLOWED_LOCATIONS | List | s3://mybucket1/mypath1/,s3://mybucket2/mypath2/ | [] | | STORAGE_BLOCKED_LOCATIONS | List | s3://mybucket1/mypath1/sensitivedata/,s3://mybucket2/mypath2/sensitivedata/ | [] | | STORAGE_AWS_IAM_USER_ARN | String | arn:aws:iam::123456789001:user/abc1-b-self1234 | | | STORAGE_AWS_ROLE_ARN | String | arn:aws:iam::001234567890:role/myrole | | | STORAGE_AWS_EXTERNAL_ID | String | MYACCOUNT_SFCRole=2_a123456/s0aBCDEfGHIJklmNoPq= | | +---------------------------+---------------+--------------------------------------------------------------------------------+------------------+
- 复制并保存以下属性的值:
- STORAGE_AWS_IAM_USER_ARN
- STORAGE_AWS_EXTERNAL_ID
- 前往 AWS 管理控制台。
- 依次选择 IAM > 角色。
- 选择您之前创建的角色。
- 选择信任关系标签页。
- 点击修改信任政策。
使用 DESC INTEGRATION 输出值更新政策文档:
{ "Version": "2012-10-17", "Statement": [ { "Sid": "", "Effect": "Allow", "Principal": { "AWS": "<snowflake_user_arn>" }, "Action": "sts:AssumeRole", "Condition": { "StringEquals": { "sts:ExternalId": "<snowflake_external_id>" } } } ] }将
snowflake_user_arn是您记录的STORAGE_AWS_IAM_USER_ARN值。snowflake_external_id是您记录的STORAGE_AWS_EXTERNAL_ID值。
点击更新政策。
在 Snowflake 中配置 JSON 文件格式
在 Snowflake 中,输入以下命令:
CREATE OR REPLACE FILE FORMAT my_json_format type = json COMPRESSION = 'gzip' null_if = ('NULL', 'null');
在 Snowflake 中创建 S3 阶段
在 Snowflake 中,替换以下字段并输入命令:
<DB_NAME><DB_SCHEMA_NAME><AWS_S3_BUCKET_PATH>
use database '<DB_NAME>'; use schema '<DB_SCHEMA_NAME>'; CREATE OR REPLACE STAGE my_s3_stage storage_integration = s3_integration url = '<AWS_S3_BUCKET_PATH>' file_format = my_json_format;
配置 Snowflake 以导出数据
运行 UNLOAD 命令,将数据从表导出到暂存区,然后再导出到 AWS S3:
use database '<DB_NAME>'; use WAREHOUSE '<WAREHOUSE_NAME>'; copy into @my_s3_stage/login_history from (SELECT OBJECT_CONSTRUCT('application', 'snowflake' ,'environment', '<PUT_HERE_ENV_NAME>', 'log_type', 'login_history', 'EVENT_TIMESTAMP', EVENT_TIMESTAMP, 'EVENT_TYPE', EVENT_TYPE, 'USER_NAME', USER_NAME, 'CLIENT_IP', CLIENT_IP, 'REPORTED_CLIENT_TYPE', REPORTED_CLIENT_TYPE, 'FIRST_AUTHENTICATION_FACTOR',FIRST_AUTHENTICATION_FACTOR, 'IS_SUCCESS', IS_SUCCESS, 'ERROR_CODE', ERROR_CODE, 'ERROR_MESSAGE', ERROR_MESSAGE) from snowflake.account_usage.Login_history) FILE_FORMAT = (TYPE = JSON) ; copy into @my_s3_stage/access_history from (SELECT OBJECT_CONSTRUCT('application', 'snowflake' ,'environment', '<PUT_HERE_DB_NAME>', 'log_type', 'access_history', 'QUERY_START_TIME',QUERY_START_TIME, 'USER_NAME', USER_NAME, 'DIRECT_OBJECTS_ACCESSED',DIRECT_OBJECTS_ACCESSED, 'BASE_OBJECTS_ACCESSED', BASE_OBJECTS_ACCESSED, 'OBJECTS_MODIFIED', OBJECTS_MODIFIED) from snowflake.account_usage.Access_History ) FILE_FORMAT = (TYPE = JSON);针对以下所有用于存储日志和审核相关数据的 Snowflake 表重复执行导出流程:
Databases ; WAREHOUSE_EVENTS_HISTORY ; WAREHOUSE_LOAD_HISTORY ; WAREHOUSE_METERING_HISTORY ; DATABASE_STORAGE_USAGE_HISTORY ; DATA_TRANSFER_HISTORY ; GRANTS_TO_ROLES ; GRANTS_TO_USERS ; METERING_DAILY_HISTORY ; PIPE_USAGE_HISTORY ; REPLICATION_USAGE_HISTORY ; STAGE_STORAGE_USAGE_HISTORY ; STORAGE_USAGE ; TASK_HISTORY ; COPY_HISTORY ;
为 Google SecOps 配置 AWS IAM
- 登录 AWS 管理控制台。
- 按照以下用户指南创建用户:创建 IAM 用户。
- 选择创建的用户。
- 选择安全凭据标签页。
- 在访问密钥部分中,点击创建访问密钥。
- 选择第三方服务作为使用情形。
- 点击下一步。
- 可选:添加说明标记。
- 点击创建访问密钥。
- 点击下载 CSV 文件,保存访问密钥和秘密访问密钥,以供日后参考。
- 点击完成。
- 选择权限标签页。
- 在权限政策部分中,点击添加权限。
- 选择添加权限。
- 选择直接附加政策。
- 搜索并选择 AmazonS3FullAccess 政策。
- 点击下一步。
- 点击添加权限。
设置 Feed
如需配置 Feed,请按以下步骤操作:
- 依次前往 SIEM 设置 > Feed。
- 点击添加新 Feed。
- 在下一页上,点击配置单个 Feed。
- 在 Feed 名称字段中,输入 Feed 的名称(例如 Snowflake 日志)。
- 选择 Amazon S3 V2 作为来源类型。
- 选择 Snowflake 作为日志类型。
- 点击下一步。
为以下输入参数指定值:
- S3 URI:存储桶 URI(格式应为:
s3://your-log-bucket-name/)。 请替换以下内容:your-log-bucket-name:相应存储桶的名称。
- 源删除选项:根据您的偏好选择删除选项。
- S3 URI:存储桶 URI(格式应为:
点击下一步。
在最终确定界面中查看新的 Feed 配置,然后点击提交。
UDM 映射表
| 日志字段 | UDM 映射 | 逻辑 |
|---|---|---|
column4_label |
additional.fields |
已合并 |
column7_label |
additional.fields |
已合并 |
first_authentication_factor_label |
additional.fields |
已合并 |
host_list |
additional.fields |
已合并 |
query_text_label |
additional.fields |
已合并 |
query_type_label |
additional.fields |
已合并 |
roleIds_list |
additional.fields |
已合并 |
roleNames_list |
additional.fields |
已合并 |
rolecount_label |
additional.fields |
已合并 |
user_count_label |
additional.fields |
已合并 |
has_principal |
extensions.auth.type |
已映射:true → AUTHTYPE_UNSPECIFIED |
START_TIME |
metadata.event_timestamp |
解析为 yyyy-MM-dd HH:mm:ss.SSS Z |
column2 |
metadata.event_timestamp |
解析为 yyyy-MM-dd HH:mm:ss.SSS Z |
column20 |
metadata.event_timestamp |
解析为 yyyy-MM-dd HH:mm:ss.SSS Z |
ts |
metadata.event_timestamp |
解析为 ISO8601 |
event_type |
metadata.event_type |
直接映射 |
has_principal |
metadata.event_type |
已映射:true → NETWORK_CONNECTION、true → STATUS_UPDATE、true → USER_LOGIN |
has_principal_user |
metadata.event_type |
已映射:true → USER_UNCATEGORIZED |
column10 |
metadata.product_event_type |
直接映射 |
QUERY_ID |
metadata.product_log_id |
直接映射 |
column1 |
metadata.product_log_id |
直接映射 |
column6 |
metadata.product_version |
直接映射 |
SESSION_ID |
network.http.session_id |
直接映射 |
RECEIVED_BYTES |
network.received_bytes |
已重命名/已映射 |
BYTES_SENT_OVER_THE_NETWORK |
network.sent_bytes |
已重命名/已映射 |
SENT_BYTES |
network.sent_bytes |
已重命名/已映射 |
APPLICATION |
principal.application |
直接映射 |
data.user_name |
principal.asset.hostname |
直接映射 |
CLIENT_IP |
principal.asset.ip |
已合并 |
IP |
principal.asset.ip |
已合并 |
column5 |
principal.asset.ip |
已合并 |
SOURCE_REGION |
principal.cloud.availability_zone |
直接映射 |
SOURCE_CLOUD |
principal.cloud.environment |
映射:(?i)azure → MICROSOFT_AZURE、(?i)amazon → AMAZON_WEB_SERVICES、(?i)google ... |
data.user_name |
principal.hostname |
直接映射 |
CLIENT_IP |
principal.ip |
已合并 |
IP |
principal.ip |
已合并 |
column5 |
principal.ip |
已合并 |
OS |
principal.platform |
映射:(?i)Linux → LINUX、(?i)windows → WINDOWS、(?i)mac/ios → MAC |
OS_VERSION |
principal.platform_version |
直接映射 |
SOURCE_CLOUD_label |
principal.resource.attribute.labels |
已合并 |
roles |
principal.user.attribute.roles |
已合并 |
data.role_name |
principal.user.role_name |
直接映射 |
column9 |
principal.user.user_display_name |
直接映射 |
USER_NAME |
principal.user.userid |
直接映射 |
column10 |
principal.user.userid |
直接映射 |
column3 |
principal.user.userid |
直接映射 |
EXECUTION_STATUS |
security_result.action |
已映射:(?i)success → action,(?i)fail → security_result_action_block |
STATUS |
security_result.action |
映射:(?i)success → action,(?i)fail → action |
action |
security_result.action |
已合并 |
security_result_action_block |
security_result.action |
已合并 |
OCSP_MODE |
security_result.action_details |
直接映射 |
column11 |
security_result.action_details |
直接映射 |
column3 |
security_result.action_details |
直接映射 |
BYTES_DELETED_label |
security_result.detection_fields |
已合并 |
BYTES_READ_FROM_RESULT_label |
security_result.detection_fields |
已合并 |
BYTES_SCANNED_label |
security_result.detection_fields |
已合并 |
BYTES_SPILLED_TO_LOCAL_STORAGE_label |
security_result.detection_fields |
已合并 |
BYTES_SPILLED_TO_REMOTE_STORAGE_label |
security_result.detection_fields |
已合并 |
BYTES_WRITTEN_TO_RESULT_label |
security_result.detection_fields |
已合并 |
BYTES_WRITTEN_label |
security_result.detection_fields |
已合并 |
CHILD_QUERIES_WAIT_TIME_label |
security_result.detection_fields |
已合并 |
CLUSTER_NUMBER_label |
security_result.detection_fields |
已合并 |
COMPILATION_TIME_label |
security_result.detection_fields |
已合并 |
CREDITS_USED_CLOUD_SERVICES_label |
security_result.detection_fields |
已合并 |
DATABASE_ID_label |
security_result.detection_fields |
已合并 |
DATABASE_NAME_label |
security_result.detection_fields |
已合并 |
END_TIME_label |
security_result.detection_fields |
已合并 |
ERROR_MESSAGE_label |
security_result.detection_fields |
已合并 |
EXECUTION_TIME_label |
security_result.detection_fields |
已合并 |
EXTERNAL_FUNCTION_TOTAL_INVOCATIONS_label |
security_result.detection_fields |
已合并 |
EXTERNAL_FUNCTION_TOTAL_RECEIVED_BYTES_label |
security_result.detection_fields |
已合并 |
EXTERNAL_FUNCTION_TOTAL_RECEIVED_ROWS_label |
security_result.detection_fields |
已合并 |
EXTERNAL_FUNCTION_TOTAL_SENT_BYTES_label |
security_result.detection_fields |
已合并 |
EXTERNAL_FUNCTION_TOTAL_SENT_ROWS_label |
security_result.detection_fields |
已合并 |
INBOUND_DATA_TRANSFER_BYTES_label |
security_result.detection_fields |
已合并 |
IS_CLIENT_GENERATED_STATEMENT_label |
security_result.detection_fields |
已合并 |
LIST_EXTERNAL_FILES_TIME_label |
security_result.detection_fields |
已合并 |
OUTBOUND_DATA_TRANSFER_BYTES_label |
security_result.detection_fields |
已合并 |
PARTITIONS_SCANNED_label |
security_result.detection_fields |
已合并 |
PARTITIONS_TOTAL_label |
security_result.detection_fields |
已合并 |
PERCENTAGE_SCANNED_FROM_CACHE_label |
security_result.detection_fields |
已合并 |
QUERY_ACCELERATION_BYTES_SCANNED_label |
security_result.detection_fields |
已合并 |
QUERY_ACCELERATION_PARTITIONS_SCANNED_label |
security_result.detection_fields |
已合并 |
QUERY_ACCELERATION_UPPER_LIMIT_SCALE_FACTOR_label |
security_result.detection_fields |
已合并 |
QUERY_HASH_VERSION_label |
security_result.detection_fields |
已合并 |
QUERY_HASH_label |
security_result.detection_fields |
已合并 |
QUERY_LOAD_PERCENT_label |
security_result.detection_fields |
已合并 |
QUERY_PARAMETERIZED_HASH_VERSION_label |
security_result.detection_fields |
已合并 |
QUERY_TAG_label |
security_result.detection_fields |
已合并 |
QUERY_TYPE_label |
security_result.detection_fields |
已合并 |
QUEUED_OVERLOAD_TIME_label |
security_result.detection_fields |
已合并 |
QUEUED_PROVISIONING_TIME_label |
security_result.detection_fields |
已合并 |
QUEUED_REPAIR_TIME_label |
security_result.detection_fields |
已合并 |
RELEASE_VERSION_label |
security_result.detection_fields |
已合并 |
ROLE_TYPE_label |
security_result.detection_fields |
已合并 |
ROWS_DELETED_label |
security_result.detection_fields |
已合并 |
ROWS_INSERTED_label |
security_result.detection_fields |
已合并 |
ROWS_PRODUCED_label |
security_result.detection_fields |
已合并 |
ROWS_UNLOADED_label |
security_result.detection_fields |
已合并 |
ROWS_UPDATED_label |
security_result.detection_fields |
已合并 |
ROWS_WRITTEN_TO_RESULT_label |
security_result.detection_fields |
已合并 |
SCHEMA_ID_label |
security_result.detection_fields |
已合并 |
SCHEMA_NAME_label |
security_result.detection_fields |
已合并 |
TOTAL_ELAPSED_TIME_label |
security_result.detection_fields |
已合并 |
TRANSACTION_BLOCKED_TIME_label |
security_result.detection_fields |
已合并 |
TRANSACTION_ID_label |
security_result.detection_fields |
已合并 |
WAREHOUSE_ID_label |
security_result.detection_fields |
已合并 |
WAREHOUSE_NAME_label |
security_result.detection_fields |
已合并 |
WAREHOUSE_SIZE_label |
security_result.detection_fields |
已合并 |
WAREHOUSE_TYPE_label |
security_result.detection_fields |
已合并 |
authentication_factor_label |
security_result.detection_fields |
已合并 |
column4_label |
security_result.detection_fields |
已合并 |
column6_label |
security_result.detection_fields |
已合并 |
column7_label |
security_result.detection_fields |
已合并 |
column8_label |
security_result.detection_fields |
已合并 |
event_id_label |
security_result.detection_fields |
已合并 |
event_type_label |
security_result.detection_fields |
已合并 |
is_success_label |
security_result.detection_fields |
已合并 |
python_compiler_label |
security_result.detection_fields |
已合并 |
python_runtime_label |
security_result.detection_fields |
已合并 |
python_version_label |
security_result.detection_fields |
已合并 |
reported_client_type_label |
security_result.detection_fields |
已合并 |
reported_client_version_label |
security_result.detection_fields |
已合并 |
tracing_label |
security_result.detection_fields |
已合并 |
EXECUTION_STATUS |
security_result.summary |
直接映射 |
STATUS |
security_result.summary |
直接映射 |
column17 |
security_result.summary |
直接映射 |
TARGET_REGION |
target.cloud.availability_zone |
直接映射 |
TARGET_CLOUD |
target.cloud.environment |
映射:(?i)azure → MICROSOFT_AZURE、(?i)amazon → AMAZON_WEB_SERVICES、(?i)google ... |
TARGET_CLOUD_label |
target.resource.attribute.labels |
已合并 |
column2_label |
target.resource.attribute.labels |
已合并 |
column7_label |
target.resource.attribute.labels |
已合并 |
USER_NAME |
target.user.userid |
直接映射 |
column4 |
target.user.userid |
直接映射 |
| 不适用 | extensions.auth.type |
常量:AUTHTYPE_UNSPECIFIED |
| 不适用 | metadata.event_type |
常量:NETWORK_CONNECTION |
| 不适用 | metadata.product_name |
常量:SNOWFLAKE |
| 不适用 | metadata.vendor_name |
常量:SNOWFLAKE |
| 不适用 | principal.cloud.environment |
常量:MICROSOFT_AZURE |
| 不适用 | principal.platform |
常量:LINUX |
| 不适用 | target.cloud.environment |
常量:MICROSOFT_AZURE |