Skip to content

Feat/ws grants bug 215 - #260

Open
solus161 wants to merge 4 commits into
aimdb-dev:mainfrom
solus161:feat/ws_grants_bug_215
Open

solus161 wants to merge 4 commits into
aimdb-dev:mainfrom
solus161:feat/ws_grants_bug_215

Conversation

@solus161

Copy link
Copy Markdown
Contributor

Description

Issue 215 pointed out the tangled up nature of record keys and topics. This PR decouples these two namespaces by adding distinct logics (paths are relative to aimdb-websocket-connection crate by default). The core idea is to keep this logic clear: clients keep speaking topic, server speaks record key, and the two namespaces joined at outbound route:

  • /src/server/auth::Permissions now has read_patterns renamed from subscribe_pattern. This indicates a change of authorization logic from topic to record key. Meanwhile, write_patterns remains with topic. This is followed by a change of fn can_subscribe() to fn can_read(), which is naming change not logic change;
  • /src/server/auth::RecordsBits added to encode per-client read permissions. Each bit decice whether the client having read access to a record. Bit indexes are the same as record indexes which are registration order (in AimDbInner.storage. RecordsBits is built during ws upgrade process, and carried by ClientInfo;
  • /src/server/auth: several AuthHandler fn become obsolete due to this logic change and being removed, including fn authorize_subscribe() (authorization is resolved at upgrade and enforced at delivery), fn authorize_query() (the filtering logic is now based on record permissions), and fn authorize_list();
  • src/server/http: the fn ws_upgrade_handler() now build the per-client permission bitmask based on the server's registered records and configured Permissions. The handler does not deny the upgrade even if the client has no grant (permission bitmask is empty or all bits are zero).
  • The server building process now has to incorporate additional record id logic:
    • /src/server/connector::SnapshotCache is updated to carry record id logic. A snapshot is now identified by record id and associated topic, instead of just topic. trait SnapshotProvider output also changes accordingly;
    • aimdb-core/src/builder::AimDb.collect_outbound_routes() now build OutboundRoute with extra key-value pair of "record_index"-"{record_id}" in .config: ConnectorConfig attr. ConnectorConfig carries that pair till /src/server/connector::WsBusSink.publish() where the snapshot cache is built and message is broadcasted. It is the ClientManager deciding which subscriptions/clients get the message;
  • As a result of the decoupling logic, some behaviors worth mentioned:
    • Client having no permissions is denied at subscription at WsSession.subscribe(), /src/server/dispatch.rs;
    • Client could subscribe to topics not registered yet by server;
    • record.list returns only records that the client has permissions for;
    • record.query could return a set of records smaller than what the name pattern asks for. If the asked name and grant bits do not overlap, the query is denied;

Also, several tests added to ensure these behaviors hold.

Related Issue

Checklist

  • I have read the CONTRIBUTING.md document.
  • My code follows the project's coding standards.
  • I have added tests to cover my changes.
  • All new and existing tests passed (make check).
  • I have updated the documentation accordingly.

The record key pattern  now rule permissions for read, while write
permissions still based on topic pattern.
@solus161
solus161 requested a review from lxsaah as a code owner September 20, 2026 02:52
@solus161

Copy link
Copy Markdown
Contributor Author

Hi @lxsaah, plz check the PR. The large part of added code is test to cover different behaviors stem from decoupled record and topic. Btw I missed your collab invite, could you send again?

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.

[BUG] ws grants are ws-topic patterns — record.list/record.query authorize with them in key space

1 participant