Set up external access for Snowflake Notebooks¶
When working with notebooks, you might need to call external services, which often require sensitive credentials such as API keys. To keep sensitive information secure, you can use secrets managed within Snowflake instead of hardcoding credentials in your notebook.
External access integrations (EAIs) are configured using network rules and can optionally use Snowflake secrets for authentication.
By default, Snowflake restricts network traffic from external endpoints. To access external endpoints, follow these steps:
Create a network rule.
Create an external network access integration that uses the rule.
Create a secret for authentication (if needed). Generic string secrets also require an EAI.
Associate the secret with the EAI.
Associate the EAI and secret with the notebook.
Note
EAIs and network rules must be created by an organization administrator. For required privileges, see Access control requirements.
Configure a notebook with external access and secrets¶
This end-to-end example shows how to configure a notebook to access the OpenAI API using a generic string secret.
Note
Secrets must be associated with both the external access integration (EAI) and the notebook. If a secret is associated with only one, it will not be accessible from notebook code.
Access the secret inside a notebook¶
After associating the secret with the notebook, to access its value in notebook code, use the
st.secretsobject:
Additional EAI examples¶
These examples show how to set up external access for common data science and machine learning sites:
EAI for PyPI¶
EAI for Hugging Face¶
Grant USAGE privileges to use external access integrations¶
After you create the EAIs, grant the USAGE privilege on the integration to roles that will use them:
The role used to create the notebook must have USAGE on the EAI. Granting USAGE to the PUBLIC role will not work.
Enable external access integrations in Snowsight¶
After you create and provision EAIs, restart the notebook session in order to see the access integrations you created in the External Access pane.
To enable integrations using Snowsight:
Additional authentication examples¶
OAuth access token¶
Secret type: GENERIC_STRING¶
Use a GENERIC_STRING secret to store a single value, such as an API key or token.
Create the secret:
For GENERIC_STRING secrets, access them by dictionary or attribute style:
Secret type: PASSWORD (example: GitHub Basic Auth)¶
Use a PASSWORD secret to store a username and password pair. These are often required for basic authentication with external APIs.
In this example, the notebook accesses the GitHub REST API using a PASSWORD secret and an external access integration.
Create the secret:
Use the secret as part of an EAI:
Access the secret in your code:
Additional resources¶
For detailed syntax, see External network access overview.
For details on using CREATE SECRET, see Creating a secret to represent credentials.
For additional examples of EAIs, see External network access examples or Setting up External Access for Snowflake Notebooks on Github.
