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

fix(rds): add ReadReplicaSourceDBInstanceIdentifier to db_instance #3912

Merged

Conversation

uridealo
Copy link
Contributor

@uridealo uridealo commented May 2, 2024

Context

We need a way not to generate findings for an RDS Instance replica since could be a read replica in PostgreSQL and Oracle and a read/write replica in MySQL and MariaDB.

Description

  • Get ReadReplicaSourceDBInstanceIdentifier in the RDS service for instances.
  • Create a new config parameter check_rds_instance_replicas set to False by default to skip those instances.

Including ReadReplicaSourceDBInstanceIdentifier helps skipping replica instances in rds_instance_backup_enabled

License

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

@uridealo uridealo requested review from a team May 2, 2024 11:32
@github-actions github-actions bot added the provider/aws Issues/PRs related with the AWS provider label May 2, 2024
@jfagoagas jfagoagas self-assigned this May 3, 2024
jfagoagas
jfagoagas previously approved these changes May 3, 2024
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.

That's great @uridealo! I think you are planning to use this in an upcoming check or maybe to improve/fix something, am I right?

@uridealo
Copy link
Contributor Author

uridealo commented May 3, 2024

@jfagoagas yes, i wrote a customized check on the basis of rds_instance_backup_enabled to skip replica instances.
What means the failing linter? Can i do something here? I can reproduce but don't know how to fix.

@jfagoagas
Copy link
Member

jfagoagas commented May 3, 2024

@jfagoagas yes, i wrote a customized check on the basis of rds_instance_backup_enabled to skip replica instances.

Are you planning to make a PR with that? Could be interesting to include a flag in the configuration to check that instances whether the value is set or not.

What means the failing linter? Can i do something here? I can reproduce but don't know how to fix.

I think you have to configure your local development environment following this guide in our documentation. You have to enable the pre-commit to run the formatters and linters.

@jfagoagas jfagoagas changed the title feat(aws_rds_service) add ReadReplicaSourceDBInstanceIdentifier to db… feat(aws_rds_service) add ReadReplicaSourceDBInstanceIdentifier to db_instance May 6, 2024
@jfagoagas jfagoagas changed the title feat(aws_rds_service) add ReadReplicaSourceDBInstanceIdentifier to db_instance feat(rds) add ReadReplicaSourceDBInstanceIdentifier to db_instance May 6, 2024
@uridealo
Copy link
Contributor Author

uridealo commented May 6, 2024

@jfagoagas i committed the customized check but not sure if its worth. Its very close to rds_instance_backup_enabled and would be better to have it as an option for this. But i don't know how to do so. Let me know what think about the check.

I followed the guide but i still don't understand the error message. Maybe i start from scratch.

@jfagoagas
Copy link
Member

@jfagoagas i committed the customized check but not sure if its worth. Its very close to rds_instance_backup_enabled and would be better to have it as an option for this. But i don't know how to do so. Let me know what think about the check.

I think it would be better to adjust that check, let me push some changes and I'll get back to you.

I followed the guide but i still don't understand the error message. Maybe i start from scratch.

@jfagoagas
Copy link
Member

Hi @uridealo, I've pushed a new version using the Prowler configuration file with a new check_rds_replicas value set to True by default. Please execute it agains your environment and let me know if that works, thanks!

@jfagoagas jfagoagas changed the title feat(rds) add ReadReplicaSourceDBInstanceIdentifier to db_instance feat(rds): add ReadReplicaSourceDBInstanceIdentifier to db_instance May 6, 2024
@jfagoagas jfagoagas requested a review from MrCloudSec May 6, 2024 12:25
Copy link

codecov bot commented May 6, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 86.40%. Comparing base (722554a) to head (9ee1b94).
Report is 34 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3912      +/-   ##
==========================================
+ Coverage   86.32%   86.40%   +0.08%     
==========================================
  Files         748      749       +1     
  Lines       23295    23389      +94     
==========================================
+ Hits        20110    20210     +100     
+ Misses       3185     3179       -6     

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

@MrCloudSec
Copy link
Member

@jfagoagas @uridealo why we have only done this for this check? It would be interesting to add this logic for the rest of RDS Instance checks.

@MrCloudSec MrCloudSec requested a review from jfagoagas May 6, 2024 16:14
@jfagoagas
Copy link
Member

@jfagoagas @uridealo why we have only done this for this check? It would be interesting to add this logic for the rest of RDS Instance checks.

I think for know we should apply this to the instance backups and then analyze if this can be included in other checks.

@uridealo
Copy link
Contributor Author

uridealo commented May 7, 2024

@jfagoagas i tested your changes. ImO the logic is weird. I only skip replicas when check_rds_replicas is NOT set in config. When leaving out "True" in rds_instance_backup_enabled.py:24 i can control the skipping via True/False in config. Do i see something wrong?

@jfagoagas
Copy link
Member

@jfagoagas i tested your changes. ImO the logic is weird. I only skip replicas when check_rds_replicas is NOT set in config. When leaving out "True" in rds_instance_backup_enabled.py:24 i can control the skipping via True/False in config. Do i see something wrong?

I don't get that. Currently the logic does the following:

if db_instance.replica_source and not rds_client.audit_config.get(
    "check_rds_replicas", True
):
    continue

So as you can see in the tests there are two possible scenarios:

  • check_rds_replicas == True -> If the DB instance is a replica the finding is added to the list of findings.
  • check_rds_replicas == False -> If the DB instance is a replica the finding is discarded.

Also by default we set that value to True since it is the current behaviour.

@uridealo
Copy link
Contributor Author

uridealo commented May 7, 2024

@jfagoagas yes i see your tests. i tested in real, but maybe its my bad. When you are sure you can merge. I am fine with this

MrCloudSec
MrCloudSec previously approved these changes May 8, 2024
@jfagoagas
Copy link
Member

jfagoagas commented May 8, 2024

Hi @uridealo we've made the decision to set the check_rds_instance_replicas by default to False so you don't need to do anything and your RDS instance replicas won't be included in the report.

MrCloudSec
MrCloudSec previously approved these changes May 8, 2024
@uridealo
Copy link
Contributor Author

uridealo commented May 8, 2024

@jfagoagas That sounds great. Thanks a lot for your help

@jfagoagas jfagoagas changed the title feat(rds): add ReadReplicaSourceDBInstanceIdentifier to db_instance fix(rds): add ReadReplicaSourceDBInstanceIdentifier to db_instance May 8, 2024
@jfagoagas jfagoagas merged commit 73b7d76 into prowler-cloud:master May 8, 2024
11 of 12 checks passed
@uridealo
Copy link
Contributor Author

uridealo commented May 13, 2024

@jfagoagas In which version will this be released? Also in v3?

pedrooot pushed a commit that referenced this pull request May 15, 2024
@jfagoagas
Copy link
Member

@jfagoagas In which version will this be released? Also in v3?

Hi @uridealo this will be included in the following v4.2.0 and v3.16.5. Thanks!

MrCloudSec pushed a commit that referenced this pull request May 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation provider/aws Issues/PRs related with the AWS provider
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants