May dave export invoice d1? No. Strig says which grant decided, and where.
Request · Rust
let dave = Subject::user("dave")
.with_role_in("member", Anchor::new("org", "acme"));
let invoice = Resource::new("document", "d1")
.within("doc_type", "invoice")
.within("project", "p1")
.within("org", "acme");
let decision = engine.decide(
&Context::new(&grants),
&Request::new(&dave, "document.invoice.export", &invoice),
);
assert!(!decision.is_allowed());Deny
g2 denies on doc_type:invoice, the most specific step with a grant.
Resource path, broad to specific
- org:acme
g1allowsdocument.export, which implies the request. Candidate, outranked. - project:p1No grant on this step.
- doc_type:invoice
g2deniesdocument.invoice.exportto anyone. Decides. - document:d1No grant on this step.
Strategy: MostSpecific, the default. On the deciding step, deny wins.
Request · Rust
let dave = Subject::user("dave")
.with_role_in("member", Anchor::new("org", "acme"));
let report = Resource::new("document", "d2")
.within("doc_type", "report")
.within("project", "p1")
.within("org", "acme");
let decision = engine.decide(
&Context::new(&grants),
&Request::new(&dave, "document.export", &report),
);
assert!(decision.is_allowed());Allow
g1 allows on org:acme, the only step with a grant.
Resource path, broad to specific
- org:acme
g1allowsdocument.exportto rolememberinorg:acme. Decides. - project:p1No grant on this step.
- doc_type:reportNo grant on this step.
g2sits ondoc_type:invoiceonly. - document:d2No grant on this step.
Strategy: MostSpecific, the default.
Strig is an authorization engine for Rust, with a policy language and a WebAssembly build. Every answer carries its reason.
The same grants, written as policy. Three syntaxes, one result.
Rules reads aloud, Blocks is explicit, Actors groups by who acts. All three parse to the same policy, so dave gets the same two answers.
language rules
kinds doc_type, document, project
broad org
permission document.export on project, document
permission document.invoice.export on doc_type, document implied by document.export
role member
user:dave has role member in org:acme
g1: allow role member to document.export on org in org:acme
g2: deny anyone to document.invoice.export on doc_type:invoicelanguage blocks
target_kinds = [doc_type, document, project]
broad_targets = [org]
permission document.export {
targets = [project, document]
}
permission document.invoice.export {
targets = [doc_type, document]
implied_by = [document.export]
}
role member {
}
subject user:dave {
assign member {
scope = org:acme
}
}
grant g1 {
effect = allow
subject = role member
permission = document.export
target = org
scope = org:acme
}
grant g2 {
effect = deny
subject = anyone
permission = document.invoice.export
target = doc_type:invoice
}language actors
role member
in org:acme
allow document.export on org as g1
anyone
deny document.invoice.export on doc_type:invoice as g2
subject user:dave
role member in org:acme
catalog
kinds doc_type, document, project
broad org
document.export on project, document
document.invoice.export on doc_type, document implied by document.exportChange a line. Watch the ruling change. The playground runs the real engine.
Loading the recording
Read a decision after the fact. Strig Inspect, on the desktop.
It fails closed
A condition or relation that cannot be evaluated never opens access. The allow is dropped and the deny applies.
Three models, one set of grants
RBAC with inheritance, ABAC with conditions, ReBAC with relation tuples.
A core that does no IO
The same engine runs in Rust, in Node and Bun, and in the browser through WebAssembly.
Install. Rust first, then Node, Bun and the browser.
Strig is pre-1.0: the API can still change between minor versions. The changelog lists each change.
cargo add strignpm install @the-hades-organization/strigFirst decision · Rustsrc/main.rs
use strig::{dsl::fs::read_file, Context, Request, Resource};
fn main() -> Result<(), Box<dyn std::error::Error>> {
let policy = read_file("policy.strig")?.policy;
let engine = policy.engine_spec().build()?;
let dave = policy.subjects.iter()
.find(|s| s.id.as_deref() == Some("dave"))
.expect("dave is in the policy");
let d1 = Resource::new("document", "d1")
.within("doc_type", "invoice")
.within("project", "p1")
.within("org", "acme");
let decision = engine.decide(
&Context::new(&policy.grants),
&Request::new(dave, "document.invoice.export", &d1),
);
assert!(!decision.is_allowed());
Ok(())
}Reading a .strig file takes two features: cargo add strig --features dsl,dsl-fs. The policy is the one above.