Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MSC1772: Matrix spaces #1772

Merged
merged 89 commits into from
May 5, 2021
Merged
Changes from 75 commits
Commits
Show all changes
89 commits
Select commit Hold shift + click to select a range
6c499db
WIP groups as rooms MSC
ara4n Jan 3, 2019
346f7ac
add hyperlinks
ara4n Jan 3, 2019
1e81fbd
md
ara4n Jan 3, 2019
a884fd8
wordwrap fix
ara4n Jan 3, 2019
43ae6ad
md
ara4n Jan 3, 2019
e00eff5
add thought about splitting events
ara4n Jan 4, 2019
cd5a842
flesh out how flair could work
ara4n Jan 6, 2019
19e9420
flesh out state events split per state-key for defining groups
ara4n Jan 6, 2019
010246e
typo
ara4n Jan 6, 2019
88ff3de
spell out deps
ara4n Jan 6, 2019
54bf339
typo
ara4n Jan 6, 2019
1bbe638
typo
ara4n Jan 6, 2019
417501d
various minor edits
richvdh Oct 20, 2020
96cd76c
remove 'one big event' proposal
richvdh Oct 20, 2020
6464e90
Merge branch 'master' into matthew/msc1772
richvdh Oct 20, 2020
0baf49a
We are not considering hidden-membership rooms yet
richvdh Oct 20, 2020
4040254
Update for new terminology and current thinking
richvdh Oct 27, 2020
52853b5
more updates
richvdh Oct 27, 2020
c145d39
Notes on propagating PLs etc
richvdh Oct 29, 2020
15f34e5
supporting trad PLs
richvdh Oct 29, 2020
e746aa3
Apply suggestions from code review
richvdh Oct 30, 2020
2f557da
Clarifications to room/space relationship
richvdh Oct 30, 2020
11bb604
add an xxx
richvdh Oct 30, 2020
d42da58
Apply suggestions from code review
richvdh Nov 9, 2020
1aede33
clarify introduction
richvdh Nov 9, 2020
e323ade
Switch to room IDs
richvdh Nov 9, 2020
a73dd9c
clarification
richvdh Nov 9, 2020
839ea0e
inheriting join rules
richvdh Nov 9, 2020
109c31c
Avoiding abuse via false `parent` claims
richvdh Nov 10, 2020
06b5c83
notes on children and recursion
richvdh Nov 10, 2020
29b07c1
update power level mappings
richvdh Nov 10, 2020
ae71a62
Restricting room membership via spaces
richvdh Nov 11, 2020
b40f7da
Record alternatives
richvdh Nov 11, 2020
4e3b0ed
add a length limit to `order`
richvdh Nov 11, 2020
3b2825f
Descope autokick and rename allowed_spaces
richvdh Nov 11, 2020
e6a6941
rename allowed_join again
richvdh Nov 11, 2020
fbad757
update dependencies links
richvdh Nov 11, 2020
1f1e3c9
MSC1840 is in
richvdh Nov 16, 2020
d4abe40
one parent per room
richvdh Nov 16, 2020
39af7f3
Update 1772-groups-as-rooms.md (#2866)
grinapo Nov 17, 2020
45f2608
No cross-room auth
richvdh Nov 19, 2020
6cc3995
explain a bit
richvdh Nov 20, 2020
51aa5e2
Update proposals/1772-groups-as-rooms.md
richvdh Nov 26, 2020
6989758
Update proposals/1772-groups-as-rooms.md
richvdh Jan 4, 2021
037894a
replace 'default' with 'auto_join'
ara4n Jan 13, 2021
803e70a
typo
ara4n Jan 13, 2021
42c332b
fix parent claiming plurality
ara4n Jan 13, 2021
2de3dc4
more plurality fixing
ara4n Jan 13, 2021
302d5d8
clarify autojoin and mention 'suggested' rooms
ara4n Jan 13, 2021
a0d06c7
factor out ACLs into a separate MSC
ara4n Jan 14, 2021
b8e3a0b
include invite state notes
ara4n Jan 14, 2021
f8fb325
replace m.room.parent with m.space.parent for symmetry
ara4n Jan 14, 2021
343e1f6
incorporate @joepie91's clarification on secret rooms
ara4n Jan 14, 2021
97103c4
clarify that auto-joins are not force joins
ara4n Jan 14, 2021
91fe7a7
switch to allowing multiple parents
ara4n Jan 14, 2021
b10856d
let's create spaces with `events_default` PL100
ara4n Jan 14, 2021
a0f89bd
add XXX about via propagation
ara4n Jan 14, 2021
a709671
tie break on multiple parents
ara4n Jan 14, 2021
ff85e61
fix dev identifier
ara4n Jan 15, 2021
1cfe6bc
MSC1840 is out again.
richvdh Mar 16, 2021
bc14662
related MSCs
richvdh Mar 16, 2021
62b9154
Remove lost footnotes
richvdh Mar 16, 2021
469b64c
rip out m.room.description
richvdh Mar 16, 2021
dcb18f0
Move security consideration to MSC2962
richvdh Mar 17, 2021
7d757ce
minor wording tweaks
richvdh Mar 17, 2021
acdb6f1
Move "auto-join" out to "future extensions"
richvdh Mar 17, 2021
2e6d7d1
spaces are *primarily* referred to by their room ID.
richvdh Mar 17, 2021
0bdbec2
Accept m.space.parent links if there is a reverse link
richvdh Mar 17, 2021
6c9d469
add an issue about lost parent links
richvdh Mar 17, 2021
8a61ce9
remove 'present' flag
richvdh Mar 17, 2021
c0c5138
Move "via" problem to a "potential issue"
richvdh Mar 17, 2021
9ca9423
Suggested rooms
richvdh Mar 17, 2021
5e7ed2b
Tweak wording about lexicographic ordering
richvdh Mar 22, 2021
065b099
Update proposals/1772-groups-as-rooms.md
richvdh Mar 23, 2021
e704152
Include `create` in invite_room_state
richvdh Mar 26, 2021
6d007e8
Defer a TODO to the future.
clokep Apr 14, 2021
12d08ca
Consistency and update links.
clokep Apr 14, 2021
00912f9
clarify how to deterministically cut cycles
ara4n Apr 29, 2021
f07e82e
clarify the charsets of our lexicographic orderings
ara4n Apr 29, 2021
37e04f7
tiebreak ordered spaces sensibly
ara4n Apr 29, 2021
1e2ed52
add more justification for immutable room types
ara4n Apr 29, 2021
0d71150
remove confusing mention of peeking & dependent MSCs
ara4n Apr 29, 2021
7432d25
incorporate travis feedback
ara4n Apr 29, 2021
2981baa
Update proposals/1772-groups-as-rooms.md
ara4n Apr 29, 2021
acdf985
incorporate uhoreg feedback
ara4n Apr 29, 2021
413e346
note the rationale behind using the # sigil
ara4n Apr 29, 2021
757218c
relax requirements on cycle-cutting and link to valere's alg
ara4n Apr 30, 2021
c2d0d1e
include m.room.create in knock_state (will be overtaken by MSC3173)
ara4n May 3, 2021
9773759
Remove cycle breaking algorithm to be specced in the future, if neces…
clokep May 4, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
391 changes: 391 additions & 0 deletions proposals/1772-groups-as-rooms.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,391 @@
# Proposal for Matrix "spaces" (formerly known as "groups as rooms (take 2)")
richvdh marked this conversation as resolved.
Show resolved Hide resolved
richvdh marked this conversation as resolved.
Show resolved Hide resolved

richvdh marked this conversation as resolved.
Show resolved Hide resolved
This MSC, and related proposals, supercede
[MSC1215](https://github.com/matrix-org/matrix-doc/issues/1215).

## Background and objectives

Collecting rooms together into groups is useful for a number of
purposes. Examples include:

* Allowing users to discover different rooms related to a particular topic:
for example "official matrix.org rooms".
* Allowing administrators to manage permissions across a number of rooms: for
example "a new employee has joined my company and needs access to all of our
rooms".
* Letting users classify their rooms: for example, separating "work" from
"personal" rooms.

We refer to such collections of rooms as "spaces".

Synapse and Element-Web currently implement an unspecced "groups" API (referred
to as "`/r0/groups`" in this document) which attempts to provide this
functionality (see
[matrix-doc#971](https://github.com/matrix-org/matrix-doc/issues/971)). However,
this is a complex API which has various problems (see
[appendix](#appendix-problems-with-the-r0groups-api)).

This proposal suggests a new approach where spaces are themselves represented
by rooms, rather than a custom first-class entity. This requires few server
changes, other than better support for peeking (see Dependencies below).
ara4n marked this conversation as resolved.
Show resolved Hide resolved

The existing `/r0/groups` API would be deprecated in Synapse and remain
unspecified.

## Proposal
richvdh marked this conversation as resolved.
Show resolved Hide resolved

Each space is represented by its own room, known as a "space-room". The rooms
within the space are determined by state events within the space-room.

Space-rooms are distinguished from regular messaging rooms by the presence of a
`type: m.space` property in the content of the `m.room.create` event. This allows clients to
ara4n marked this conversation as resolved.
Show resolved Hide resolved
ara4n marked this conversation as resolved.
Show resolved Hide resolved
offer slightly customised user experience depending on the purpose of the
room. Currently, no server-side behaviour is expected to depend on this property.

As with regular rooms, public spaces are expected to have an alias, for example
`#foo:matrix.org`, which can be used to refer to the space.

Space-rooms may have `m.room.name` and `m.room.topic` state events in the same
way as a normal room.
ara4n marked this conversation as resolved.
Show resolved Hide resolved

Normal messages within a space-room are discouraged (but not blocked by the
server): user interfaces are not expected to have a way to enter or display
ara4n marked this conversation as resolved.
Show resolved Hide resolved
such messages. Space-rooms should be created with a power level for
`events_default` of 100, to prevent the rooms accidentally/maliciously
clogging up with messages from random members of the space.

### Membership of spaces

Users can be members of spaces (represented by `m.room.member` state events as
normal). The existing [`m.room.history_visibility`
mechanism](https://matrix.org/docs/spec/client_server/r0.6.1#room-history-visibility)
controls whether membership of the space is required to view the room list,
richvdh marked this conversation as resolved.
Show resolved Hide resolved
membership list, etc.

"Public" or "community" spaces would be set to `world_readable` to allow clients
ara4n marked this conversation as resolved.
Show resolved Hide resolved
to see the directory of rooms within the space by peeking into the space-room
(thus avoiding the need to add `m.room.member` events to the event graph within
the room).

Join rules, invites and 3PID invites work as for a normal room, with the
exception that `invite_state` sent along with invites should be amended to
include the `m.room.create` event, to allow clients to discern whether an
invite is to a space-room or not.
ara4n marked this conversation as resolved.
Show resolved Hide resolved

XXX: Should we also include a MSC2946 summary of the space in the invite too?

### Relationship between rooms and spaces

The intention is that rooms and spaces form a hierarchy, which clients can use
to structure the user's room list into a tree view. The parent/child
relationship can be expressed in one of two ways:

1. The admins of a space can advertise rooms and subspaces for their space by
setting `m.space.child` state events. The `state_key` is the ID of a child
room or space, and the content should contain a `via` key which gives a list
ara4n marked this conversation as resolved.
Show resolved Hide resolved
of candidate servers that can be used to join the room. Something like:

```js
{
"type": "m.space.child",
"state_key": "!abcd:example.com",
richvdh marked this conversation as resolved.
Show resolved Hide resolved
ara4n marked this conversation as resolved.
Show resolved Hide resolved
"content": {
"via": ["example.com", "test.org"]
}
}

{
"type": "m.space.child",
"state_key": "!efgh:example.com",
"content": {
richvdh marked this conversation as resolved.
Show resolved Hide resolved
"via": ["example.com"],
"order": "abcd",
}
}

richvdh marked this conversation as resolved.
Show resolved Hide resolved
// no longer a child room
{
"type": "m.space.child",
"state_key": "!jklm:example.com",
"content": {}
}
ara4n marked this conversation as resolved.
Show resolved Hide resolved
```

Children where `via` is not present are ignored.
ara4n marked this conversation as resolved.
Show resolved Hide resolved

The `order` key is a string which is used to provide a default ordering of
richvdh marked this conversation as resolved.
Show resolved Hide resolved
siblings in the room list. (Rooms are sorted based on a lexicographic
ordering of the characters in `order` values; rooms with no `order`
come last. `order`s which are not strings, or do not consist solely of
ascii characters in the range `\x20` (space) to `\x7F` (`~`), or consist of
more than 50 characters, are forbidden and should be ignored if received.)

richvdh marked this conversation as resolved.
Show resolved Hide resolved
2. Separately, rooms can claim parents via the `m.space.parent` state
event.

Similar to `m.space.child`, the `state_key` is the ID of the parent space,
and the content should contain a `via` key which gives a list of candidate
servers that can be used to join the parent.

```js
{
"type": "m.space.parent",
"state_key": "!space:example.com",
"content": {
"via": ["example.com"],
"canonical": true,
}
}
```

Parents where `via` is not present are ignored.
ara4n marked this conversation as resolved.
Show resolved Hide resolved

`canonical` determines whether this is the main parent for the space. When
a user joins a room with a canonical parent, clients may switch to view the
room in the context of that space, peeking into it in order to find other
rooms and group them together. In practice, well behaved rooms should only
have one `canonical` parent, but given this is not enforced: if multiple
are present the client should select the one with the lowest room ID, as
determined via a lexicographic ordering of the Unicode code-points.

To avoid abuse where a room admin falsely claims that a room is part of a
space that it should not be, clients could ignore such `m.space.parent`
events unless either (a) there is a corresponding `m.space.child` event in
the claimed parent, or (b) the sender of the `m.space.child` event has a
sufficient power-level to send such an `m.space.child` event in the
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does mean that if an admin leaves the parent space the child relationship will break, which is a bit weird. I don't know how you'd handle it any differently though.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/leaves/is demoted/. And yes, this is called out in the issues.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup, agreed it's weird. but nobody has found a better solution. speak now or forever...

parent. (It is not necessarily required that that user currently be a
member of the parent room - only the `m.room.power_levels` event is
inspected.) [Checking the power-level rather than requiring an *actual*
`m.space.child` event in the parent allows for "secret" rooms (see below).]

Where the parent space also claims a parent, clients can recursively peek
into the grandparent space, and so on.

This structure means that rooms can end up appearing multiple times in the
room list hierarchy, given they can be children of multiple different spaces
(or have multiple parents in different spaces).

In a typical hierarchy, we expect *both* parent->child and child->parent
relationships to exist, so that the space can be discovered from the room, and
vice versa. Occasions when the relationship only exists in one direction
include:

* User-curated lists of rooms: in this case the space will not be listed as a
parent of the room.

* "Secret" rooms: rooms where the admin does not want the room to be
advertised as part of a given space, but *does* want the room to form part
of the hierarchy of that space for those in the know.

Cycles in the parent->child and child->parent relationships are *not*
permitted, but clients (and servers) should be aware that they may be
encountered, and ignore the relationship rather than recursing infinitely.
ara4n marked this conversation as resolved.
Show resolved Hide resolved

XXX: we need to deterministically specify where the cycles get cut.
I think kegan found a solution for this when implementing MSC2946 in Dendrite.
richvdh marked this conversation as resolved.
Show resolved Hide resolved
ara4n marked this conversation as resolved.
Show resolved Hide resolved

### Suggested children

Space admins can mark particular children of a space as "suggested". This
mainly serves as a hint to clients that that they can be displayed differently
(for example by showing them eagerly in the room list), though future
server-side interfaces (such as the summary API proposed in MSC2946) might also
make use of it.

A suggested child is identified by a `"suggested": true` property in the
`m.space.child` event:


```jsonc
{
"type": "m.space.child",
"state_key": "!abcd:example.com",
"content": {
"via": ["example.com", "test.org"],
"suggested": true
}
}
```

### Extended "room invite state"

The specification is currently vague about what room state should be available
to users that have been invited to a room, though the Federation API spec does
recommend that the `invite_room_state` sent over federation via [PUT
`/_matrix/federation/v2/invite`](https://matrix.org/docs/spec/server_server/r0.1.4#put-matrix-federation-v2-invite-roomid-eventid)
should include "the join rules, canonical alias, avatar, and name of the room".

This MSC proposes adding `m.room.create` to that list, so that the recipient of
an invite can distinguish invites to spaces from other invites.

## Future extensions

The following sections are not blocking parts of this proposal, but are
included as a useful reference for how we imagine it will be extended in future.

### Auto-joined children

We could add an `auto_join` flag to `m.space.child` events to allow a space
admin to list the sub-spaces and rooms in that space which should be
automatically joined by members of that space.

This would be distinct from a force-join: the user could subsequently part any
auto-joined room if they desire.

Joining would be performed by the client. This could possibly be sped up by
using a summary API (such as that proposed in
[MSC2946](https://github.com/matrix-org/matrix-doc/pull/2946)) to get a summary
of the spacetree to be joined, and then using a batch join API to join
whichever subset of it makes most sense for the client's UX.

richvdh marked this conversation as resolved.
Show resolved Hide resolved
Obviously auto-joining can be a DoS vector, and we consider it to be antisocial
for a space to try to autojoin its members to more than 100 children (in total).
richvdh marked this conversation as resolved.
Show resolved Hide resolved

Clients could display the auto-joined children in the room list whenever the
space appears in the list - thus helping users discover other rooms in a space
even if they're not joined to that space. For instance, if you join
`#matrix:matrix.org`, your client could show that room in the context of its
parent space, with that space's auto-joined children shown alongside it as
siblings.

### Restricting access to the spaces membership list

In the existing `/r0/groups` API, the group server has total control over the
visibility of group membership, as seen by a given querying user. In other
words, arbitrary users can see entirely different views of a group at the
server's discretion.

Whilst this is very powerful for mapping arbitrary organisational structures
into Matrix, it may be overengineered. Instead, the common case is (we believe)
a space where some users are publicly visible as members, and others are not.

One way to of achieving this would be to create a separate space for the
private members - e.g. have `#foo:matrix.org` and `#foo-private:matrix.org`.
`#foo-private:matrix.org` is set up with `m.room.history_visibility` to not to
allow peeking; you have to be joined to see the members.
richvdh marked this conversation as resolved.
Show resolved Hide resolved
ara4n marked this conversation as resolved.
Show resolved Hide resolved

### Flair

("Flair" is a term we use to describe a small badge which appears next to a
user's displayname to advertise their membership of a space.)

The flair image for a group is given by the room avatar. (In future it might
preferable to use hand-crafted small resolution images: see
[matrix-doc#1778](https://github.com/matrix-org/matrix-doc/issues/1778).

One way this might be implemented is:

* User publishes the spaces they wish to announce on their profile
([MSC1769](https://github.com/matrix-org/matrix-doc/issues/1769)
as an `m.flair` state event: it lists the spaces which they are advertising.

* When a client wants to know the current flair for a set of users (i.e.
those which it is currently displaying in the timeline), it peeks the
profile rooms of those users. (Ideally there would be an API to support
richvdh marked this conversation as resolved.
Show resolved Hide resolved
peeking multiple rooms at once to facilitate this.)

* The client must check that the user is *actually* a member of the advertised
richvdh marked this conversation as resolved.
Show resolved Hide resolved
spaces. Nominally it can do this by peeking the membership list of the
space; however for efficiency we could expose a dedicated Client-Server API
to do this check (and both servers and clients can cache the results fairly
aggressively.)

richvdh marked this conversation as resolved.
Show resolved Hide resolved
## Related MSCs

* [MSC2946](https://github.com/matrix-org/matrix-doc/issues/2946): Spaces
Summary API.

* [MSC2962](https://github.com/matrix-org/matrix-doc/issues/2962): Group
access control via Spaces.

* [MSC2753](https://github.com/matrix-org/matrix-doc/issues/2753) for
effective peeking over the C/S API.

* [MSC2444](https://github.com/matrix-org/matrix-doc/issues/2444) (or similar)
for effective peeking over Federation.

## Security considerations

None at present.

## Potential issues

* If the membership of a space would be large (for example: an organisation of
several thousand people), this membership has to be copied entirely into the
room, rather than querying/searching incrementally.

* If the membership list is based on an external service such as LDAP, it is
hard to keep the space membership in sync with the LDAP directory. In
practice, it might be possible to do so via a nightly "synchronisation" job
which searches the LDAP directory, or via "AD auditing".

* No allowance is made for exposing different 'views' of the membership list to
different querying users. (It may be possible to simulate this behaviour
using smaller spaces).

* The requirement that `m.room.parent` links be ignored unless the sender has a
high PL in the parent room could lead to suprising effects where a parent
link suddenly ceases to take effect because a user loses their PL in the
parent room. This is mitigated in the general case by honouring the parent
link when there is a corresponding `m.room.child` event, however it remains
a problem for "secret" rooms.

* The `via` servers listed in the `m.room.child` and `m.room.parent` events
could get out of date, and will need to be updated from time to time. This
remains an unsolved problem.

## Rejected alternatives

### Use a separate state event for type of room

[MSC1840](https://github.com/matrix-org/matrix-doc/pull/1840) proposes the use
of a separate `m.room.type` state event to distinguish different room
types. This implies that rooms can dynamically switch between being a Space,
and being a regular non-Space room. That is not a usecase we consider useful,
and allowing it would impose significant complexity on client implementations.

## Unstable prefix

The following mapping will be used for identifiers in this MSC during
development:

Proposed final identifier | Purpose | Development identifier
------------------------------- | ------- | ----
`type` | property in `m.room.create` | `org.matrix.msc1772.type`
`m.space` | value of `type` in `m.room.create` | `org.matrix.msc1772.space`
`m.space.child` | event type | `org.matrix.msc1772.space.child`
`m.space.parent` | event type | `org.matrix.msc1772.space.parent`

## History

* This replaces MSC1215: https://docs.google.com/document/d/1ZnAuA_zti-K2-RnheXII1F1-oyVziT4tJffdw1-SHrE
* Other thoughts that led into this are at: https://docs.google.com/document/d/1hljmD-ytdCRL37t-D_LvGDA3a0_2MwowSPIiZRxcabs

## Appendix: problems with the `/r0/groups` API

The existing `/r0/groups` API, as proposed in
[MSC971](https://github.com/matrix-org/matrix-doc/issues/971), has various
problems, including:

* It is a large API surface to implement, maintain and spec - particularly for
all the different clients out there.
* Much of the API overlaps significantly with mechanisms we already have for
managing rooms:
* Tracking membership identity
* Tracking membership hierarchy
* Inviting/kicking/banning user
* Tracking key/value metadata
* There are membership management features which could benefit rooms which
would also benefit groups and vice versa (e.g. "auditorium mode")
* The current implementations on Riot Web/iOS/Android all suffer bugs and
issues which have been solved previously for rooms.
* no local-echo of invites
* failures to set group avatars
* ability to specify multiple admins
* It doesn't support pushing updates to clients (particularly for flair
membership): https://github.com/vector-im/riot-web/issues/5235
* It doesn't support third-party invites.
* Groups could benefit from other features which already exist today for rooms
* e.g. Room Directories
* Groups are centralised, rather than being replicated across all
participating servers.