收集 Snowflake 記錄
本文說明如何使用 AWS S3,將 Snowflake 記錄擷取至 Google Security Operations。剖析器會使用一系列 Grok 和 KV 模式比對規則,從記錄訊息中擷取欄位,這些規則專門用於處理 Snowflake 記錄格式。接著,系統會將擷取的欄位對應至整合式資料模型 (UDM),並以額外情境資訊擴充資料,以及將資料表示法標準化,以供進一步分析。
事前準備
請確認您已完成下列事前準備事項:
- Google SecOps 執行個體
- AWS 的特殊存取權
- Snowflake 的特殊存取權 (ACCOUNTADMIN)
設定 Amazon S3 儲存貯體
- 按照這份使用者指南建立 Amazon S3 bucket:建立 bucket
- 請儲存值區的「名稱」和「區域」,以供日後參考。
設定 Snowflake AWS IAM 政策
- 登入 AWS 管理主控台。
- 搜尋並選取「IAM」。
- 選取「帳戶設定」。
- 在「Endpoints」(端點) 清單的「Security Token Service」(安全權杖服務) (STS) 下方,找出帳戶所在的 Snowflake 區域。
- 如果 STS 狀態為「inactive」(停用),請將切換鈕移至「Active」(啟用)。
- 選取「政策」。
- 選取「建立政策」。
- 在「政策編輯器」中,選取「JSON」。
複製並貼上下列政策 (JSON 格式),為 Snowflake 提供必要權限,以便使用單一 bucket 和資料夾路徑載入或卸載資料。您也可以使用 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」。
- 按一下「建立角色」。
- 選取「AWS 帳戶」做為信任的實體類型。
- 選取「Another AWS account」(其他 AWS 帳戶)。
- 在「帳戶 ID」欄位中,暫時輸入您自己的 AWS 帳戶 ID。稍後,您會修改信任關係,並授予 Snowflake 存取權。
- 選取「需要外部 ID」選項。
- 輸入預留位置 ID,例如 0000。在後續步驟中,您將修改 IAM 角色的信任關係,並指定儲存空間整合的外部 ID。
- 點選「下一步」。
- 選取您先前建立的 IAM 政策。
- 點選「下一步」。
- 輸入角色的名稱和說明。
- 按一下「建立角色」。
- 在角色摘要頁面中,複製並儲存「Role ARN value」。
設定 Snowflake S3 整合
- 連線至 Snowflake 資料庫。
取代下列欄位並執行指令:
<integration_name>是新整合的名稱 (例如 s3_integration)。<iam_role>是您先前建立的角色 Amazon Resource Name (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 匯出資料
執行卸載指令,將資料從資料表匯出至暫存區,然後匯出至 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 使用者。
- 選取建立的「使用者」。
- 選取「安全憑證」分頁標籤。
- 在「Access Keys」部分中,按一下「Create Access Key」。
- 選取「第三方服務」做為「用途」。
- 點選「下一步」。
- 新增說明標記 (如有需要)。
- 按一下「建立存取金鑰」。
- 按一下「下載 CSV 檔案」,儲存「存取金鑰」和「私密存取金鑰」,以供日後參考。
- 按一下 [完成]。
- 選取「權限」分頁標籤。
- 在「權限政策」部分中,按一下「新增權限」。
- 選取「新增權限」。
- 選取「直接附加政策」。
- 搜尋並選取 AmazonS3FullAccess 政策。
- 點選「下一步」。
- 按一下「Add permissions」。
設定動態饋給
如要設定動態饋給,請按照下列步驟操作:
- 依序前往「SIEM 設定」>「動態饋給」。
- 按一下「新增動態消息」。
- 在下一個頁面中,按一下「設定單一動態饋給」。
- 在「動態饋給名稱」欄位中,輸入動態饋給的名稱 (例如「Snowflake Logs」)。
- 選取「Amazon S3 V2」做為「來源類型」。
- 選取「Snowflake」做為「記錄類型」。
- 點選「下一步」。
指定下列輸入參數的值:
- S3 URI:值區 URI (格式應為
s3://your-log-bucket-name/)。 請替換下列項目:your-log-bucket-name:值區名稱。
- 來源刪除選項:根據偏好設定選取刪除選項。
- S3 URI:值區 URI (格式應為
點選「下一步」。
在「Finalize」(完成) 畫面中檢查新的動態饋給設定,然後按一下「Submit」(提交)。
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 |
變更記錄
還有其他問題嗎?向社群成員和 Google SecOps 專業人員尋求答案。