Repository navigation
feat: add authz schema validation - #477
Conversation
|
Thanks for the pull request, @rodmgwgu! This repository is currently maintained by 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 approvalIf you haven't already, check this list to see if your contribution needs to go through the product review process.
🔘 Provide contextTo 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:
🔘 Get a green buildIf one or more checks are failing, continue working on your changes until this is no longer the case and your build turns green. DetailsWhere 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:
💡 As a result it may take up to several weeks or months to complete a review and merge your PR. |
8eb558d to
3e3f69a
Compare
7039856 to
7828722
Compare
7828722 to
ad046ff
Compare
| return issues | ||
|
|
||
| @staticmethod | ||
| def _register(index: dict, key: str, value, kind: str, sid: str) -> list[ValidationIssue]: |
There was a problem hiding this comment.
We're passing several of these structures around by reference and modifying them directly. Could some of this state live on the SchemaValidator instance instead? Maybe issues as well.
My thought process is that documents and the indexes we build from them are used across multiple validation steps, and right now we pass them through several methods and mutate them along the way. I wonder if keeping the state for a validation run on the validator instance would make it a bit easier to manage and reduce the amount of arguments we need to pass around.
Just a thought though, I'm not completely sure how it would look in practice.
There was a problem hiding this comment.
I did some exploring and one issue of making the state live in SchemaValidator is that it would break the pattern that is already being used on all the other modules (they are stateless).
One potential alternative would be to define an internal dataclass that holds all the "state" and we only pass that everywhere.
What do you think, would this be worth a try?
There was a problem hiding this comment.
I think this is more about the pros and cons of keeping it stateless, as it is now, versus making it stateful by instantiating it or making it part of the class. If this is a deliberate design decision, I think it would be useful to define it as such.
84ff71c to
24fd7ca
Compare
5ff8614 to
673e099
Compare
673e099 to
8c74869
Compare
ede9d29 to
20ceb15
Compare
mariajgrimaldi
left a comment
There was a problem hiding this comment.
This looks good to me! Thanks so much for addressing my comments and for explaining the decisions behind it as well. I think the main thing left is documenting those deliberate decisions somewhere so we have a clearer picture of the overall architecture and the reasoning behind it.
Thanks so much :)
| return [] | ||
| if index[key] == value: | ||
| return [ValidationIssue(IssueLevel.WARNING, f"Duplicate identical {kind} {key!r}.", sid)] | ||
| return [ValidationIssue(IssueLevel.ERROR, f"Conflicting {kind} definition for {key!r}.", sid)] |
There was a problem hiding this comment.
[question] How should priority apply to conflicting base definitions? This is not specified in the ADRs or schema reference.
I tested two files defining the same category, permission, and role with different metadata. One had priority 100 and the other priority 200. The command rejected all three definitions:
Conflicting category definition for 'acceptance_category'.
Conflicting permission definition for 'acceptance.view'.
Conflicting role definition for 'acceptance_editor'.
Schema validation failed with 3 error(s).
The compiler behavior and its test expect the priority 200 definitions to win, but the full command rejects them before that happens. Could we decide which behavior we want and make it consistent?
There was a problem hiding this comment.
Good catch, I see that the ADR 0017 specifies: Priority resolves conflicts between role extensions; it does not apply to individual permissions or control how roles or permissions appear in the UI.
So the current overall behavior would be consistent with that.
Do you see any use case where we may want to support priority on base definitions? if so, we could define it and change it to work as that, or just remove the priority logic for those in the compiler.
20ceb15 to
a6a6c0e
Compare
a6a6c0e to
50e9493
Compare
Problem
An invalid schema must stop a deployment before anything is written, and it must report every problem at once rather than failing on the first one — a deployment operator fixing schema files one error per run is the failure mode to avoid (ADR 0018 §1).
Approach
PLEASE NOTE: jsonschema-based validation hasn't been implemented at this point, this means that some cases like validation of required priority and other fields are not complete. The implementation of the jsonschema validation will cover these, that is tracked by this issue: #459
openedx_authz/engine/schema/validation.py—SchemaValidator,ValidationIssueopenedx_authz/tests/schema/test_validation.pyTwo entry points, matching the two things that can only be checked at different stages:
validate()covers each document and the document set (identifier shape, required fields, duplicates), andvalidate_compiled()covers the rules only a resolved schema can answer (a role referencing a permission that does not exist, a permission in an unknown category). Issues are collected and returned with their source, so a caller can report all of them;SchemaValidationErrorcarries the full list.Manual testing instructions
Rollback plan
Revert this PR. Nothing consumes the validator 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 (4/8) — #446 split into reviewable pieces. Bases chain bottom-up; merge in order.
rod/authz-schema-compiler)rod/authz-schema-models— definition models + migrationrod/authz-schema-renderer— policy rendererrod/authz-schema-applier— schema applierload_authz_schemacommand, version bump and changelogMerge checklist:
authz-schema-v1.jsonis tracked separately in Extend schema loader validation to use schema reference defined in #431 #459