Commit Graph

367 Commits

Author SHA1 Message Date
Rory& 561cd96488 Read secrets from command line provided paths, if specified (#242)
This provides two new arguments for paths to load secretes for `--access-token-path` and `--pantalaimon-password-path` from.
The intention being that they can be used with a credentials system such as https://systemd.io/CREDENTIALS/.
They will take precedence over anything within the config file.
Suggested after https://github.com/NixOS/nixpkgs/pull/274052#discussion_r1481633083.


---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2024-02-09 17:20:24 +00:00
Gnuxie eceea6f21c Stop processing redaction queue before bans. (#230)
Introduced in
https://github.com/the-draupnir-project/Draupnir/commit/ea49b0a5363861b3729dcc720ff091b2480c4165.
Quite easy to see how.
Future redaction work should unit test for this.
This can be done quite easily by using a setTimeout, and non hackily
if you can make the fake request to ban a user resolve only
when an item in the redaction queue has been processed.

Fixes https://github.com/the-draupnir-project/Draupnir/issues/210.
Follow up https://github.com/the-draupnir-project/Draupnir/231
2024-02-01 12:05:32 +00:00
Marcel 5738d764d4 Add support for bot-sdk crypto as an experimental flag (#145)
* Add support for bot-sdk crypto as an experimental flag

* Import and use StoreType enum

* Fail hard instead of continuing in case of having pantalaimon and bot-sdk set up

* Document Option in default.yaml

* Remove obsolete comment
2023-10-21 12:18:10 +01:00
Gnuxie 69b7209739 Fix RoomUpdateError roomId argument typo (#123)
We were clearly in the process of deleting the
member decleration to just have the decleration be in the constructor.

When we were distracted, leaving a property named `readonly`, which
shouldn't be possible imo, need to add some rule for that prompto.
2023-09-12 11:57:50 +01:00
Gnuxie 26468afcde Only CommandExceptions should log at creation. (#99)
Before CommandError's where and they are used
liberally for validating command arguments by
returning a CommandResult for several possible
options. Which gives a lot of spam. It's not necessary
anyways since these should only be used for known errors.
2023-09-07 15:59:20 +01:00
Gnuxie 4b656306ed Deprecate config.verboseLogging (#98)
Shouldn't change what is being logged to the log file,
but it does change what gets sent to the management room.
I've been meaning to disable this for some time as it generally
confuses new users and it makes the bot feel very confusing and
low quality. It also means you are likely to miss more important
messages in the magement room.

Another problem it causes is an inconsistent view when testing
the software and it's an unreasonable burden to test for both
settings.

It's not clear what the value of this setting is apart from
providing comfort to some users who want to see the ACL readout.
But even then it's a very inefficient way of doing that,
so i'd rather another feature be requested by users that want to see that.
2023-09-07 15:27:00 +01:00
gnuxie 9d841697b2 Rework RoomUpdateErrors to be CommandErrors or CommandExceptions
https://github.com/Gnuxie/Draupnir/pull/93/
2023-09-05 19:53:02 +01:00
gnuxie 3ec37e3fe8 Introduce concept of Known and Unknown exceptions.
Sometimes we don't need exceptions to be reported on the error level.
This is especially true when the user does something out of order
and there's a permission error.
If we're aware of that possibility as developers and have accounted
for it, then it's unnecessary for it to be treated the same way
as a fatal error.

We also decided to log CommandExceptions and CommandErrors as
early as possible.

https://github.com/Gnuxie/Draupnir/pull/93/
2023-09-05 19:53:02 +01:00
gnuxie 73601687a8 Add UnbanPropagation BanPropagationProtection.
https://github.com/Gnuxie/Draupnir/pull/93/
2023-09-05 19:53:02 +01:00
gnuxie 2a4829dc1e Use <details> for error detail.
https://matrix.to/#/!IaWNErZAgQUhGqJXjX:matrix.org/$634tyYnNJK_zpNb4wH1zHbYeMOsDBHMpwdWPg1GdAEU?via=matrix.org&via=the-apothecary.club&via=envs.net
2023-09-04 15:25:35 +01:00
gnuxie e8847a2524 Allow Draupnir to ignore m.room.server_acl
https://github.com/Gnuxie/Draupnir/pull/85
2023-09-04 15:25:35 +01:00
gnuxie 1e82c15d82 Add font tag to DeadDocument
https://github.com/Gnuxie/Draupnir/pull/85
2023-09-04 15:25:35 +01:00
gnuxie ea49b0a536 Use JSX for the protected rooms set's printActionResult.
We've done this to make the implementation a lot cleaner and
managable. However, we've taken the opportunity to simplify
all of the client code that would use this method.

Some of these simplifications might come at a small cost.
Updating server ACL, member bans and checking power levels
would all be clearly titled as seperate checks.
However, it should still be obvious what has gone wrong,
since any error would have to give a more detailed explanation.
And not everything is going to fail all at once (and if it does,
there are bigger issues).

a lot cleaner
https://github.com/Gnuxie/Draupnir/pull/85
2023-09-04 15:25:35 +01:00
gnuxie 601aa33bc6 Remove Mjolnir's ErrorCache.
A bizarre contraption.
The ErrorCache was seemingly introduced to reduce the number of errors
in the management room.
https://github.com/matrix-org/mjolnir/commit/82214c6cd88d83abed05fec4a871a874e6e0265b
It makes sense why it was added if you consider that many admins
will run Draupnir without giving it the permission to manage server
ACL in its rooms. Though, I'm not sure why then you would add the error
cache rather than properly supporting that use case.
So perhaps there were other reasons.
Either way, what is drawing the line for me is that the ErrorCache
will suppress any error within rooms that is not a permission error,
if there was any error that was not a permission error within a
15 minute window.
Considering the typical Draupnir will not even sync
for hours at a time, even in large communities.
It does present a problem for rooms with a lot of join/leave events.
I think that's probably why the error cache was added.

Ahh, well, fuck.

Well what is the real solution to this?

The real solution when the kind is acl is to allow the bot to run
without applying ACLs.

Ok fine but, hey wait a minute.
Why would there be any other kind of persistent error
when banning someone that would be unimportant enough to silently
hide in an ErrorCache??

IDK let's just add an opttion to disable server ACL,
since they might want to use another tool for that anyhow.

Out of scope for the current work though.
https://github.com/Gnuxie/Draupnir/pull/85
2023-09-04 15:25:35 +01:00
Marcel 0de9ad3333 Add command that allows to easily set the Displayname of a bot (#91)
This adds the `displayname` command which just sets the displayname of the user.

-----

* Add command that allows to easily set the Displayname of a bot

* Only set the displayname once

* Add missing matrix interface adaptor and use CommandError

* Make displaynames with spaces work
2023-09-04 12:34:26 +01:00
Marcel f55d8a453d Add health endpoint to appservice and add metrics via prometheus (#70)
This adds a `/healthz` endpoint to the appservice which allows this to work more nicely in kubernetes.

It also adds some metrics for tracking the provisioning state.

Grafana result:
![image](https://github.com/Gnuxie/Draupnir/assets/1374914/9426c8e6-2c1c-469c-8902-1b9e2b6db529)

Note: The ts-ignore are sadly required since the `_getValue` method is not public :/ I didnt find another solution apart from tracking it maybe elsewhere.

* Add health endpoint to appservice and add metrics via prometheus

* Ensure that we dont have duplicate metrics when the appservice is registered multiple times

* Move gauge modifications to utils function

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Fix typo
2023-09-04 12:32:26 +01:00
Marcel 2ea8ddf864 Use the new help style on the appservice commands and add missing descriptions for the arguments (#69)
* Use the new help style on the appservice commands and add missing descriptions for the arguments

* Make the first letter of the table name uppercase in the help table
2023-09-04 12:30:50 +01:00
Aminda Suomalainen e4c02b96cd Add pre-commit configuration (#34)
* add .pre-commit-config.yaml

Signed-off-by: Aminda Suomalainen <suomalainen+git@mikaela.info>

* .editorconfig: decrease indent size for text

* .pre-commit-config.yaml: remove prettier

Signed-off-by: Aminda Suomalainen <suomalainen+git@mikaela.info>

* .editorconfig consistency.

* .pre-commit-config.yaml: restore sample hooks

* .editorconfig: disable indent_size for LICENSE & NOTICE

* pre-commit run --all-files

* tsconfig.json: tabs to spaces

* .pre-commit-config.yaml: update editorconfig-checker to 2.7.2

* .editorconfig: disable indent_size for markdown

* mjolnir-entrypoint.sh: retab

* .editorconfig: also exclude json from indent checking

* test/nginx.conf: retab

* test/integration/commands/redactCommandTest.ts: remove leading space

* retab or remove leading whitespaces for the rest of the files

* src/appservice/datastore.ts remove newlines

* test/integration/commands/roomTest.ts: remove leading space.

---------

Signed-off-by: Aminda Suomalainen <suomalainen+git@mikaela.info>
Co-authored-by: gnuxie <Gnuxie@protonmail.com>
2023-08-29 13:38:00 +01:00
Gnuxie 56ddbdf96c Failure to ban a single member should not stop other bans being applied. (#79)
Fixes https://github.com/Gnuxie/Draupnir/issues/74.
2023-08-28 16:38:24 +01:00
Catalan Lover 53d79f5ded D4A: Give the requesting user admin in management room at creation. (#73)
The requesting user would previously be unable to manage the room in order to change the room name etc.

Co-authored-by: gnuxie <Gnuxie@protonmail.com>
2023-08-28 12:38:48 +01:00
Gnuxie c11fb6ef06 Fix an issue where protected rooms could not be removed. (#65)
This was introduced in https://github.com/Gnuxie/Draupnir/pull/54/ (and therefore 1.83.0). Essentially we forgot to remove the room from the protected rooms set, when the remove command was used.

Ontop of this something to note is that during testing it is clear that the protected rooms set is loaded when configuring mjolnir, not when starting it. This is problematic as it means setup code in `fixtures.ts` does not actually wipe the protected rooms set.
2023-07-04 17:19:03 +01:00
Gnuxie ea3947df9f Typo unwatching lists. (#55)
This is actually really bad.
For multiple reasons.
The best way for this to be avoided is to drop everything
and reload it when the account data for watched lists is changed.
Then there isn't a situation where you have to inform anyone
about a change in what lists are being watched.
2023-06-08 17:03:42 +01:00
gnuxie fe349d42fb Clear up the "rooms add" error message when a room cannot be joined. 2023-05-30 11:14:49 +01:00
gnuxie e4689b1287 basic conversion of rooms commands to interface adaptor 2023-05-30 11:14:49 +01:00
gnuxie 89e25786f5 Support matrix.to URLs as MatrixRoomReferences in CommandReader. 2023-05-30 11:14:49 +01:00
gnuxie 006ba3dd1e Improve error reporting of CommandException 2023-05-30 11:14:49 +01:00
Gnuxie 8e1f930240 Merge pull request #52 from Gnuxie/gnuxie/update-to-node-18
Update to node 18.
2023-05-13 15:45:30 +01:00
Gnuxie 3ad7079216 Appservice test: postgres container networking.
The docker network is ipv4 but we tell node it can use `localhost`
which it then tries to connect to via ipv6.
2023-05-13 15:32:17 +01:00
Gnuxie 88bf0acf5e Add the sender when showing a policy rule change. (#51)
![image](https://github.com/Gnuxie/Draupnir/assets/50846879/1e445d60-d816-4bd1-bec2-c6b4128793d7)

Mainly useful for Community Moderation Effort.
2023-05-10 23:07:32 +01:00
Gnuxie 9f43e1186b Incorperate Do not interrupt redact sequences due to error when backfilling (#50)
* Do not interrupt redact sequences due to error when backfilling

... Mainly timeouts.

* Change caught redaction error LogLevel from DEBUG to ERROR.

From matrix-org/mjolnir#479

---------

Co-authored-by: Marco Cirillo <marco.cirillo@aria-net.org>
2023-05-03 16:56:17 +01:00
Gnuxie 99e6f168ca Appservice convenience (#47)
Canonicalise the existence of the "admin room" for managing the appservice and Draupnir instances

* Add utilities for managing users in the admin room

* Merge the appservice admin room and access control list.

The majority of admins will need to use the draupnir admin commands
to manage the list.

* Utility methods for creating generic rules in PolicyLists.

* Commands for managing appservice users.
2023-05-03 16:31:28 +01:00
Gnuxie 9e8783312a Use matrix-appservice-bridge's PostgreSQL datastore for Draupnir appservice (#46)
* use matrix-appservice-bridge support for postgres

* upgrade matrix-appservice-bridge to include postgres fixes.

These are unreleased and a specific develop commit, but we're the only ones
who have made changes so far to the develop branch,
so should be fine.

* Upgrade matrix-appservice-bridge to 8.1.1.

8.0.1 was never added to npm for some weird reason.
2023-03-31 18:16:23 +01:00
gnuxie 2d78cbbee5 Remember to resolve policy lists where we can. 2023-03-28 22:00:50 +01:00
Gnuxie 924bed5813 PolicyListManager watch/unwatch should use MatrixRoomReferences. (#42) 2023-03-28 19:55:34 +01:00
gnuxie 7750773a7f Glue was calling shutdown room rather than deactivate user. 2023-03-28 13:53:58 +01:00
gnuxie 1fbeda0d4c Stop MatrixReactionHandler reacting to itself. 2023-03-24 18:57:25 +00:00
gnuxie 492230d61d Update references to a now non-existant IProtection in tests. 2023-03-24 18:57:25 +00:00
gnuxie 1a73492178 Update protectionSettingsTest for Protection changes.
Worried about when IProtection existed and when it was removed??
Idk but this wasn't going great to begin with.
2023-03-24 18:57:25 +00:00
gnuxie 06b3f71c92 Update BanPropagationProtection to use MatrixReactionHandler. 2023-03-24 18:57:25 +00:00
gnuxie f565b010a4 Add MatrixReactionHandler that allows us to create advanced prompts.
These prompts don't have a timeout and don't need a backing store,
so this is ideal for the ban propagation protection.
2023-03-24 18:57:25 +00:00
gnuxie d390ce8772 Allow protections to hook into mjolnir startup. 2023-03-24 18:57:25 +00:00
gnuxie ffcc3c6804 Bugfix: !draupnir status was matching against !draupnir joins. 2023-03-14 13:42:59 +00:00
gnuxie 598f5483d9 type guards for updated Permalink helper 2023-03-09 15:20:52 +00:00
gnuxie a960025b61 Add Permalink changes from
https://github.com/turt2live/matrix-bot-sdk/pull/300
Element takes forever reviewing anything so i suspect
it'll be months before Travis even sniffs it.
2023-03-09 15:20:52 +00:00
gnuxie d05db20a49 Improve help for command parameters by listing their descriptions. 2023-03-07 19:59:08 +00:00
gnuxie f122beadef Help page.
TODO:
- Needs description adding into the detail rather than the summary
- needs rich text
- needs markdown detail/summary to not just be the HTML tags, unacceptable since it's supposed to be fallback
- More commands
2023-03-07 19:59:08 +00:00
gnuxie 7d29d68aa2 Add name to CommandTable 2023-03-07 19:59:08 +00:00
gnuxie 7d3f222f2b Add destructuring of command tables for imported tables 2023-03-07 19:59:08 +00:00
gnuxie 1aa97b7c09 Add AliasCommands to Synapse admin table
Not sure whether this will be their home in the long term but
for now it'll do.
2023-03-07 19:59:08 +00:00
gnuxie 1e51aded59 MatrixRoomReference has distinct RoomID and Alias parts. 2023-03-07 19:59:08 +00:00