pub struct RuleBuilder { /* private fields */ }Expand description
Per-closure state and rule accumulator.
Lives only within a .rule() / .egress() / .ingress() /
.any() closure; its accumulated rules and errors are drained into
the parent NetworkPolicyBuilder when the closure returns.
Implementations§
Source§impl RuleBuilder
impl RuleBuilder
Sourcepub fn egress(&mut self) -> &mut Self
pub fn egress(&mut self) -> &mut Self
Set direction to Egress for subsequent rule-adders. Last-write-wins.
Sourcepub fn ingress(&mut self) -> &mut Self
pub fn ingress(&mut self) -> &mut Self
Set direction to Ingress for subsequent rule-adders. Last-write-wins.
Sourcepub fn any(&mut self) -> &mut Self
pub fn any(&mut self) -> &mut Self
Set direction to Any for subsequent rule-adders.
Rules committed after this apply in both directions. Last-write-wins.
Sourcepub fn tcp(&mut self) -> &mut Self
pub fn tcp(&mut self) -> &mut Self
Add Tcp to the protocols set (set semantics; duplicates dedupe).
Sourcepub fn icmpv4(&mut self) -> &mut Self
pub fn icmpv4(&mut self) -> &mut Self
Add Icmpv4 to the protocols set. Egress-only at build-time
(commits will record an BuildError::IngressDoesNotSupportIcmp
if direction is Ingress or Any).
Sourcepub fn port_range(&mut self, lo: u16, hi: u16) -> &mut Self
pub fn port_range(&mut self, lo: u16, hi: u16) -> &mut Self
Add an inclusive port range to the ports set. lo > hi records
a BuildError::InvalidPortRange for .build() to surface.
Sourcepub fn ports<I: IntoIterator<Item = u16>>(&mut self, ports: I) -> &mut Self
pub fn ports<I: IntoIterator<Item = u16>>(&mut self, ports: I) -> &mut Self
Add multiple single ports to the ports set. Equivalent to calling
Self::port once per element; duplicates dedupe via set semantics.
Sourcepub fn allow_public(&mut self) -> &mut Self
pub fn allow_public(&mut self) -> &mut Self
Allow the Public group: any IP not in another named category.
Sourcepub fn deny_public(&mut self) -> &mut Self
pub fn deny_public(&mut self) -> &mut Self
Deny the Public group.
Sourcepub fn allow_private(&mut self) -> &mut Self
pub fn allow_private(&mut self) -> &mut Self
Allow the Private group (RFC1918 + ULA + CGN).
Sourcepub fn deny_private(&mut self) -> &mut Self
pub fn deny_private(&mut self) -> &mut Self
Deny the Private group.
Sourcepub fn allow_loopback(&mut self) -> &mut Self
pub fn allow_loopback(&mut self) -> &mut Self
Allow the Loopback group: 127.0.0.0/8 and ::1 — the
guest’s own loopback interface, not the host machine.
Standard loopback traffic inside the guest stays in the guest
kernel and never reaches this rule; it only fires for crafted
packets that route loopback destinations out through the
gateway (e.g. raw sockets bound to eth0 with dst=127.0.0.1).
To reach a service on the host’s localhost, use
Self::allow_host instead.
Sourcepub fn deny_loopback(&mut self) -> &mut Self
pub fn deny_loopback(&mut self) -> &mut Self
Deny the Loopback group. Useful in default_egress = Allow
configurations to block crafted-packet leaks where a process
inside the guest binds a raw socket to eth0 and writes a
packet with dst=127.0.0.1 directly. The packet bypasses the
guest’s routing table, smoltcp on the host parses the
destination, and the connection lands on the host’s loopback.
.deny_loopback() blocks that vector.
Sourcepub fn allow_link_local(&mut self) -> &mut Self
pub fn allow_link_local(&mut self) -> &mut Self
Allow the LinkLocal group (169.254.0.0/16, fe80::/10).
Excludes the metadata IP 169.254.169.254 (categorized as
Metadata).
Sourcepub fn deny_link_local(&mut self) -> &mut Self
pub fn deny_link_local(&mut self) -> &mut Self
Deny the LinkLocal group.
Sourcepub fn allow_meta(&mut self) -> &mut Self
pub fn allow_meta(&mut self) -> &mut Self
Allow the Metadata group (169.254.169.254). Dangerous on
cloud hosts — exposes IAM credentials.
Sourcepub fn allow_multicast(&mut self) -> &mut Self
pub fn allow_multicast(&mut self) -> &mut Self
Allow the Multicast group (224.0.0.0/4, ff00::/8).
Sourcepub fn deny_multicast(&mut self) -> &mut Self
pub fn deny_multicast(&mut self) -> &mut Self
Deny the Multicast group.
Sourcepub fn allow_host(&mut self) -> &mut Self
pub fn allow_host(&mut self) -> &mut Self
Allow the Host group: per-sandbox gateway IPs that back
host.microsandbox.internal. This is the right shortcut for
“let the sandbox reach my host’s localhost” — not
Self::allow_loopback.
Sourcepub fn allow_local(&mut self) -> &mut Self
pub fn allow_local(&mut self) -> &mut Self
Allow Loopback + LinkLocal + Host — the three “near the
sandbox” groups a developer typically wants together when
running locally. Adds three rules atomically, each using
the closure’s current state.
Metadata is explicitly NOT included — even though
169.254.169.254 falls inside the link-local CIDR by raw
address, the schema’s Metadata carve-out is preserved here.
Users wanting cloud metadata access add Self::allow_meta
separately.
Sourcepub fn deny_local(&mut self) -> &mut Self
pub fn deny_local(&mut self) -> &mut Self
Deny Loopback + LinkLocal + Host (no Metadata). See
Self::allow_local for the membership rationale.
Sourcepub fn allow_domains<I, S>(&mut self, names: I) -> &mut Self
pub fn allow_domains<I, S>(&mut self, names: I) -> &mut Self
Allow each name as a Destination::Domain rule.
Sourcepub fn deny_domains<I, S>(&mut self, names: I) -> &mut Self
pub fn deny_domains<I, S>(&mut self, names: I) -> &mut Self
Deny each name as a Destination::Domain rule.
Sourcepub fn allow_domain_suffixes<I, S>(&mut self, suffixes: I) -> &mut Self
pub fn allow_domain_suffixes<I, S>(&mut self, suffixes: I) -> &mut Self
Allow each suffix as a Destination::DomainSuffix rule.
Sourcepub fn deny_domain_suffixes<I, S>(&mut self, suffixes: I) -> &mut Self
pub fn deny_domain_suffixes<I, S>(&mut self, suffixes: I) -> &mut Self
Deny each suffix as a Destination::DomainSuffix rule.
Sourcepub fn allow(&mut self) -> RuleDestinationBuilder<'_>
pub fn allow(&mut self) -> RuleDestinationBuilder<'_>
Begin an explicit-destination rule with action Allow. Returns
an RuleDestinationBuilder that requires a destination call
(.ip, .cidr, .domain, .domain_suffix, .group, .any)
to commit the rule.
Sourcepub fn deny(&mut self) -> RuleDestinationBuilder<'_>
pub fn deny(&mut self) -> RuleDestinationBuilder<'_>
Begin an explicit-destination rule with action Deny.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for RuleBuilder
impl RefUnwindSafe for RuleBuilder
impl Send for RuleBuilder
impl Sync for RuleBuilder
impl Unpin for RuleBuilder
impl UnsafeUnpin for RuleBuilder
impl UnwindSafe for RuleBuilder
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more