Skip to content

feat: add authz schema definition models - #478

Open
rodmgwgu wants to merge 1 commit into
rod/authz-schema-validatorfrom
rod/authz-schema-models
Open

rodmgwgu wants to merge 1 commit into
rod/authz-schema-validatorfrom
rod/authz-schema-models

Conversation

@rodmgwgu

Copy link
Copy Markdown
Contributor

Problem

Compiled definitions and their provenance need first-class tables. Casbin p rows alone cannot answer which distribution contributed a role, whether a contribution was a base definition or an extension, or which rows the schema loader owns — and ownership is what makes later pruning safe instead of guesswork (ADR 0025).

Approach

  • openedx_authz/models/schema.py — definition tables (permission categories, permission definitions, role definitions, role-permission grants) and provenance tables (schema sources plus one source-link table per definition kind)
  • openedx_authz/migrations/0011_authz_schema_definitions.py — additive migration
  • openedx_authz/models/__init__.py — export the new module

Source attribution is recorded at the role-permission grain, so contributions from different applications to the same role stay distinguishable. The query helpers (origins_for_role, origins_for_permission, origins_for_category, origin_for_role_permission) land with the models.

Nothing writes to these tables in this PR — the applier does, in 7/8.

Manual testing instructions

pytest openedx_authz/tests/

Confirm the migration is complete and applies cleanly:

./manage.py makemigrations --check --dry-run openedx_authz   # No changes detected
tutor dev run cms ./manage.py cms migrate openedx_authz

Rollback plan

Revert this PR and run the reverse migration if it was applied. The migration is purely additive — it creates new tables and alters none — so a revert cannot affect existing data.

Retro compatibility

No authorization behavior changes. The tables are created empty and nothing reads or writes them until the applier lands.

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 (5/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. This PR — definition models + migration (base: rod/authz-schema-validator)
  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

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 validation #477; contains a DB migration (0011, additive). If another 0011 lands on main first this needs renumbering

@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-models branch 5 times, most recently from 71278c7 to e3d19f1 Compare September 24, 2026 23:01
@rodmgwgu
rodmgwgu force-pushed the rod/authz-schema-models branch 2 times, most recently from ba61be7 to a7ba6ac 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-models branch from a7ba6ac to 16e9cc8 Compare September 30, 2026 22:54

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

A few comments for you to review! This will probably will need to be updated according the changes down the stack, mainly the model fields.

Comment on lines +21 to +36
__all__ = [
"OriginKind",
"AuthzSchemaSource",
"AuthzPermissionCategory",
"AuthzPermissionDefinition",
"AuthzRoleDefinition",
"AuthzRolePermission",
"AuthzCategorySource",
"AuthzPermissionSource",
"AuthzRoleSource",
"AuthzRolePermissionSource",
"origins_for_role",
"origins_for_permission",
"origins_for_category",
"origin_for_role_permission",
]

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: I think it's nice we document we try to prefix all models with authz for easier identification?

Comment on lines +78 to +79
content_digest = models.CharField(max_length=64, blank=True, default="")
schema_version = models.CharField(max_length=16, blank=True, default="")

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.

Is it okay to allow this to be empty? Just making sure.

Comment on lines +110 to +111
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)

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.

Maybe we can create an abstract model for managing these timestamps

# ---------------------------------------------------------------------------


def origins_for_role(role_id: str) -> list[str]:

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.

Would this (and below) be better implemented as managers?



class AuthzRolePermission(models.Model):
"""A single role-permission-scope grant (one per rendered Casbin ``p`` row).

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: I wouldn't call this a grant, since technically it doesn't grant any permission. This adds semantic meaning to each Casbin row, but the actual permission attribution is still managed by Casbin. It might be a bit misleading as is.

@BryanttV BryanttV linked an issue Oct 2, 2026 that may be closed by this pull request
@rodmgwgu
rodmgwgu force-pushed the rod/authz-schema-models branch from 6b463f9 to 6a26f70 Compare October 2, 2026 23:13
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.

Core Loader, Compilation, and Definition Validation

5 participants