Crate capsicum_net

Source
Expand description

Rust bindings to FreeBSD’s cap_net(3) library.

cap_net allows access to several network APIs that are forbidden in capability mode by delegating them to an unsandboxed process, the Casper daemon.

The main entry point for this library is CapNetAgent. The agent may be created at any time, whether in capability mode or not, as long as the Casper daemon was started prior to entering capability mode. After creating the agent, this library has three interfaces:

  • Low-level methods directly on the CapNetAgent object. These work well with the nix crate.
  • Extension traits that work on the standard socket types, like UdpSocketExt.
  • Extension traits that work with tokio types, like TcpSocketExt.

§Example

In this example, we create a new UdpSocket and bind it to a port. Such a thing is normally not allowed in capability mode, but cap_bind lets us do it.

use std::{io, str::FromStr, net::UdpSocket };

use capsicum::casper::Casper;
use capsicum_net::{CasperExt, std::UdpSocketExt};

// Safe because we are single-threaded
let mut casper = unsafe { Casper::new().unwrap() };
let mut cap_net = casper.net().unwrap();

capsicum::enter();

// At this point regular bind(2) will fail because we're in capability mode.
UdpSocket::bind("127.0.0.1:8086").unwrap_err();

// But cap_bind will still succeed.
let socket = UdpSocket::cap_bind(&mut cap_net, "127.0.0.1:8086")
    .unwrap();

Modules§

std
Extension traits for socket types from the standard library

Structs§

CapNetAgent
A connection to the Casper cap_net(3) service.
Limit
Used to limit which operations will be allowed by the CapNetAgent.
LimitFlags
Used by CapNetAgent::limit to restrict which functions are permitted.

Traits§

CasperExt
Extension trait for ::capsicum::casper::Casper that spawns this service.