mirror of
https://github.com/outline/outline.git
synced 2026-12-02 09:42:07 +03:00
Re-authorize collaboration connections when access changes (#13454)
* feat: Re-authorize collaboration connections when access changes Collaboration connections are authorized once, when the websocket is first established, so a connection outlives changes to the access it was granted. Add a processor that publishes access changes to the collaboration servers over Redis. Each server closes the connections it holds within the scope of the change and clients reconnect, at which point they are authorized as normal. Authorization stays in one place, the published scope only has to cover the connections that may be affected. The API update subscriber now shares a single Redis connection rather than opening its own. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> * refactor: Log an access change once rather than per connection Every closed connection is already logged by LoggerExtension, so record the reason and the number of connections affected once instead. The count also makes a scope that matches nothing visible. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
f4b9c7c910
commit
7f54d5ea10
9 files changed
+683
-21
No files matched your search
@@ -7,7 +7,6 @@ import type {
|
||||
} from "@hocuspocus/server";
|
||||
import type { Document as HocuspocusDocument } from "@hocuspocus/server";
|
||||
import * as Y from "yjs";
|
||||
import env from "@server/env";
|
||||
import Logger from "@server/logging/Logger";
|
||||
import { trace } from "@server/logging/tracing";
|
||||
import Document from "@server/models/Document";
|
||||
@@ -51,19 +50,7 @@ export class APIUpdateExtension implements Extension {
|
||||
this.configured = true;
|
||||
|
||||
try {
|
||||
// Create a dedicated subscriber for API update notifications
|
||||
this.subscriber = new RedisAdapter(
|
||||
env.REDIS_COLLABORATION_URL || env.REDIS_URL,
|
||||
{
|
||||
connectionNameSuffix: "collab-api-updates",
|
||||
maxRetriesPerRequest: null,
|
||||
}
|
||||
);
|
||||
|
||||
// Handle Redis connection errors
|
||||
this.subscriber.on("error", (err) => {
|
||||
Logger.error("Redis subscriber error in APIUpdateExtension", err);
|
||||
});
|
||||
this.subscriber = RedisAdapter.collaborationSubscriber;
|
||||
|
||||
// Subscribe to the API update channel pattern
|
||||
await this.subscriber.psubscribe(`${CHANNEL_PREFIX}:*`, (err) => {
|
||||
@@ -99,8 +86,8 @@ export class APIUpdateExtension implements Extension {
|
||||
|
||||
async onDestroy(_data: onDestroyPayload): Promise<void> {
|
||||
if (this.subscriber) {
|
||||
this.subscriber.off("pmessage", this.handleMessage);
|
||||
await this.subscriber.punsubscribe(`${CHANNEL_PREFIX}:*`);
|
||||
await this.subscriber.quit();
|
||||
this.subscriber = null;
|
||||
}
|
||||
this.documents.clear();
|
||||
|
||||
Reference in new issue
Block a user