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

Add config option to disable kicking Matrix users from rooms #1294

Merged
merged 3 commits into from
Apr 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions changelog.d/1294.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add new `kickOn` config option to disable kicking Matrix users under certain conditions
11 changes: 11 additions & 0 deletions config.sample.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,17 @@ ircService:
# Whilst the IRCd *should* be sending pings to us to keep the connection alive, it appears
# that sometimes they don't get around to it and end up ping timing us out.
# pingRateMs: 60000
# Choose which conditions the IRC bridge should kick Matrix users for. Decisions to this from
# defaults should be taken with care as it may dishonestly repesent Matrix users on the IRC
# network, and cause your bridge to be banned.
kickOn:
# Kick a Matrix user from a bridged room if they fail to join the IRC channel.
channelJoinFailure: true
# Kick a Matrix user from ALL rooms if they are unable to get connected to IRC.
ircConnectionFailure: true
# Kick a Matrix user from ALL rooms if they choose to QUIT the IRC network.
userQuit: true


# Set information about the bridged channel in the room state, so that client's may
# present relevant UI to the user. MSC2346
Expand Down
9 changes: 9 additions & 0 deletions config.schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,15 @@ properties:
type: "integer"
pingRateMs:
type: "integer"
kickOn:
type: "object"
properties:
channelJoinFailure:
type: "boolean"
ircConnectionFailure:
type: "boolean"
userQuit:
type: "boolean"
excludeUsers:
type: "array"
properties:
Expand Down
47 changes: 30 additions & 17 deletions src/bridge/MatrixHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,18 @@ export class MatrixHandler {

const intent = this.ircBridge.getAppServiceBridge().getIntent();

for (let i = 0; i < clients.length; i++) {
const bridgedClient = clients[i];
for (const bridgedClient of clients) {
req.log.info(
`Killing bridgedClient (nick = ${bridgedClient.nick}) for ${bridgedClient.userId}`
);
if (!bridgedClient.server.config.ircClients.kickOn.userQuit) {
req.log.info(
`Not leaving ${userId} from rooms on ${bridgedClient.server.domain}`
);
await bridgedClient.kill(reason);
continue;
}

if (bridgedClient.chanList.size === 0) {
req.log.info(
`Bridged client for ${userId} is not in any channels ` +
Expand Down Expand Up @@ -339,9 +349,6 @@ export class MatrixHandler {
}));
}

req.log.info(
`Killing bridgedClient (nick = ${bridgedClient.nick}) for ${bridgedClient.userId}`
);
// The success message will effectively be 'Your connection to ... has been lost.`
await bridgedClient.kill(reason);
}
Expand Down Expand Up @@ -529,18 +536,24 @@ export class MatrixHandler {
);
}
catch (e) {
// We need to kick on failure to get a client.
req.log.info(`${user.getId()} failed to get a IRC connection. Kicking from room: ${e}`);
this.incrementMetric(room.server.domain, "connection_failure_kicks");
const excluded = room.server.isExcludedUser(user.getId());
await this.membershipQueue.leave(
event.room_id,
user.getId(),
req,
true,
excluded && excluded.kickReason ? excluded.kickReason : `IRC connection failure.`,
this.ircBridge.appServiceUserId,
);
req.log.info(`${user.getId()} failed to get a IRC connection.`, e);
if (room.server.config.ircClients.kickOn.ircConnectionFailure) {
// We need to kick on failure to get a client.
req.log.info(`Kicking from room`);
this.incrementMetric(room.server.domain, "connection_failure_kicks");
const excluded = room.server.isExcludedUser(user.getId());
await this.membershipQueue.leave(
event.room_id,
user.getId(),
req,
true,
excluded && excluded.kickReason ? excluded.kickReason : `IRC connection failure.`,
this.ircBridge.appServiceUserId,
);
}
else {
req.log.info(`Not kicking - disabled in config`);
}
}

if (!bridgedClient || !bridgedClient.userId) {
Expand Down
3 changes: 3 additions & 0 deletions src/irc/ClientPool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -670,6 +670,9 @@ export class ClientPool {
if (!userId || bridgedClient.isBot) {
return; // the bot itself can get these join errors
}
if (!bridgedClient.server.config.ircClients.kickOn.channelJoinFailure) {
return; // The bridge is configured not to kick on failure.
}
// TODO: this is a bit evil, no one in their right mind would expect
// the client pool to be kicking matrix users from a room :(
log.info(`Kicking ${userId} from room due to ${err}`);
Expand Down
10 changes: 10 additions & 0 deletions src/irc/IrcServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@ export interface IrcServerConfig {
realnameFormat?: "mxid"|"reverse-mxid";
pingTimeoutMs: number;
pingRateMs: number;
kickOn: {
channelJoinFailure: boolean;
ircConnectionFailure: boolean;
userQuit: boolean;
}
};
excludedUsers: Array<
{
Expand Down Expand Up @@ -694,6 +699,11 @@ export class IrcServer {
lineLimit: 3,
pingTimeoutMs: 1000 * 60 * 10,
pingRateMs: 1000 * 60,
kickOn: {
ircConnectionFailure: true,
channelJoinFailure: true,
userQuit: true
}
},
membershipLists: {
enabled: false,
Expand Down