Grabit connects to Snowflake using key pair authentication

2021/09/07 Grabit SQLFlow 1480 characters,About 5 minutes

Snowflake supports using key pair authentication for enhanced authentication security as an alternative to basic authentication (i.e. username and password).

Grabit supports using key pair authentication as well. In order to connect to Snowflake using key pair authentication, you need to configure Key Pair Authentication first.

Configure the grabit

After that, you may use a grabit config file like this to connect to Snowflake:

{
    "databaseServer":{
        "hostname":"127.0.0.1",
        "port":"433",
        "username":"USERNAME",
        "privateKeyFile":"/data/rsa_key.p8",
      	"privateKeyFilePwd":"123456",
        "database":"DATABASE",
      	"enableQueryHistory":true,
      	"queryHistoryBlockOfTimeInMinutes":30,
      	"queryHistorySqlType":"SELECT,UPDATE",
      	"snowflakeDefaultRole":"custom_role"
    },
    "SQLFlowServer":{
        "server":"http:127.0.0.1",
        "serverPort":"8081",
        "userId":"gudu|0123456789",
        "userSecret":""
    },
    "SQLScriptSource":"database",
    "databaseType":"snowflake"
}
  • privateKeyFile, this is the file that store the private key.
  • privateKeyFilePwd, this is the password used when generate the key, leave it empty if not used.
  • other optins, please check this document for detailed explanation.

Fetch SQL from qurey history

In order to fetch SQL from query history, we need to create a role that able to access SNOWFLAKE database, and this role is able to access WAREHOUSE as well.

For example, we create a role: custom_role, and assign privileges of test_warehouse to this role like this:

use role accountadmin;
grant imported privileges on database snowflake to role custom_role;
use role custom_role;

use role sysadmin
GRANT ALL PRIVILEGES ON WAREHOUSE test_warehouse TO role custom_role;

Official Document about QUERY_HISTORY

Document information

Search

    Table of Contents