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>withAccept: text/markdowngets 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#
| Language | Command | Stability |
|---|---|---|
| Rust | cargo add strig (--features dsl for the policy language) | stable core |
| Node, Bun, browser | npm install @the-hades-organization/strig | stable |
| Python | pip install strig-auth (import strig) | experimental |
| Go | go get github.com/The-Hades-Organization/Strig/bindings/go@latest | experimental |
| Java, Kotlin | io.github.the-hades-organization:strig | experimental |
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.
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");
import { load, scopeFromString } from '@the-hades-organization/strig';
const { Engine, Context } = await load(); // native on Node and Bun, wasm in the browser
const engine = new Engine({
catalog: {
targetKinds: ['project'],
broadTargets: ['org'],
permissions: [
{ key: 'project.view', targets: ['project'] },
{ key: 'project.edit', targets: ['project'] },
],
},
});
const ctx = new Context({
grants: [{ id: 'g1', subject: { kind: 'role', id: 'member' }, permission: 'project.view', target: { kind: 'project' }, effect: 'allow' }],
});
const ana = { kind: 'user', id: 'ana', roles: [{ role: 'member' }] };
const ask = (permission) => ({ subject: ana, permission, resource: scopeFromString('project:p1/org:acme') });
engine.check(ctx, ask('project.view')); // true
engine.check(ctx, ask('project.edit')); // false
engine.whyNot(ctx, ask('project.edit')); // { remedies: [...] }; null when already allowed
engine.whoCan(ctx, 'project.view'); // [{ type: 'role', id: 'member' }]
import strig
engine = strig.Engine({"catalog": {
"targetKinds": ["project"], "broadTargets": ["org"],
"permissions": [{"key": "project.view", "targets": ["project"]},
{"key": "project.edit", "targets": ["project"]}]}})
ctx = strig.Context([{"id": "g1", "subject": {"kind": "role", "id": "member"},
"permission": "project.view", "target": {"kind": "project"}, "effect": "allow"}])
ana = {"kind": "user", "id": "ana", "roles": [{"role": "member"}]}
def ask(permission):
return {"subject": ana, "permission": permission, "resource": strig.scope_from_string("project:p1/org:acme")}
engine.check(ctx, ask("project.view")) # True
engine.check(ctx, ask("project.edit")) # False
engine.why_not(ctx, ask("project.edit")) # {"remedies": [...]}; None when already allowed
engine.who_can(ctx, "project.view") # [{"type": "role", "id": "member"}]
engine, _ := strig.NewEngine(spec) // spec: the same catalog JSON as in the Node tab
defer engine.Close()
ctx, _ := engine.NewContext(map[string]any{"grants": grants})
request := map[string]any{
"subject": map[string]any{"kind": "user", "id": "ana", "roles": []map[string]any{{"role": "member"}}},
"permission": "project.view",
"resource": map[string]any{"path": []map[string]any{{"kind": "project", "id": "p1"}, {"kind": "org", "id": "acme"}}},
}
allowed, err := engine.Check(ctx, request) // an error is never an allow
parties, _ := engine.WhoCan(ctx, "project.view")
try (Engine engine = new Engine(spec); Context ctx = engine.newContext(Map.of("grants", List.of(grant)))) {
boolean allowed = engine.check(ctx, request); // an exception is never an allow
List<Map<String, Object>> parties = engine.whoCan(ctx, "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#
| Question | Rust | JavaScript | Python |
|---|---|---|---|
| May this subject do this to this resource? | decide, check_for | check, decide | check, decide |
| Why did it come out that way? | explain | explain | explain |
| What would turn a denial into an allow? | why_not | whyNot | why_not |
| Which resources of a kind can the subject reach? | list | list | list |
| Who holds this permission? | who_can, who_can_on, access_of | whoCan, whoCanOn, accessOf | who_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
explainto 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.
PermissionClientin 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
Governancein Rust orengine.applyin the other languages: it applies the change only if every invariant passes and audits the outcome.
Where to read more#
- Getting started, Concepts and JavaScript.
- Reference for the Rust API, and docs.rs.
- Security for reporting a vulnerability.