# Introduction

Strig answers one question: may this subject do this to this resource?

You write a policy. You ask questions. Each answer is a verdict and the grant that produced it. The examples on this page run against Strig 0.10.

Three questions, all about Bruno and `document.edit`:

| Question | Verdict | Why |
| --- | --- | --- |
| A document in Apollo's `plans` folder | allow | `g-edit` gives editors the permission on the project. |
| A document in Apollo's `legal` folder | deny | `g-seal` sits on the folder, a step closer to the document than the project, so it decides. |
| A document in Zephyr | deny | Bruno has no role in Zephyr, so no grant applies. |

Bruno can still read the `legal` folder: `g-view` allows `document.view`, and an editor inherits the viewer role.

> **Note**
>
> With no grant that applies, the answer is deny. A condition Strig cannot evaluate never opens access.

## How it thinks

Five things make up every decision.

**Subject.** Who is asking: an id, roles (optionally limited to a place), and attributes. Bruno holds `editor` in `project:apollo`, so the role does not reach Zephyr.

**Resource.** What is being touched, written as a path from the most specific step to the broadest: `document:spec → folder:legal → project:apollo → org:acme`. The path is how a grant on a project reaches a document inside it.

**Permission.** A dotted key from the catalog, such as `document.edit`. The catalog is validated when the policy loads. A permission that is not in it is denied, and `depends_on` means `document.edit` only holds where `document.view` does.

**Grant.** An `allow` or a `deny` for a subject, a permission and a target, optionally limited by scope, a condition or a validity window.

**Decision.** The engine collects the grants that apply along the resource path, then picks one. The default strategy, `most_specific`, lets the grant on the closest step decide, and a `deny` beats an `allow` on the same step. That is why `g-seal` overrides `g-edit` above. The other strategies (`deny_overrides`, `permit_overrides`, `first_applicable`) are one line in the policy.

The decision names the grant that settled it, so "why was this denied?" has an answer without reading code.

### One policy, three models

The same grants carry all three access-control models.

- **RBAC.** Roles inherit roles, as `editor` inherits `viewer` above.
- **ABAC.** A grant can carry a condition over `subject.*`, `resource.*` and `env.*`, for example `when subject.dept == "legal"`.
- **ReBAC.** A grant can apply to whoever holds a relation, such as `editor` on a document, read from tuples you store.

## Ask it

**Rust**

```rust
use strig::{Context, Reason, Request, Resource};

let policy = strig::dsl::parse("documents.strig", SOURCE)?.policy;
let engine = policy.engine_spec().builder()?.build()?;
let bruno = policy.subjects.iter().find(|s| s.id.as_deref() == Some("bruno")).expect("in the policy");
let ctx = Context::new(&policy.grants);

let legal = Resource::new("document", "spec")
    .within("folder", "legal")
    .within("project", "apollo")
    .within("org", "acme");

let decision = engine.decide(&ctx, &Request::new(bruno, "document.edit", &legal));
assert!(!decision.is_allowed());
assert!(matches!(&decision.reason, Reason::Grant { grant_id, .. } if grant_id == "g-seal"));
```

**Node**

```js
import { load, scopeFromString } from '@the-hades-organization/strig';

const strig = await load();
const policy = strig.compile(SOURCE, { file: 'documents.strig' });

const { catalog, roles, strategy } = policy;
const engine = new strig.Engine({ catalog, roles, strategy });
const ctx = new strig.Context({ grants: policy.grants });
const bruno = policy.subjects.find((s) => s.id === 'bruno');

const resource = scopeFromString('document:spec/folder:legal/project:apollo/org:acme');
engine.check(ctx, { subject: bruno, permission: 'document.edit', resource }); // false
engine.explain(ctx, { subject: bruno, permission: 'document.edit', resource }).decision.reason.grantId; // 'g-seal'
```

`SOURCE` is the policy above. The same policy compiles to the same canonical JSON whether you write it as Rules, Blocks or Actors; see the [policy language](https://strig.vercel.app/docs/policy-language.md).

## Where it runs

The core does no IO, needs no async runtime and compiles to WebAssembly. Everything else is a separate crate or package you add only when you need it.

| You want | Use |
| --- | --- |
| Decisions inside a Rust service | `strig` |
| Decisions in Node or Bun, native or WebAssembly | `@the-hades-organization/strig` |
| Decisions in the browser, from the same engine | the WebAssembly build of the same package |
| Decisions from Python, Go or Java | [`strig-auth`](https://strig.vercel.app/docs/integrations/python.md), [the Go module](https://strig.vercel.app/docs/integrations/go.md), [the JVM artifact](https://strig.vercel.app/docs/integrations/jvm.md) |
| Decisions for services that do not embed the engine | `strig-server`, an HTTP server with a Rust client that denies when it gets no answer ([guide](https://strig.vercel.app/docs/integrations/server.md)) |
| Grants kept in Postgres or Redis | [`strig-postgres` and `strig-redis`](https://strig.vercel.app/docs/storage/postgres.md) |
| Permission changes pushed to clients as they happen | `strig-sync`, with Redis or Postgres between instances, and `strig-axum` for SSE and WebSocket |
| A policy checked while your crate compiles | `strig-macros`: `policy!` and `include_policy!` |
| A policy tested, diffed and linted in CI | `strig test`, `strig diff`, `strig lint` ([tools](https://strig.vercel.app/docs/tools/testing.md)) |
| The trace of a decision, grant simulation and the audit trail | the [inspector](https://strig.vercel.app/docs/tools/inspector.md), in a window or from the terminal |

On top of the decision, Strig covers how permissions change:

- **Field permissions.** A permission can name the fields it covers, and a grant narrows to some of them ([modeling](https://strig.vercel.app/docs/modeling/field-permissions.md)).
- **Governed changes.** Governance applies a change only if every invariant passes (no escalation, no lockout, your own rules), and reports who gains and who loses access before it applies ([impact](https://strig.vercel.app/docs/governance/impact.md)).
- **Approvals.** A change can wait for an approver, be time-boxed as an [elevation](https://strig.vercel.app/docs/governance/elevation.md), or be reviewed in a [recertification](https://strig.vercel.app/docs/governance/recertification.md) campaign. [Separation of duties](https://strig.vercel.app/docs/governance/separation-of-duties.md) keeps incompatible permissions apart.
- **Audit.** With the `audit` feature, each change, applied or refused, becomes a hash-chained record, and if the record cannot be written the change is refused. A third party can [verify the trail](https://strig.vercel.app/docs/audit.md) without trusting you.
- **Consistency.** A decision can require the revision of a change you just made ([consistency](https://strig.vercel.app/docs/storage/consistency.md)).

## When to use it, and when not

Use Strig when permissions depend on where a resource sits (an organization, a project, a folder), when a deny should be a first-class answer, or when you need to explain a decision or audit a change after the fact.

Skip it when the check is a single flag on a user and will stay one. A column is simpler.

Two limits to know before you start:

- **Stable from 1.0, not yet released.** The current release is 0.10, where a minor version can still break the API. From 1.0, a breaking change to the Rust engine, the JSON spec, the policy language, the audit format or the npm package takes a new major version, with a deprecation window first. The Python, Go and Java and Kotlin packages, the Wasm ABI and the command-line tools are experimental: no semver guarantee until the versioning policy says otherwise. [Upgrading](https://strig.vercel.app/docs/upgrading.md) lists exactly what that covers.
- **The client does not guard anything.** `PermissionClient` decides locally for the interface. The server still decides on every operation.

## Where to next

- [Getting started](https://strig.vercel.app/docs/getting-started.md): Install the crate or the package and ask the first question.

- [Concepts](https://strig.vercel.app/docs/concepts.md): Permissions, roles, grants and how a verdict is reached.

- [Policy language](https://strig.vercel.app/docs/policy-language.md): One policy in three syntaxes, with the grammar.

- [Reference](https://strig.vercel.app/docs/reference.md): Every public name by crate and package, the HTTP API and the error codes.

- [Playground](https://github.com/The-Hades-Organization/Strig/tree/main/playground): Edit a policy and watch the engine answer, in the browser. There is no hosted copy yet; build it from the repository.
