Skip to main content

RuleBuilder

Struct RuleBuilder 

Source
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

Source

pub fn egress(&mut self) -> &mut Self

Set direction to Egress for subsequent rule-adders. Last-write-wins.

Source

pub fn ingress(&mut self) -> &mut Self

Set direction to Ingress for subsequent rule-adders. Last-write-wins.

Source

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.

Source

pub fn tcp(&mut self) -> &mut Self

Add Tcp to the protocols set (set semantics; duplicates dedupe).

Source

pub fn udp(&mut self) -> &mut Self

Add Udp to the protocols set.

Source

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).

Source

pub fn icmpv6(&mut self) -> &mut Self

Add Icmpv6 to the protocols set. Egress-only.

Source

pub fn port(&mut self, port: u16) -> &mut Self

Add a single port to the ports set.

Source

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.

Source

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.

Source

pub fn allow_public(&mut self) -> &mut Self

Allow the Public group: any IP not in another named category.

Source

pub fn deny_public(&mut self) -> &mut Self

Deny the Public group.

Source

pub fn allow_private(&mut self) -> &mut Self

Allow the Private group (RFC1918 + ULA + CGN).

Source

pub fn deny_private(&mut self) -> &mut Self

Deny the Private group.

Source

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.

Source

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.

Allow the LinkLocal group (169.254.0.0/16, fe80::/10). Excludes the metadata IP 169.254.169.254 (categorized as Metadata).

Deny the LinkLocal group.

Source

pub fn allow_meta(&mut self) -> &mut Self

Allow the Metadata group (169.254.169.254). Dangerous on cloud hosts — exposes IAM credentials.

Source

pub fn deny_meta(&mut self) -> &mut Self

Deny the Metadata group.

Source

pub fn allow_multicast(&mut self) -> &mut Self

Allow the Multicast group (224.0.0.0/4, ff00::/8).

Source

pub fn deny_multicast(&mut self) -> &mut Self

Deny the Multicast group.

Source

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.

Source

pub fn deny_host(&mut self) -> &mut Self

Deny the Host group.

Source

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.

Source

pub fn deny_local(&mut self) -> &mut Self

Deny Loopback + LinkLocal + Host (no Metadata). See Self::allow_local for the membership rationale.

Source

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.

Source

pub fn deny(&mut self) -> RuleDestinationBuilder<'_>

Begin an explicit-destination rule with action Deny.

Trait Implementations§

Source§

impl Debug for RuleBuilder

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> AsAny for T
where T: Any,

Source§

fn as_any(&self) -> &(dyn Any + 'static)

Source§

fn as_mut_any(&mut self) -> &mut (dyn Any + 'static)

Source§

impl<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

Source§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

Source§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

Source§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more