pub struct NetworkPolicy { /* private fields */ }Expand description
Deny-by-default IP/CIDR allowlist for ingest endpoints.
§Usage
Build a policy with NetworkPolicy::new, populate it with
allow_ip / allow_cidr, then call
check with the source address of each incoming connection
before passing the payload to IngestService.
use std::net::IpAddr;
use edgesentry_rs::NetworkPolicy;
let mut policy = NetworkPolicy::new();
policy.allow_cidr("10.0.0.0/8").unwrap();
let trusted: IpAddr = "10.1.2.3".parse().unwrap();
assert!(policy.check(trusted).is_ok());
let untrusted: IpAddr = "192.168.1.1".parse().unwrap();
assert!(policy.check(untrusted).is_err());Implementations§
Source§impl NetworkPolicy
impl NetworkPolicy
Sourcepub fn allow_cidr(
&mut self,
cidr: &str,
) -> Result<&mut Self, NetworkPolicyError>
pub fn allow_cidr( &mut self, cidr: &str, ) -> Result<&mut Self, NetworkPolicyError>
Permit all addresses within a CIDR block, e.g. "10.0.0.0/8" or "fd00::/8".
Sourcepub fn check(&self, source: IpAddr) -> Result<(), NetworkPolicyError>
pub fn check(&self, source: IpAddr) -> Result<(), NetworkPolicyError>
Returns Ok(()) if source is covered by at least one allowlist entry,
or Err(NetworkPolicyError::Denied) if not.
Sourcepub fn entries(&self) -> &[AllowedSource]
pub fn entries(&self) -> &[AllowedSource]
Returns the list of configured allowlist entries.
Trait Implementations§
Source§impl Clone for NetworkPolicy
impl Clone for NetworkPolicy
Source§fn clone(&self) -> NetworkPolicy
fn clone(&self) -> NetworkPolicy
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for NetworkPolicy
impl Debug for NetworkPolicy
Source§impl Default for NetworkPolicy
impl Default for NetworkPolicy
Source§fn default() -> NetworkPolicy
fn default() -> NetworkPolicy
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for NetworkPolicy
impl RefUnwindSafe for NetworkPolicy
impl Send for NetworkPolicy
impl Sync for NetworkPolicy
impl Unpin for NetworkPolicy
impl UnsafeUnpin for NetworkPolicy
impl UnwindSafe for NetworkPolicy
Blanket Implementations§
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
Mutably borrows from an owned value. Read more