For AI agents

What Strig is, when to use it, how to install it, a minimal example per language, the questions the engine answers and the usual mistakes. Written for coding assistants and the people who use them.

This page describes Strig in the terms a coding assistant needs to write correct code against it. Every docs page is also available as markdown, and the repository has an AGENTS.md with the same guide plus the commands to build and test the repository.

Machine-readable docs#

  • /llms.txt: the index of the pages, one section per group.
  • /llms-full.txt: the text of every page in one file.
  • /docs/<page>.md: the markdown of one page, for example /docs/concepts.md. A request to /docs/<page> with Accept: text/markdown gets the same text.
  • API reference on docs.rs for the Rust crate.

What it is#

Strig is an authorization library with one decision engine for RBAC, ABAC and ReBAC, for Rust, Node, Bun, the browser, Python, Go and the JVM. You declare a catalog of permissions, hand the engine grants, and ask whether a subject may do something to a resource. The answer comes with the reason, and the engine can say what would turn a denial into an allow. Changes to grants can go through governance rules, be audited with a hash chain and be pushed in real time to other instances and the browser.

Use it when the question is "who can do what to which resource", the rules mix roles, attributes and relations, and you want decisions you can explain and audit.

It does not authenticate anyone. It takes the subject you give it as already established, and it is not an identity provider, a session store or a login flow. The optional decision server does not authenticate its callers either, so put it behind your own authentication.

Install#

LanguageCommandStability
Rustcargo add strig (--features dsl for the policy language)stable core
Node, Bun, browsernpm install @the-hades-organization/strigstable
Pythonpip install strig-auth (import strig)experimental
Gogo get github.com/The-Hades-Organization/Strig/bindings/go@latestexperimental
Java, Kotlinio.github.the-hades-organization:strigexperimental

Getting started has the install snippets with versions, and Upgrading says what changed between them.

The model in one paragraph#

A catalog lists dotted permission keys (project.edit) and the kinds of target each accepts. A resource is a path of steps from the most specific to the broadest (project:p1/org:acme). A subject has an id, roles (optionally scoped to a step), principals and attributes. A grant says who (a user, a role, a principal, a relation or anyone), which permission, on which target, allow or deny, with an optional scope and condition. The engine collects the grants that apply to the request and a strategy picks the deciding one. The default strategy lets the grant closest to the resource decide, and a deny wins on the same step. With no applicable grant the answer is deny. A condition or relation that cannot be evaluated never opens access. See Concepts.

A minimal example#

One catalog, one role grant, and the questions: may she, why, what would allow it, who can. Each example is a file that the repository's CI runs.

Rust
use strig::*;

let catalog = Catalog::builder()
    .target_kinds(["project"])
    .broad_target("org")
    .permission(PermissionDef::new("project.view").targets(["project"]))
    .permission(PermissionDef::new("project.edit").targets(["project"]))
    .build()?;
let engine = Engine::builder(catalog).build()?;

let grants = vec![Grant::allow("g1", SubjectMatcher::role("member"), "project.view", TargetSelector::kind("project"))];
let ana = Subject::user("ana").with_role("member");
let project = Resource::new("project", "p1").within("org", "acme");
let ctx = Context::new(&grants);

let view = engine.decide(&ctx, &Request::new(&ana, "project.view", &project)); // Effect::Allow
let edit = engine.decide(&ctx, &Request::new(&ana, "project.edit", &project)); // Effect::Deny
let remedies = engine.why_not(&ctx, &Request::new(&ana, "project.edit", &project), &WhyNotOptions::default());
let who = engine.who_can(&QueryContext::new(&grants), "project.view");

explain and why_not exist in Rust, JavaScript and Python. Go and Java have Explain and explain, and no why_not yet.

Questions the engine answers#

QuestionRustJavaScriptPython
May this subject do this to this resource?decide, check_forcheck, decidecheck, decide
Why did it come out that way?explainexplainexplain
What would turn a denial into an allow?why_notwhyNotwhy_not
Which resources of a kind can the subject reach?listlistlist
Who holds this permission?who_can, who_can_on, access_ofwhoCan, whoCanOn, accessOfwho_can, who_can_on, access_of

Why not covers the remedies, and Concepts the rest of the model.

Common mistakes#

  • Treating a denial as an error. Deny is the default answer; read the reason or explain to see which grant, override or missing grant decided.
  • Treating the library as authentication. The subject you pass is trusted as given.
  • Checking only in the interface. PermissionClient in the browser decides from capabilities the server sent, to shape the interface; the server still decides on every operation.
  • Forgetting the time. A grant with a validity window fails closed when the engine has no instant: pass now (milliseconds, UTC) or set it on the context.
  • Wrong names in the JSON spec. Spec, grants, subjects and results use camelCase fields in every language (targetKinds, validFrom, grantId).
  • Expecting callbacks outside Rust, JavaScript and Python. Custom conditions, overrides and invariants written in Go or Java are not supported yet, and a spec that needs one fails closed.
  • Matching on error messages. Every binding reports the same errorCode (INVALID_INPUT, UNKNOWN_SUBJECT, and so on); match on the code.
  • Changing grants by hand when rules apply. Use Governance in Rust or engine.apply in the other languages: it applies the change only if every invariant passes and audits the outcome.

Where to read more#