HTTP rules¶
HTTP rules are schema-level objects that allow outgoing HTTP requests by destination, method, and path.
A network rule with TYPE = HOST_PORT allows every request to the hosts it names. An HTTP rule allows
only the requests that match it: for example, GET and HEAD requests under /simple/ on pypi.org, but no POST, and no other path.
You add HTTP rules to an external access integration with the
ALLOWED_HTTP_RULES parameter, alongside or instead of network rules.
Where HTTP rules apply¶
HTTP rules apply to Cortex Code cloud sandboxes. A sandbox that uses an external access integration can send each request that one of the integration’s network rules or HTTP rules allows.
Only Cortex Code cloud sandboxes check the method and path of each request, so only they can apply HTTP rules. Other features that use external access integrations, such as UDFs, stored procedures, Snowpark Container Services, notebooks, and Streamlit apps, allow or block requests by host and port: they ignore an integration’s HTTP rules and use only its network rules. Adding an integration that holds HTTP rules to these features doesn’t cause an error, but its HTTP rules allow nothing there.
Note
Enforcement of HTTP rules in Cortex Code cloud sandboxes is being rolled out by region. Until it reaches your region, an HTTP rule allows nothing in a sandbox, and the integration’s network rules still apply.
How HTTP rules combine with network rules¶
A request from a sandbox is allowed if any network rule or any HTTP rule in any of the sandbox’s external access integrations allows it:
- A network rule allows every method and path on the hosts and ports it names.
- An HTTP rule allows a request only if the request’s destination, transport, method, and path all match one of its entries.
Because either kind of rule can allow a request, an HTTP rule can’t narrow what a network rule for the same host allows. To limit a host to certain methods and paths, name the host in an HTTP rule and in no network rule.
Writing an HTTP rule¶
An HTTP rule holds one property, its specification: a YAML document that lists destinations and, for each destination, the requests it
allows. For example, the following specification allows GET and HEAD requests for Python package indexes and package files:
Each entry in matches names one destination:
destinationnames a host, or a host and port, such aspypi.orgor'example.com:8443'. The default port is 443. A host can start with one wildcard label, such as'*.example.com'.tlslists the requests allowed over HTTPS.httplists the requests allowed over plain HTTP, and needs a port in the destination, such as'deb.debian.org:80'.- Each request entry can hold a
methodpattern and apathpattern. A request is allowed if it matches both patterns of any one entry. An entry without amethodmatches every method, and an entry without apathmatches every path.
Patterns are regular expressions in a restricted subset. Each pattern must match the whole method or path, and matching is case-sensitive. For the full specification format, the pattern syntax, and the limits, see CREATE HTTP RULE.
Creating an HTTP rule¶
You need the CREATE HTTP RULE privilege on the schema to create an HTTP rule. By default, only the schema owner has this privilege.
To create an HTTP rule, run the CREATE HTTP RULE command. For example, to use a custom role to create an HTTP rule that allows reading one item and creating items in an API:
When you create or alter an HTTP rule, Snowflake checks that each host that doesn’t contain a wildcard resolves to a public IPv4 address.
Using an HTTP rule in an external access integration¶
To add an HTTP rule to an external access integration, the role that runs the CREATE or ALTER EXTERNAL ACCESS INTEGRATION statement needs the USAGE privilege on the rule. For example:
An integration can hold network rules, HTTP rules, or both, and at most 32 HTTP rules. Users of a sandbox need the USAGE privilege on the integration, as with any external access integration.
An integration refers to its HTTP rules by name:
- Altering or replacing an HTTP rule changes what every integration that names it allows. Sandboxes that are already running pick up the change within a few minutes.
- If an integration names an HTTP rule that was dropped, or that the integration’s owner can no longer use, a sandbox that uses the integration fails to start, and the error names the rule. A running sandbox loses only that rule’s access.
What a refused request looks like¶
When no rule allows a request, the sandbox refuses it:
- A request to a host that no rule names fails. Depending on the sandbox, either the host name doesn’t resolve or the request gets an
HTTP
403response. - A request to a host that a rule names, but with a method or path that no entry allows, gets an HTTP
403response.
Identifying HTTP rules in your account¶
To list the HTTP rules that you have privileges on, run SHOW HTTP RULES. To see a rule’s specification, run DESCRIBE HTTP RULE with a role that owns the rule.
Modifying an HTTP rule¶
To replace a rule’s specification, run ALTER HTTP RULE … SET SPECIFICATION. The new specification replaces the old one; it isn’t merged with it. You can’t change the name or schema of an HTTP rule.
Limitations¶
- HTTP rules have no comment, and don’t support tags, GET_DDL, or UNDROP. A dropped HTTP rule can’t be recovered.
- There are no Information Schema or Account Usage views for HTTP rules.
- HTTP rules match the method and path of a request. They don’t match headers, query parameters, or request bodies.
Privileges and commands¶
| Command | Privilege | Description |
|---|---|---|
| CREATE HTTP RULE | CREATE HTTP RULE on SCHEMA | Creates a new HTTP rule. |
| ALTER HTTP RULE | OWNERSHIP on HTTP RULE | Replaces the specification of an existing HTTP rule. |
| DROP HTTP RULE | OWNERSHIP on HTTP RULE | Removes an existing HTTP rule from the system. |
| DESCRIBE HTTP RULE | OWNERSHIP on HTTP RULE | Describes an existing HTTP rule, including its specification. |
| SHOW HTTP RULES | OWNERSHIP or USAGE on HTTP RULE | Lists the HTTP rules in the system. |
| CREATE EXTERNAL ACCESS INTEGRATION, ALTER EXTERNAL ACCESS INTEGRATION | USAGE on HTTP RULE | Adds an HTTP rule to an external access integration. |