Function normalize_egress_pattern
pub fn normalize_egress_pattern(raw: &str) -> Result<String, String>Expand description
Canonicalize one egress allowlist entry, or explain why it is rejected.
This is the single grammar for both halves of the egress contract: the signed
manifest’s egress.hosts declaration and the operator’s
plugins.entries[].egress_hosts grant. Both validate here so a pattern that
a publisher can declare is exactly a pattern an operator can grant.
Accepted forms:
- an exact host: a lowercase domain name, IPv4 literal, or IPv6 literal
(bare
::1or bracketed[::1]; both canonicalize to bare). It matches that host and nothing else — a bare domain never implies its subdomains. - an explicit suffix pattern
*.example.com: matches strict subdomains ofexample.comand not the apex itself. Grant the apex by listing it separately.
Rejected, each with a message naming the reason:
- a bare
*. There is no “everything” pattern; deny-by-default has no escape hatch at the grammar level. - empty or whitespace-bearing entries.
- anything carrying a scheme, path, query, fragment, or userinfo (
/,@,?,#,\), so an entry is never a URL that silently loses its path. - a
*anywhere other than the leading*.(noa*.b, no*.*.c). - a port (
example.com:8443). Ports are deliberately not part of this slice’s grammar: a granted host is granted on every port, all-or-nothing. Rejecting the syntax outright keeps an operator from writing a port and believing it narrowed the grant when it would in fact have been dropped. - a wildcard over an IP literal (
*.10.0.0.1), which has no meaning. - a single-label wildcard suffix (
*.com,*.internal). This is a footgun guard, not a public-suffix check: no public-suffix list is imported here, so*.co.ukis accepted even though it is just as broad. The rule only removes the most obvious way to write an accidental internet-wide grant. - any entry that is not already canonical (a trailing dot, uppercase, or a
form
normalize_domainwould silently rewrite), so the file an operator audits reads exactly as the policy that is enforced.
§Errors
Returns the human-readable reason the entry is not a legal egress pattern.