The RuleGate Guide

August 1, 2026 · View on GitHub

This guide teaches RuleGate as a complete authorization system, not as a list of unrelated APIs. It begins with the authorization question, builds one working application, and then extends that application through roles, permissions, attributes, request context, resources, identity providers, frontends, testing, diagnostics, reload, and production operations.

You do not need previous RBAC, ABAC, or CBAC experience. You should be comfortable reading small C#, YAML, and—when using the frontend chapters— TypeScript examples.

What you will learn

By the end of the guide, you will be able to:

  • explain the boundary between authentication and authorization;
  • model role-, permission-, attribute-, context-, and resource-based rules;
  • select and install the correct NuGet and npm packages;
  • write, validate, test, explain, and lint rulegate.yaml;
  • protect Minimal APIs, MVC controllers, and imperative service operations;
  • load trusted subject, resource, and context data through providers;
  • integrate any standards-based identity system and use the optional Keycloak helpers where appropriate;
  • project backend grants into modern Angular, legacy Angular, or a framework-independent TypeScript application;
  • load policies from files, embedded resources, configuration, memory, or an application-defined source and replace them atomically;
  • diagnose decisions without exposing sensitive authorization data;
  • test positive, negative, missing-data, and failure paths;
  • extend RuleGate with custom factories, providers, requirements, evaluators, diagnostics sinks, clocks, and policy sources;
  • deploy RuleGate with a fail-closed production posture.

How to read this guide

For a first integration, read the chapters in order. Experienced readers can use the package and capability indexes to jump directly to a recipe.

ChapterOutcome
1. Authorization foundationsUnderstand authentication, authorization, RBAC, PBAC, ABAC, CBAC, resources, and fail-closed decisions
2. Packages and installationSelect the correct NuGet and npm packages for the host and framework version
3. First protected APIRun one policy through YAML, ASP.NET Core, authentication, and HTTP authorization
4. Policy languageExpress every built-in requirement and combine them safely
5. ASP.NET Core integrationProtect Minimal APIs, MVC endpoints, services, and custom resources
6. Trusted attributes and contextImplement subject, resource, and context providers with clear trust boundaries
7. Identity and KeycloakConnect existing authentication while keeping policies provider-independent
8. Frontend integrationUse the TypeScript client, Angular guards, directives, generators, and Keycloak adapter
9. CLI and policy lifecycleValidate, generate, test, explain, and lint policies locally and in CI
10. Testing and diagnosticsProve allow and deny behavior and operate safe diagnostics and telemetry
11. Policy sources and reloadChoose a source and activate new policy snapshots atomically
12. ExtensibilityAdd application-specific mapping, requirements, providers, clocks, and sinks
13. Real-world recipesApply the model to ownership, tenancy, approvals, classification, MFA, schedules, and service identities
14. Production checklistReview security, operations, troubleshooting, compatibility, and upgrades
GlossaryLook up RuleGate and authorization terminology

Every chapter ends with links to the next chapter and to the detailed reference documents. The guide explains the journey; the references enumerate complete contracts, operators, error codes, and security boundaries.

Capability coverage

Use this table to locate a feature without reading the guide linearly.

CapabilityTeaching chapterExhaustive reference
Authentication vs authorizationFoundationsSecurity
Roles and permissionsFoundationsAuthorization model
Subject/resource/context attributesPolicy languageManifest reference
String, number, date, collection, presence, null, and empty operatorsPolicy languageManifest operators
Attribute-to-attribute comparisonPolicy languageAttribute comparison
all, any, and notPolicy languageLogical requirements
Time, date-time, authentication age, and MFA agePolicy languageTime requirements
Minimal API and MVC protectionASP.NET CoreASP.NET Core reference
Imperative and direct engine authorizationASP.NET CoreImperative authorization
Subject/resource/context providersTrusted attributesEnrichment
Organization-specific application contextTrusted attributesContext trust
Generic identity-provider mappingIdentitySubject mapping
Keycloak realm/client rolesIdentity and KeycloakKeycloak reference
Framework-independent frontend stateFrontendFrontend compatibility
Modern and legacy Angular guards/directivesFrontendAngular reference
C# and TypeScript generationCLI lifecycleC# generation
Policy validation, tests, explanation, and lintingCLI lifecycleCLI
Safe diagnostics and OpenTelemetryTesting and diagnosticsDiagnostics
File, embedded, configuration, memory, and custom sourcesPolicy sourcesPolicy sources reference
Atomic reload and last-valid snapshotPolicy sourcesReload sequence
Factories, evaluators, sources, sinks, and clocksExtensibilityExtension references
Ownership, tenancy, approvals, confidential access, service identitiesRecipesReference applications
Production security and troubleshootingProduction checklistSecurity model

The running example

Most chapters use a document-approval system with these facts:

  • a user is authenticated by an external identity provider;
  • permissions describe capabilities such as DOC.READ and DOC.APPROVE;
  • roles group responsibilities such as DOCUMENT.APPROVER;
  • a user belongs to an organization and has a clearance level;
  • a document has an owner, organization, status, and classification level;
  • approval may require a trusted device, an internal network, fresh MFA, and a weekday business-hours window;
  • the backend makes the authoritative decision;
  • the frontend uses a limited grant projection only to shape the interface.

This example is deliberately richer than a single role check. Real systems usually combine identity, business data, request context, and resource state.

The one rule to remember

Frontend visibility is never the security boundary. Identity tokens, JavaScript state, route guards, hidden buttons, and disabled controls do not authorize a backend operation. The protected backend must evaluate RuleGate against trusted data for every operation.

Guide conventions

  • Identifiers are exact, ordinal, and case-sensitive. DOC.READ and doc.read are different.
  • Examples use stable 1.0.0 package APIs.
  • YAML examples use schema version 1.
  • Missing policies, missing required data, invalid values, provider failures, evaluator failures, and unsupported input deny access.
  • Placeholder authentication in the first sample is explicitly marked. Use a real validated authentication handler in production.
  • Commands run from the repository or application root unless stated otherwise.

Complete references

Use these after the teaching chapters when you need exhaustive detail:


Next: Authorization foundations