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

manymjolnir appservice #364

Merged
merged 47 commits into from
Nov 15, 2022
Merged

manymjolnir appservice #364

merged 47 commits into from
Nov 15, 2022

Conversation

jesopo
Copy link
Contributor

@jesopo jesopo commented Aug 30, 2022

No description provided.

src/appservice/Api.ts Show resolved Hide resolved
src/appservice/AppService.ts Show resolved Hide resolved
src/appservice/MjolnirManager.ts Show resolved Hide resolved
src/appservice/MjolnirManager.ts Outdated Show resolved Hide resolved
mx-tester.yml Show resolved Hide resolved
@Gnuxie Gnuxie force-pushed the gnuxie/appservice-mjolnir branch 2 times, most recently from bd919e4 to c6def0b Compare October 19, 2022 14:31
@Gnuxie Gnuxie force-pushed the gnuxie/appservice-mjolnir branch 5 times, most recently from 3057d05 to 2d40fdb Compare October 24, 2022 17:05
@Gnuxie Gnuxie force-pushed the gnuxie/appservice-mjolnir branch 3 times, most recently from 092044d to 818e4cf Compare November 4, 2022 13:02
@Gnuxie Gnuxie marked this pull request as ready for review November 4, 2022 13:02
@Gnuxie Gnuxie requested a review from Yoric November 4, 2022 13:43
docs/appservice.md Outdated Show resolved Hide resolved
docs/appservice.md Outdated Show resolved Hide resolved
docs/appservice.md Show resolved Hide resolved

`docker run -rm -v /mjolnir/data/path:/data matrixdotorg/mjolnir appservice -r -u "http://$HOST:$MATRIX_PORT" -f /data/config/mjolnir-registration.yaml`

5. Invite the application service bot (specified in the registration) to the access control room you made earlier.
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: "made" => "created"

Also, I'd rephrase:

"Step 4 created an application service bot. You now need to invite it in the access control room that you have created in Step 1."

However, don't we need to start the application service (step 6) before inviting the bot?

Copy link
Contributor

Choose a reason for hiding this comment

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

We don't need to start the service before inviting the bot

Copy link
Contributor

Choose a reason for hiding this comment

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

The appservice doesn't need to be aware of the invite, only the homeserver

Copy link
Contributor

Choose a reason for hiding this comment

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

as the appservice will try joining anyways

docs/appservice.md Outdated Show resolved Hide resolved
export interface MjolnirRecord {
local_part: string,
owner: string,
management_room: string,
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we clarify that it's a management_room_id?

Copy link
Contributor

Choose a reason for hiding this comment

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

Probably too late now, but we should follow up once schema management is sorted out, added to #415

}

public async store(mjolnirRecord: MjolnirRecord): Promise<void> {
await this.pgClient.query(
Copy link
Contributor

Choose a reason for hiding this comment

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

How does this behave if the connection to the client is lost at some point, i.e. if Postgres is upgraded while Mjölnir is on?

Copy link
Contributor

Choose a reason for hiding this comment

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

Probably explodes, how are you supposed to handle that? (genuine)

Copy link
Contributor

Choose a reason for hiding this comment

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

Generally, in my code, I use a connection pool. I drop the connection as soon as I stop using it and I request a connection from the pool when I need a new one. The connection pool is smart enough to reconnect if I have been disconnected. This limits the risks of exploding in flight.

Sounds like a followup issue?

Copy link
Contributor

Choose a reason for hiding this comment

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

test/appservice/integration/webAPITest.ts Outdated Show resolved Hide resolved
test/appservice/utils/harness.ts Outdated Show resolved Hide resolved
private constructor(
private readonly matrixClient: MatrixClient,
/**
* This will want refactoring later on since, well, for some reason our API is designed to accept the token in request body and not authorization header :(
Copy link
Contributor

Choose a reason for hiding this comment

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

Certainly true, but that's not documentation :)

Is this something that can be done quickly?

Copy link
Contributor

Choose a reason for hiding this comment

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

Probably not #416

Copy link
Contributor

@Yoric Yoric left a comment

Choose a reason for hiding this comment

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

Looks pretty good! I have a few questions but I feel that we're nearly there.

docs/appservice.md Outdated Show resolved Hide resolved
docs/appservice.md Outdated Show resolved Hide resolved
src/appservice/AccessControl.ts Show resolved Hide resolved
try {
response = JSON.parse(body);
} catch (e) {
reject(null);
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't see it documented?

src/appservice/Api.ts Outdated Show resolved Hide resolved
this.user = user;
const roomsInvitedTo: string[] = [];
await new Promise(async resolve => {
user.on('room.invite', (roomId: string) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't understand why we're using user to watch for a room.invite. Aren't we expecting the bot or a new virtual user to be invited?

Copy link
Contributor

Choose a reason for hiding this comment

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

The user gets invited to a management and policy room by the newly provisioned mjolnir

user.on('room.invite', (roomId: string) => {
roomsInvitedTo.push(roomId)
// the appservice should invite it to a policy room and a management room.
if (roomsInvitedTo.length === 2) {
Copy link
Contributor

Choose a reason for hiding this comment

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

We're only checking the length of roomsInvitedTo? Not the actual rooms?

Copy link
Contributor

Choose a reason for hiding this comment

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

We check those later, it would be nice to describe the rooms we are looking for upfront, but I'm not sure matrix is introspective enough for that.

test/appservice/integration/provisionTest.ts Outdated Show resolved Hide resolved
const mjolnirDetails: CreateMjolnirResponse = await new Promise(async resolve => {
const mjolnirDetailsPromise = apiClient.createMjolnir(roomToProtectId);
user.on('room.invite', (roomId: string) => {
roomsInvitedTo.push(roomId)
Copy link
Contributor

Choose a reason for hiding this comment

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

Basically, same questions as in the previous test.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, seems they are almost the same

test/appservice/utils/webAPIClient.ts Outdated Show resolved Hide resolved
@Gnuxie Gnuxie force-pushed the gnuxie/appservice-mjolnir branch 2 times, most recently from 55a4b7f to f6b8f45 Compare November 15, 2022 17:00
jesopo and others added 26 commits November 15, 2022 17:05
matrix-bot-sdk imporved the types for this
still needs hooking up when mjolnir restarts, and when the access control changes
It's much harder to forget to initialize the components now that you have to in order to construct them in the first place.
this means that the appsrvice bot is now called 'mjolnir-bot' by default
which was easier than going through old code base and renaming
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants