Skip to content

feat: add authz schema policy renderer - #479

Open
rodmgwgu wants to merge 1 commit into
rod/authz-schema-modelsfrom
rod/authz-schema-renderer
Open

rodmgwgu wants to merge 1 commit into
rod/authz-schema-modelsfrom
rod/authz-schema-renderer

Conversation

@rodmgwgu

Copy link
Copy Markdown
Contributor

Problem

A compiled schema carries bare identifiers; the enforcer stores namespaced Casbin p rows. Something has to translate between the two, and it has to be the single place that applies the namespacing — two places would drift, and a later comparison against the stored policy would silently stop matching (ADR 0018 §5).

Approach

  • openedx_authz/engine/renderer.py — PolicyRow, RenderedPolicy, policy_row(), PolicyRenderer
  • openedx_authz/tests/schema/test_renderer.py

render() emits one p row per (role, permission, supported scope), applies the internal form (role^, act^, <scope>^*) at this boundary, and is deterministic so the output can be diffed against a stored policy. It emits definition rows only — never g assignments or legacy g2 action inheritance — so data owned by other services is out of reach by construction.

The render phase is pure: no Casbin, no Django, no database. The apply phase, which does touch both, is the next PR in the stack.

Manual testing instructions

pytest openedx_authz/tests/schema/test_renderer.py

Rollback plan

Revert this PR. Nothing consumes the renderer yet, so the revert is inert.

Retro compatibility

No authorization behavior changes. Rendering produces rows in memory and writes nothing.

AI Usage

Kiro was used to assist on feature planning and implementation. Implementation was done step by step with human guidance and validation, based on the ADRs.


Stack (6/8) — #446 split into reviewable pieces. Bases chain bottom-up; merge in order.

  1. feat: add authz schema discovery #474 — schema discovery
  2. feat: add authz schema loading #475 — schema loading
  3. feat: add authz schema compilation #476 — schema compilation
  4. feat: add authz schema validation #477 — schema validation
  5. feat: add authz schema definition models #478 — definition models + migration
  6. This PR — policy renderer (base: rod/authz-schema-models)
  7. rod/authz-schema-applier — schema applier
  8. feat: add authz schema pipeline and load_authz_schema command #446 — pipeline + load_authz_schema command, version bump and changelog

In #446 render and apply shared one 686-line module. They are split here so the pure, easily-reviewed render step is not bundled with the transactional apply step; 7/8 adds the rest of the same file.

Merge checklist:

  • Version bumped — deferred to 8/8 so the stack does not conflict on every restack
  • Changelog record added — deferred to 8/8
  • Documentation updated (not only docstrings) — covered by the already-merged ADRs
  • Fixup commits are squashed away
  • Unit tests added/updated
  • Manual testing instructions provided
  • Noted any: Concerns, dependencies, migration issues, deadlines, tickets — depends on feat: add authz schema definition models #478; no migration

@openedx-webhooks

Copy link
Copy Markdown

Thanks for the pull request, @rodmgwgu!

This repository is currently maintained by @openedx/committers-openedx-authz.

Once you've gone through the following steps feel free to tag them in a comment and let them know that your changes are ready for engineering review.

🔘 Get product approval

If you haven't already, check this list to see if your contribution needs to go through the product review process.

  • If it does, you'll need to submit a product proposal for your contribution, and have it reviewed by the Product Working Group.
    • This process (including the steps you'll need to take) is documented here.
  • If it doesn't, simply proceed with the next step.
🔘 Provide context

To help your reviewers and other members of the community understand the purpose and larger context of your changes, feel free to add as much of the following information to the PR description as you can:

  • Dependencies

    This PR must be merged before / after / at the same time as ...

  • Blockers

    This PR is waiting for OEP-1234 to be accepted.

  • Timeline information

    This PR must be merged by XX date because ...

  • Partner information

    This is for a course on edx.org.

  • Supporting documentation
  • Relevant Open edX discussion forum threads
🔘 Get a green build

If one or more checks are failing, continue working on your changes until this is no longer the case and your build turns green.

Details
Where can I find more information?

If you'd like to get more details on all aspects of the review process for open source pull requests (OSPRs), check out the following resources:

When can I expect my changes to be merged?

Our goal is to get community contributions seen and reviewed as efficiently as possible.

However, the amount of time that it takes to review and merge a PR can vary significantly based on factors such as:

  • The size and impact of the changes that it introduces
  • The need for product review
  • Maintenance status of the parent repository

💡 As a result it may take up to several weeks or months to complete a review and merge your PR.

@openedx-webhooks openedx-webhooks added open-source-contribution PR author is not from Axim or 2U core contributor PR author is a Core Contributor (who may or may not have write access to this repo). labels Sep 23, 2026
@github-project-automation github-project-automation Bot moved this to Needs Triage in Contributions Sep 23, 2026
@rodmgwgu
rodmgwgu added this pull request to stack #481 September 23, 2026 16:41
@rodmgwgu
rodmgwgu force-pushed the rod/authz-schema-renderer branch from 9f7350f to d22ebbe Compare September 23, 2026 17:03
@rodmgwgu
rodmgwgu force-pushed the rod/authz-schema-renderer branch 5 times, most recently from 3a2f951 to b73023f Compare September 24, 2026 23:01
@rodmgwgu
rodmgwgu force-pushed the rod/authz-schema-renderer branch 2 times, most recently from d912d58 to 9ac87a4 Compare September 29, 2026 15:12
@mphilbrick211 mphilbrick211 added the mao-onboarding Reviewing this will help onboard devs from an Axim mission-aligned organization (MAO). label Sep 29, 2026
@rodmgwgu
rodmgwgu force-pushed the rod/authz-schema-renderer branch from 9ac87a4 to 8fa7e9b Compare September 30, 2026 22:57
@rodmgwgu
rodmgwgu force-pushed the rod/authz-schema-renderer branch from 8fa7e9b to a6abbef Compare September 30, 2026 23:22

@mariajgrimaldi mariajgrimaldi left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a few comments for you to review!

Comment on lines +30 to +35
# Namespace prefixes for the internal Casbin form (schema objects never carry them).
ROLE_PREFIX = "role"
ACTION_PREFIX = "act"
SCOPE_WILDCARD = "*"
ALLOW = "allow"
POLICY_PTYPE = "p"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't have this already defined in data.py?

Comment on lines +59 to +62
def from_policy(cls, values: list[str]) -> "PolicyRow":
"""Build from a stored ``p`` row (``[subject, action, scope, effect]``)."""
subject, action, scope, effect = (list(values) + ["", "", "", ""])[:4]
return cls(POLICY_PTYPE, subject, action, scope, effect)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[non-blocking] Could we reuse the existing policy parsing here? PolicyIndex already defines these field positions, and get_permission_from_policy() parses and validates the same list shape. It may be worth extracting shared parsing so the mapping and validation stay in one place.

rows: list[PolicyRow] = field(default_factory=list)


def policy_row(role_id: str, permission_id: str, scope: str) -> PolicyRow:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks more than a constructor that should be part of PolicyRow?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core contributor PR author is a Core Contributor (who may or may not have write access to this repo). mao-onboarding Reviewing this will help onboard devs from an Axim mission-aligned organization (MAO). open-source-contribution PR author is not from Axim or 2U

Projects

Status: In Eng Review

Development

Successfully merging this pull request may close these issues.

5 participants