1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
//! Authorization for id_effect services: policies are capabilities.
//!
//! - **Who** — the [`Principal`] trait (implemented by `id_effect_auth`'s principals and by
//! [`BasicPrincipal`]), installed per request or job as the [`CurrentPrincipal`] capability.
//! - **Rules** — a [`Policy<Res>`](Policy) evaluates the principal against a resource as an
//! effect returning a [`Decision`]; policies compose ([`PolicyExt`], [`all_of`], [`any_of`]).
//! - **Roles and permissions** — [`Rbac`]: role → permission table with inheritance and
//! `area:*` wildcards ([`Rbac::require`], [`has_permission`]).
//! - **Resources** — ownership ([`owner`]), tenant match ([`same_tenant`]) and access lists
//! ([`Acl`], [`acl_permits`]).
//! - **Tenant isolation** — automatic: every policy defined for a [`Tenanted`] resource, or run
//! on one with [`check_with`] / [`authorize_with`], first requires the principal's tenant to be
//! the resource's ([`TenantScope`]); crossing tenants is the recorded opt-out
//! [`PolicyExt::dangerous_cross_tenant`]. Resource types of no tenant declare so with
//! `impl TenantScope for T {}`.
//! - **Attributes** — claim predicates ([`claim_equals`], [`claim_contains`], [`claim`],
//! [`claim_matches`]).
//! - **Named policies** — [`Policies`], a registry capability; [`authorize`] and [`check`]
//! evaluate a rule by name for the principal in the environment.
//!
//! A denial is a value ([`Decision::Deny`] with a [`Denial`] reason) until
//! [`authorize`] / [`authorize_with`] turn it into an [`AuthzError`] whose
//! [`http_status`](AuthzError::http_status) is 401 for an anonymous principal and 403 otherwise.
//!
//! ```
//! use id_effect::{Effect, Exit, HCons, HNil, hlist};
//! use id_effect_authz::{
//! AuthzError, BasicPrincipal, CurrentPrincipal, Policies, Rbac, authorize,
//! };
//!
//! let rbac = Rbac::builder().grant("accountant", ["ledger:post"]).build();
//! let policies = Policies::builder().define::<()>("ledger.post", rbac.require("ledger:post")).build();
//!
//! fn post_entry() -> Effect<(), AuthzError, HCons<CurrentPrincipal, HCons<Policies, HNil>>> {
//! authorize("ledger.post", ())
//! }
//!
//! let carol = CurrentPrincipal::new(BasicPrincipal::new("carol").with_role("accountant"));
//! assert_eq!(post_entry().provide_all(hlist![carol, policies]).block_on(), Exit::Success(()));
//! ```
//!
//! - **Decision events** — every decision can be recorded as a serialisable [`DecisionEvent`] to
//! the [`AuthzEvents`] sink capability ([`PoliciesBuilder::events`], [`AuthzEvents::observe`]).
//! - **Route guards** (feature `axum`) — `guard::Guard`, a Tower layer answering 401/403 with
//! Problem Details, attached with `guard::AuthorizeExt::authorize`.
//! - **Test helpers** (feature `testing`) — `testing::AuthzTest` with `assert_allows` /
//! `assert_denies` and the decisions it recorded.
//!
//! Tier `platform` (ADR 0010 Amendment 5): the Ledger reference app under
//! `examples/reference/` depends on it.
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
/// Compiles and runs the README's code block as a doctest.
;