AegisTesting 0.8.0
See the version list below for details.
dotnet add package AegisTesting --version 0.8.0
NuGet\Install-Package AegisTesting -Version 0.8.0
<PackageReference Include="AegisTesting" Version="0.8.0" />
<PackageVersion Include="AegisTesting" Version="0.8.0" />
<PackageReference Include="AegisTesting" />
paket add AegisTesting --version 0.8.0
#r "nuget: AegisTesting, 0.8.0"
#:package AegisTesting@0.8.0
#addin nuget:?package=AegisTesting&version=0.8.0
#tool nuget:?package=AegisTesting&version=0.8.0
Aegis
A modern, cloud-native authorization platform for .NET
Build expressive, policy-driven authorization by combining the best ideas from Cerbos, Cedar, Zanzibar, OpenFGA, and AuthZEN—while embracing the .NET ecosystem from the ground up.
Aegis is domain-agnostic, but the primary target vertical is regulated finance — banking, SACCOs, insurance — where authorization decisions need to be explainable to an auditor, not just correct. See Compliance notes for regulated finance below for how that shapes the design.
Status
Phase 0 (MSSQL + existing ASP.NET Identity/IdentityServer/OpenIddict auth
server integration) is done. Phase 1's core engine slice — policy loading,
validation, the expression engine, the decision engine, the explain API, DI/
ASP.NET Core registration, and a CLI — is also done, except the compiler/IR
pipeline described below, which is deliberately deferred: still a
tree-walking interpreter, and that's a later optimization once the
expression surface is stable. Policies can also share reusable ${name}
variables and derived roles (roles computed from a condition, or from
Cedar-style entity-hierarchy membership, rather than held directly by the
principal) via imports: -- see Policy as Code below.
No standalone server, no dashboard yet.
src/
Aegis.Core Principal, Resource, AuthorizationDecision, DecisionExplanation,
IAttributeProvider, IClaimsPrincipalMapper
Aegis.Expressions Tokenizer, parser, tree-walking evaluator for condition expressions
(member paths, literals, `${name}` variable references)
Aegis.Policies ResourcePolicy/ActionRule/AllowRule/DerivedRoleDefinition model,
IPolicyProvider, YAML loader (variables/derivedRoles/imports)
Aegis.Relationships Cedar-style entity hierarchy (EntityUid/EntityParent), pluggable
IRelationshipProvider, RelationshipGraph (`in` membership, #15-#18)
Aegis.Evaluator PolicyEvaluator (decision engine), PolicyValidator, opt-in decision
caching (AegisEngine.WithDecisionCache), AegisEngine facade
Aegis.Sql SQL Server-backed IAttributeProvider + IPolicyProvider
Aegis.AspNetCore services.AddAegis(...) DI registration, HttpContext.User authorization
Aegis.Cli `aegis validate`/`aegis authorize` -- a dotnet tool (AegisCli)
Aegis.Testing ShouldAllowAsync/ShouldDenyAsync -- CI-friendly policy regression tests,
no application host required
tests/
Aegis.Tests Fast, no external dependencies -- the required CI check
Aegis.IntegrationTests Real SQL Server via Testcontainers -- separate, non-required CI job
samples/
Aegis.Sample Runnable loan-approval walkthrough (see below)
Getting started
dotnet test # run the test suite
dotnet run --project samples/Aegis.Sample # role-based + attribute-based + relationship-based decisions, with explain output
The sample models a SACCO/bank loan approval: a loan officer can approve an application only if it's in their own branch, within their lending limit, and not their own application.
var engine = AegisEngine.Create("Policies");
var decision = await engine.AuthorizeAsync(
principal: loanOfficer,
resource: loanApplication,
action: "approve");
if (decision.Allowed)
{
// Disburse the loan
}
resource: loan_applications
imports:
- lending-common # shared variables/derived roles -- see lending-common.yaml
actions:
approve:
allow:
when: ${sameBranch} && ${withinLimit} && !${isApplicant}
flag_conflict_of_interest:
allow:
roles:
- applicant # a derived role from lending-common.yaml, not a static one
Or via DI (Aegis.AspNetCore), authorizing straight off HttpContext.User --
any IAttributeProvider/IPolicyProvider registered elsewhere (e.g.
Aegis.Sql's AddSqlServerAttributeProvider) is picked up automatically,
in any registration order:
services.AddAegis(options => options.AddPolicies("Policies"));
// in an endpoint/controller:
var decision = await engine.AuthorizeAsync(HttpContext, loanApplication, "approve");
Or from the command line (dotnet tool install -g AegisCli, exposing an
aegis command) -- useful in CI to catch a broken policy before it ships,
or to sanity-check a decision without writing code:
aegis validate Policies
aegis authorize Policies \
--principal-id officer-1 --role LoanOfficer \
--principal-attr branch=nairobi-cbd --principal-attr approvalLimit=500000 \
--resource-kind loan_applications --resource-id LN-1001 \
--resource-attr branch=nairobi-cbd --resource-attr amount=250000 --resource-attr applicantId=member-42 \
--action approve # exit code 0 = allowed, 1 = denied, 2 = error; prints the explain JSON either way
Or as CI-friendly policy regression tests (Aegis.Testing) -- no application host,
no DI container, works with any test framework:
using Aegis.Testing;
var engine = AegisEngine.Create("Policies");
await engine.ShouldAllowAsync(officer, withinLimitApplication, "approve");
await engine.ShouldDenyAsync(officer, ownApplication, "approve"); // segregation of duties
A mismatch throws PolicyAssertionException with the full decision
explanation attached, so a failing test tells you which condition didn't
evaluate the way the policy intended -- not just "expected allow, got deny".
Compliance notes for regulated finance
Three patterns regulated-finance deployments care about, and where each one stands today versus the roadmap below:
- Audit trail. Every decision already carries a
DecisionExplanation— which policy and rule matched, and the result of every condition evaluated. That's an audit record for free on every call today; what's missing is a persistence layer for it, which is Phase 4's "Audit logs." - Segregation of duties. No special engine feature — it's just an ABAC
condition, as in the loan sample's
principal.id != resource.applicantId. Any "can't act on your own thing" rule follows the same shape. - Branch/tenant isolation. Also expressible today as ABAC
(
principal.branch == resource.branch), which is fine for single-tenant or branch-scoped deployments. True multi-tenant isolation — separate policy sets per tenant, enforced at the storage layer rather than by convention in every policy — is Phase 3 work. Until then, ABAC-based scoping is the pattern, and it's on the policy author to apply it consistently rather than the engine enforcing it structurally. - Data residency. Policy Storage (see below) is designed pluggable
specifically so a regulated deployment can pick a backend that keeps
policy data in-region. The filesystem loader and a SQL Server backend
(
Aegis.Sql) both exist today; blob storage, Git, and the rest of the README's Policy Storage list remain future work.
Vision
Aegis aims to become the de facto authorization platform for .NET, much like:
- ASP.NET Core for web applications
- OpenIddict for OAuth/OpenID Connect
- OpenTelemetry for observability
Rather than being a rewrite of an existing project, Aegis is designed as a first-class .NET authorization ecosystem that combines proven ideas from existing systems while remaining implementation-independent.
Philosophy
Aegis is inspired by existing authorization systems but not constrained by them.
| Project | Inspiration | Reference |
|---|---|---|
| Cerbos | Policy-driven authorization, PDP architecture, resource policies, explainability | docs.cerbos.dev |
| Cedar | Safe policy language, formal authorization model, expressive conditions | Cedar language reference · Cedar paper (Amazon Science) |
| Zanzibar | Relationship-based authorization (ReBAC), graph authorization, scalability | Zanzibar: Google's Consistent, Global Authorization System (USENIX ATC '19) |
| OpenFGA | Relationship tuples and authorization modeling | openfga.dev docs |
| AuthZEN | Standard authorization APIs and interoperability | Authorization API 1.0 (OpenID AuthZEN WG) |
| ASP.NET Core | Dependency Injection, middleware, authorization handlers | ASP.NET Core docs |
| OpenTelemetry | Observability, metrics, tracing | opentelemetry.io |
The objective is to combine the strongest concepts from each into a cohesive, modern authorization platform.
Design Principles
Aegis should be:
- .NET-first
- Cloud-native
- Embedded or standalone
- Policy-driven
- Explainable
- Extensible
- High-performance
- Standards-friendly
- Observable
- Developer-friendly
What Aegis Is
Aegis is an authorization engine, not an authentication system.
Authentication
↓
Identity + Access Token
↓
Aegis Authorization Engine
↓
Authorization Decision
Authentication remains the responsibility of OAuth, OpenID Connect, Microsoft Entra ID, OpenIddict, Keycloak, etc.
Aegis answers one question:
"Can this principal perform this action on this resource?"
Core Capabilities
Policy as Code
Policies should live alongside application code.
resource: invoices
actions:
view:
allow:
roles:
- Finance
approve:
allow:
when:
principal.department == resource.department
Policies become versioned, testable, and deployable through normal CI/CD pipelines.
Repeated conditions can be named with ${name} variables, and roles that
depend on a condition rather than being held directly by the principal can
be expressed as derived roles -- both shareable across policies via
imports::
# lending-common.yaml -- a library: identified by `name:`, no `resource:` key
name: lending-common
variables:
sameBranch: principal.branch == resource.branch
isApplicant: principal.id == resource.applicantId
derivedRoles:
applicant:
when: principal.id == resource.applicantId
resource: loan_applications
imports:
- lending-common
actions:
approve:
allow:
when: ${sameBranch} && !${isApplicant}
flag_conflict_of_interest:
allow:
roles:
- applicant
Hybrid Authorization Model
Rather than forcing developers into a single authorization model, Aegis should support multiple models together.
RBAC
User
↓
Role
↓
Permission
ABAC
Principal Attributes
+
Resource Attributes
+
Environment
↓
Decision
Example:
principal.department == resource.department
ReBAC
Alice
Member
Project
Owns
Repository
Relationships become first-class citizens.
Policies should be able to combine all three approaches naturally.
Architecture
Applications
│
┌─────────────────┼──────────────────┐
│ │ │
ASP.NET Core Minimal APIs Background Workers
│ │ │
└─────────────────┼──────────────────┘
│
Aegis SDK
│
┌───────────────────┼───────────────────┐
│ │ │
Policy Compiler Decision Engine Storage Providers
│
▼
Intermediate Representation (IR)
│
▼
Policy Runtime
│
▼
Relationship Engine
│
▼
Attribute Providers
│
▼
Authorization Decision
The authorization engine is the core.
Everything else becomes an adapter.
Compilation Pipeline
Policies should be compiled rather than interpreted on every request.
YAML / Cedar
↓
Parser
↓
AST
↓
Semantic Validation
↓
Intermediate Representation (IR)
↓
Optimization
↓
Compiled Policy
↓
Evaluation
Benefits:
- Faster execution
- Better diagnostics
- Static validation
- Future support for multiple policy languages
Expression Engine
Expressions compile once.
Expression
↓
Compile
↓
Delegate
↓
Evaluate
Example:
principal.department == resource.department
avoids repeated parsing during evaluation.
Explainable Decisions
Every authorization decision should explain why it was reached.
Example:
{
"effect": "allow",
"matchedPolicy": "invoice-policy",
"matchedRule": "department-match",
"conditions": [
{
"expression": "principal.department == resource.department",
"result": true
}
]
}
Explainability improves:
- Debugging
- Auditing
- Compliance
- Developer experience
Policy Storage
Support multiple policy sources.
Filesystem
Git
Database
Azure Blob Storage
Amazon S3
Redis
HTTP
Storage should be pluggable through provider interfaces.
Attribute Providers
Authorization often requires additional data.
Example:
Principal
↓
SQL
↓
Manager
↓
Department
↓
Decision
Developers can register providers:
services.AddAttributeProvider<UserAttributeProvider>();
Relationship Engine
Relationships become data rather than application logic. Originally scoped
against Zanzibar/OpenFGA-style
named relation tuples, but built against
Cedar's entity-hierarchy model instead —
Aegis is leaning toward Cedar's conventions since adopting Cedar itself is
the direction of travel, so reusing its shape here means less to reconcile
later. An entity has a set of parents; a derived role's in check is
Cedar's own in operator
(https://docs.cedarpolicy.com/policies/syntax-datatypes.html#operator-in):
true if the principal equals the target entity, or reaches it by walking up
the parent hierarchy — covering direct membership and nested groups
(a member of a sub-team is transitively a member of the parent team) alike.
# Relationships/audit_committee.yaml -- Cedar's own entity data format
# (https://docs.cedarpolicy.com/auth/entities-syntax.html), in YAML.
entities:
- uid: { type: User, id: officer-1 }
parents:
- type: Group
id: senior-auditors
- uid: { type: Group, id: senior-auditors }
parents:
- type: Group
id: audit-committee
derivedRoles:
committeeMember:
in:
type: Group
id: "'audit-committee'"
actions:
review:
allow:
roles:
- committeeMember
var engine = await AegisEngine.Create("Policies")
.WithRelationshipsAsync(new YamlRelationshipProvider("Relationships"));
officer-1 is allowed to review even though they only hold a direct
membership in senior-auditors, not audit-committee itself — the graph
walk (breadth-first, cycle-safe) finds the two-hop path. Storage is
pluggable via IRelationshipProvider (YamlRelationshipProvider for
files, InMemoryRelationshipProvider for tests), separate from policy
storage.
AuthZEN Compatibility
Aegis should expose a standards-based authorization API — see the Authorization API 1.0 specification from the OpenID Foundation's AuthZEN Working Group (tracked in #20).
Application
↓
AuthZEN Request
↓
Aegis Runtime
↓
Authorization Decision
The runtime should remain independent of transport protocols.
Observability
Every decision should produce telemetry.
Metrics:
- Policy compilation time
- Evaluation latency
- Cache hit ratio
- Cache misses
- Authorization throughput
Tracing:
HTTP Request
↓
Authentication
↓
Authorization
↓
Database
↓
Response
Logging:
- Policy loaded
- Policy updated
- Rule matched
- Decision produced
.NET-Native Experience
Aegis should embrace modern .NET features.
- Dependency Injection
- Generic Host
- Minimal APIs
- Native AOT
ILoggerIOptionsSystem.Text.Json- Source Generators
- OpenTelemetry
Developers should feel like they're using another Microsoft-style library.
Package Layout
Aegis
├── Aegis.Core
├── Aegis.Compiler
├── Aegis.IR
├── Aegis.Expressions
├── Aegis.Evaluator
├── Aegis.Relationships
├── Aegis.Storage
├── Aegis.Models
├── Aegis.AuthZEN
├── Aegis.AspNetCore
├── Aegis.Server
├── Aegis.Cli
├── Aegis.Dashboard
└── Aegis.Testing
Development Roadmap
Tracked as issues, not duplicated here — this list drifts from reality the moment something ships or gets reprioritized, and it already has once.
- Milestones — Phase 0 (MSSQL & existing auth server integration, first priority) through Phase 4 (Platform), each with its issues.
- Project board — same issues, Todo/In Progress/Done view.
Long-Term Vision
Aegis Platform
+-----------------------+
| Dashboard |
+-----------+-----------+
|
v
Aegis Authorization Server
|
+-------------------+-------------------+
| |
v v
AuthZEN API REST / gRPC API
| |
+-------------------+-------------------+
|
v
Aegis Runtime
|
+-----------+--------------+---------------+-------------+
| | | | |
v v v v v
Compiler IR Evaluator Relationships Policy Store
|
v
YAML / Cedar / JSON / Git / Database
Guiding Principle
Aegis should not compete by being "Cerbos in C#".
Instead, it should become a modern authorization platform for .NET that:
- Learns from Cerbos' policy architecture.
- Adopts Cedar's expressive and safe policy model.
- Incorporates Zanzibar/OpenFGA relationship-based authorization.
- Exposes AuthZEN-compatible APIs for interoperability.
- Feels completely natural to .NET developers.
- Supports embedded libraries and standalone PDP deployments.
- Prioritizes performance, observability, and explainability.
The ultimate goal is to provide a robust, extensible authorization platform that empowers .NET developers to build secure systems with confidence while remaining adaptable to evolving standards and authorization models.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- AegisEvaluator (>= 0.8.0)
- Ehncraft.Aegis.Core (>= 0.8.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.