This project has been archived by its maintainers, and is no longer receiving any updates.
initguard
Unmaintained. initguard is no longer maintained and will not get security fixes. The GitHub repository is being deleted. Existing releases stay on PyPI so old lockfiles keep resolving. Don't use it in new projects.
Embedded ABAC policy engine for AI agents.
Write authorization policies in YAML with CEL conditions, evaluate them in-process. No sidecar, no HTTP, no external service. Policies use when/unless clauses for readable rules and return structured Decision objects with human-readable reasons and advice.
Install
pip install initguard
Quick start
Create a policy file:
# policies/tool_policy.yaml
apiVersion: initguard/v1
kind: ResourcePolicy
resource: tool
rules:
- actions: ["execute"]
effect: allow
roles: ["agent"]
when: request.resource.attr.tool_type in ["http", "search"]
- actions: ["execute"]
effect: deny
roles: ["agent"]
when: request.resource.attr.tool_type == "shell"
unless: request.principal.attr.tags.exists(t, t == "trusted")
advice: "Shell tools require the 'trusted' tag."
Load and evaluate:
from initguard import PolicyEngine, Principal, load_policies
engine = PolicyEngine(load_policies("./policies"))
agent = Principal(
id="agent:helper",
roles=["agent"],
attrs={"tags": ["basic"]},
)
decision = engine.check(agent, "tool", "execute", resource_attrs={"tool_type": "shell"})
print(decision.allowed) # False
print(decision.reason) # "denied by tool_policy.yaml:rules[1]"
print(decision.advice) # "Shell tools require the 'trusted' tag."
Policy format
Three document kinds, all in YAML.
Schema (optional)
Lint your policies against known attribute names. Catches typos at load time.
apiVersion: initguard/v1
kind: Schema
principals:
agent:
attrs:
team: string
tags: list
resources:
tool:
attrs:
tool_type: string
actions: [execute]
DerivedRoles
Conditional role elevation using CEL. A definition matches when when is true and unless is false (or absent). Names must be globally unique.
apiVersion: initguard/v1
kind: DerivedRoles
name: agent_roles
definitions:
- name: trusted_agent
parentRoles: ["agent"]
when: request.principal.attr.tags.exists(t, t == "trusted")
- name: same_team
parentRoles: ["agent"]
when: request.principal.attr.team != ""
unless: request.principal.attr.team != request.resource.attr.team
ResourcePolicy
Allow/deny rules for a resource kind. Deny always wins over allow. Every rule must declare at least one of roles or derivedRoles.
apiVersion: initguard/v1
kind: ResourcePolicy
resource: tool
importDerivedRoles: [agent_roles]
rules:
- actions: ["execute"]
effect: allow
derivedRoles: ["trusted_agent"]
- actions: ["execute"]
effect: deny
roles: ["agent"]
when: request.resource.attr.tool_type in ["shell", "python"]
unless: request.principal.attr.tags.exists(t, t == "trusted")
advice: "Requires the 'trusted' tag."
Derived roles are scoped to imports -- a ResourcePolicy only sees roles from the sets it explicitly imports, preventing privilege leakage across policy domains.
API
load_policies(policy_dir) -> PolicySet
Load all *.yaml / *.yml files from a directory. Files are loaded in sorted order for deterministic precedence. All CEL expressions are compiled at load time. Raises PolicyLoadError on invalid YAML, bad CEL syntax, duplicate role names, or broken references.
PolicyEngine(policy_set)
engine = PolicyEngine(policy_set)
engine.check(principal, resource_kind, action, resource_id="*", resource_attrs=None) -> Decision
Evaluate policies and return a Decision. Also available as check_async for async contexts.
engine.info() -> EngineInfo
Returns loaded policy summary: resource kinds, derived role sets, policy/rule counts, schema presence.
Decision
| Field | Type | Description |
|---|---|---|
allowed |
bool |
Whether the action is permitted |
reason |
str |
Human-readable explanation, always populated |
matched_rule |
str |
Stable rule identifier, e.g. "tool_policy.yaml:rules[1]" |
advice |
str |
From the rule's advice field, or empty |
Principal
| Field | Type | Description |
|---|---|---|
id |
str |
Identity string, e.g. "agent:code-reviewer" |
roles |
list[str] |
Role list, e.g. ["agent", "team:platform"] |
attrs |
dict[str, Any] |
Attributes for CEL conditions |
CEL expressions
Conditions use Google Common Expression Language. Supported patterns:
# List membership
request.resource.attr.tool_type in ["shell", "python"]
# Existential quantifier
request.principal.attr.tags.exists(t, t == "trusted")
# Attribute equality
request.principal.attr.team == request.resource.attr.team
# Boolean operators
!request.principal.attr.tags.exists(t, t == "admin") && request.resource.attr.tool_type == "shell"
Missing attributes in CEL expressions evaluate to false (condition not met), not an error.
Development
uv sync --all-extras
uv run pytest tests/ -v
uv run ruff check . && uv run ruff format --check .
License
MIT OR Apache-2.0
Metadata
Release files for initguard 2026.3.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| initguard-2026.3.4.tar.gz | 62.3 kB | With provenance | Details for initguard-2026.3.4.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| initguard-2026.3.4-py3-none-any.whl | Python 3 | none | any | Details for initguard-2026.3.4-py3-none-any.whl |
Total release size: 79.0 kB
Release files / initguard-2026.3.4.tar.gz
| Download URL | initguard-2026.3.4.tar.gz |
|---|---|
| Size | 62.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7418b66713054fe4ac96f5fbeb8524ea6d224d51638fdc8f0c1cd5f1b054ae73
|
|
BLAKE2b-256 checksum How to use checksums |
09dcc82870ba9a4d1f16cc347653cd9758bdda26eb26da9af3e57f07cafc5d71
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 16, 2026.
Transparency logRelease files / initguard-2026.3.4-py3-none-any.whl
| Download URL | initguard-2026.3.4-py3-none-any.whl |
|---|---|
| Size | 16.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
718fe0d903aae6852785e20979f424692974055224278835b5f574b40b1c2f43
|
|
BLAKE2b-256 checksum How to use checksums |
0d9ea5c8d186192f6eb826574b41d5b3c705aedad4e5df5bfaa01de31445f45e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 16, 2026.
Transparency logSecurity for initguard 2026.3.4
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for initguard-2026.3.4.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 16, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.