The pieces / weirdnet-access

weirdnet-access

Access policy: Private/Public and Open/Gated, a shared permission core apps extend, ranked roles, and the enforcement order.

v0.1.2 GitHub crates.io docs.rs weirdnet-access = "0.1.2"

What it brings

One answer to "may this peer do this to this resource?" across every Weirdnet app, so Morph sites and Muninn orgs behave the same: who can see a resource exists, who can get in, what each role may do, and whether the reply must be sealed. Apps supply role defaults and their own permissions; they don't hard-code forum or org types into it.

What it is

Access policy for Weirdnet apps. It answers “may this peer do this to this resource?” the same way in every app, from facts the app has already checked.

How it works

Two independent settings

Visibility is Private (only the owner and trusted peers know it exists; members must be trusted too) or Public. Access is Open (no membership needed) or Gated (a valid membership is needed). On the wire it is always gated; CLIs may also accept members, member and closed. New resources default to Private + Open.

Permissions and roles

The core Catalog is read, members.list, members.approve, members.invite, members.kick, members.role, members.defaults and roles.manage. Apps add their own with implications (files.delete includes files.write, which includes files.read), followed transitively; cycles are refused. Roles have a name, a rank and permissions. Presets: owner_member (Morph) and ranked (owner/admin/user/viewer, Muninn). The owner can do everything and alone grants the builtin owner role (always *); everyone else manages only roles and members ranked below them. Removing a role moves its members to the lowest remaining role. Apps that keep roles elsewhere use roles::check_grant and check_over (0.1.1).

Enforcement order

StepPrivatePublic
1. Identityrevoked node: not foundrevoked node: denied
2. Visibilitynot the owner and not trusted: not foundcontinue
3. Membership (Gated)none: not foundnone: join first
4. Rolethe role must allow itthe role must allow it
5. Transportsealedsealed if Gated, plain if Open

Guests act under the resource's guest role only on Open resources, never with managing permissions. The crate doesn't depend on weirdnet-net: the app passes in Facts it has already checked (the node certificate, the trust list and the presented membership).

Key types and modules

  • Visibility, Access: the two independent settings.
  • Catalog, Permission: the core permissions, app permissions and implications.
  • Role, RoleSet, Actor, presets, check_grant, check_over: ranked roles and rank rules.
  • decide, Facts, Settings, Decision, Transport: enforcement.

Feature flags

None: everything is on by default.

Usage

In Cargo.toml:

[dependencies]
weirdnet-access = "0.1.2"

Then (built and run against the published crate when this page was made):

// A public, members-only resource: a member may write (sealed), a stranger must join first.
use weirdnet_access::*;

fn main() -> Result<()> {
    let mut catalog = Catalog::core();
    catalog.add("files.read", "download files", false)?;
    catalog.add("files.write", "upload and change files", false)?;
    catalog.imply("files.write", &["files.read"])?;
    let roles = presets::ranked(&catalog, &["files.write"], &["files.read"])?;

    let settings = Settings { visibility: Visibility::Public, access: Access::Gated };
    // From weirdnet-net: the node cert, the trust list, and `check_presented` on the membership.
    let member = Facts { user: Some("ulf".into()), membership_role: Some("user".into()), ..Default::default() };
    assert!(matches!(decide(&catalog, &roles, settings, &member, "files.write"), Decision::Allow { transport: Transport::Sealed, .. }));
    let stranger = Facts { user: Some("someone".into()), ..Default::default() };
    assert_eq!(decide(&catalog, &roles, settings, &stranger, "files.read"), Decision::JoinFirst);
    Ok(())
}

Where it fits

  • Used by Muninn (org roles), Morph.
  • Extracted from Muninn.
  • License: BSD-3-Clause.