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(elasticache): Ensure Redis replication groups have automatic failover enabled #4853

Conversation

HugoPBrito
Copy link
Member

Context

A check was done to ensure ElastiCache (Redis OSS) replication groups have automatic failover enabled for high availability.

Description

I added a new check elasticache_redis_cluster_automatic_failover_enabled that ensures Elasticache Redis OSS cache clusters use automatic failover to maximize high availability and minimize downtime during failures.

Checklist

License

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

@HugoPBrito HugoPBrito requested review from a team as code owners August 23, 2024 10:35
@github-actions github-actions bot added the provider/aws Issues/PRs related with the AWS provider label Aug 23, 2024
Copy link

codecov bot commented Aug 23, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 88.93%. Comparing base (b7e2034) to head (7b62c9c).
Report is 1293 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4853      +/-   ##
==========================================
- Coverage   89.20%   88.93%   -0.28%     
==========================================
  Files         933      954      +21     
  Lines       28567    29256     +689     
==========================================
+ Hits        25483    26018     +535     
- Misses       3084     3238     +154     
Components Coverage Δ
prowler 88.93% <100.00%> (-0.28%) ⬇️
api ∅ <ø> (∅)

Comment on lines 182 to 183
auto_minor_version_upgrade: bool = False
automatic_failover: Optional[str] = None
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 setting a default value when creating the model inside the function.

Suggested change
auto_minor_version_upgrade: bool = False
automatic_failover: Optional[str] = None
auto_minor_version_upgrade: bool
automatic_failover: str

Copy link
Member Author

Choose a reason for hiding this comment

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

If I don't set the default value here, several tests for this and other checks will fail as a result. This occurs because when we mock them, the value is never assigned.

Should I leave it as it was, or should I update every mock instance across all checks?

@@ -106,6 +106,9 @@ def _describe_replication_groups(self, regional_client):
auto_minor_version_upgrade=repl_group.get(
"AutoMinorVersionUpgrade", False
),
automatic_failover=repl_group.get(
"AutomaticFailover", None
Copy link
Member

Choose a reason for hiding this comment

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

We always set the non-compliant value as the default.

Suggested change
"AutomaticFailover", None
"AutomaticFailover", "disabled"

@@ -192,4 +192,5 @@ def test_describe_replication_groups(self):
multi_az=REPLICATION_GROUP_MULTI_AZ,
tags=REPLICATION_GROUP_TAGS,
auto_minor_version_upgrade=AUTO_MINOR_VERSION_UPGRADE,
automatic_failover=None,
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
automatic_failover=None,
automatic_failover="disabled",

@@ -0,0 +1,32 @@
{
"Provider": "aws",
"CheckID": "elasticache_redis_cluster_automatic_failover_enabled",
Copy link
Member

Choose a reason for hiding this comment

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

I think we should now something more like: elasticache_replication_group_redis_has_automatic_failover

"SubServiceName": "",
"ResourceIdTemplate": "arn:partition:service:region:account-id:resource-id",
"Severity": "medium",
"ResourceType": "AWSElastiCacheClusters",
Copy link
Member

Choose a reason for hiding this comment

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

I think this ResourceType is not supported by AWS, please refer to the docs

report.resource_arn = repl_group.arn
report.resource_tags = repl_group.tags
report.status = "FAIL"
report.status_extended = f"Elasticache Redis cache cluster {repl_group.id} does not have automatic failover enabled."
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
report.status_extended = f"Elasticache Redis cache cluster {repl_group.id} does not have automatic failover enabled."
report.status_extended = f"ElastiCache Redis replication group {repl_group.id} does not have automatic failover enabled."

assert result[0].status == "PASS"
assert (
result[0].status_extended
== f"Elasticache Redis cache cluster {REPLICATION_GROUP_ID} does have automatic failover enabled."
Copy link
Member

Choose a reason for hiding this comment

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

Change this according to new changes in the checks

},
"Recommendation": {
"Text": "Enable automatic failover for ElastiCache (Redis OSS) clusters to ensure high availability and minimize downtime during failures.",
"Url": "https://docs.aws.amazon.com/AmazonElastiCache/latest/red-ug/Clusters.Modify.html#Clusters.Modify.CON"
Copy link
Member

Choose a reason for hiding this comment

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

I think this link is not working as expected, the tags at the end are not doing anything. And I cannot see the Automatic Failover recommendation. Please, review it.

puchy22
puchy22 previously approved these changes Sep 12, 2024
Copy link
Member

@puchy22 puchy22 left a comment

Choose a reason for hiding this comment

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

LGTM!

@MrCloudSec MrCloudSec merged commit cc8bc78 into master Sep 12, 2024
10 of 11 checks passed
@MrCloudSec MrCloudSec deleted the PRWLR-4508-elasti-cache-redis-oss-replication-groups-should-have-automatic-failover-enabled branch September 12, 2024 16:23
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.

3 participants