For the complete documentation index, see llms.txt. This page is also available as Markdown.

Snowflake

Install the Snowflake (AI) integration so agents behind the P0 AI Gateway can request temporary Snowflake roles and object privileges through Snowflake's managed MCP server.

The Snowflake (AI) integration lets agents behind the P0 AI Gateway (see P0 Runtime Access for AI) request temporary access to a Snowflake account. Each approved request gets its own Snowflake user and role, both named P0_AGENT_<request ID>. The gateway calls Snowflake's managed MCP server as that user. When the grant ends, P0 disables the user, which stops its running queries, then removes the user, its role and its token. Tables and other objects the agent created stay in your account, owned by an empty role named P0_AGENT_<request ID>_OWNER that has no privileges.

Agents can request two kinds of access:

  • Role: an existing role in your account.

  • Objects: SELECT, INSERT, UPDATE, or DELETE on a database, a schema, a table, or a view.

Only agents can use this integration. People request Snowflake access through the Snowflake integration, which is separate.

The Snowflake (AI) integration is in beta. Functionality and configuration may change.

The connector also gets IMPORTED PRIVILEGES on the SNOWFLAKE database, which lets it read all of SNOWFLAKE.ACCOUNT_USAGE. That includes the text of every query in your account's query history, and its login history, not only the lists of databases, schemas, tables, and views that P0 uses.

The connector creates, changes, and drops only users and roles named P0_AGENT_<request ID>, and refuses any other. In your secret manager it can read only its own private key. In Google Secret Manager it can create a secret of any name in the project, but read, write, and delete only agents' token secrets, whose names start with p0_access-token_snowflake-ai_<account>_. In AWS Secrets Manager it can create, write, and delete only agents' token secrets, whose names start with p0/access-token/snowflake-ai/<account>/.

Setup has three parts, in this order:

  1. Install the account in P0. You create the connector's key pair, create P0's objects in Snowflake with the Terraform or SQL that P0 generates, deploy P0's connector in AWS or Google Cloud with its Terraform, and store the connector's private key.

  2. Add the Snowflake MCP server to your gateway.

  3. Write the policies that decide which agents get which access.

Prerequisites

  • A registered Gateway component, with the gateway deployed in your environment.

  • One of these, with permission to apply Terraform where it's installed. P0's connector runs there, and agents' Snowflake tokens are stored there.

    • The AWS Secrets Manager integration installed on an AWS account. The connector runs on AWS Lambda. Applying its Terraform also needs Docker and the AWS CLI, signed in to that account, to copy P0's connector image into your Amazon ECR.

    • The Google Secret Manager integration installed on a Google Cloud project. The connector runs on Cloud Run.

  • A Snowflake user with the ACCOUNTADMIN role, to create P0's objects and grant USERADMIN and SECURITYADMIN to the connector.

  • openssl on the machine you set up from.

Network policies

P0 gives every agent user the authentication policy P0_AI.MCP.P0_AGENT_AUTH. It lets agents sign in only with their programmatic access token, and lets Snowflake accept that token without a network policy, so agents' tool calls work from your gateway without you listing its IP addresses.

If your account has a network policy, it must still allow the IP addresses P0's connector reaches Snowflake from. Neither Lambda nor Cloud Run has a fixed outbound IP address unless you route it through one: on AWS, a VPC with a NAT gateway, and on Google Cloud, a static IP address.

Install the account in P0

  1. Navigate to Integrations on p0.app, select Snowflake (AI), and choose the Credential provisioning component.

  2. Click to add an account, and enter its account identifier in upper case, in the form <ORGNAME>-<ACCOUNTNAME>, such as MYORG-PROD. Agents and policies use this identifier for the account.

  3. For Secret manager provider, choose where the connector will run:

    • AWS Secrets Manager: choose the installation for the AWS account, and enter the region that stores the secrets.

    • Google Secret Manager: choose the installation for the project.

    Click Next.

  4. P0 generates the install configuration in two tabs. Both create the same objects:

    • Terraform: the Snowflake objects on Snowflake's Terraform provider, and P0's connector.

    • Shell: the Snowflake objects as SQL, to run in a Snowflake worksheet as ACCOUNTADMIN, and the Terraform for P0's connector on its own.

    The configuration creates, in Snowflake:

    • A service user and a role, both named P0_AI_CONNECTOR. The role has USERADMIN and SECURITYADMIN.

    • A warehouse, P0_AI_WH, size XSMALL with auto-suspend. P0 uses it only to list your roles, warehouses, databases, schemas, tables, and views.

    • IMPORTED PRIVILEGES on the SNOWFLAKE database, which gives the connector read access to all of SNOWFLAKE.ACCOUNT_USAGE, including query history and login history.

    • A database, P0_AI, a schema, P0_AI.MCP, and the managed MCP server P0_AI.MCP.P0_SQL_V1.

    • The authentication policy P0_AI.MCP.P0_AGENT_AUTH, which P0 gives every agent user, and APPLY on it for P0_AI_CONNECTOR.

    In AWS, it creates an Amazon ECR repository with a copy of P0's connector image, a Lambda function that runs it with its own IAM role, the secret that holds the connector's private key, and the IAM that lets P0 invoke the function and the connector manage agents' token secrets.

    In Google Cloud, it turns on the Cloud Resource Manager, IAM, Cloud Run, and Secret Manager APIs. It creates a service account and a Cloud Run service that runs P0's connector as it, the secret that holds the connector's private key, and custom roles that let the connector manage agents' token secrets.

    The Terraform tab also shows the same install as resources of P0's Terraform provider, for when you manage P0 in Terraform. These resources, p0_snowflake_ai_staged and p0_snowflake_ai, need version 0.77.0 or later, and 0.80.0 or later for AWS Secrets Manager.

    The Snowflake Terraform needs Snowflake's provider version 2.21.0 or later, the first with a stable snowflake_mcp_server resource.

  5. Generate the connector's key pair with the commands P0 shows. The connector signs in to Snowflake with this key pair. P0 never sees the private key.

    The connector needs an unencrypted PKCS8 key, which these commands create.

  6. Apply the configuration. Snowflake takes the public key on one line, without its BEGIN and END lines. Print it in that form with:

    • On the Terraform tab, apply the Terraform, passing that output as the variable p0_connector_public_key.

    • On the Shell tab, apply the connector's Terraform. Then replace <public key> in the SQL with that output, and run the SQL as ACCOUNTADMIN.

  7. Store the private key in the secret that the Terraform created, with the command P0 shows. In the secret name, the account identifier has each _ replaced by -.

    On AWS, it sets rsa_key.p8 as the value of the secret p0/install/snowflake-ai/<account>/private-key:

    On Google Cloud, it adds rsa_key.p8 as a version of the secret p0_install_snowflake-ai_<account>_private-key:

    The connector can't sign in until the secret holds the key. Delete the local copy of rsa_key.p8 once it is stored, then click Next.

  8. P0 checks the install. It checks that the connector can read its private key and sign in, that its role has USERADMIN and SECURITYADMIN, that it can read SNOWFLAKE.ACCOUNT_USAGE, that the MCP server P0_AI.MCP.P0_SQL_V1 exists, and that the authentication policy P0_AI.MCP.P0_AGENT_AUTH exists. If a check fails, P0 names it. Fix it and try again.

  9. Review the summary and click Finish. The account now appears with the state Installed.

Repeat for each Snowflake account you want agents to reach.

Rotate the connector's key

The key doesn't expire. To rotate it without a gap, use the user's second key slot, so Snowflake accepts both keys while the connector switches:

  1. Generate a new key pair with the commands above.

  2. Add the new public key as the user's second key:

  3. Store the new private key in the same secret, with the same command as at install.

  4. Remove the old public key:

If you manage the user in Terraform, make the same changes to its rsa_public_key_2 and rsa_public_key attributes. At the next rotation, the slots swap: set the new key as RSA_PUBLIC_KEY, then unset RSA_PUBLIC_KEY_2.

Add the Snowflake MCP server

  1. Follow the shared steps in Add an MCP server to name the server and choose its gateway. On the configuration screen, set the following fields, then click Finish:

    • Definition: choose P0, then select Snowflake (<account>) for the account this server reaches.

    • Credential source: choose Vaulted credential. Each grant names the secret that holds the agent's Snowflake token, and the gateway reads the token from there.

  2. The server now appears with the state Installed.

To add the server with P0's Terraform provider instead, use the p0_ai_gateway_server resource. Set definition.id to snowflake: followed by the account identifier exactly as you installed it, in upper case:

Add one server for each Snowflake account agents should reach. Each server reaches only its own account: agents requesting access through it don't name an account.

The server has one tool, sql_exec_tool, which runs a SQL statement as the agent's Snowflake user. The agent's grants are the only limit on what that SQL can do.

How agents request access

An agent requests access with the server's access tool, for the account that server reaches. Every request names a warehouse and how long the access lasts, which can be at most 365 days. P0 refuses a request with no end time or a longer one. If an approver sets a later expiry, the grant fails when P0 provisions it. P0 grants the agent that warehouse and makes it the agent's default, so its queries run there, and Snowflake bills its use to your account.

  • Role: one or more existing roles in the account, by name.

  • Objects: one or more grants, each written as <PRIVILEGE>:<OBJECT>. The object is a database (SALES), a schema (SALES.PUBLIC), or a table or view (SALES.PUBLIC.ORDERS). For example, SELECT:SALES.PUBLIC and INSERT:SALES.PUBLIC.ORDERS.

A grant on a database or schema covers the tables and views that exist in it when access is granted. Tables and views created later aren't covered. Views take SELECT only. P0 adds USAGE on the parent database and schema.

New databases, schemas, tables, and views can take up to about 90 minutes to appear in P0's lists.

Once a request is approved, the agent's tool calls run as its own Snowflake user. Snowflake's query history shows its queries under that user's name, P0_AGENT_<request ID>.

Access ends in Snowflake even if P0 can't revoke it. The agent's user and its token expire on their own within a day of the grant's end.

See Requesting access for how agents submit and use requests.

Write policies for Snowflake

Match Snowflake requests in an agentic access policy (see Agentic access policies) with service: snowflake-ai, and accessType: role or accessType: objects. These filters narrow them:

  • account: the account, keyed on id, its identifier.

  • warehouse: the warehouse, keyed on name.

  • role: the requested role, keyed on name. Role requests only.

  • object: the requested object, keyed on name, as DB, DB.SCHEMA, or DB.SCHEMA.OBJECT. Objects requests only.

  • privilege: the requested privilege, keyed on name. Objects requests only.

  • grant: the whole grant, keyed on entry, as <PRIVILEGE>:<OBJECT>. Objects requests only.

P0 writes names in upper case, and patterns are case-sensitive, so write your patterns in upper case. A lower-case pattern never matches. In a filter with effect: keep, that only refuses requests. In a policy that denies requests, or a filter with effect: remove, it excludes nothing, so the policy allows access you meant to stop. A role, warehouse, or object whose name was created in quotes with lower-case letters can't be requested.

One policy must cover a whole request. For a request with several roles or grants, a single policy must allow every one of them. An agent that needs access allowed by two different policies makes two requests.

Anchor your patterns

In a pattern, . matches any character, so ^SALES.PUBLIC$ also matches a database named SALES_PUBLIC. Write \. to match only a dot, as the examples below do.

Start each pattern with ^, and end it with $ or \.. A pattern without anchors matches more than it looks like it does. SALES also matches PRESALES, and ^SALES also matches SALES_ARCHIVE.

  • ^SALES\. matches every schema, table, and view in the SALES database, but not the database itself.

  • ^SALES(\.|$) also matches the SALES database.

  • ^SALES\.PUBLIC\.ORDERS$ matches one table.

Grant objects

The object and privilege filters each check every grant on their own. A policy that allows the objects ^(SALES|HR)\. and the privileges ^(SELECT|DELETE)$ also allows DELETE on SALES. To tie a privilege to an object, use the grant filter.

For example, auto-approve read-only access to the SALES database for one agent, in the MYORG-PROD account:

Grant roles

For example, auto-approve one read-only role for one agent:

Next steps

Last updated