apparmor-policy 0.1.0

Typed, lossless parser and serializer for the AppArmor policy language.
Documentation
  • Coverage
  • 100%
    268 out of 268 items documented15 out of 56 items with examples
  • Size
  • Source code size: 186.8 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 2.3 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 3s Average build duration of successful builds.
  • all releases: 3s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • lenitain/apparmor-policy
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • lenitain

apparmor-policy

Typed, lossless parser and serializer for the AppArmor policy language.

Crates.io Docs.rs License: MIT CI

Overview

apparmor-policy is a typed, lossless parser and serializer for AppArmor policy text — a mechanism layer, so tools that read or write profiles don't each reimplement a broken half-parser.

Highlights:

  • Complete grammar: profile / hat / sub-profile headers, file rules with the full AARE glob language (*, **, ?, [...], {...}, @{} variables), and typed rules for file, capability, network, mount, pivot_root, link, change_profile, set rlimit, dbus, unix, mqueue, userns, io_uring, signal, ptrace and all.
  • Lossless and fault tolerant: variables stay @{...} (never expanded), unknown rules degrade to RawRule nodes with their original text — nothing is dropped, and partially supported policies still parse.
  • Round-trippable: parse(render(x)) == x, so a normalized policy can be written back out.
  • Precise errors: structural failures carry 1-based line/column plus the offending source line, for incremental-repair tooling.
  • No policy decisions: this crate never evaluates rules against paths, reads kernel state, merges or loads profiles, or binds an async runtime — those are caller concerns.

Usage

Add to your Cargo.toml:

[dependencies]
apparmor-policy = "0.1"

The crate is pure Rust with no dependencies and works on any platform (parsing is text-only).

Quick start

use apparmor_policy::parse_str;

let src = r#"
profile /usr/bin/foo flags=(complain) {
  /etc/foo.conf r,
  owner @{HOME}/** rw,
  /bin/bash ix,
  capability setuid,
  network inet stream,
  deny /proc/*/mem rw,
}
"#;

let profiles = parse_str(src).unwrap();
assert_eq!(profiles[0].name, "/usr/bin/foo");

// AST -> text -> AST round trip.
let text = profiles[0].to_string();
assert_eq!(parse_str(&text).unwrap(), profiles);

Documentation

  • The crate-level docs cover the API surface and the round-trip guarantee.
  • Each public type and method carries a runnable doctest showing real usage.