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

A moderation role labels only in the spaces its scopes reach

Merged
Merged chadtmiller.com asked to merge into main from chadtmiller.com/group-host:rbac/label-spaces

What changes

Labels in a space need scopes that reach it. A member may write a label (com.atproto.label.record, !takedown among them) as the group in a space only where their roles' scopes cover writing labels there: the moderation sets' (authModerate, authManageGroup) in the meta and members spaces, as their permissions name them; space:*?collection=com.atproto.label.record, or a scope naming every collection, in every space; or a scope the space's policy grants the role, in that space alone. The host asks this at each write, when getGroupAuth mints a group token, and when it narrows an OAuth grant. A role holding only include:fyi.opensocial.authModerate still labels accounts and records in the meta and members spaces, but no longer anything in the group's other spaces. The label action now means labels in every space, space:*?collection=com.atproto.label.record as the roles editor gives it, so the moderation sets no longer read as carrying it: the roles editor leaves label to tick beside Moderation rather than greying it as coming with the set (its guide's picture drawn again by just shots). A new group's admin role and the CLI's seeded moderator role hold that scope, so their moderators label as before.

getGroup says where. A member's viewer now carries labelSpaces, beside grantable, (each a fyi.opensocial.defs#spaceRef, {space}), the group's spaces where their roles write labels. The console's moderation page offers labelling a subject, and finding an account to label, only where the subject's labels go in one of them; a reported record in a space the moderator cannot label shows resolving alone. A label on a public record now goes in the members space, where the host's design puts it, rather than at a URI made from the record's path. mod label and mod_label say they label where the member's roles write labels, and the host refuses elsewhere as for any write.

Why

The label action was group-wide: authModerate and authManageGroup gave it, and holding it let a token write labels in any space. The proposal's permission sets name labels only in the meta and members spaces, and its example moderator role adds space:*?collection=com.atproto.label.record to label elsewhere, so a moderation set alone was reaching further than the set says. Reading the roles' scopes, the sets made into their permissions, against the space being written answers the question the same way the scope itself would, rather than keeping a second list of what each set reaches.

How it was checked

New tests come first. labels_only_in_the_spaces_the_roles_scopes_reach (tests/moderation.rs): a role with only authModerate labels in the meta and members spaces, gets no group token for a calendar space, and labelSpaces names the two; adding space:*?collection=com.atproto.label.record lets it label there (!takedown too), and taking it away refuses the same token's next write as Forbidden; a board whose policy grants moderators that scope lets them label there and still not in the calendar. keeps_labels_only_in_the_spaces_the_roles_label_in (tests/oauth_scope.rs) does the same for narrowing: space:*?collection=…label.record keeps the meta and members spaces only for authModerate, the calendar with the raw scope, and the calendar by its policy's grant. Ran the moderation, oauth_scope, group_tokens, rbac, members, authorization, mcp and groups suites here, just lex, svelte-check, and the strings and layers harnesses; the whole gate is left to CI.

Shortcomings

labelSpaces lists spaces where the member may create a label; a role that may only delete labels somewhere is not offered taking them back there.

Approved

This pull makes label writes depend on the space. It adds rbac::label_writes, which reads the roles' scopes against the space being written, and uses it in four places: the write check in may_space, the group token's scope, OAuth narrowing, and the new viewer.labelSpaces in getGroup. The console's moderation page now offers labelling only where the subject's labels go in one of those spaces.

I read the Rust diff, the lexicon and the console changes. I traced label_writes through concrete, Permissions::space and Policy::writes. Policy grants add to the scope-derived writes. They aren't a second source that could widen them by accident. A write: true grant doesn't give labels, because Policy::writes only lists collections named in scopes. The new tests cover each of the cases the body describes: the moderation set alone, the set plus space:*?collection=…label.record, revoking the scope on a live token, and a policy grant in one space.

One small point, which isn't blocking: label_spaces in group_api.rs calls .expect("a space the group has") on a value read separately from spaces_of. If a space is deleted between the two reads, getGroup panics instead of skipping it. Skipping a None policy is simpler and safe.

The coverage gate may count that expect as an unrun path. CI will say.

crates/group-host/src/group_api.rsline 434Outdated
let mut out = Vec::new();
for uri in spaces {
let policy = host.policy(&uri).map_err(XrpcError::internal)?;
let policy = policy.expect("a space the group has");
review.knotless.dev

policy is read apart from spaces_of, so a space removed in between would panic here. let Some(policy) = ... else { continue } avoids that.

Approved

Carried forward: the change this pull makes at 679f842514f12982a441b6bf01b5d69e7967fd68 is the one reviewed at 6efb9e2758a7d17a0449d2752353bbdaed291d5c, so that review stands. What is new comes from its base.

Approved

Since the approved commit, the only change is in keeps_labels_only_in_the_spaces_the_roles_label_in (tests/oauth_scope.rs). It now compares against std::slice::from_ref(&named) instead of building a new array. The assertion is the same, so my approval stands. The expect in label_spaces that I raised as a non-blocking point is outside this change.

Approved

Carried forward: the change this pull makes at 185b79b79990e2c477e6019b0b426106e07a416c is the one reviewed at 264a5e86425cf13e445bb292cc4be03c143e297c, so that review stands. What is new comes from its base.

Approved

My approval at 185b79b stands. I read what came since. One change belongs to this pull, 3b67698. The other two commits are merges of main and bring in its changes, not the pull's.

3b67698 takes label out of rbac::MODERATES (Rust) and out of MODERATES in web/src/lib/actions.ts, so the sets no longer read as granting labels in every space. That matches the body: the sets label in the meta and members spaces through label_writes, and label means space:*?collection=com.atproto.label.record. The tests, the design docs, the guide text and the redrawn screenshots all agree with it.

I didn't read the diff from the approved commit to the head. The merges bring in other pulls' work, and it came to over 100k characters.

Merged as d3e36b8