Skip to content

Conversation

@jychp
Copy link
Collaborator

@jychp jychp commented Feb 3, 2026

Type of change

  • New feature (non-breaking change that adds functionality)

Summary

This PR introduces a Framework dataclass to link rules to compliance frameworks (CIS, NIST, etc.) with structured fields for filtering and querying.

Key changes:

  • Framework class: New dataclass with name, short_name, requirement, scope, and revision fields. All fields are normalized to lowercase for case-insensitive comparison.
  • Rule.frameworks: Rules can now declare compliance framework references via a frameworks tuple.
  • Rule.has_framework(): Method to check if a rule matches given framework criteria.
  • CLI enhancements:
    • --framework / -f filter option for list and run commands
    • New frameworks command to list all compliance frameworks
    • Auto-select all rules when --framework is provided without a rule argument
  • Runner functions: get_all_frameworks() and filter_rules_by_framework() for programmatic filtering.
  • RuleResult: Now exposes rule_tags and rule_frameworks for downstream consumers.
  • Migration: All existing CIS rules migrated to use Framework objects.

Example usage:

# List all CIS rules
cartography-rules list --framework CIS

# Run only CIS AWS 5.0 rules
cartography-rules run --framework CIS:aws:5.0

# List available frameworks
cartography-rules frameworks

How was this tested?

  • make test_unit - 483 tests passed
  • make test_lint - All checks passed
  • Manual CLI testing with --framework filter

Checklist

General

  • I have read the contributing guidelines.
  • The linter passes locally (make lint).
  • I have added/updated tests that prove my fix is effective or my feature works.

Proof of functionality

  • New or updated unit/integration tests.

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.

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>
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a 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.

jychp and others added 2 commits February 3, 2026 14:49
- 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>
Copy link
Collaborator

@kunaals kunaals left a 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
Copy link
Collaborator

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

Copy link
Collaborator Author

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.

jychp and others added 2 commits February 3, 2026 16:27
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>
@jychp jychp enabled auto-merge (squash) February 4, 2026 00:30
@jychp jychp merged commit b35042f into master Feb 4, 2026
8 checks passed
@jychp jychp deleted the jeremy/rich-tags-cartography-rules branch February 4, 2026 00:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants