-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
chore(aws): Add failed_checks to track #4018
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #4018 +/- ##
==========================================
+ Coverage 86.27% 86.28% +0.01%
==========================================
Files 783 783
Lines 24562 24599 +37
==========================================
+ Hits 21190 21226 +36
- Misses 3372 3373 +1 ☔ View full report in Codecov by Sentry. |
Hi @kagahd I like your idea but we are not sure about including it at this time since we want to create an execution manager in top of Prowler's scan. Maybe it'll be easier for now to save something within the EC2 service, what do you think? |
Hi @jfagoagas,
I preferred a separation of concerns by using the |
…d and region of the failed check
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.
Could you add a test for each check while checking that ec2_client.is_failed_check()
returns true, thus no findings will be generated?
The work is this PR is neat 💯
Sure, I will add them later today. |
It's done. |
…because all ports are already open
…ed to avoid reported twice because all ports are already open
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.
@kagahd I left some comments about the tests and a tiny detail in the service logic, please let me know if you need help. Thanks!
..._from_internet_to_any_port/ec2_securitygroup_allow_ingress_from_internet_to_any_port_test.py
Show resolved
Hide resolved
...gress_from_internet_to_any_port/ec2_securitygroup_allow_ingress_from_internet_to_any_port.py
Outdated
Show resolved
Hide resolved
...rom_internet_to_all_ports/ec2_securitygroup_allow_ingress_from_internet_to_all_ports_test.py
Outdated
Show resolved
Hide resolved
..._from_internet_to_any_port/ec2_securitygroup_allow_ingress_from_internet_to_any_port_test.py
Outdated
Show resolved
Hide resolved
check_all_ports = ( | ||
ec2_securitygroup_allow_ingress_from_internet_to_all_ports() | ||
) | ||
result_all_ports = check_all_ports.execute() | ||
|
||
# Verify that the all ports check has detected the issue | ||
assert any( | ||
sg.status == "FAIL" and sg.resource_id == default_sg_id | ||
for sg in result_all_ports | ||
) |
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.
Maybe is easier just to call AWSService.set_failed_check
and then run the ec2_securitygroup_allow_ingress_from_internet_to_any_port
and verify that the finding's status extended is the new one.
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 comment applies to all the tests.
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.
Maybe is easier just to call
AWSService.set_failed_check
and then run theec2_securitygroup_allow_ingress_from_internet_to_any_port
and verify that the finding's status extended is the new one.
Yes, sure, it would be easier but it's cheating because it would not reflect the exact way how the values are set/get in real life by the app.
To be consistent, we need to first execute the check ec2_securitygroup_allow_ingress_from_internet_to_all_ports
by checking an open security group to all ports. And after that, we have to verify that a specific port check such as ec2_securitygroup_allow_ingress_from_internet_to_any_port
is in status PASS
, only because the previous run check ec2_securitygroup_allow_ingress_from_internet_to_all_ports
is in status FAIL
, in order to avoid to report the specific open ports twice.
You need to do it this way to respect and verify by unit tests the call chain of the app.
Hi @jfagoagas
And these 2 failing unit tests are not from me. I didn't touch them. |
I think your forked repo wasn't up to date with Prowler's |
Hi @jfagoagas, the github workflow failed again with the same errors. Do you have another idea what the reason could be? In line 155 it says
What's wrong with it? |
Yesterday we merged a PR which changes the location of the |
That makes sense, thanks a bunch! |
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.
Thanks for this super improvement again @kagahd 👏
It's been a pleasure to work with you and review a PR with such a great level of quality 🚀
result = check.execute() | ||
|
||
# Verify set_failed_check was called with the correct arguments | ||
mock_set_failed_check.assert_called_with( |
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.
Pretty smart 💯
I have just one question left because I'm not sure, what was the previous behaviour when running an specific port check with the |
Exactly, you were not raising a finding, the status was "PASS". |
Thanks for confirming that, maybe we can remove that |
Co-authored-by: Pepe Fagoaga <[email protected]>
Context
This PR makes the AWS ec2 service and around around 15 prowler checks, that verify whether ports are open to the Internet, more concise. This PR relates to PR #3977 and PR #3979.
Description
I find it more concise to introduce a
state_manager
instead to share with a dozen of other checks a specific propertypublic_ports
of a specific checkec2_securitygroup_allow_ingress_from_internet_to_all_ports
within theec2_service
.I find the the code now clearer, cleaner, easier to extend and easier to maintain. It also saves some CPU cycles because the method
check_security_group
in theec2_service
does not need to be called for each check anymore.License
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.