A fully generic, trait-based authentication and authorization framework for Rust. Provides identity types, credential management, passport challenges, a complete RBAC system (RBAC0/1/2) implementing the ANSI INCITS 359-2004 standard, and a dynamic authorization layer with trust scoring, anomaly detection, and DO-178C inspired autonomy levels (L0โL4).
The name kirino comes from the character Kirino in the game Blue Archive.
Still in development, the API may change in the future.
Features
- ๐ก๏ธ Zero-Trust Architecture: Anonymous, Basic, Temporary, and Service identity types
- ๐ Multi-Credential Support: One-time tokens, JWT, service tokens, and more
- ๐ซ Passport Challenges: Static password, key pair, OAuth, TOTP/HOTP, captcha, biometric
- ๐ Argon2 Password Hashing: Secure password verification out of the box
- ๐ฏ Full RBAC System: RBAC0 (base), RBAC1 (hierarchy), RBAC2 (constraints)
- ๐ Role Inheritance: Multi-level role hierarchies with cycle detection
- โ๏ธ Separation of Duty: SSD (static) and DSD (dynamic) constraint enforcement
- ๐ Cardinality & Prerequisite Constraints: Limit role holders and enforce role prerequisites
- โฑ๏ธ Temporal Constraints: Time-bounded role validity with automatic expiry
- ๐พ In-Memory First: Zero-dependency reference implementations for all backends
- ๐๏ธ Pluggable Storage: Trait-based backends for SQL, Redis, and more
- ๐ Audit Logging: Three-layer composable audit (sink + policy engine + analyzer)
- ๐ง Dynamic Authorization: Runtime risk scoring with trust decay, anomaly detection, and domain scoping
- ๐๏ธ Autonomy Levels: DO-178C inspired L0โL4 autonomy levels with configurable strategies
- ๐ Anomaly Detection: Sliding-window z-score pattern deviation with adaptive baselines
- ๐ Trust Decay: Configurable exponential trust decay with background worker
- ๐งฉ Fully Generic: Define your own
PermissionandSubjecttypes via traits - โก Async/Tokio: Built on async Rust with Tokio runtime
- ๐ JWT Integration: Built-in JWT issuance and verification
Quick Start
Add kirino to your Cargo.toml:
[]
= "0.5"
= { = "1", = ["full"] }
= { = "1", = ["derive"] }
Define your permissions and roles:
use *;
Or use the built-in AuthService for a complete setup:
use ;
use InMemoryUserDatabase;
let db = new;
let engine = build_default_engine;
let service = new;
Documentation
Multilingual documentation is available:
| Language | Index |
|---|---|
| English | docs/en/guides/index.md |
| ็ฎไฝไธญๆ (Simplified Chinese) | docs/zh-Hans/guides/index.md |
| ็น้ซไธญๆ (Traditional Chinese) | docs/zh-Hant/guides/index.md |
| ๆฅๆฌ่ช (Japanese) | docs/ja/guides/index.md |
| ํ๊ตญ์ด (Korean) | docs/ko/guides/index.md |
| ะ ัััะบะธะน (Russian) | docs/ru/guides/index.md |
| Espaรฑol (Spanish) | docs/es/guides/index.md |
| Franรงais (French) | docs/fr/guides/index.md |
Crate-level API documentation is available at docs.rs/kirino.
Architecture
Kirino is a layered authentication and authorization framework:
graph TD
subgraph SERVICE["Service Layer"]
AUTH["AuthService<br/>register / login / verify"]
SESSION["SessionManager<br/>create / activate / destroy"]
end
subgraph AUTHN["Authentication Layer"]
IDENTITY["Identity<br/>Anonymous / Basic / Temporary / Service"]
CREDENTIAL["Credential<br/>OneTime / JWT / ServiceToken"]
PASSPORT["Passport<br/>StaticPassword / KeyPair / OAuth / DynamicPassword / Captcha / Biometric"]
end
subgraph AUTHZ["Authorization Layer (RBAC)"]
ENGINE["RbacEngine<br/>check / check_batch / check_hierarchical"]
STORE["AssignmentStore / RoleStore"]
CONSTRAINTS["ConstraintValidator<br/>SSD / DSD / Cardinality / Prerequisite"]
CACHE["PermissionCache<br/>TTL-based LRU"]
AUDIT["AuditLogger<br/>Sink + PolicyEngine + Analyzer"]
end
subgraph DYN["Dynamic Authorization"]
ARBITER["AuthorizationArbiter<br/>authorize / risk_score / feedback"]
TRUST["TrustScore + TrustDecayWorker"]
ANOMALY["AnomalyDetector<br/>Sliding window + z-score"]
POLICY["DynamicPolicy<br/>5-dim risk + autonomy L0-L4"]
DOMAIN["TaskDomain + DomainScope"]
end
subgraph DB["Database Layer"]
MEMORY["InMemory Stores<br/>(zero-dependency ref impl)"]
DYNAMIC["Dynamic Auth<br/>(feature: rbac-dynamic)"]
CACHE["Permission Cache<br/>(TTL-based)"]
end
IDENTITY --> CREDENTIAL --> PASSPORT --> AUTH --> SESSION
SESSION --> ENGINE
ENGINE --> STORE
ENGINE --> CONSTRAINTS
ENGINE --> CACHE
ENGINE --> AUDIT
ENGINE --> ARBITER
ARBITER --> TRUST
ARBITER --> ANOMALY
ARBITER --> POLICY
ARBITER --> DOMAIN
ARBITER --> AUDIT
STORE --> MEMORY
STORE --> SQL
CACHE --> REDIS
Core Concepts
Authentication Pipeline
Kirino authenticates users through a three-step pipeline:
flowchart LR
I["Identity<br/>Who are you?"]
C["Credential<br/>Prove it"]
P["Passport<br/>Challenge accepted"]
I --> C --> P
RBAC Layers
Implements all three levels of the ANSI INCITS 359-2004 RBAC standard:
graph TD
subgraph RBAC0["RBAC0 โ Base"]
B0["Subject โ Role โ Permission"]
end
subgraph RBAC1["RBAC1 โ Hierarchy"]
B1["Role inheritance with cycle detection"]
end
subgraph RBAC2["RBAC2 โ Constraints"]
B2["SSD / DSD / Cardinality / Prerequisite / Temporal"]
end
RBAC0 --> RBAC1 --> RBAC2
Decision Flow
flowchart TD
START(["check(subject, permission)"]) --> CACHE{"Cache hit?"}
CACHE -->|yes| RETURN_CACHED(["Return cached result"])
CACHE -->|no| DENIED{"In denied_permissions?"}
DENIED -->|yes| RETURN_DENY(["DENY โ persist to cache"])
DENIED -->|no| EXTRA{"In extra_permissions?"}
EXTRA -->|yes| RETURN_ALLOW(["ALLOW โ persist to cache"])
EXTRA -->|no| ROLES["Resolve assigned roles"]
ROLES --> HIER["Expand role hierarchy"]
HIER --> CHECK["Permission โ role permissions?"]
CHECK -->|yes| RETURN_ALLOW2(["ALLOW โ persist to cache"])
CHECK -->|no| RETURN_DENY2(["DENY โ persist to cache"])
Deny-override semantics: Denied permissions always take precedence over granted ones โ even over role-based or extra permissions.
Dynamic Authorization
On top of static RBAC, kirino provides a runtime risk-scoring layer inspired by NIST SP 800-207/162 and DO-178C:
flowchart TD
REQ["ActionRequest<br/>(delegator + category + domain)"]
REQ --> RISK["Compute 5-dimension risk score"]
RISK --> D1["Trust (30%)"]
RISK --> D2["Sensitivity (25%)"]
RISK --> D3["Domain Scope (25%)"]
RISK --> D4["Anomaly (10%)"]
RISK --> D5["Delegator Type (10%)"]
D1 & D2 & D3 & D4 & D5 --> MAP["Map risk โ Autonomy Level"]
MAP --> L0["L0: Lockdown (reject all)"]
MAP --> L1["L1: Human approval required"]
MAP --> L2["L2: Escalate + audit"]
MAP --> L3["L3: Proceed with audit"]
MAP --> L4["L4: Autonomous"]
Trust scores decay exponentially over time. Anomaly detection uses sliding-window z-score analysis. The arbiter supports lockdown/restore and compliance/violation feedback loops.
Identity Types
| Identity | Description |
|---|---|
| Anonymous | Unauthenticated visitor, minimal permissions |
| Basic | Standard user, starts with minimal permissions |
| Temporary | Time-limited account, auto-expires |
| Service | Service account for permission delegation |
Built-in Roles (Default Engine)
| Role | Permissions |
|---|---|
admin |
All permissions (13 across 6 domains) |
operator |
agent:, config:read, knowledge:, container:read, system:read |
viewer |
agent:read, config:read, knowledge:read, container:read, system:read |
agent |
agent:execute, agent:read |
Feature Flags
[]
= ["rbac-inmemory", "auth-password", "auth-jwt"]
= [] # Traits and engine only
= ["rbac-core"] # In-memory assignment/role stores
= ["rbac-core"] # RBAC1 hierarchical role inheritance
= ["rbac-core"] # RBAC2 constraint models (SSD/DSD)
= ["rbac-core"] # Dynamic risk-based authorization
= [ # All features enabled
"rbac-inmemory", "rbac-hierarchy", "rbac-constraints",
"rbac-dynamic", "auth-password", "auth-jwt"
]
= ["dep:argon2"] # Argon2 password hashing
= ["dep:jsonwebtoken"] # JWT token issuance/verification
Design Philosophy
Kirino is designed to be a pure library consumed by downstream projects:
- โ Provides generic trait-based abstractions for RBAC
- โ Implements ANSI INCITS 359-2004 standard (RBAC0/1/2)
- โ Zero-dependency in-memory reference implementations
- โ
Domain-agnostic: define your own
SubjectandPermissiontypes - โ Deny-override semantics for security-first access control
- โ Cache-aware permission checks with TTL support
It does not prescribe:
- โ Specific permission or role types (you define your own)
- โ Authentication UI or middleware (library-level only)
- โ Database schema (trait-based โ bring your own backend)
- โ Network protocols (expose via your own API layer)
Requirements
- Rust 1.75+ (edition 2021)
- Tokio async runtime
License
Licensed under the Synthetic Source License (SySL), Version 1.0.