-
Notifications
You must be signed in to change notification settings - Fork 0
01 Authorization Foundations
Authorization answers a business question: may this subject perform this action on this resource under the current context?
RuleGate represents that sentence directly:
subject + resource + action + context -> policy -> allow or deny
flowchart LR
S[Subject<br/>identity, roles, permissions, attributes]
R[Resource<br/>type, ID, business state]
A[Action<br/>read, update, approve]
C[Context<br/>time, network, device, session]
S --> P[Policy requirement tree]
R --> P
A --> P
C --> P
P --> D{Decision}
D -->|Satisfied| Y[Allow]
D -->|Not satisfied or indeterminate| N[Deny]
Before writing code, learn what each part means and where its data should come from.
Authentication establishes who or what is calling. OpenID Connect, OAuth 2.0, JWT bearer authentication, cookies, Keycloak, Microsoft Entra ID, Auth0, and a custom identity service can all authenticate callers.
Authorization decides what an authenticated caller may do. A valid token does not imply permission to approve an invoice, read another tenant's document, or export confidential records.
RuleGate does not log users in, issue tokens, store passwords, or manage users.
It receives an authenticated ClaimsPrincipal or an explicitly constructed
subject and evaluates local policies. This separation keeps policies
provider-independent.
The subject is the authenticated actor:
id: alice
roles: [DOCUMENT.APPROVER]
permissions: [DOC.READ, DOC.APPROVE]
attributes:
organizationId: records
clearanceLevel: 3
approvalLimit: 50000
Subject data may include a stable identifier, roles, permissions, and trusted application attributes. Claims can supply identity facts, while a subject attribute provider can load current organization or clearance data from an application service.
The resource is the business object being protected:
type: document
id: doc-1042
attributes:
ownerId: alice
organizationId: records
classificationLevel: 2
status: submitted
totalAmount: 12000
A route identifier is not enough for resource-based authorization. The backend must resolve that identifier to trusted domain data before RuleGate can compare ownership, organization, status, or classification.
The action is a stable business verb such as read, update, submit,
approve, reject, publish, or export. Prefer domain language over HTTP
verbs. approve remains meaningful whether the operation is exposed by HTTP,
a queue consumer, or an application service.
Context describes trusted facts about this decision rather than durable facts about the subject or resource:
evaluationTime: 2026-08-01T09:30:00+03:00
attributes:
networkZone: internal
requestChannel: web
trustedDevice: true
authenticationTime: 2026-08-01T08:00:00+03:00
multiFactorAuthenticationTime: 2026-08-01T09:25:00+03:00
Context should be derived by trusted server-side components. Never trust an
arbitrary X-Network-Zone header or a browser-provided trustedDevice flag.
The common acronyms describe where a rule gets its evidence. RuleGate can use them separately or compose them in one policy.
flowchart TD
P[One RuleGate policy]
P --> RBAC[RBAC<br/>roles]
P --> PBAC[PBAC<br/>permissions]
P --> ABAC[ABAC<br/>typed attributes]
P --> CBAC[CBAC<br/>request context]
P --> RES[Resource rules<br/>ownership and state]
RBAC grants access because the subject has a role:
requirement:
role: DOCUMENT.APPROVERUse roles for stable responsibilities such as auditor, approver, or administrator. Avoid one role per individual document or tenant; that turns the identity system into a copy of application state.
PBAC grants access because the subject has a capability:
requirement:
permission: DOC.APPROVEPermissions are often more precise than roles. A role may aggregate several permissions, while policies still ask for the capability they need. RuleGate does not expand roles into permissions; the identity/application mapping must supply the effective values.
ABAC evaluates typed attributes:
requirement:
attributeComparison:
left:
source: subject
name: clearanceLevel
operator: greaterThanOrEqual
right:
source: resource
name: classificationLevelABAC is a good fit for ownership, organization, department, classification,
limits, document status, employment type, labels, regions, and other domain
facts. Attribute values are typed; the number 3 is not the string "3".
CBAC evaluates the circumstances of the request:
requirement:
all:
- context:
property: networkZone
operator: in
valueType: stringCollection
value: [internal, vpn]
- context:
property: trustedDevice
operator: equal
valueType: boolean
value: true
- contextAge:
timestamp: mfa
maximumAge: '00:15:00'Use context for request channel, trusted network classification, device trust, tenant selection, authentication age, MFA age, and the evaluation clock.
Resource-based authorization evaluates the actual object, not only a global claim:
requirement:
all:
- attributeComparison:
left: { source: subject, name: userId }
operator: equal
right: { source: resource, name: ownerId }
- attribute:
source: resource
name: status
operator: equal
valueType: string
value: draftIt is the difference between “Alice can update documents” and “Alice can update this draft because she owns it.”
A realistic approval policy can require all of the following:
-
DOC.APPROVEpermission; -
DOCUMENT.APPROVERrole; - same organization as the document;
- sufficient approval limit;
- not the document owner;
- submitted document state;
- internal or VPN network;
- trusted device;
- MFA no older than 15 minutes;
- weekday business hours.
This is PBAC + RBAC + ABAC + CBAC + resource-based authorization. The policy is more expressive and easier to audit than a single giant role.
RuleGate selects exactly one policy by the pair:
resourceType + action
For example, document/read and document/approve are different routes.
Policy IDs are stable names used for diagnostics, tests, generated constants,
and frontend projections; the route is what the backend engine evaluates.
If no matching policy exists, RuleGate denies. Duplicate routes are rejected during manifest validation.
Requirements produce one of three internal outcomes:
-
Satisfied: the requirement passed; -
NotSatisfied: trusted data was present and the rule did not match; -
Indeterminate: the rule could not be evaluated safely.
Policies combine requirements with:
-
all: every child must be satisfied; -
any: at least one child must be satisfied; -
not: the child must be not satisfied.
An indeterminate result is never converted into an allow. This matters for
not: missing data does not become permission simply because the positive
rule could not be evaluated.
RuleGate denies when:
- no policy matches;
- a requirement is not satisfied;
- a required attribute is missing;
- an attribute has an incompatible type;
- a provider cannot load trusted data;
- a policy source fails before the first valid snapshot;
- an evaluator or integration extension fails;
- manifest input is invalid;
- evaluation is cancelled.
This is the central security promise: uncertainty cannot silently become access.
| Fact | Put it on | Example |
|---|---|---|
| Stable actor identity | Subject | id = alice |
| Actor capability | Subject permission | DOC.READ |
| Actor responsibility | Subject role | DOCUMENT.APPROVER |
| Actor business assignment | Subject attribute | organizationId = records |
| Protected object state | Resource attribute | status = submitted |
| Protected object ownership | Resource attribute | ownerId = alice |
| Request circumstance | Context attribute | networkZone = internal |
| Decision time | Context evaluation time | current trusted clock |
Do not copy every token claim into attributes. Explicit mapping makes the trust boundary reviewable.
For every protected operation, complete this sentence:
A subject may action this resource when requirements, using trusted sources for each fact.
Example:
An authenticated approver may approve this submitted document when the user and document belong to the same organization, the amount is within the user's limit, the user is not the owner, the request comes from a trusted device on an internal network, and MFA is fresh. Identity facts come from a validated token; assignments and document facts come from application services; network and device facts come from the server trust evaluator.
If you cannot name the trusted source, the policy is not ready.
Previous: Guide home · Next: Packages and installation
Canonical source: docs/guide · Documentation index · RuleGate 1.0.0
- Home
- 1. Authorization foundations
- 2. Packages and installation
- 3. First protected API
- 4. Policy language
- 5. ASP.NET Core integration
- 6. Trusted attributes and context
- 7. Identity and Keycloak
- 8. Frontend integration
- 9. CLI and policy lifecycle
- 10. Testing and diagnostics
- 11. Policy sources and reload
- 12. Extensibility
- 13. Real-world recipes
- 14. Production checklist
- Glossary