Skip to content

feat: add authz schema compilation - #476

Merged
rodmgwgu merged 13 commits into
mainfrom
rod/authz-schema-compiler
Oct 6, 2026
Merged

rodmgwgu merged 13 commits into
mainfrom
rod/authz-schema-compiler

Conversation

@rodmgwgu

Copy link
Copy Markdown
Contributor

Problem

Several distributions can contribute to the same authorization schema, and one can extend a role defined by another. The loaded documents need to be resolved into a single set of definitions with per-contribution provenance, and role extensions merged deterministically (ADR 0018 §1, ADR 0023).

Approach

  • openedx_authz/engine/schema/compilation.py — SchemaCompiler
  • openedx_authz/tests/schema/test_compilation.py

Merge rules follow ADR 0023: metadata replace, add/remove permissions, tri-state hidden, and priority to resolve conflicts. An unresolvable equal-priority conflict raises SchemaCompileError rather than picking a winner. Compilation is pure — no database, no Casbin.

Manual testing instructions

pytest openedx_authz/tests/schema/

Rollback plan

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

Retro compatibility

No authorization behavior changes. No models, no migration, no automatic code path.

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 (3/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. This PR — schema compilation (base: rod/authz-schema-loader-only)
  4. rod/authz-schema-validator — schema validation
  5. rod/authz-schema-models — definition models + migration
  6. rod/authz-schema-renderer — policy renderer
  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

Compilation lands before validation because the post-compile validation rules — and their tests — operate on a CompiledSchema. The compiler itself does not depend on the validator.

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 loading #475; no migration

@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
@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.

@rodmgwgu
rodmgwgu force-pushed the rod/authz-schema-compiler branch 5 times, most recently from 9c964ac to 2c77167 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
Comment thread src/openedx_authz/engine/schema/compilation.py Outdated
Comment thread src/openedx_authz/engine/schema/compilation.py Outdated
Comment thread src/openedx_authz/engine/schema/compilation.py Outdated
Comment thread src/openedx_authz/engine/schema/compilation.py
Comment thread src/openedx_authz/engine/schema/compilation.py
Comment thread src/openedx_authz/engine/schema/compilation.py
Comment thread src/openedx_authz/engine/schema/compilation.py Outdated
Comment thread src/openedx_authz/engine/schema/compilation.py Outdated
Comment thread src/openedx_authz/engine/schema/compilation.py Outdated
Comment thread src/openedx_authz/engine/schema/compilation.py Outdated
@rodmgwgu
rodmgwgu force-pushed the rod/authz-schema-compiler branch from 2c77167 to 3ed5882 Compare September 30, 2026 22:44
Base automatically changed from rod/authz-schema-loader-only to main October 2, 2026 17:01
@rodmgwgu
rodmgwgu force-pushed the rod/authz-schema-compiler branch from 3ed5882 to c2f7048 Compare October 2, 2026 17:01
@BryanttV BryanttV linked an issue Oct 2, 2026 that may be closed by this pull request
@rodmgwgu
rodmgwgu force-pushed the rod/authz-schema-compiler branch from d0df6c5 to 126c05e Compare October 5, 2026 19:09

@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.

LGTM! Thanks so much for addressing all of my comments :)

permission_changes_for_role["remove"].append((perm, document.priority, document.source))
return permission_changes

def _resolve_contributions(

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.

Suggested change
def _resolve_contributions(
def _resolve_contributions_based_on_priority(

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Applied, thanks!

Comment on lines +475 to +481
if action == "add":
extension_sources = [
RelationshipSource(src, SchemaOriginKind.EXTENSION, max_priority) for src in winning_sources
]
self._apply_added_permission(role_id, perm, current, provenance, extension_sources)
else: # remove
self._apply_removed_permission(role_id, perm, current, provenance)

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.

nit:

Suggested change
if action == "add":
extension_sources = [
RelationshipSource(src, SchemaOriginKind.EXTENSION, max_priority) for src in winning_sources
]
self._apply_added_permission(role_id, perm, current, provenance, extension_sources)
else: # remove
self._apply_removed_permission(role_id, perm, current, provenance)
match action:
case ACTION.ADD
case ACTION.REMOVE
...

I'd also change all references to the hardcoded "add" to ACTION.ADD and so on.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

changed, thanks

Comment on lines +458 to +462
actions: dict[str, list[tuple[str, int, SourceRecord]]] = {}
for perm, priority, src in permission_changes["add"]:
actions.setdefault(perm, []).append(("add", priority, src))
for perm, priority, src in permission_changes["remove"]:
actions.setdefault(perm, []).append(("remove", priority, src))

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.

Took me a while to understand this so thanks for the inline comment!

@rodmgwgu
rodmgwgu merged commit c5e1ea2 into main Oct 6, 2026
8 checks passed
@rodmgwgu
rodmgwgu deleted the rod/authz-schema-compiler branch October 6, 2026 21:18
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: Done

Development

Successfully merging this pull request may close these issues.

Core Loader, Compilation, and Definition Validation

5 participants