Commit Graph

32 Commits

Author SHA1 Message Date
David Teller
b7d5e5d7bc
PolicyListManager: Let's not forget to remove the room also from the set of rooms we failed to resolve (#463) 2022-12-22 09:42:09 +01:00
David Teller
cff9b43207
This should hopefully fix some startup woes (#462)
Splitting PolicyListManager from Mjolnir, making it more resilient to startup errors
2022-12-21 19:32:27 +01:00
Gnuxie
433ff7eadd
A look at PolicyList.update (#454)
This started out as just a way to find out why mjolnir was syncing with lists several times for each update to a policy list.

The main changes are

- Verbosity was irrelevant to the sync command but for some reason was an option.
  Unfortunately all this did was suppress whether to tell you when it had finished, meaning it wouldn't
  when verbose logging was disabled. Historically this was probably a parameter that got passed through
  to applyServerAcl/applyUserBans, which can be horribly verbose, but they access the config directly.

- Stop emitting `'PolicyList.update'` when there are no changes.
- Include a revision ID for the `'PolicyList.update'`method and event.
- Use the revision ID in the `ProtectedRoomsSet` so that we don't unnecessarily resynchronize all rooms when the `'PolicyList.update'` event is received. Though not when the `sync` command is used. Since this is supposed to `sync` in the case when there is a state reset or otherwise or the user has changed some room settings.
- insert an await lock around the `PolicyList.update` method to avoid a race condition where a call can be started and finished within the extent of an existing call (via another task, this can happen if the server is slow with handling one request). `PolicyList.udpate` now has a helper that is synchronous to be called directly after requesting the room state. The reason for this is to enforce that no one `await`s while updating the policy list's cache of rules. Which is important because it is one of the biggest methods that I tolerate and visually checking for `await` is impossible.
- The revision ID uses a ULID, but this is unnecessary and could have just been a "dumb counter".

closes https://github.com/matrix-org/mjolnir/issues/447
2022-12-08 16:09:55 +00:00
Gnuxie
5de0dae62a
Make updateForEvent actually update PolicyLists. (#448)
For some reason we were relying on a mjolnir listening to
`'PolicyList.batch'` to update policy lists.

This was exposing an implementation detail to Mjolnir
and including it as part of the implementation of
`PolicyList.updateForEvent()` which is supposed to cause
the `PolicyList` to update (eventually).

I am confident this was because of a need before batching was
introduced to get the changes to a policy list directly
from the method call to `PolicyList.update()`, whereas
now you can just listen to `PolicyList.update`.

The `'PolicyList.batch'` event has now been removed
and the PolicyList event batcher (`UpdateBatcher`)
now calls `PolicyList.update()` internally.
2022-12-07 13:57:39 +00:00
Gnuxie
704bb660c2
Refactor how we listen for matrix events. (#446)
* Refactor Matrix event listener in Mjolnir and ManagedMjolnir.

closes https://github.com/matrix-org/mjolnir/issues/411.

Issue #411 says that we have to be careful about room.join,
but this was before we figured how to make matrix-appservice-bridge
echo events sent by its own intents.

* Remove MatrixClientListener since it isn't actually needed.

* Protect which config values can be used for ManagedMjolnirs.

* Introduce MatrixSendClient

so listeners aren't accidentally added to a MatrixClient instead
of MatrixEmitter.

* doc

* Move provisioned mjolnir config to src/config.

This just aids maintance so whenever someone goes to change the config
of the bot they will see this and update it.

* doc for matrix intent listener.
2022-12-06 17:17:40 +00:00
Jess Porter
50f80f2392
manymjolnir appservice (#364)
Mjolnir can now be run as an application service,
meaning it will host multiple independent mjolnirs that can be requested by users.
If the user is on the same homeserver as the appservice is deployed on,
then they can provision a mjolnir via a widget https://github.com/matrix-org/mjolnir-widget.
Otherwise they can invite the appservice bot to a room they want to protect.
This will create them a mjolnir, a management room and a policy list.

The appservice shares the same docker image as the bot,
but is started slightly differently by specifying "appservice"
as the first argument to docker run (this s managed by `mjolnir-entrypoint.sh`. 
We could have used another Dockerfile for the appservice,
extending the existing one but we decided not to because there
would have been lots of fiddling around the entrypoint
and logistics involved around adding a tag for it via github actions.
Not to mention that this would be duplicating the image
just to run it with a different binary.

A list of followup issues can be found here https://github.com/issues?q=is%3Aopen+is%3Aissue+author%3AGnuxie+archived%3Afalse+label%3AA-Appservice.

Somewhat relevant and squashed commit messages(regrettably squashing because frankly these won't make sense in isolation): 

* draft widget backend

* add `managementRoomId` to `provisionNewMjolnir`

* remove ratelimits from appservice mjolnirs

* add /join endpoint to api backend


* tighter guard around room type in PolicyList

matrix-bot-sdk imporved the types for this

* enable esModuleInterop

* launch and use postgres in a container whilst using mx-tester


* limited access control

policy list used for access control

* Redesign initialization API of many mjolnir.

It's much harder to forget to initialize the components now that you have to in order to construct them in the first place.


* Ammend config not to clash with existing CI

this means that the appsrvice bot is now called 'mjolnir-bot' by default
which was easier than going through old code base and renaming


* Change entrypoint in Dockerfile so that we can start the appservice.

We could have used another Dockerfile for the appservice,
extending the exising one but we decided not to because there
would have been lots of fiddling around the entrypoint
and logistics involved around adding a tag for it via github actions.
Not to mention that this would be duplicating the image
just to run it with a different binary.

This solution is much simpler, backwards compatible, and conscious about the future.


Co-authored-by: gnuxie <gnuxie@element.io>
2022-11-15 18:03:06 +00:00
Gnuxie
da084328a9
Refactor list creation with MSC3784 support. (#386)
https://github.com/matrix-org/matrix-spec-proposals/pull/3784

This was extracted from the appservice mjolnir work to reduce review burden.
2022-10-19 10:33:12 +01:00
Gnuxie
5bd23ced9b
Access Control Unit (#378)
The ACL unit allows you to combine an policy lists and conveniently test users and servers against them.
The main motivation for this work is provide access control on who can provision and continue to use mjolnir instances in the appservice component.
We include a new recommendation type org.matrix.mjolnir.allow which can be used with user and server entity types to create allow lists.
We have also replaced the destructing of policy lists in applyServerACL and applyMemberBans (in ProtectedRooms.ts) with calls to the AccessControlUnit.
Adding commands to add/remove allowed entities is not something i want to do at the moment.
2022-10-18 16:28:11 +01:00
Gnuxie
4d5447cb50
Rework the banning and unbanning of entities in PolicyLists. (#345)
* Rework the banning and unbanning of entities in PolicyLists.

1. We keep track of the event that created a list rule so that we
can remove the rule by having a way to determine the original state key for the rule.
This is because the state key of rules can be anything and should not be
relied on by Mjolnir to unban things (which it was doing).

2. The old scheme for producing a state key was causing for some entities to escape bans
https://github.com/matrix-org/mjolnir/issues/322.

We could have used a hash or something similar, but we know that
the reason for the `rule:${entity}` scheme existed was for ease of debugging
and finding rules in devtools. So instead we have followed a scheme simalar to
bridges where the first character of an mxid is replaced with an underscore.
Everything else just gets put into the state key. Since domains can't have '@'
and room ids, aliases can't either.

3. We have stopped the need for Mjolnir to wait for the next response from sync after banning,
unbanning an entity so that we can apply ACL's sooner.

* Use PolicyList's `banEntity` method to create imported rules.
2022-08-19 13:09:08 +01:00
David Teller
829e1bd0aa
Towards opinions in PolicyLists. (#336)
Towards opinions in PolicyLists.

This changeset is part of an ongoing effort to implement "opinions"
within policy lists, as per MSC3847.

For the time being:
- we rename BanList into PolicyList;
- we cleanup a little dead code;
- we replace a few `string`s with `enum`;
- `ListRule` becomes an abstract class with two concrete subclasses `ListRuleBan` and `ListRuleOpinion`.
2022-07-26 21:47:26 +02:00
DeepBlueV7.X
9f872f78e1
Use stable prefixes for policy recommendations (#329)
They have been in the spec for ~3 years now and most mjolnirs should be
able to handle them. Let's use the stable endpoint now, so that other
moderation tools don't need to implement the legacy identifier to handle
new bans at some point.

Signed-off-by: Nicolas Werner <nicolas.werner@hotmail.de>
2022-07-11 14:28:57 +01:00
Gnuxie
941cc32ddd
Add !mjolnir rules matching <entity> to search watched lists. (#307)
* Add `!mjolnir rules matching <entity> to search watched lists.

Lists all the rules that will match the entity.
2022-07-07 13:03:03 +01:00
Gnuxie
332da15d0d
Remove old rules when unbanning entities from BanLists. (#227)
* Remove old rules when unbanning entities from BanLists.

Fixes #220
2022-02-21 16:51:14 +00:00
Gnuxie
e9dff8fd5a
Batch events from ban lists together during sync (#221)
* Test for batching ACL.

* Batch events from sync within BanList.

* Introduce the BanList.batch event to the BanList emitter to let Mjolnir sync after new events have been added from sync.

Fixes #203
2022-02-15 13:51:20 +00:00
Gnuxie
ff9a7db159
Make ACL safe so that Mjolnir will not ban itself. (#213) 2022-02-07 17:02:06 +00:00
Jess Porter
f70d97e4d9
enable noImplicitAny (#209) 2022-02-02 12:43:05 +00:00
gnuxie
1a65122b0d Initial Ruleserver prototype.
This is an experimental ruleserver that will serve the combined rules from
the active policy lists to a Synapse module over a web api.
This makes it easier to communicate changes in policy lists to Synapse workers
that do not have an immediate view over all of the policy rooms at
the same time.
This also allows us to express moderation actions to the homeserver
beyond what is currently expressible via MSC2313 policy
lists.
2022-01-21 12:13:04 +00:00
gnuxie
33011ddb04 Store BanList rules only in the room state cache.
We do this so that there is only one source of truth for which rules
are active and it simplifies de-duplicating rules of conflicting event
types (e.g. m.room.rule.user vs m.policy.rule.user).
2021-11-29 11:45:22 +00:00
gnuxie
0bbfe93a4b Use MSC2313 m.policy.rule.* for rules and always prefer these types.
The reason for doing this is because otherwise there may be duplicate
rules under different state types for the same entity.
This simplifies the process of modifying or invalidating rules affecting
an entity because the rule with the most recent type will always be
preferred.
2021-11-29 11:45:22 +00:00
gnuxie
9c47fc917a Provide notice showing how a BanList has changed after updating.
Only shows changes to lists made by other accounts (than the one used by Mjolnir).
Displays when rules are added, removed and modified by either replacing the state event or redacting them.
2021-11-29 11:45:22 +00:00
David Teller
2e22154870 Lint: Enabling 'strictNullChecks' 2021-07-22 08:40:29 +02:00
David Teller
2a77509f9e Lint: Enabling 'noImplicitReturns' 2021-07-22 08:24:12 +02:00
Travis Ralston
ff4cbc018f Update matrix-bot-sdk and use request cleaning function 2021-07-01 15:11:27 -06:00
Travis Ralston
fa6a6547ee Add very basic subscription server for Synapse module 2020-01-25 20:34:15 -07:00
Travis Ralston
fd2343dd28 Add some null safety to ban lists 2019-12-04 19:28:31 -07:00
Travis Ralston
4f8b55c45f Update matrix-bot-sdk 2019-12-04 18:46:00 -07:00
Travis Ralston
82214c6cd8 Avoid spamming the management room with errors
The intervals are arbitrarily defined.

Fixes https://github.com/matrix-org/mjolnir/issues/10
2019-11-06 19:17:11 -07:00
Travis Ralston
eccbac9ccf Check if ACLs match before applying them
Fixes https://github.com/matrix-org/mjolnir/issues/9
2019-10-30 14:49:59 -06:00
Travis Ralston
aecc6e4882 Support multiple ban lists 2019-10-08 17:57:03 +01:00
Travis Ralston
149cbcfbd2 Remove unused function from ban lists 2019-09-27 19:54:07 -06:00
Travis Ralston
39b59dbee1 Add commands for managing a personal ban list 2019-09-27 15:44:28 -06:00
Travis Ralston
d32ad18f3a Update server ACLs when they change 2019-09-27 14:26:57 -06:00