Skip to content
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

feat(arm): arm custom policy support #6769

Merged
merged 28 commits into from
Oct 28, 2024
Merged

Conversation

omriyoffe-panw
Copy link
Contributor

@omriyoffe-panw omriyoffe-panw commented Oct 13, 2024

User description

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

Description

Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change.

Fixes # (issue)

New/Edited policies (Delete if not relevant)

Description

Include a description of what makes it a violation and any relevant external links.

Fix

How does someone fix the issue in code and/or in runtime?

Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added tests that prove my feature, policy, or fix is effective and works
  • New and existing tests pass locally with my changes

Generated description

Dear maintainer, below is a concise technical summary of the changes proposed in this PR:

Introduce support for custom ARM policies by enhancing the ARM graph builder and integrating it with the custom policies framework. The ArmLocalGraph class is updated to handle both explicit and implicit dependencies, improving the graph's accuracy. New utility functions extract_resource_name_from_resource_id_func and extract_resource_name_from_reference_func are added to facilitate resource name extraction. The CustomPoliciesIntegration class now includes ARM in its supported frameworks, allowing custom ARM policies to be registered and validated.

TopicDetails
Utility Functions Add utility functions to extract resource names from ARM resource IDs and references, aiding in dependency resolution.
Modified files (2)
  • tests/arm/test_utils.py
  • checkov/arm/utils.py
Latest Contributors(1)
EmailCommitDate
[email protected]fix-arm-correctly-hand...August 30, 2023
Custom ARM Policies Implement support for custom ARM policies by integrating ARM into the custom policies framework.
Modified files (3)
  • checkov/common/bridgecrew/integration_features/features/custom_policies_integration.py
  • tests/common/integration_features/test_custom_policies_integration.py
  • checkov/common/checks_infra/registry.py
Latest Contributors(2)
EmailCommitDate
iifrach@paloaltonetwor...feat-general-Support-m...August 18, 2024
123508988+taviassaf@us...feat-general-support-m...August 05, 2024
ARM Graph Enhancements Enhance the ARM graph builder to support explicit and implicit dependencies, improving the accuracy of the graph representation.
Modified files (4)
  • checkov/arm/graph_builder/context_definitions.py
  • tests/arm/graph_builder/test_local_graph.py
  • checkov/arm/graph_builder/local_graph.py
  • checkov/arm/graph_builder/graph_to_definitions.py
Latest Contributors(2)
EmailCommitDate
49649760+lirshindalman...feat-arm-add-variable-...October 22, 2024
[email protected]fix-arm-correctly-hand...August 30, 2023
Testing Enhancements Add test cases to validate the new ARM graph building capabilities and custom policy integration.
Modified files (7)
  • tests/arm/examples/ImplicitDepsResources/storage.json
  • tests/arm/examples/ImplicitDepsResources/interface.json
  • tests/arm/examples/ExplicitDepsResources/storage.json
  • tests/arm/rendering/test_rendering.py
  • tests/arm/examples/ExplicitDepsResources/interface.json
  • tests/arm/examples/ExplicitDepsResources/subnet.json
  • tests/arm/examples/ImplicitDepsResources/subnet.json
Latest Contributors(1)
EmailCommitDate
49649760+lirshindalman...feat-arm-add-variable-...October 22, 2024
This pull request is reviewed by Baz. Join @omriyoffe-panw and the rest of your team on (Baz).

@omriyoffe-panw omriyoffe-panw marked this pull request as ready for review October 22, 2024 11:54
@@ -29,12 +29,14 @@ def build_graph(self, render_variables: bool = False) -> None:
self._create_vertices()
logging.debug(f"[ArmLocalGraph] created {len(self.vertices)} vertices")

self._create_edges()
logging.debug(f"[ArmLocalGraph] created {len(self.edges)} edges")
self._create_vars_and_parameters_edges()
Copy link
Contributor

Choose a reason for hiding this comment

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

shouldn't this be a part of the create_edges function from line 37?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, but the variable rendering needs to happen before the creation of the edges since some of the dependencies names can be brought from variables or parameters

Copy link
Contributor

@bo156 bo156 Oct 28, 2024

Choose a reason for hiding this comment

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

doesn't it work the other way around as well? meaning you might be missing variables to render if you didn't compute all edges first?

In terraform the order is "vertices->edges->render-vars", but I'm not sure this should also apply here, just to understand this is the correct order.

Also - if it is here specifically for that, it should probably be documented in the code as well that this part should be before variable renedering. Perhaps in the name of the function as well, as it's confusing that you have a specific case of create edges which should not run as part of the general create_edges function

checkov/arm/graph_builder/local_graph.py Outdated Show resolved Hide resolved
checkov/arm/graph_builder/local_graph.py Outdated Show resolved Hide resolved
checkov/arm/graph_builder/local_graph.py Outdated Show resolved Hide resolved
checkov/arm/graph_builder/local_graph.py Outdated Show resolved Hide resolved
checkov/arm/graph_builder/local_graph.py Outdated Show resolved Hide resolved
checkov/arm/utils.py Show resolved Hide resolved
@omriyoffe-panw omriyoffe-panw merged commit 7713e73 into main Oct 28, 2024
33 of 39 checks passed
@omriyoffe-panw omriyoffe-panw deleted the arm-custom-policy-support branch October 28, 2024 12:55
Ali-Razmjoo pushed a commit to fork-the-planet/checkov that referenced this pull request Oct 29, 2024
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.

3 participants