Skip to content

Policy Lifecycle: load & clear management #69

Closed
1 of 1 issue completed
Closed

Description

@mariajgrimaldi

Description

The current Public API and REST API for authorization assume that the Casbin enforcer is always up to date with the policy datastore. However, the enforcer only works with what is loaded into its in-memory state, and there is no lifecycle management in place to ensure that the enforcer reflects the latest policies. This creates a risk of stale or incomplete policy enforcement.

Problem

  • No automatic lifecycle management: The API does not currently load or clear the enforcer. It relies on an external process to ensure freshness.
  • Test suite workaround: Our test cases explicitly clear and reload the full policy between tests, but this is not a production-ready solution.
  • Memory concerns: The enforcer loads all specified policy lines into memory through the adapter. Loading everything on each request is not scalable.
  • Partial policy loading: We need a strategy for loading only the pertinent subset of policies required for the request context, without overloading the enforcer.

Requirements

  1. Define when to load policies into the enforcer:

    • On every API call?
    • On demand when stale?
    • Cached until invalidated?
  2. Define when and how to clear policies from memory to prevent stale data.

  3. Ensure the API and REST API are self-contained and do not require external orchestration for policy lifecycle management.

  4. Support scoped/filtered loading (e.g., by org, lib, or user) to avoid loading the entire policy store unnecessarily.

Acceptance Criteria

  • The enforcer always reflects the latest state of the policy datastore when API methods (e.g., get_roles_for_user) are invoked.
  • The system has a clear strategy for clearing and reloading policies (documented and implemented).
  • Subset loading is supported to avoid memory saturation.
  • Tests confirm correctness under concurrent API usage.

Notes

  • This issue is not about the policy model itself, but about the operational lifecycle of the enforcer.
  • We may need to explore caching + watcher patterns (e.g., Redis invalidation) in later iterations, but the MVP should establish a reliable baseline.

Activity

  1. mariajgrimaldi commented on Sep 30, 2025

    @mariajgrimaldi
    MemberAuthor
  2. mariajgrimaldi commented on Sep 30, 2025

    @mariajgrimaldi
    MemberAuthor

    I'm going to do some load and clear management for the has_permission call in case it needs to be self-contained for other services to directly consume from the public API. I think that for the rest API we can do some of this management at the view level. Another solution could be to have a decorator that uses the load_filtered_policy.

  3. removed their assignment
    on Oct 22, 2025
  4. added
    MVPRequired for an MVP release of this feature
    on Oct 22, 2025
  5. mariajgrimaldi commented on Oct 22, 2025

    @mariajgrimaldi
    MemberAuthor

    This was addressed by #103

    Should we close it? And open a different one if we're going to consider to load_filtered_policies in the future @BryanttV

  6. BryanttV commented on Oct 22, 2025

    @BryanttV
    Contributor

    Yes, I agree with that.

  7. removed
    MVPRequired for an MVP release of this feature
    on Nov 12, 2025
  8. mariajgrimaldi commented on Dec 5, 2025

    @mariajgrimaldi
    MemberAuthor

    closing for now, I'll open a new issue to consider loading filtered policies

  9. moved this from In Progress to Done in RBAC AuthZ Boardon Dec 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions