Expand description
§capsec — Compile-Time Capability-Based Security for Rust
capsec enforces the principle of least privilege at the type level.
Functions declare their I/O capabilities via trait bounds, and the compiler
ensures they cannot exceed them.
§Quick Start
ⓘ
use capsec::prelude::*;
fn main() {
let root = capsec::root();
let fs_cap = root.grant::<FsRead>();
let data = load_data("/tmp/data.csv", &fs_cap).unwrap();
}
fn load_data(path: &str, cap: &impl Has<FsRead>) -> Result<String, capsec::CapSecError> {
capsec::fs::read_to_string(path, cap)
}§Architecture
This is a facade crate that re-exports from three internal crates:
capsec-core— capability tokens, permission traits, compositioncapsec-macro—#[requires],#[deny],#[main], and#[context]proc macroscapsec-std— capability-gatedstdwrappers
Modules§
- env
- Capability-gated environment variable access. See
capsec_std::env. - fs
- Capability-gated filesystem operations. See
capsec_std::fs. - net
- Capability-gated network operations. See
capsec_std::net. - prelude
- Common imports for working with capsec.
- process
- Capability-gated subprocess execution. See
capsec_std::process.
Structs§
- Ambient
- Full ambient authority — grants every permission.
- ApproverA
- First approval handle for a
DualKeyCap. - ApproverB
- Second approval handle for a
DualKeyCap. - Attenuated
- A capability that has been narrowed to a specific scope.
- Cap
- A zero-sized capability token proving the holder has permission
P. - CapRoot
- The root of all capabilities. Only one can exist per process.
- DirScope
- Restricts filesystem operations to a directory subtree.
- Dual
KeyCap - A dual-authorization capability requiring two independent approvals.
- Dual
KeySend Cap - A thread-safe dual-authorization capability token.
- EnvRead
- Permission to read environment variables.
- EnvWrite
- Permission to modify or remove environment variables.
- FsAll
- Permission for all filesystem operations. Subsumes
FsReadandFsWrite. - FsRead
- Permission to read files, list directories, and check metadata.
- FsWrite
- Permission to write, create, rename, and delete files and directories.
- Host
Scope - Restricts network operations to a set of allowed host prefixes.
- LogEntry
- A record of a single capability exercise attempt.
- Logged
Cap - An audited capability token that logs every exercise attempt.
- Logged
Send Cap - A thread-safe audited capability token.
- NetAll
- Permission for all network operations. Subsumes
NetConnectandNetBind. - NetBind
- Permission to bind TCP listeners and UDP sockets to local ports.
- NetConnect
- Permission to open outbound TCP and UDP connections.
- Revoker
- A handle that can revoke its associated
RuntimeCap(and all clones). - Runtime
Cap - A revocable capability token proving the holder has permission
P. - Runtime
Send Cap - A thread-safe revocable capability token.
- SendCap
- A thread-safe capability token that can be sent across threads.
- Spawn
- Permission to spawn and execute subprocesses via
std::process::Command. - Timed
Cap - A time-bounded capability token proving the holder has permission
P. - Timed
Send Cap - A thread-safe time-bounded capability token.
Enums§
- CapSec
Error - Errors that can occur when using capsec capabilities.
Traits§
- Has
- Proof that a capability token includes permission
P. - Permission
- Marker trait for all capability permissions.
- Scope
- A restriction that narrows the set of targets a capability can act on.
- Subsumes
- Indicates that
Selfimplies permissionP.
Functions§
- root
- Creates the singleton capability root. Panics if called more than once.
- run
- Creates a
CapRootand passes it to the given closure. - test_
root - Creates a capability root for testing. Bypasses the singleton check.
- try_
root - Creates the singleton capability root, returning
Noneif already created.
Attribute Macros§
- context
- Transforms a struct with permission-type fields into a capability context.
- deny
- Marks a function as capability-free.
- main
- Injects
CapRootcreation into a function entry point. - permission
- Defines a user-defined permission type for capability-based security.
- requires
- Declares the capability requirements of a function.