-
Notifications
You must be signed in to change notification settings - Fork 487
feat(rules): Add Framework object for structured compliance metadata #2335
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Introduce a Framework dataclass to link rules to compliance frameworks (CIS, NIST, etc.) with structured fields for filtering and querying. - Add Framework class with case-insensitive matching (name, short_name, requirement, scope, revision) - Add Rule.frameworks tuple and Rule.has_framework() method - Add CLI --framework filter option (e.g., --framework CIS:aws:5.0) - Add 'frameworks' command to list all compliance frameworks - Add filter_rules_by_framework() and get_all_frameworks() in runners - Expose rule_tags and rule_frameworks in RuleResult - Migrate all CIS rules to use Framework objects - Auto-select all rules when --framework is provided without rule arg Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> Signed-off-by: Jeremy Chapeau <jeremy@subimage.io>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
3 issues found across 13 files
Prompt for AI agents (all issues)
Check if these issues are valid — if so, understand the root cause of each and fix them.
<file name="cartography/rules/data/rules/cis_aws_networking.py">
<violation number="1" location="cartography/rules/data/rules/cis_aws_networking.py:107">
P2: The `cis:aws-5.0` tag was removed from this rule, but no `Framework` object was added to replace it. Since `unrestricted_all_ports` explicitly references `CIS_REFERENCES`, it implies this rule is part of the CIS benchmark (or at least related).
If this rule is part of the framework, it must be migrated to use the `Framework` object (like the other rules in this file) to be discoverable via the new `--framework` CLI filter. If it is *not* part of the framework, consider removing `CIS_REFERENCES` to avoid confusion.</violation>
</file>
<file name="tests/unit/rules/test_runners.py">
<violation number="1" location="tests/unit/rules/test_runners.py:46">
P2: The tests update `mock_rule` with `tags` and `frameworks`, but do not verify that these values are correctly propagated to the `RuleResult`.
(Based on your team's feedback about ensuring tests exercise the change they claim to validate.) [FEEDBACK_USED]</violation>
</file>
<file name="cartography/rules/data/rules/cis_google_workspace.py">
<violation number="1" location="cartography/rules/data/rules/cis_google_workspace.py:96">
P2: The scope 'google_workspace' is inconsistent with the standard module identifier 'googleworkspace' used in `Module.GOOGLEWORKSPACE`, previous tags (e.g., `cis:googleworkspace-1.4`), and the internal `MODULE_TO_CARTOGRAPHY_INTEL` mapping.
Using the standard identifier 'googleworkspace' ensures consistency across CLI filters, internal metadata, and potential downstream consumers.
(Note: Tests asserting this scope string may also need updates.)</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
- Fix scope inconsistency: change 'google_workspace' to 'googleworkspace' to match Module.GOOGLEWORKSPACE identifier - Add tests to verify tags and frameworks are correctly propagated to RuleResult Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> Signed-off-by: Jeremy Chapeau <jeremy@subimage.io>
Signed-off-by: Jeremy Chapeau <jeremy@subimage.io>
kunaals
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this seems great! one small nit: might be good to add details about Frameworks in the create-rule.md doc
| """ | ||
| List all compliance frameworks referenced by rules. | ||
|
|
||
| \b |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think extra character got left behind
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
\b is the Typer/Click literal block marker.
Add documentation for the new Framework dataclass that provides structured compliance metadata for rules. Updates include: - New "Compliance Frameworks" section explaining the Framework object - CLI filtering examples with --framework option - Updated CIS conventions to use Framework instead of cis:* tags - Added Framework to Essential Imports - Updated complete CIS example with Framework usage Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> Signed-off-by: Jeremy Chapeau <jeremy@subimage.io>
Type of change
Summary
This PR introduces a
Frameworkdataclass to link rules to compliance frameworks (CIS, NIST, etc.) with structured fields for filtering and querying.Key changes:
name,short_name,requirement,scope, andrevisionfields. All fields are normalized to lowercase for case-insensitive comparison.frameworkstuple.--framework/-ffilter option forlistandruncommandsframeworkscommand to list all compliance frameworks--frameworkis provided without a rule argumentget_all_frameworks()andfilter_rules_by_framework()for programmatic filtering.rule_tagsandrule_frameworksfor downstream consumers.Example usage:
How was this tested?
make test_unit- 483 tests passedmake test_lint- All checks passed--frameworkfilterChecklist
General
make lint).Proof of functionality
Notes for reviewers
This 'tag' approach for linking to a Framework was chosen (rather than the old composition system where a rule only existed for one framework) to offer maximum flexibility and reusability.
This design follows the existing pattern in the codebase and enables downstream systems like SubImage to build rule collections based on compliance frameworks.