Skip to main content

Overview

LibXMTP implements a flexible permission system for group management. Permissions are stored as MLS Unknown Group Context Extensions and control who can perform various group actions.

PolicySet

The PolicySet struct defines all permission policies for a group.

Fields

Methods

new

Creates a new PolicySet with specified policies.

new_dm

Creates a PolicySet for DM conversations (all membership/admin actions denied).

evaluate_commit

Core client-side verification that a commit adheres to the permission policies. Parameters:
  • commit - Validated commit to evaluate
Returns: true if commit is valid, false otherwise Validation Rules:
  1. Add member policy not violated
  2. Remove member policy not violated (super admins cannot be removed)
  3. Metadata update policies not violated
  4. Admin add/remove policies not violated
  5. Super admin changes require super admin privileges
  6. Last super admin cannot be removed
  7. Permission changes require super admin privileges

to_bytes / from_bytes

Serialize/deserialize PolicySet for storage.

Preconfigured Policies

PreconfiguredPolicies Enum

to_policy_set

Converts a preconfigured policy to a full PolicySet.

from_policy_set

Detects which preconfigured policy matches a PolicySet (if any).

All Members (Default)

The default preconfigured policy allows broad member participation:

Admin Only

The admin-only policy restricts most actions to admins:

Membership Policies

MembershipPolicies Enum

Policies for adding/removing members and installations.

Factory Methods

BasePolicies

Base membership policies:
  • Allow - Allow unconditionally
  • Deny - Deny unconditionally
  • AllowSameMember - Allow if change applies to actor’s own installations
  • AllowIfAdminOrSuperAdmin - Allow if actor is admin or super admin
  • AllowIfSuperAdmin - Allow if actor is super admin

MembershipPolicy Trait

Implemented by all membership policy types.

Metadata Policies

MetadataPolicies Enum

Policies for updating metadata fields.

Factory Methods

default_map

Creates a default map of metadata policies for all supported fields. Special Cases:
  • MessageDisappearInNS and MessageDisappearFromNS default to admin-only
  • MinimumSupportedProtocolVersion defaults to super-admin-only
  • Other fields use the provided policy

MetadataBasePolicies

MetadataPolicy Trait

Permissions Policies

PermissionsPolicies Enum

Policies for updating group permissions and admin lists.

Factory Methods

PermissionsBasePolicies

Note: There is no “Allow” base policy for permissions (more restrictive than membership/metadata).

PermissionsPolicy Trait

Composite Policies

AndCondition

Evaluates to true if all contained policies evaluate to true.

AnyCondition

Evaluates to true if any contained policy evaluates to true.

GroupMutablePermissions

Wrapper struct for storing permissions as an MLS extension.

Methods

new

preconfigured_policy

Detects if the policies match a preconfigured policy.

Conversions

Helper Function

Extracts permissions from an OpenMLS group.

Admin Roles

Admin

  • Can perform actions allowed by admin-or-super-admin policies
  • Cannot modify super admins
  • Cannot change permission policies

Super Admin

  • Can perform all admin actions
  • Can add/remove other super admins (but not the last one)
  • Can add/remove regular admins
  • Can change permission policies
  • Automatically set as the group creator
  • Cannot be removed from the group (must remain at least one)
  • Cannot leave the group (must be demoted first)

Unrecognized Metadata Fields

When evaluating metadata changes for fields without explicit policies:
  • Fields starting with _ (super admin prefix): Require super admin
  • All other fields: Require admin or super admin

Error Handling

PolicyError

GroupMutablePermissionsError

Usage Examples

Creating a Custom Policy

Using Preconfigured Policies

Extracting Permissions from a Group

Source References

  • PolicySet: crates/xmtp_mls/src/groups/group_permissions.rs:884
  • Preconfigured Policies: crates/xmtp_mls/src/groups/group_permissions.rs:1311
  • Membership Policies: crates/xmtp_mls/src/groups/group_permissions.rs:670
  • Metadata Policies: crates/xmtp_mls/src/groups/group_permissions.rs:173
  • Permissions Policies: crates/xmtp_mls/src/groups/group_permissions.rs:430