chadtmiller.com/group-host
atmosphere group host
0
0
Approval keeps reading a space the group has yet to make
.changeset/read-spaces-to-come.mdnew+7−0
| @@ -0,0 +1,7 @@ | ||
--- | ||
default: minor | ||
--- | ||
| ||
# An app keeps reading a space the group makes after approving it | ||
| ||
Approval now keeps a scope that only reads spaces of a type (`space:T?action=read`), or of a type and key, where the group has no such space yet. Before, it was withheld, and a grant keeps its scope through every refresh, so an app approved before the group made the space could never read it without being approved again. Each credential still asks whether the member reads the space at that moment, so the scope reads nothing the member doesn't. A scope that writes, or reads a space the group already has that the roles don't read, is withheld as before. Grants already made keep the scope they were given: an app reads a space made since only once a member approves it again. | ||
crates/group-host/src/oauth_scope.rs+13−3
| @@ -280,7 +280,9 @@ impl Host { | ||
/// roles holding the action it asks, checked again at each call; | ||
/// - `space:T?…`, where some space of the group's of type `T` lets the | ||
/// roles write each collection asked for, as asked, as the group; or | ||
/// read it, if reading is all it asks; | ||
/// read it, if reading is all it asks; and a scope that only reads | ||
/// where the group has no such space yet, as each credential asks | ||
/// whether the member reads the space then; | ||
/// - `space:org.atgrp.inbox?…`, people's inboxes, for roles that | ||
/// may invite, as far as it asks for invites; | ||
/// - `space:*?…`, made into one scope for each of the group's spaces | ||
| @@ -344,7 +346,10 @@ impl Host { | ||
each.push(any_kind(group, want, &rooms)); | ||
continue; | ||
} else if let Some(want) = &space { | ||
rooms.iter().any(|room| allows(want, room)) | ||
match rooms.iter().any(|room| is_of(want, room)) { | ||
true => rooms.iter().any(|room| allows(want, room)), | ||
false => want.read_only, | ||
} | ||
} else { | ||
false | ||
}; | ||
| @@ -455,9 +460,14 @@ fn inbox_scope(scope: &str) -> Option<SpaceScope> { | ||
SpaceScope::parse(scope).filter(|w| w.kind == format!("{NS}.inbox")) | ||
} | ||
| ||
/// Whether `room` is a space the space scope `want` names. | ||
fn is_of(want: &SpaceScope, room: &Room) -> bool { | ||
room.kind == want.kind && (want.skey == "*" || room.skey == want.skey) | ||
} | ||
| ||
/// Whether `room` lets the roles have the space scope `want`. | ||
fn allows(want: &SpaceScope, room: &Room) -> bool { | ||
if room.kind != want.kind || (want.skey != "*" && room.skey != want.skey) { | ||
if !is_of(want, room) { | ||
return false; | ||
} | ||
if want.read_only { | ||
crates/group-host/tests/oauth_scope.rs+19−2
| @@ -205,12 +205,18 @@ async fn keeps_a_space_scope_a_spaces_policy_grants() { | ||
format!("space:{CALENDAR}?action=read&action=read_self"), | ||
true, | ||
), | ||
(format!("space:{CALENDAR}?skey=other&action=read"), false), | ||
// Reading a space the group has yet to make is kept: each | ||
// credential asks whether the member reads it then. | ||
(format!("space:{CALENDAR}?skey=other&action=read"), true), | ||
( | ||
format!("space:{CALENDAR}?authority=did:plc:other&action=read"), | ||
false, | ||
), | ||
("space:com.example.forum?action=read".to_string(), false), | ||
("space:com.example.forum?action=read".to_string(), true), | ||
( | ||
"space:com.example.forum?collection=com.example.topic&action=create".to_string(), | ||
false, | ||
), | ||
] { | ||
let narrowed = member(&["atproto", &scope, "blob:*/*"]); | ||
let expected = if !kept { | ||
| @@ -233,6 +239,17 @@ async fn keeps_a_space_scope_a_spaces_policy_grants() { | ||
) | ||
.unwrap(); | ||
assert_eq!(admin, [format!("space:{CALENDAR}")]); | ||
// Not reading a space the group has, that its policy keeps from them. | ||
let poster = h | ||
.host | ||
.narrow( | ||
&did, | ||
&roles(&["poster"]), | ||
&asked(&[&format!("space:{CALENDAR}?action=read")]), | ||
&Default::default(), | ||
) | ||
.unwrap(); | ||
assert_eq!(poster, Vec::<String>::new()); | ||
} | ||
| ||
#[tokio::test] | ||
crates/group-host/tests/tokens.rs+15−0
| @@ -695,6 +695,21 @@ async fn reads_a_space_with_a_delegation_while_its_member_may() { | ||
assert_eq!(said.error(), (403, "NotAuthorized"), "{}", said.body); | ||
} | ||
| ||
#[tokio::test] | ||
async fn reads_a_space_the_group_made_after_approving_its_session() { | ||
let h = start(&[], false).await; | ||
let (did, _, [alice, bob, _]) = group(&h).await; | ||
let forum = "com.example.forum"; | ||
let app = App::loopback(&format!("atproto space:{forum}?action=read")); | ||
let access = token(&h, &app, &bob, &did).await; | ||
let readers = | ||
json!({"$type": format!("{NS}.policy"), "grants": [{"role": "member", "read": true}]}); | ||
let made = make_space(&h, &alice, &did, forum, "talk", readers).await; | ||
let delegated = delegation(&h, &app, &access, &made).await; | ||
let ((status, error), _, _) = buy(&h, &made, &delegated, None).await; | ||
assert_eq!(status, 200, "{error}"); | ||
} | ||
| ||
#[tokio::test] | ||
async fn configures_the_group_as_its_methods_would() { | ||
let h = start(&[], false).await; | ||
docs/design/signing-in.md+5−1
| @@ -338,7 +338,11 @@ takes, lowercase, the way atproto writes one. | ||
methods. | ||
- `space:T?…` is kept if some space of type `T` lets the roles write | ||
what's asked there. For a scope that only reads, reading it there is | ||
enough. In the members space, the roles write its roles and labeler | ||
enough, and where the group has no space of type `T` (and key, if it | ||
names one) yet, it's kept all the same: an app approved before the | ||
group makes the space can read it once it does, as the member reads | ||
it then ([below](#checking-each-write)). In the members space, the | ||
roles write its roles and labeler | ||
if they hold `authManageAdmin`, and its rules if they hold | ||
`authManageBasic` or `authManageAdmin`. They write memberships as | ||
they hold `admit` (create), `role.assign` (update) and `eject` | ||