使用出口 IP 地址保护 Snowflake 请求的入口¶
您可以通过允许 Snowflake 生成的出口 IP 地址范围通过资源的网络防火墙,安全地允许 Snowflake 对您的外部资源进行入口访问。
您可以生成 Snowflake 出口 IP 地址范围列表(如无类别域间路由 (CIDR) 地址),可用于代表 Snowflake 允许通过外部服务器的网络防火墙进行访问。
支持的部署
稳定出口 IP 地址可用于 AWS 商业部署。
支持的用法
使用 Snowflake 生成的出口 IP 地址,您可以允许从以下 Snowflake 功能进行入口访问:
- External access from UDFs and procedures
- Snowpark Container Services external access and Snowflake Openflow on Snowpark Container Services
- Snowflake Git integration with IP-restricted Git servers
生成出口 IP 地址范围¶
You can generate IP address ranges that Snowflake uses for egress traffic by using the SYSTEM$GET_SNOWFLAKE_EGRESS_IP_RANGES function.
The generated IP addresses expire, so for ongoing needs you should set up a means to automate refreshing your external server’s firewall with fresh egress IP addressess, as described in 自动化 IP 地址范围刷新.
要生成和使用 Snowflake 出口 IP 地址,请按照以下步骤操作:
- Call SYSTEM$GET_SNOWFLAKE_EGRESS_IP_RANGES to get the current and upcoming IP ranges and their expiration times.
以下代码显示了该函数的示例输出。
- The
IP CIDR RANGE_EFFECTIVEcolumn shows the start date when a range starts carrying traffic. A new range should emerge in function output at least 60 days before being “effective”. - The
IP CIDR RANGE_EXPIRATIONcolumn shows the date when an IP range stops carrying traffic.
- Use the IP ranges you obtain to update firewall rules by using APIs, CLIs, or configuration management tools, as described in 自动化 IP 地址范围刷新.
自动化 IP 地址范围刷新¶
Snowflake 出口 IP 地址过期。为了确保访问安全,您必须更新允许通过外部服务器防火墙的 Snowflake 出口 IP 地址,保持其最新状态。
To keep IP addresses fresh, implement a mechanism to trigger these updates to your external server regularly, such as daily or weekly. You might do this, for example, by using your environment’s tools.
要进行更新,请在脚本中执行以下步骤:
- Retrieve Snowflake egress IP address ranges by using SYSTEM$GET_SNOWFLAKE_EGRESS_IP_RANGES.
- 将新检索到的范围与您当前使用的范围进行比较。
您可以通过仅在地址范围不同时进行更新来避免不必要的更改。
- If they aren’t different, have your script use expiration dates to set a time to check again, such as a few days before the expiration.
- If the newly-retrieved list is different, update your firewall rule programmatically with the new addresses. You can then have the script set a new date to check, such as a few days before the new expiration.
- 记录脚本所做的更改,并设置更新成功或失败时的警报。
使用环境工具自动更新
您可以使用脚本和工具,自动执行保持 Snowflake IP 地址最新状态的任务。下面介绍两个示例:
- 编写脚本时使用 APIs 和 CLIs 云提供商,例如 AWS、Azure 和 Google Cloud。
对于云环境,您可以使用 Python、PowerShell 和 Bash 等工具来编写脚本。您的工具可以执行以下任务:
- Call SYSTEM$GET_SNOWFLAKE_EGRESS_IP_RANGES to retrieve the latest IP address ranges and expiration dates.
- 使用云提供商的 API 或 CLI 来更新安全组规则、网络 ACLs 或防火墙策略。
- Schedule scripts that perform these actions to run periodically (such as daily or weekly) or based on expiry dates using cron jobs. You can run these by using stored procedures with Snowflake tasks.
- 基础设施即代码 (IaC) 工具
您可以使用 Terraform、Ansible 或 CloudFormation 等工具以代码形式管理防火墙规则。下面描述的方法还为防火墙规则变更提供版本控制和审计跟踪。
使用这些工具,您可以执行以下任务:
- 在 IaC 配置中定义防火墙规则。
- Call SYSTEM$GET_SNOWFLAKE_EGRESS_IP_RANGES to retrieve the latest IP address ranges and expiration dates.
- 当有新的 Snowflake 出口 IP 范围可用时,请使用新范围更新您的 IaC 配置。
- 使用 IaC 工具应用变更,确保以编程方式和幂等方式更新防火墙规则。