Skip to content

Watcher-Based Policy Invalidation & Sync #73

Closed

Description

@mariajgrimaldi

Description

Implement and document a Casbin watcher strategy to keep the enforcers’ in-memory policy state fresh. The watcher should notify enforcers when policies change and trigger a synchronization callback that aligns with our Policy Lifecycle Load/Clear approach.
MVP note: This must remain simple and reliable sufficient to validate the approach during the MVP, without complex orchestration.

Problem

  • Notification-only today: The watcher broadcasts changes, but our callback only logs; no real sync occurs.
  • Heavy reloads are costly: Blindly calling enforcer.load_policy() on every change may be too expensive.
  • Risk of staleness: Without a proper callback, in-memory state can drift from the datastore and cause incorrect enforcement (and potential duplicates).

Requirements

  1. Provide a minimal, MVP-ready watcher integration: redis-wather properly configured
  2. Implement a synchronization callback that:
    • Prefers a lightweight refresh (e.g., filtered/targeted where feasible), falling back to a safe simple path when needed.
    • Coordinates with the Load/Clear lifecycle so both mechanisms stay consistent.
  3. Make behavior configurable for MVP (if needed):
    • Enable/disable watcher.
    • Select simple full reload vs. lighter refresh if adapter support exists.
  4. Document how the watcher is wired, what the callback does, and how it interacts with lifecycle and duplicate prevention.
  5. Ensure compliance with MVP goals: prioritize correctness and predictability over optimization.

Acceptance Criteria

  • On policy changes, the enforcer receives watcher notifications and performs a meaningful sync beyond logging.
  • Under common change scenarios, the enforcer becomes fresh without requiring heavy reloads by default (fallback allowed).
  • Tests show:
    • Watcher-driven sync updates in-memory policies appropriately.
    • No conflicts with Load/Clear lifecycle.
    • No duplicates introduced as a side effect.

Notes

Activity

  1. mariajgrimaldi commented on Oct 10, 2025

    @mariajgrimaldi
    MemberAuthor

    I assigned you this issue to figure out the scope of this for the MVP @BryanttV. This also includes the appropriate default configuration for the watcher here: https://github.com/openedx/openedx-authz/blob/main/openedx_authz/settings/common.py#L31-L32

    Let me know!

  2. moved this to In Progress in RBAC AuthZ Boardon Oct 15, 2025
  3. mariajgrimaldi commented on Oct 22, 2025

    @mariajgrimaldi
    MemberAuthor

    The watcher-based enforcer was replaced by syncenforcer approach. @BryanttV: let's close this once we merge #103 and remove the references of the redis-watcher from the repo. Thanks!

  4. added
    MVP
    on Oct 22, 2025
  5. moved this from In Progress to Ready for testing in RBAC AuthZ Boardon Oct 22, 2025
  6. MaferMazu commented on Nov 6, 2025

    @MaferMazu
    Contributor

    I'll close this based that we closed #103

  7. moved this from Ready for review to Done in RBAC AuthZ Boardon Nov 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

MVP

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions