touchifyapp / casbin-pg-adapter

PostgreSQL native adapter for Node-Casbin with advanced filter capability and improved performance.
MIT License
16 stars 5 forks source link

Add auto-loading of new policies #9

Open mattbishop opened 2 years ago

mattbishop commented 2 years ago

When Casbin is used in a multi-node configuration, one node may change the Casbin configuration, yet the others are unaware of this change. It would be possible for all nodes to use Postgres' LISTEN/NOTIFY feature to listen for changes on the tables and reload their policies as they change.

See https://www.postgresql.org/docs/current/sql-listen.html

hsluoyz commented 2 years ago

@mattbishop you can use watchers: https://casbin.org/docs/en/watchers

SomaticIT commented 2 years ago

@mattbishop, I think the safest way to work on a multi-node configuration is the one @hsluoyz mention. Watchers were built exactly for this purpose.

mattbishop commented 2 years ago

Thanks, I read about watchers but am hoping to avoid standing up another process for this purpose. I only have node servers next Postgres would be simpler for this task in my situation.

— Matt Bishop

On Sep 14, 2021, at 3:15 AM, Maxime LUCE @.***> wrote:

 @mattbishop, I think the safest way to work on a multi-node configuration is the one @hsluoyz mention. Watchers were built exactly for this purpose.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe.

hsluoyz commented 2 years ago

Then you have to implement the feature in this repo.

ping @nodece @Zxilly @gabriel-403

SomaticIT commented 2 years ago

I agree to have a Watcher implementation in this repo:

  1. Create a watcher.ts file in lib
  2. Implement the Watcher interface from casbin
  3. Export the PostgresWatcher in index.ts

However, if you want to implement this in this repo, you should stick using node-postgres.

Maybe the simplest way would be to create another repo and package using pg-listen.

mattbishop commented 2 years ago

I like this approach! I won't be able to get to it until October or November so please keep recording your thoughts in this ticket.

On Wed, Sep 15, 2021 at 2:09 PM Maxime LUCE @.***> wrote:

I agree to have a Watcher implementation in this repo:

  1. Create a watcher.ts file in lib
  2. Implement the Watcher interface from casbin
  3. Export the PostgresWatcher in index.ts

However, if you want to implement this in this repo, you should stick using node-postgres https://node-postgres.com/.

Maybe the simplest way would be to create another repo and package using pg-listen https://www.npmjs.com/package/pg-listen.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/touchifyapp/casbin-pg-adapter/issues/9#issuecomment-920377455, or unsubscribe https://github.com/notifications/unsubscribe-auth/AACY3BO63JKIBLWSWNWG5DTUCEDPXANCNFSM5D7H3LVA .