OutboundRoute
class OutboundRoute(object)A route in an OutboundPolicy: which outbound traffic it matches.
Create routes with the OutboundRoute.tls, OutboundRoute.https,
OutboundRoute.ip and OutboundRoute.any factories. Traffic a route
matches goes to its original destination, except that the any route can
block what it matches. Routes are immutable: block() returns a new route.
Usage
import modal
# Allow TLS connections to a domain and its subdomains.
modal.OutboundRoute.tls(domains=["example.com", "*.example.com"])
# Block everything no earlier route matched.
modal.OutboundRoute.any().block()tls
tls(cls, *, domains)Match connections that carry TLS from the first byte to one of domains, on tcp/443.
Connections are matched by the domain the client requests during the TLS handshake (SNI). TLS routes never decrypt traffic: the connection's contents are passed through as-is. Traffic to these domains on other ports or transports isn't matched by this route.
Parameters
https
https(cls, *, domains, header_replacements=None)Match HTTPS connections to one of domains, on tcp/443.
HTTPS routes always decrypt traffic, which requires the policy to be
created with allow_tls_decryption=True, even when the route has no
header replacements. Requests whose Host header doesn't match the domain
requested for the connection are refused. Traffic to these domains on
other ports or transports isn't matched by this route.
Header values support templating with keys in a replacement's secret:
a $-prefixed key name in the secret is replaced with the secret value.
Literal $ characters are written $$. Secret values never enter the
Sandbox: they are injected into matching requests outside the container.
Parameters
Usage
secret = modal.Secret.from_name("api-token")
route = modal.OutboundRoute.https(
domains=["api.example.com"],
header_replacements=[
{"secret": secret, "headers": {"Authorization": "Bearer $API_TOKEN"}},
],
)ip
ip(cls, *, cidrs)Match all traffic to one of cidrs, on any transport and port.
Parameters
any
any(cls)Match all traffic that no earlier route in the policy matched.
Every OutboundPolicy needs exactly one any route, as its last
route. Without a redirect, the traffic it matches goes to its original
destination; call .block() on the route to block it instead.
block
block(self)Return a new route that blocks the traffic it matches.
Only OutboundRoute.any() supports block().