Add new "evaluations" format support to Anchorectl parser #12425
Conversation
… array This commit updates the AnchoreCTL Policies parser to support both the legacy and new format reports generated by the AnchoreCTL tool. Changes: - Added detection for the new format which has an object with evaluations array instead of a root-level list - Implemented conversion logic to transform the new format into a compatible structure for parsing - Improved error handling with more descriptive messages - Made field extraction more robust with proper fallbacks between formats The parser now successfully processes both: - Legacy format (list at root level) - New format from anchorectl policy evaluate -o json (object with evaluations array)
|
This pull request reveals multiple security concerns, including potential information disclosure through verbose error handling, unsafe JSON parsing, root user permissions in Docker images, and two significant vulnerabilities (high and medium severity) in a test binary, which collectively suggest the need for improved security practices and vulnerability management. 💭 Unconfirmed Findings (5)
All finding details can be found in the DryRun Security Dashboard. |
|
Hello @cosmel-dojo, welcome to the team. Does this PR fix #12362? I think it does, but the example report in there contains a little bit more date than the samples in this PR. |
I used the sample file the user attached, to apply the solution. The tests I added are using the new format that the AnchoreCTL uses. |
|
@cosmel-dojo Would it make sense to one or two lines to |
I updated the Anchorectl Policies. |
…#12425) * Fix AnchoreCTL Policies parser to support new format with evaluations array This commit updates the AnchoreCTL Policies parser to support both the legacy and new format reports generated by the AnchoreCTL tool. Changes: - Added detection for the new format which has an object with evaluations array instead of a root-level list - Implemented conversion logic to transform the new format into a compatible structure for parsing - Improved error handling with more descriptive messages - Made field extraction more robust with proper fallbacks between formats The parser now successfully processes both: - Legacy format (list at root level) - New format from anchorectl policy evaluate -o json (object with evaluations array) * Added tests for the new format to verify correct parsing * Fixed linter errors * Update AnchoreCTL Policies Report documentation for clarity and format support * Removed unnecessary text from anchorectl_policies
Description
This PR fixes the AnchoreCTL Policies Report parser to support both legacy and new formats generated by the AnchoreCTL tool. Users reported issues importing newer format policy reports from AnchoreCTL with the
-o jsonflag, as the parser expected a list at the root level, but new format has an object with anevaluationsarray.The changes:
Test results
Extended the test suite by adding 4 new test cases that specifically target the new format:
test_new_format_anchore_engine_parser_has_no_findingtest_new_format_anchore_engine_parser_has_one_finding_and_it_is_correctly_parsedtest_new_format_anchore_engine_parser_has_many_findingstest_new_format_anchore_engine_parser_has_one_finding_and_description_has_severityAll tests pass successfully, verifying that both the legacy and new formats are properly supported.
Commands to run tests locally:
Documentation
No documentation update needed as the parser description already mentions both formats are supported.
Checklist
dev.dev.bugfixbranch.