~ knotless Search/
↑↓ move↵ open⇧↵ all results
0
0

Group sessions get the tiers of a permission set their roles grant

Merged chadtmiller.com asked to merge into feature/proposal-nov from chadtmiller.com/group-host:oauth/permission-sets
crates/group-host/src/authorization.rs+22−7
@@ -127,12 +127,17 @@ impl Host {
}
}
/// What each of this host's permission sets asked for is called, and
/// says it is for.
fn labels(requested: &[String]) -> Value {
let ours = requested.iter().filter_map(|s| Some((s, set_of(s)?)));
ours.map(|(s, set)| json!({"scope": s, "title": set["title"], "text": set["detail"]}))
.collect()
/// What each of this host's permission sets among `scopes` is called,
/// and says it is for, once each.
fn labels(scopes: &[&str]) -> Value {
let mut out: Vec<Value> = Vec::new();
for (i, s) in scopes.iter().enumerate() {
let set = set_of(s).filter(|_| !scopes[..i].contains(s));
out.extend(
set.map(|set| json!({"scope": s, "title": set["title"], "text": set["detail"]})),
);
}
out.into()
}
/// An app's pending request to sign in as a group, as the caller would
@@ -170,10 +175,20 @@ pub async fn get_authorization(
for group in &groups {
offered.push(host.offered(group, &me, &requested)?.0);
}
// Each set asked for, and any within it a group would give in its
// place.
let granted = offered
.iter()
.flat_map(|g| g["granted"].as_array().into_iter().flatten());
let named: Vec<&str> = requested
.iter()
.map(String::as_str)
.chain(granted.filter_map(|g| g["scope"].as_str()))
.collect();
let mut out = json!({
"client": client,
"requested": objects("scope", &requested),
"labels": labels(&requested),
"labels": labels(&named),
"groups": offered,
});
if let Some(hint) = request.parameters.get("login_hint") {
crates/group-host/src/group.rs+16−8
@@ -6,7 +6,7 @@
//! space is its policy, against the reader's roles.
use crate::Host;
use crate::rbac::{ACTIONS, EVERY_ROLE, Grant, NS, POLICY, grants, roles_of};
use crate::rbac::{EVERY_ROLE, Grant, NS, POLICY, grants, roles_of};
use crate::repo::{Write, invalid};
use crate::store::Record;
use crate::time::{iso, now_millis};
@@ -229,17 +229,25 @@ impl Host {
put(&c("labeler"), "self", labeler()),
];
self.space_write(&did, &meta, &meta_writes).await?;
// Its founders run it, holding every action, writing any record as
// it, in its repo and in its spaces (so that they may give any
// scope a space's policy may hold), and giving any role; everyone
// else is a member.
let mut admin = Grant::with("admin", &ACTIONS, &[EVERY_ROLE], &["*"]);
admin.scopes.push("space:*?collection=*".into());
// Its founders run it: administering it, labeling, making,
// changing and ending spaces, writing any record as it, in its
// repo and in its spaces (so that they may give any scope a
// space's policy may hold), and giving any role; everyone else is
// a member.
let administers = format!("include:{NS}.authManageGroup");
let scopes = [
administers.as_str(),
"space:*?collection=com.atproto.label.record",
"space:*?manage=update",
"space:*?manage=create&manage=delete",
"space:*?collection=*",
"repo:*",
];
let mut members_writes = vec![
put(
&c("role"),
"admin",
json!({"$type": c("role"), "displayName": "Admin", "description": "Runs the group.", "scopes": admin.scopes, "assignable": admin.assignable, "createdAt": at}),
json!({"$type": c("role"), "displayName": "Admin", "description": "Runs the group.", "scopes": scopes, "assignable": [EVERY_ROLE], "createdAt": at}),
),
put(
&c("role"),
crates/group-host/src/lexicons.rs+4−5
@@ -34,13 +34,16 @@ pub const FILES: &[&str] = &[
lexicon!("fyi/opensocial/activateGroup"),
lexicon!("fyi/opensocial/addRecoveryKey"),
lexicon!("fyi/opensocial/approveAuthorization"),
lexicon!("fyi/opensocial/authManageGroup"),
lexicon!("fyi/opensocial/authManageProfile"),
lexicon!("fyi/opensocial/authModerate"),
lexicon!("fyi/opensocial/authParticipate"),
lexicon!("fyi/opensocial/cancelAccountMove"),
lexicon!("fyi/opensocial/cancelJoinRequest"),
lexicon!("fyi/opensocial/checkAddress"),
lexicon!("fyi/opensocial/checkGroupHandle"),
lexicon!("fyi/opensocial/checkImport"),
lexicon!("fyi/opensocial/completeImport"),
lexicon!("fyi/opensocial/configure"),
lexicon!("fyi/opensocial/createAppPassword"),
lexicon!("fyi/opensocial/createGroup"),
lexicon!("fyi/opensocial/createReport"),
@@ -83,8 +86,6 @@ pub const FILES: &[&str] = &[
lexicon!("fyi/opensocial/listModSubjects"),
lexicon!("fyi/opensocial/listRecoveryKeys"),
lexicon!("fyi/opensocial/listSpaceRecords"),
lexicon!("fyi/opensocial/manageMembers"),
lexicon!("fyi/opensocial/manageSpaces"),
lexicon!("fyi/opensocial/members"),
lexicon!("fyi/opensocial/membership"),
lexicon!("fyi/opensocial/meta"),
@@ -93,8 +94,6 @@ pub const FILES: &[&str] = &[
lexicon!("fyi/opensocial/migrateExport"),
lexicon!("fyi/opensocial/migratePrepare"),
lexicon!("fyi/opensocial/migrateReceive"),
lexicon!("fyi/opensocial/moderate"),
lexicon!("fyi/opensocial/participate"),
lexicon!("fyi/opensocial/policy"),
lexicon!("fyi/opensocial/profile"),
lexicon!("fyi/opensocial/provisionGroup"),
crates/group-host/src/oauth_scope.rs+143−45
@@ -4,13 +4,14 @@
//! is read later.
//!
//! No lexicon is resolved: the only permission sets a token keeps are
//! this host's own for a group's session (`fyi.opensocial.configure`,
//! `manageMembers`, `manageSpaces`, `moderate`), read from their lexicons
//! here, and a space scope naming no collection keeps every one, which
//! this host's own for a group's session (`fyi.opensocial.authManageProfile`
//! within `authModerate` within `authManageGroup`), read from their
//! lexicons here, each an upper bound: the parts of it the roles grant
//! are kept. A space scope naming no collection keeps every one, which
//! narrowing allowed only to roles that may write every one there.
use crate::Host;
use crate::group::members_space;
use crate::group::{members_space, meta_space};
use crate::lexicons::lexicons;
use crate::rbac::{self, LABEL, NS, actions_for, repo_collections_for};
use crate::scopes::{decoded, is_blob, repo_collections};
@@ -20,31 +21,33 @@ use std::collections::{BTreeMap, BTreeSet};
pub use crate::rbac::WRITES;
/// This host's permission sets for a group's session, each by its name,
/// with the actions a member's roles must hold, every one, to give it.
pub const SETS: [(&str, &[&str]); 4] = [
("configure", &["group.configure"]),
(
"manageMembers",
&["admit", "eject", "role.assign", "invite"],
),
("manageSpaces", &["space.configure"]),
("moderate", &["mod.read", "mod.resolve", "label"]),
/// This host's permission sets for a group's session, by name, each
/// within the next.
pub const TIERS: [&str; 3] = ["authManageProfile", "authModerate", "authManageGroup"];
/// The action each of the host's methods a permission set lists asks of
/// the member who signed the app in.
const ASKS: [(&str, &str); 6] = [
("listJoinRequests", "admit"),
("denyJoinRequest", "admit"),
("listInvites", "invite"),
("listModSubjects", "mod.read"),
("getModSubjectHistory", "mod.read"),
("resolveModSubject", "mod.resolve"),
];
/// The permission set of this host's that `scope` includes, from its
/// lexicon, if it is one: `include:fyi.opensocial.manageMembers`.
/// lexicon, if it is one: `include:fyi.opensocial.authModerate`.
pub fn set_of(scope: &str) -> Option<&'static Value> {
let name = scope.strip_prefix(&format!("include:{NS}."))?;
let set = lexicons().def(&format!("{NS}.{name}"));
set.filter(|d| d["type"] == "permission-set")
}
/// The actions a member's roles must hold to give an app `scope`, if it
/// is one of [`SETS`].
fn needs(scope: &str) -> Option<&'static [&'static str]> {
/// The permission set `scope` includes, if it is one of [`TIERS`].
fn tier_of(scope: &str) -> Option<&'static Value> {
let name = scope.strip_prefix(&format!("include:{NS}."))?;
SETS.iter().find(|(n, _)| *n == name).map(|(_, a)| *a)
TIERS.contains(&name).then(|| set_of(scope)).flatten()
}
/// The parts of a `space:` scope that decide whether a role may have it.
@@ -185,7 +188,11 @@ impl Host {
let policy = self.policy(&uri).map_err(XrpcError::internal)?;
let policy = policy.expect("a space the group has");
let mut writable = policy.writes(roles);
// The members space's own records, as the group grants them.
// The meta and members spaces' own records, as the group's
// roles grant them.
if uri == meta_space(group) {
writable.extend(meta_writes(actions));
}
if uri == members_space(group) {
writable.extend(self.members_writes_of(group, roles)?);
}
@@ -228,8 +235,8 @@ impl Host {
/// an app acting as the group:
///
/// - `atproto`, always;
/// - one of this host's permission sets for a group's session, for
/// roles holding every action it needs ([`SETS`]);
/// - one of this host's permission sets for a group's session
/// ([`TIERS`]), as far as the roles grant it ([`parts`]);
/// - `repo:C`, for roles whose grants hold `repo:C` or `repo:*`;
/// - `rpc:M`, a method of another service, for roles with `repo:*`,
/// never one of this host's own;
@@ -258,13 +265,15 @@ impl Host {
let held = actions_for(&grants, roles);
let rooms = self.rooms(group, roles, &held)?;
let invite = format!("{NS}.invite");
let (mut kept, mut made) = (Vec::new(), Vec::new());
// What each scope asked for gives, in the order asked.
let mut each: Vec<Vec<String>> = Vec::new();
for s in requested {
let space = SpaceScope::parse(s).filter(|w| w.for_group(group));
let keep = if s == "atproto" {
true
} else if let Some(needs) = needs(s) {
needs.iter().all(|a| held.contains(a))
} else if let Some(set) = tier_of(s) {
each.push(parts(set, &held, &rooms));
continue;
} else if let Some(named) = repo_collections(s) {
let each = !named.is_empty() && named.iter().all(|c| repo.contains(c));
everything || each
@@ -276,37 +285,116 @@ impl Host {
} else if let Some(want) = inbox_scope(s) {
held.contains("invite") && want.collections.iter().all(|c| *c == invite)
} else if let Some(want) = space.as_ref().filter(|w| w.kind == "*") {
made.extend(any_kind(group, want, &rooms));
false
each.push(any_kind(group, want, &rooms));
continue;
} else if let Some(want) = &space {
rooms.iter().any(|room| allows(want, room))
} else {
false
};
if keep {
kept.push(s.clone());
}
each.push(keep.then(|| s.clone()).into_iter().collect());
}
let writes = |s: &String| {
needs(s).is_some()
tier_of(s).is_some()
|| repo_collections(s).is_some()
|| SpaceScope::parse(s).is_some_and(|w| !w.read_only)
};
let any_write = kept.iter().chain(&made).any(writes);
let mut out: Vec<String> = requested
.iter()
.filter(|s| kept.contains(s) || (any_write && is_blob(s)))
.cloned()
.collect();
for m in made {
if !out.contains(&m) {
out.push(m);
let any_write = each.iter().flatten().any(writes);
let mut out: Vec<String> = Vec::new();
for (s, mut gives) in requested.iter().zip(each) {
if any_write && is_blob(s) {
gives.push(s.clone());
}
for g in gives {
if !out.contains(&g) {
out.push(g);
}
}
}
Ok(out)
}
}
/// What a holder of `actions` may write as the group in its meta space,
/// by collection, beyond what its policy grants: every record of it, if
/// they run the group.
pub fn meta_writes(actions: &BTreeSet<&'static str>) -> BTreeMap<String, BTreeSet<String>> {
let all: BTreeSet<String> = WRITES.map(String::from).into();
let records = ["profile", "rule", "labeler"].map(|r| (format!("{NS}.{r}"), all.clone()));
match actions.contains("group.configure") {
true => records.into(),
false => BTreeMap::new(),
}
}
/// Of `set`, one of [`TIERS`], what holders of `actions`, with `rooms`,
/// grant: each of its methods whose action they hold; of its space
/// permissions, what they may write of each collection it names, and do
/// to the space itself. All they grant of a tier is that tier.
fn parts(set: &Value, actions: &BTreeSet<&'static str>, rooms: &[Room]) -> Vec<String> {
let mut out = Vec::new();
for scope in scopes_of(set) {
if let Some(rpc) = scope.strip_prefix(&format!("rpc:{NS}.")) {
let method = rpc.split('?').next().unwrap_or_default();
let asks = ASKS.iter().find(|(m, _)| *m == method);
if asks.is_some_and(|(_, a)| actions.contains(a)) {
out.push(scope);
}
continue;
}
let want = SpaceScope::parse(&scope).expect("a set's permissions are rpc or space");
let whole = if !want.manage.is_empty() {
manages(&want, actions, rooms)
} else if want.kind == format!("{NS}.invites") {
actions.contains("invite")
} else {
let room = rooms.iter().find(|r| r.kind == want.kind);
out.extend(room.map(|r| written(&want, r)).into_iter().flatten());
false
};
if whole {
out.push(scope);
}
}
let tier = TIERS.iter().map(|t| format!("include:{NS}.{t}")).find(|t| {
let set = set_of(t).expect("each tier has its lexicon");
scopes_of(set) == out
});
match tier {
Some(tier) => vec![tier],
None => out,
}
}
/// Of the space permission `want`, a set's, what `room` lets the roles
/// write of each collection it names, as one scope for each set of
/// writes, naming the collections written so.
fn written(want: &SpaceScope, room: &Room) -> Vec<String> {
let mut by: Vec<(Vec<&String>, Vec<&String>)> = Vec::new();
for c in &want.collections {
let may = |w: &&String| may_write(&room.writable, c, w);
let writes: Vec<&String> = want.writes.iter().filter(may).collect();
match by.iter_mut().find(|(w, _)| *w == writes) {
_ if writes.is_empty() => {}
Some((_, collections)) => collections.push(c),
None => by.push((writes, vec![c])),
}
}
let at = format!(
"space:{}?authority={}&skey={}",
want.kind, want.authority, want.skey
);
let listed = |key: &str, values: &[&String]| -> String {
values.iter().map(|v| format!("&{key}={v}")).collect()
};
by.iter()
.map(|(writes, collections)| {
let (c, w) = (listed("collection", collections), listed("action", writes));
format!("{at}{c}&action=read{w}")
})
.collect()
}
/// `scope`, if it is for people's inboxes, where a group writes its
/// invites: any inbox, or one person's.
fn inbox_scope(scope: &str) -> Option<SpaceScope> {
@@ -415,7 +503,9 @@ pub fn concrete(granted: &[String], group: &str) -> String {
}
/// The scopes a permission set lists: a space permission as a space
/// scope, and an rpc one as a scope for each of its methods.
/// scope, or two where it both writes records and manages the space (the
/// second reading, and managing), and an rpc one as a scope for each of
/// its methods.
pub(crate) fn scopes_of(set: &Value) -> Vec<String> {
let mut out = Vec::new();
for p in set["permissions"].as_array().into_iter().flatten() {
@@ -425,14 +515,22 @@ pub(crate) fn scopes_of(set: &Value) -> Vec<String> {
out.extend(strings(&p["lxm"]).map(|m| format!("rpc:{m}?aud={aud}")));
continue;
}
let mut q = vec![
let space = |q: &[String]| format!("space:{}?{}", text("spaceType"), q.join("&"));
let listed = move |key: &'static str| strings(&p[key]).map(move |v| format!("{key}={v}"));
let at = vec![
format!("authority={}", text("authority")),
format!("skey={}", text("skey")),
];
for key in ["collection", "action", "manage"] {
q.extend(strings(&p[key]).map(|v| format!("{key}={v}")));
let mut q = at.clone();
q.extend(listed("collection").chain(listed("action")));
let manage: Vec<String> = listed("manage").collect();
if !manage.is_empty() && p["collection"].is_array() {
out.push(space(&q));
q = at;
q.push("action=read".into());
}
out.push(format!("space:{}?{}", text("spaceType"), q.join("&")));
q.extend(manage);
out.push(space(&q));
}
out
}
crates/group-host/src/rbac.rs+23−5
@@ -182,6 +182,21 @@ const BY_METHOD: [(&str, &str); 2] = [
("resolveModSubject", "mod.resolve"),
];
/// The actions holding `fyi.opensocial.authModerate` gives, as its
/// permissions do: memberships, invites, labels, join requests and the
/// moderation methods. `authManageGroup` gives them, and
/// `group.configure`; `authManageProfile` none, as who writes the
/// profile and rules is the meta space's policy's to say.
pub const MODERATES: [&str; 7] = [
"mod.read",
"mod.resolve",
"label",
"invite",
"admit",
"eject",
"role.assign",
];
/// The scope that grants each action.
pub fn scope_of(action: &str) -> Option<String> {
let rpc = |method: &str| format!("rpc:{NS}.{method}?aud=*");
@@ -189,14 +204,16 @@ pub fn scope_of(action: &str) -> Option<String> {
format!("space:{NS}.members?skey=self&collection={NS}.membership&action={write}")
};
Some(match action {
"group.configure" => format!("include:{NS}.configure"),
"group.configure" => format!("include:{NS}.authManageGroup"),
"space.create" => "space:*?manage=create".into(),
"space.delete" => "space:*?manage=delete".into(),
"space.configure" => "space:*?manage=update".into(),
"admit" => membership("create"),
"role.assign" => membership("update"),
"eject" => membership("delete"),
"invite" => format!("space:{NS}.invites?authority=*&collection={NS}.invite"),
"invite" => format!(
"space:{NS}.invites?authority=*&skey=self&collection={NS}.invite&action=read_self&action=create&action=update&action=delete"
),
"mod.read" => rpc("listModSubjects"),
"mod.resolve" => rpc("resolveModSubject"),
"label" => format!("space:*?collection={LABEL}"),
@@ -251,10 +268,11 @@ pub fn actions_of(scopes: &[String]) -> BTreeSet<&'static str> {
let mut out = BTreeSet::new();
for scope in scopes {
membership_actions(scope, &mut out);
if *scope == format!("include:{NS}.configure") {
if *scope == format!("include:{NS}.authManageGroup") {
out.extend(MODERATES);
out.insert("group.configure");
} else if *scope == format!("include:{NS}.manageMembers") {
out.extend(["admit", "eject", "role.assign", "invite"]);
} else if *scope == format!("include:{NS}.authModerate") {
out.extend(MODERATES);
} else if let Some(rpc) = scope.strip_prefix("rpc:") {
let method = rpc.split('?').next().unwrap_or_default();
let action = BY_METHOD
crates/group-host/src/token_writes.rs+10−8
@@ -24,7 +24,7 @@ use crate::group_spaces::PUBLISHED;
use crate::lexicons::{check_record, validation};
use crate::member_writes::members_writes;
use crate::oauth_resource::{Acting, Refusal};
use crate::oauth_scope::may_write;
use crate::oauth_scope::{may_write, meta_writes};
use crate::rbac::{self, LABEL, NS, actions_for, repo_collections_for};
use crate::repo::{Asked, Write, record_cid};
use crate::xrpc::XrpcError;
@@ -460,11 +460,14 @@ impl Host {
) -> Result<(), XrpcError> {
let group = &acting.grant.group;
let (roles, grants) = self.standing(acting)?;
let own = uri == meta_space(group) || uri == members_space(group);
let held = actions_for(&grants, &roles);
let configures = held.contains("group.configure");
let policy = self.policy(uri).map_err(XrpcError::internal)?;
let writable = policy.map(|p| p.writes(&roles)).unwrap_or_default();
let mut writable = policy.map(|p| p.writes(&roles)).unwrap_or_default();
// The meta space's own records, as its policy and the group's roles
// grant them.
if uri == meta_space(group) {
writable.extend(meta_writes(&held));
}
let labels = held.contains("label");
for w in writes {
let (collection, _) = w.path();
@@ -475,13 +478,12 @@ impl Host {
action(w)
)));
}
let still = match own {
_ if collection == LABEL => labels,
let still = match collection {
LABEL => labels,
_ if uri == members_space(group) => {
may_write(&members_writes(&grants, &roles), collection, action(w))
}
true => configures,
false => may_write(&writable, collection, action(w)),
_ => may_write(&writable, collection, action(w)),
};
if !still {
return Err(no_longer(collection));
crates/group-host/tests/common/members.rs+1−2
@@ -13,8 +13,7 @@ use serde_json::{Value as Json, json};
/// What an app asks for to run a group's members: its roles and what
/// each may do, and who holds them.
pub const RUNS: &str =
"atproto include:fyi.opensocial.configure include:fyi.opensocial.manageMembers";
pub const RUNS: &str = "atproto include:fyi.opensocial.authManageGroup";
/// The collection `name` of ours.
pub fn c(name: &str) -> String {
crates/group-host/tests/authorization.rs+46−5
@@ -10,7 +10,7 @@ use common::spaces::*;
use common::{Running, start};
use serde_json::{Value as Json, json};
const SCOPE: &str = "atproto repo:app.bsky.feed.post include:fyi.opensocial.configure include:fyi.opensocial.moderate";
const SCOPE: &str = "atproto repo:app.bsky.feed.post include:fyi.opensocial.authManageGroup include:fyi.opensocial.authModerate";
async fn join(h: &Running, did: &str, who: &str, roles: &[&str]) {
let membership = json!({"$type": format!("{NS}.membership"), "roles": roles, "createdAt": "2026-11-03T00:00:00Z"});
@@ -101,8 +101,8 @@ async fn offers_the_groups_where_the_caller_holds_a_role_with_what_the_app_would
assert_eq!(
offered["labels"],
json!([
{"scope": "include:fyi.opensocial.configure", "title": "Group settings", "text": "Edit the group's profile, rules, and roles, and decide what each role can do."},
{"scope": "include:fyi.opensocial.moderate", "title": "Group moderation", "text": "Review reports and moderation history, and label members."},
{"scope": "include:fyi.opensocial.authManageGroup", "title": "Group administration", "text": "Manage everything in the group's info and member list, including its roles and what each role can do."},
{"scope": "include:fyi.opensocial.authModerate", "title": "Group moderation", "text": "Approve, invite, label, and remove members, change their roles, and review reports."},
])
);
let mut theirs = dids(&offered);
@@ -136,8 +136,8 @@ async fn offers_the_groups_where_the_caller_holds_a_role_with_what_the_app_would
scopes(&at_riders["withheld"]),
[
"repo:app.bsky.feed.post",
"include:fyi.opensocial.configure",
"include:fyi.opensocial.moderate"
"include:fyi.opensocial.authManageGroup",
"include:fyi.opensocial.authModerate"
]
);
@@ -151,6 +151,47 @@ async fn offers_the_groups_where_the_caller_holds_a_role_with_what_the_app_would
assert_eq!(dids(&offered), [riders.as_str()]);
}
#[tokio::test]
async fn offers_the_tier_a_moderator_holds_of_the_one_asked() {
let h = start(&[], false).await;
let (riders, _, [_, bob, _]) = groups(&h).await;
let role = json!({"$type": format!("{NS}.role"), "displayName": "Moderator", "scopes": [format!("include:{NS}.authModerate")], "createdAt": "2026-11-03T00:00:00Z"});
let write = group_host::repo::Write::Create {
collection: format!("{NS}.role"),
rkey: "moderator".into(),
value: role,
};
let space = group_host::group::members_space(&riders);
h.host.space_write(&riders, &space, &[write]).await.unwrap();
let write = group_host::repo::Write::Update {
collection: format!("{NS}.membership"),
rkey: bob.did.clone(),
value: json!({"$type": format!("{NS}.membership"), "roles": ["member", "moderator"], "createdAt": "2026-11-03T00:00:00Z"}),
};
h.host.space_write(&riders, &space, &[write]).await.unwrap();
let app = App::loopback("atproto include:fyi.opensocial.authManageGroup");
let request_uri = app.push(&h, &[]).await;
let (status, offered) = offer(&h, &bob, &request_uri).await;
assert_eq!(status, 200, "{offered}");
let at_riders = &offered["groups"][0];
assert_eq!(
scopes(&at_riders["granted"]),
["atproto", "include:fyi.opensocial.authModerate"]
);
assert_eq!(
scopes(&at_riders["withheld"]),
["include:fyi.opensocial.authManageGroup"]
);
// Both named, for the page to say what each is.
assert_eq!(
scopes(&offered["labels"]),
[
"include:fyi.opensocial.authManageGroup",
"include:fyi.opensocial.authModerate"
]
);
}
#[tokio::test]
async fn offers_only_the_group_the_app_named_even_to_one_without_a_role() {
let h = start(&[], false).await;
crates/group-host/tests/groups.rs+14−10
@@ -10,7 +10,7 @@ use common::spaces::*;
use common::start;
use group_host::authority::Access;
use group_host::group::{members_space, meta_space};
use group_host::rbac::{ACTIONS, scope_of};
use group_host::rbac::ACTIONS;
use group_host::repo::Write;
use serde_json::{Value as Json, json};
@@ -174,11 +174,10 @@ async fn shows_a_group_as_each_viewer_may_see_it() {
assert_eq!(admin["actions"], json!(every));
assert_eq!(admin["assignable"], json!([{"role": "*"}]));
assert_eq!(admin["repoCollections"], json!([{"collection": "*"}]));
assert_eq!(mine["bindings"][1]["actions"], json!([]));
// Each role's grant in its own record: the founders hold one with
// every action's scope, any record as the group in its repo and its
// spaces, and every role to give; and the members' role, the default,
// nothing more.
// Each role's grant in its own record: the founders administer the
// group, label, make, change and end spaces, write any record as the
// group in its repo and its spaces, and give every role; and the
// members' role, the default, nothing more.
let members = members_space(&did);
let role = |key: &str| {
let found = h
@@ -186,13 +185,18 @@ async fn shows_a_group_as_each_viewer_may_see_it() {
.group_record(&did, &members, &format!("{NS}.role"), key);
found.unwrap().unwrap()
};
let mut scopes: Vec<String> = ACTIONS.iter().map(|a| scope_of(a).unwrap()).collect();
scopes.push("repo:*".into());
scopes.push("space:*?collection=*".into());
let scopes = json!([
format!("include:{NS}.authManageGroup"),
"space:*?collection=com.atproto.label.record",
"space:*?manage=update",
"space:*?manage=create&manage=delete",
"space:*?collection=*",
"repo:*",
]);
let founders = role("admin");
assert_eq!(
(&founders["scopes"], &founders["assignable"]),
(&json!(scopes), &json!(["*"]))
(&scopes, &json!(["*"]))
);
let everyone = role("member");
assert_eq!(everyone["default"], true);
crates/group-host/tests/members.rs+12−2
@@ -187,7 +187,11 @@ async fn an_admin_defines_roles_and_what_they_may_do() {
&h,
"role",
"moderator",
with("moderator", &["include:fyi.opensocial.moderate"], &[]),
with(
"moderator",
&["include:fyi.opensocial.authParticipate"],
&[],
),
)
.await,
(400, "ScopeNotHeld"),
@@ -268,7 +272,13 @@ async fn a_writer_changes_only_the_grants_of_roles_they_may_give() {
let steward = granting(&h, &did, "steward", &[&configure], &["member", "steward"]);
keep(&h, &did, "role", "steward", steward).await;
join(&h, &did, &bob.did, &["member", "steward"]).await;
let bobs = Session::of(&h, &bob, &did, "atproto include:fyi.opensocial.configure").await;
let bobs = Session::of(
&h,
&bob,
&did,
"atproto include:fyi.opensocial.authManageGroup",
)
.await;
let with = |role: &str, scopes: &[&str], assignable: &[&str]| {
granting(&h, &did, role, scopes, assignable)
};
crates/group-host/tests/oauth_scope.rs+166−54
crates/group-host/tests/rbac.rs+16−2
crates/group-host/tests/tokens.rs+5−4
crates/opensocial/src/lib.rs+5−5
crates/opensocial/tests/commands.rs+8−2
docs/design/membership.md+22−12
docs/design/moderation.md+3−1
docs/design/signing-in.md+39−23
docs/reference/cli.md+1−1
harness/lexicons.mjs+10−1
lexicons/fyi/opensocial/authManageGroup.jsonnew+86−0
lexicons/fyi/opensocial/authManageProfile.jsonnew+31−0
lexicons/fyi/opensocial/authModerate.jsonnew+76−0
lexicons/fyi/opensocial/participate.json → lexicons/fyi/opensocial/authParticipate.jsonrenamed+20−7
lexicons/fyi/opensocial/configure.jsondeleted+0−32
lexicons/fyi/opensocial/getAuthorization.json+1−1
lexicons/fyi/opensocial/manageMembers.jsondeleted+0−42
lexicons/fyi/opensocial/manageSpaces.jsondeleted+0−40
lexicons/fyi/opensocial/moderate.jsondeleted+0−42
web/src/lib/actions.ts+3−2