Snowflake log ingestion via Azure Functions — image 1

If you were curious about ingesting Login Events, Query Execution Events, System Activity & Performance Counters, Security Events..or not, I will walk you through the simple process of getting it done. Let’s also remember that there are multiple methods for forwarding logs…..Event Hubs, Cribl, etc, depending on scalability.

me rn, it’s 1:45AM me rn, it’s 1:45AM

FYSA, I tried to deploy the Funciton App manually before finally deciding on the automated deployment.

Snowflake log ingestion via Azure Functions — image 3

Step 1: Create a Log Analytics Workspace

First, make sure your Log Analytics workspace is created. For further instructions, click this embedded link for “Create a Log Analytics workspace.” Now that the first step is complete, you should have a new workspace and resource group.

Snowflake log ingestion via Azure Functions — image 4

Let’s attach Sentinel to it by following this guide; “Quickstart: Onboard Microsoft Sentinel.” The first step is complete!

Snowflake log ingestion via Azure Functions — image 5

Now that Sentinel is onboarded, we can go ahead and scroll down to data connectors and click “More content at Content Hub” on the top right.

Snowflake log ingestion via Azure Functions — image 6

You will install the Snowflake content from this page and include the Snowflake data connector.

Snowflake log ingestion via Azure Functions — image 7

Step 2: Creating a User in Snowflake

To query data from Snowflake, you need a user assigned to a role with sufficient privileges and a virtual warehouse cluster; please make sure to note down all the relevant credentials and your “Account Identifier.” The initial cluster size will be set to SMALL, but it can be adjusted as needed. FYSA, you can get 30 days of free access to Snowflake to test with (https://signup.snowflake.com/).

1. Enter the Snowflake Console and Create a Role

Switch to the SECURITYADMIN role and create a new role:

USE ROLE SECURITYADMIN;
CREATE OR REPLACE ROLE EXAMPLE_ROLE_NAME;

Snowflake log ingestion via Azure Functions — image 8

2. Create a Warehouse and Grant Access

Switch to the SYSADMIN role, create a warehouse, and grant access to the role:

USE ROLE SYSADMIN;
CREATE OR REPLACE WAREHOUSE EXAMPLE_WAREHOUSE_NAME
    WAREHOUSE_SIZE = 'SMALL'
    AUTO_SUSPEND = 5
    AUTO_RESUME = TRUE
    INITIALLY_SUSPENDED = TRUE;

GRANT USAGE, OPERATE ON WAREHOUSE EXAMPLE_WAREHOUSE_NAME TO ROLE EXAMPLE_ROLE_NAME;

Snowflake log ingestion via Azure Functions — image 9

3. Create a User

Switch back to the SECURITYADMIN role and create a new user:

USE ROLE SECURITYADMIN;
CREATE OR REPLACE USER EXAMPLE_USER_NAME
    PASSWORD = 'example_password'
    DEFAULT_ROLE = EXAMPLE_ROLE_NAME
    DEFAULT_WAREHOUSE = EXAMPLE_WAREHOUSE_NAME;

Snowflake log ingestion via Azure Functions — image 10

4. Grant Database Access

Switch to the ACCOUNTADMIN role and grant access to the Snowflake database:

USE ROLE ACCOUNTADMIN;
GRANT IMPORTED PRIVILEGES ON DATABASE SNOWFLAKE TO ROLE EXAMPLE_ROLE_NAME;

Snowflake log ingestion via Azure Functions — image 11

5. Assign Role to User

Switch back to the SECURITYADMIN role and assign the role to the user:

USE ROLE SECURITYADMIN;
GRANT ROLE EXAMPLE_ROLE_NAME TO USER EXAMPLE_USER_NAME;

Snowflake log ingestion via Azure Functions — image 12

Step 3: Automated deployment of the data connector using an ARM Template

Snowflake log ingestion via Azure Functions — image 13

The appropriate page will be found under the connector page.

Snowflake log ingestion via Azure Functions — image 14

More information on ARM templates can be found in the embedded link. Now that we have clicked “Deploy to Azure,” we will be greeted with the “Custom Deployment” page, which can be seen below. On this page, you are tasked with filling in the necessary information we noted down earlier and clicking “Review + Create” on the bottom left;

Subscription:

Resource group:

Region:

Function Name:

Snowflake Account Identifier:

Snowflake User:

Snowflake Password:

Azure Sentinel Workspace Id:

Azure Sentinel Shared Key:

App Insights Workspace Resource ID:

Snowflake log ingestion via Azure Functions — image 15

Step 4: Confirming Function App Configurations

Under “Function App” in Azure, choose the newly created function app and scroll to the “Configuration” option.

What is a function app, you may be asking. Function Apps are serverless applications that run code only when triggered.

Snowflake log ingestion via Azure Functions — image 16

This will take you to the “Environment Variables” tab, where you can view and edit all the variables within the function app:

Snowflake log ingestion via Azure Functions — image 17

Now that this is complete, you can scroll back up to Overview and click on “Invocations and more” under “Monitor”:

Snowflake log ingestion via Azure Functions — image 18

Under “Logs”, you’ll notice that there's a “Connecting to Application Insights…” message before ultimately connecting and displaying a message confirming the ingestion of logs.

Snowflake log ingestion via Azure Functions — image 19

Step 5: Confirming Snowflake Connector Status

Once you have completed the steps, your connector should show as “Connected,” and Snowflake logs should be coming in.

Snowflake log ingestion via Azure Functions — image 20

Snowflake log ingestion via Azure Functions — image 21

Let’s go check our logs!

Snowflake log ingestion via Azure Functions — image 22

You thought this was where it ended? Wrong. Now that logs are coming into Sentinel, we should create a simple analytic rule to catch possible brute-force attempts.

Snowflake log ingestion via Azure Functions — image 23

Step 6: Creating Rule To Detect Possible Bruteforce

Under your Sentinel page, scroll to “Analytics” and click “Create,” where you can choose between scheduled query rules, NRT query rules, or Microsoft incident creation rules.

Snowflake log ingestion via Azure Functions — image 24

Let's click on “ NRT query rules” and choose an appropriate name, description, severity, and MITRE ATT&CK that are relevant to the detection you're creating.

Snowflake log ingestion via Azure Functions — image 25

Click Next, and now we have to define the logic(this query finds users with 3 or more failed login attempts within each one-minute interval, grouping by user and IP address):

Snowflake_CL
| where EVENT_TYPE_s == "LOGIN"
| where IS_SUCCESS_s == "NO"  // Filter failed login attempts
| summarize FailedAttempts = count() by USER_NAME_s, bin(TimeGenerated, 1m), CLIENT_IP_s
| where FailedAttempts >= 3
| project TimeGenerated, USER_NAME_s, CLIENT_IP_s, FailedAttempts

Snowflake log ingestion via Azure Functions — image 26

Ultimately, you click “Review & Create” after tweaking any settings under “Incident Settings” and “Automated Response”. You should now have a new NRT rule created!

Snowflake log ingestion via Azure Functions — image 27

Snowflake log ingestion via Azure Functions — image 28

Finally, let’s try to lock our user from Snowflake in an attempt to trigger this alert. After locking ourselves out, we receive an alert in the queue for “Failed Logins for ENLEAK”?!

Snowflake log ingestion via Azure Functions — image 29

Thank you for reading. Have a nice day :).