p2panda_auth/lib.rs
1// SPDX-License-Identifier: MIT OR Apache-2.0
2
3//! `p2panda-auth` provides decentralised group management with fine-grained, per-member
4//! permissions.
5//!
6//! Once a group has been created, members can be added, removed, promoted and demoted. Each
7//! member has an associated access level which can be used to determine their permissions. The
8//! access levels are `Pull`, `Read`, `Write` and `Manage`. Each access level is a superset of the
9//! lower levels and can be assigned an associated set of conditions; this allows fine-grained
10//! partitioning of each access level. For example, `Read` conditions could be assigned with a
11//! path to restrict access to areas of a dataset. Finally, only members with `Manage` access are
12//! allowed to modify the group state by adding, removing, promoting or demoting other members.
13//!
14//! The access levels defined by `p2panda-auth` may prove useful when controlling replication of
15//! datasets. Custom sync protocols can be defined which rely on group membership and access
16//! levels to determine who to sync with and over which subsets of data. Access conditions can be
17//! used to define application-layer specific access rules, for example when modelling moderation
18//! rules or additional write checks.
19//!
20//! ## Features
21//!
22//! ### Eventually Consistent Group State
23//!
24//! Peers replicating group operations will all eventually arrive at the same group state, even
25//! when operations are authored concurrently or received out of order. Resolution of conflicting
26//! state happens automatically.
27//!
28//! ### Strict Group Modification
29//!
30//! Only operations authored by members with “manage” access level will be applied to the group
31//! state.
32//!
33//! ### Customisable Concurrency Resolution
34//!
35//! A group operation "resolver" is used to decide which operations should be invalidated in
36//! certain concurrent situations. While the default concurrency resolver follows a cautious
37//! "strong removal" approach, alternative approaches can be realised using custom implementations
38//! of the provided `Resolver` trait.
39//!
40//! ## Design
41//!
42//! ### Group Operations
43//!
44//! Group state is modified by the publication of group operations. Each operation is signed by
45//! the author and includes an action, along with fields to define previous operations and other
46//! dependencies. The previous field allows causal ordering of operations in relation to one
47//! another and the dependencies field allows custom application logic to define relationships
48//! between groups and group operations.
49//!
50//! ### Directed Acyclic Graph (DAG)
51//!
52//! All operations comprising a group for a Directed Acyclic Graph (DAG). This data structure
53//! allows for concurrent operations to published and later resolved by merging divergent states.
54//!
55//! ### Concurrency Resolution for Conflicting Operations
56//!
57//! Certain concurrent scenarios lead to group state conflicts which must be resolved. In such
58//! cases, all operations in the DAG are walked in a depth-first search so that any "bubbles" of
59//! concurrent operations may be identified. Resolution rules are then applied to the operations
60//! in these bubbles in order to populate a filter of operations to be invalidated. Once the
61//! offending operations have been invalidated, any dependent operations are then invalidated in
62//! turn.
63//!
64//! The provided "strong removal" resolver defines the following rules:
65//!
66//! 1) Removal or demotion of a manager causes any concurrent actions by that member to be
67//! invalidated
68//! 2) Mutual removals, where two managers remove or demote one another concurrently, are not
69//! invalidated; both removals are applied to the group state but any other concurrent actions
70//! by those members are invalidated
71//! 3) Re-adds are allowed; if Alice removes Charlie then re-adds them, they are still a member of
72//! the group but all of their concurrent actions are invalidated
73//! 4) Invalidation of transitive operations; invalidation of an operation due to the application
74//! of the aforementioned rules results in all dependent operations being invalidated
75mod access;
76pub mod graph;
77pub mod group;
78#[cfg(any(test, feature = "test_utils"))]
79pub mod test_utils;
80pub mod traits;
81
82pub use access::{Access, AccessLevel};