Skip to main content

Query Snowflake Configuration and Identities

Mondoo's snowflake provider lets you query critical data in your Snowflake account.

Requirements

To analyze and explore your Snowflake account with cnquery, you must have:

Connect to Snowflake

To explore Snowflake with cnquery, you must first authenticate with Snowflake. To do so, create a RSA key pair and assign the public key to your user account using Snowsight. To learn how, read Key-pair authentication and key-pair rotation in the Snowflake documentation.

In your shell, run:

shell snowflake --account ACCOUNT-ID --region REGION --user YOUR-ID  --role YOUR-ROLE --private-key YOUR-KEY
For...Substitute...
ACCOUNT-IDThe ID of the Snowflake account to explore (To learn how to get your Snowflake account ID, read Finding the organization and account name for an account.)
REGIONYour account's region
YOUR-USER-IDThe ID you use to log into Snowflake
YOUR-ROLEThe role you use (To learn about roles, read System-defined roles.)
YOUR-KEYThe path to your private key you generated and assigned to your account

For example, run:

shell snowflake --account zi12345 --region us-central1.gcp --user CHRIS  --role ACCOUNTADMIN --private-key ~/.ssh/id_rsa

Explore a Snowflake account with cnquery shell

Use this command to open cnquery shell and query your Snowflake configuration and identities:

cnquery shell snowflake --account ACCOUNT-ID --region REGION -- user YOUR-USER-ID -- role YOUR-ROLE --ask-pass~/.ssh/id_rsa
For...Substitute...
ACCOUNT-IDThe ID of the Snowflake account to explore (To learn how to get your Snowflake account ID, read Finding the organization and account name for an account.)
REGIONYour account's region
YOUR-USER-IDThe ID you use to log into Snowflake
YOUR-ROLEThe role you use (To learn about roles, read System-defined roles.)
YOUR-KEYThe path to your private key you generated and assigned to your account
cnquery shell snowflake --account zc74621 --region us-central1.gcp -- user STELLA -- role ACCOUNTADMIN --private-key ~/.ssh/id_rsa

Example queries

This query retrieves all users:

cnquery> snowflake.account.users
snowflake.account.users: [
0: snowflake.user name="STELLA"
1: snowflake.user name="MWEZI"
2: snowflake.user name="SNOWFLAKE"
]

This query retrieves all users that have no MFA:

cnquery> snowflake.account.users.where(extAuthnDuo == false)
snowflake.account.users.where: [
0: snowflake.user name="MWEZI"
1: snowflake.user name="SNOWFLAKE"
]

This query retrieves all users that have password authentication:

cnquery> snowflake.account.users.where(hasPassword)
snowflake.account.users.where: [
0: snowflake.user name="STELLA"
1: snowflake.user name="MWEZI"
2: snowflake.user name="SNOWFLAKE"
]

This query retrieves all users that have certificate authentication:

cnquery> snowflake.account.users.where(hasRsaPublicKey)
snowflake.account.users.where: [
0: snowflake.user name="STELLA"
]

This query retrieves all databases:

cnquery> snowflake.account.databases
snowflake.account.databases: [
0: snowflake.database name="MARS_SAMPLES"
1: snowflake.database name="SECURITY_EXPORTS"
2: snowflake.database name="VELOCITY"
]

Exit the cnquery shell

To exit the cnquery shell, either press Ctrl + D or type exit.

Learn more about querying Snowflake