Modal logo

Migration Guide: Outbound Policies

Outbound Policies replace several other options for Sandboxes with a well-defined sequence of routes. They require Modal SDK 1.7.0 (Python) or 0.12.0 (JS and Go). Except for block_network (which completely disconnects the Sandbox), the old options are deprecated:

  • CIDR allowlists (outbound_cidr_allowlist) and domain allowlists (outbound_domain_allowlist) will be removed in a future release, along with _experimental_set_outbound_network_policy().
  • modal.experimental.OutboundPolicy and _experimental_outbound_policy, Sandbox._experimental_update_outbound_policy() will be removed in Modal SDK 1.8.0 (Python) and 0.13.0 (JS and Go).

Every policy ends with an any route. OutboundRoute.any().block() blocks the traffic no other route matches, turning the policy into an allowlist, and OutboundRoute.any() lets it through, making it possible to use Secret injection without destination allowlisting. See Outbound Policies for code snippets, and note the limitations.

CIDR allowlists 

BeforeAfter
outbound_cidr_allowlistAn OutboundRoute.ip() route, then an OutboundRoute.any().block() route

DNS lookups will no longer resolve, even if the resulting IP matches an OutboundRoute.ip() route. Connect by IP, or migrate to an OutboundRoute.tls() route with the domain name.

Domain allowlists 

BeforeAfter
outbound_domain_allowlistAn OutboundRoute.tls() route, then an OutboundRoute.any().block() route

*.example.com no longer matches example.com. List both on the OutboundRoute.tls() route to match a domain and its subdomains.

For HTTPS traffic, an OutboundRoute.https() route is an improvement over a TLS route: it also verifies the Host header, which prevents domain fronting. HTTPS routes require allow_tls_decryption=True when the Sandbox is created.

CIDR and domain allowlists together 

BeforeAfter
Both outbound_cidr_allowlist and outbound_domain_allowlistOutboundRoute.ip() and OutboundRoute.tls() routes, then an OutboundRoute.any().block() route

Empty allowlists 

BeforeAfter
An empty allowlistOnly an OutboundRoute.any().block() route

Allow-all allowlists, to change the policy later 

BeforeAfter
Allowlists of "0.0.0.0/0" and "*"No outbound_policy, or, to be able to add OutboundRoute.https() routes later, outbound_policy with allow_tls_decryption=True and only an OutboundRoute.any() route

set_outbound_policy() also works on a Sandbox created without a policy. TLS decryption can only be allowed at creation.

Secret injection with the experimental Outbound Policy 

BeforeAfter
_experimental_outbound_policy with with_header_replacement() callsoutbound_policy with allow_tls_decryption=True, OutboundRoute.https() routes with header_replacements for each domain, then an OutboundRoute.any() route

*.example.com no longer matches example.com.

Overlapping secret injection 

BeforeAfter
with_header_replacement() calls for the same or overlapping domains, such as *.example.com and api.example.comOne OutboundRoute.https() route per domain, the most specific first, each with all the headers that should be replaced for it

Before, every matching call applied, and the later call won when two set the same header. With Outbound Policies, only the first route that matches a connection applies.

Changing the policy of a running Sandbox 

BeforeAfter
_experimental_set_outbound_network_policy() or _experimental_update_outbound_policy()set_outbound_policy()

The new policy replaces the whole outbound configuration, so pass the full route list, and keep allow_tls_decryption the same as in the outbound_policy the Sandbox was created with.