Karta. NetGuard
(Karta v1.0.0)
Where Karta may connect when a host name or address comes from someone
else: a recipient domain's mail servers (Karta.Outbound.MXResolver),
a domain's MTA-STS policy host (Karta.MTASTS.Fetcher) and its MX hosts
when an enforce policy is checked (Karta.MTASTS.Probe). The name is
resolved here, every address is checked, and the caller connects to the
checked addresses themselves, never to the name (for HTTP requests:
Karta.NetGuard.HTTP). A second lookup by
the connecting code could return another address (DNS rebinding);
connecting to the address that was checked cannot.
What the operator configures (the database, the object store, the DNS resolver, PowerDNS, the Public Suffix List's URL, the OpenID Connect provider) is not checked: it may well be on a private network.
Refused by default (default_blocked_networks/0): addresses that are not
on the public internet or that lead back into it in disguise:
- IPv4: this network (
0.0.0.0/8), private ranges (10.0.0.0/8,172.16.0.0/12,192.168.0.0/16), the shared address space of carrier-grade NAT (RFC 6598), loopback, link-local, the IETF protocol assignments (192.0.0.0/24), documentation ranges, the 6to4 relay anycast range, benchmarking (198.18.0.0/15), multicast and the reserved range up to the broadcast address; - IPv6: the unspecified and loopback addresses and the rest of
::/96(IPv4-compatible addresses), IPv4-translated addresses (::ffff:0:0:0/96), NAT64 (64:ff9b::/96,64:ff9b:1::/48), discard-only (100::/64), Teredo (2001::/32), benchmarking (2001:2::/48), documentation (2001:db8::/32,3fff::/20), 6to4 (2002::/16), unique local (fc00::/7), link-local, site-local (fec0::/10) and multicast. An IPv4-mapped address (::ffff:192.0.2.1) is checked as the IPv4 address it carries.
The operator may allow networks that are refused by default
(config :karta, Karta.NetGuard, allowed_networks: ["10.1.0.0/16"];
KARTA_NET_GUARD_ALLOWED_NETWORKS in production), for example a
webhook receiver or a mail server on the instance's own private network.
An invalid range stops Karta at boot (validate!/0).
Options:
:dns- options forKarta.DNS.lookup/3.:blocked_networks-Karta.CIDRranges to refuse instead of the default ones.:allowed_networks-Karta.CIDRranges allowed even when blocked, instead of the configured ones; tests use it for a server on the loopback address.
Summary
Functions
True when Karta may connect to ip under opts.
The ranges the operator allows although they are refused by default.
The ranges refused by default (see the module doc).
The addresses of host (A records first, then AAAA) that Karta may
connect to. Errors: :invalid_name, :no_address (the name has no
addresses), :dns (a lookup failed and no address was found) and
:blocked (every address is refused).
Checks the configured ranges; called when the application starts.
Functions
@spec allowed?(:inet.ip_address(), keyword()) :: boolean()
True when Karta may connect to ip under opts.
@spec allowed_networks() :: [Karta.CIDR.t()]
The ranges the operator allows although they are refused by default.
@spec default_blocked_networks() :: [Karta.CIDR.t()]
The ranges refused by default (see the module doc).
@spec resolve(String.t(), keyword()) :: {:ok, [:inet.ip_address(), ...]} | {:error, :invalid_name | :no_address | :dns | :blocked}
The addresses of host (A records first, then AAAA) that Karta may
connect to. Errors: :invalid_name, :no_address (the name has no
addresses), :dns (a lookup failed and no address was found) and
:blocked (every address is refused).
@spec validate!() :: :ok
Checks the configured ranges; called when the application starts.