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(sns): sns topics no http subscriptions #4095

Merged
merged 7 commits into from
May 28, 2024

Conversation

Davidm4r
Copy link
Contributor

@Davidm4r Davidm4r commented May 27, 2024

Context

Create a new check for the SNS service in the provider AWS

  • sns_subscription_not_using_http_endpoints

Description

This change ensures that AWS SNS topics are not subscribed to HTTP endpoints

Add a new type of Object for SNS, the Subscription.

License

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

@Davidm4r Davidm4r requested review from a team May 27, 2024 18:22
@github-actions github-actions bot added the provider/aws Issues/PRs related with the AWS provider label May 27, 2024
Comment on lines 10 to 11
if subscription.SubscriptionArn == "PendingConfirmation":
continue
Copy link
Member

Choose a reason for hiding this comment

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

You are already checking this in the service, right?

Copy link
Contributor Author

@Davidm4r Davidm4r May 28, 2024

Choose a reason for hiding this comment

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

I've moved the PendingConfirmation logic to the check. I believe that all subscriptions, including those that are pending, should be included in the object. It should be up to the check to decide if it wants to do something with those types of subscriptions.

Copy link
Member

Choose a reason for hiding this comment

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

Great idea!

Comment on lines 105 to 109
SubscriptionArn: str
Owner: str
Protocol: str
Endpoint: str
TopicArn: str
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
SubscriptionArn: str
Owner: str
Protocol: str
Endpoint: str
TopicArn: str
arn: str
owner: str
protocol: str
endpoint: str

Copy link
Member

Choose a reason for hiding this comment

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

Please, use the pattern that we have for the rest of the classes and you don't need the TopicArn since it is already attached to a Topic class.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good suggestion. Fixed!

@@ -74,6 +75,39 @@ def __list_tags_for_resource__(self):
f"{regional_client.region} -- {error.__class__.__name__}[{error.__traceback__.tb_lineno}]: {error}"
)

def __get_subscriptions__(self):
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
def __get_subscriptions__(self):
def __list_subscriptions_by_topic__(self):

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed!

@@ -74,6 +75,39 @@ def __list_tags_for_resource__(self):
f"{regional_client.region} -- {error.__class__.__name__}[{error.__traceback__.tb_lineno}]: {error}"
)

def __get_subscriptions__(self):
logger.info("SNS - Getting subscriptions...")
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
logger.info("SNS - Getting subscriptions...")
logger.info("SNS - Listing subscriptions by topic...")

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed!

Copy link
Member

@sergargar sergargar left a comment

Choose a reason for hiding this comment

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

Thanks for the check @Davidm4r ! Please, review my comments.

Copy link
Member

@jfagoagas jfagoagas left a comment

Choose a reason for hiding this comment

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

Thanks for the check @Davidm4r, I also left some comments regarding to the resource checked.

Comment on lines 14 to 16
report.resource_id = topic.name
report.resource_arn = topic.arn
report.resource_tags = topic.tags
Copy link
Member

Choose a reason for hiding this comment

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

What is the resource checked within the check? If it is the subscription, we need to modify the check name to something like sns_subscriptions_not_using_http_endpoints or similar and set the subscription as resource_id and resource_arn.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I put the subscription.arn as resource_id and resource_arn

report.resource_tags = topic.tags
report.status = "PASS"
report.status_extended = (
f"Subscription {subscription.SubscriptionArn} is HTTPS."
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
f"Subscription {subscription.SubscriptionArn} is HTTPS."
f"Subscription {subscription.SubscriptionArn} is using an HTTPS endpoint."

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed!

if subscription.Protocol == "http":
report.status = "FAIL"
report.status_extended = (
f"Subscription {subscription.SubscriptionArn} is HTTP."
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
f"Subscription {subscription.SubscriptionArn} is HTTP."
f"Subscription {subscription.SubscriptionArn} is using an HTTP endpoint."

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed!

@jfagoagas
Copy link
Member

Forgot to say that we need to update service's test with the new function.

Copy link

codecov bot commented May 28, 2024

Codecov Report

Attention: Patch coverage is 90.69767% with 4 lines in your changes are missing coverage. Please review.

Project coverage is 86.31%. Comparing base (d51fd0e) to head (2ee387b).
Report is 15 commits behind head on master.

Files Patch % Lines
prowler/providers/aws/services/sns/sns_service.py 80.95% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4095      +/-   ##
==========================================
- Coverage   86.39%   86.31%   -0.09%     
==========================================
  Files         794      795       +1     
  Lines       24874    24917      +43     
==========================================
+ Hits        21491    21508      +17     
- Misses       3383     3409      +26     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Davidm4r
Copy link
Contributor Author

Forgot to say that we need to update service's test with the new function.

I created a new test for the service.

@Davidm4r
Copy link
Contributor Author

@sergargar @jfagoagas I have reviewed all your comments. Can you check it again?

Copy link
Member

@jfagoagas jfagoagas left a comment

Choose a reason for hiding this comment

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

🔝

@sergargar sergargar merged commit 98b7df6 into prowler-cloud:master May 28, 2024
10 of 11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
provider/aws Issues/PRs related with the AWS provider
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants