Compare commits

...

1 Commits
v5.2 ... 4.5.0

Author SHA1 Message Date
Sergio Garcia
d84d0e7693 chore(backport): master changes to v4.5 branch (#5641)
Co-authored-by: sansns-aws <107269923+sansns@users.noreply.github.com>
Co-authored-by: Pepe Fagoaga <pepe@prowler.com>
2024-11-05 14:13:11 -05:00
20 changed files with 535 additions and 16 deletions

View File

@@ -63,9 +63,9 @@ It contains hundreds of controls covering CIS, NIST 800, NIST CSF, CISA, RBI, Fe
| Provider | Checks | Services | [Compliance Frameworks](https://docs.prowler.com/projects/prowler-open-source/en/latest/tutorials/compliance/) | [Categories](https://docs.prowler.com/projects/prowler-open-source/en/latest/tutorials/misc/#categories) |
|---|---|---|---|---|
| AWS | 457 | 67 -> `prowler aws --list-services` | 30 -> `prowler aws --list-compliance` | 9 -> `prowler aws --list-categories` |
| AWS | 553 | 77 -> `prowler aws --list-services` | 30 -> `prowler aws --list-compliance` | 9 -> `prowler aws --list-categories` |
| GCP | 77 | 13 -> `prowler gcp --list-services` | 2 -> `prowler gcp --list-compliance` | 2 -> `prowler gcp --list-categories`|
| Azure | 136 | 17 -> `prowler azure --list-services` | 3 -> `prowler azure --list-compliance` | 2 -> `prowler azure --list-categories` |
| Azure | 138 | 17 -> `prowler azure --list-services` | 3 -> `prowler azure --list-compliance` | 2 -> `prowler azure --list-categories` |
| Kubernetes | 83 | 7 -> `prowler kubernetes --list-services` | 1 -> `prowler kubernetes --list-compliance` | 7 -> `prowler kubernetes --list-categories` |
# 💻 Installation

View File

@@ -1262,7 +1262,9 @@ class AwsProvider(Provider):
logger.critical(
f"{error.__class__.__name__}[{error.__traceback__.tb_lineno}]: {error}"
)
raise error
if raise_on_exception:
raise error
return Connection(error=error)
@staticmethod
def create_sts_session(

View File

@@ -23,7 +23,9 @@
"Url": "https://docs.aws.amazon.com/autoscaling/ec2/userguide/as-add-availability-zone.html"
}
},
"Categories": [],
"Categories": [
"redundancy"
],
"DependsOn": [],
"RelatedTo": [],
"Notes": ""

View File

@@ -23,7 +23,9 @@
"Url": "https://www.trendmicro.com/cloudoneconformity-staging/knowledge-base/aws/DMS/multi-az.html#"
}
},
"Categories": [],
"Categories": [
"redundancy"
],
"DependsOn": [],
"RelatedTo": [],
"Notes": ""

View File

@@ -23,7 +23,9 @@
"Url": "https://redis.io/blog/highly-available-in-memory-cloud-datastores/"
}
},
"Categories": [],
"Categories": [
"redundancy"
],
"DependsOn": [],
"RelatedTo": [],
"Notes": ""

View File

@@ -23,7 +23,9 @@
"Url": "https://www.trendmicro.com/cloudoneconformity-staging/knowledge-base/aws/ElastiCache/elasticache-multi-az.html#"
}
},
"Categories": [],
"Categories": [
"redundancy"
],
"DependsOn": [],
"RelatedTo": [],
"Notes": ""

View File

@@ -23,7 +23,9 @@
"Url": "https://docs.aws.amazon.com/elasticloadbalancing/latest/classic/enable-disable-crosszone-lb.html"
}
},
"Categories": [],
"Categories": [
"redundancy"
],
"DependsOn": [],
"RelatedTo": [],
"Notes": ""

View File

@@ -23,7 +23,9 @@
"Url": "https://docs.aws.amazon.com/elasticloadbalancing/latest/application/load-balancer-subnets.html"
}
},
"Categories": [],
"Categories": [
"redundancy"
],
"DependsOn": [],
"RelatedTo": [],
"Notes": ""

View File

@@ -25,7 +25,9 @@
"Url": "https://docs.aws.amazon.com/amazon-mq/latest/developer-guide/rabbitmq-broker-architecture.html#rabbitmq-broker-architecture-cluster"
}
},
"Categories": [],
"Categories": [
"redundancy"
],
"DependsOn": [],
"RelatedTo": [],
"Notes": ""

View File

@@ -23,7 +23,9 @@
"Url": "https://docs.aws.amazon.com/securityhub/latest/userguide/neptune-controls.html#neptune-9"
}
},
"Categories": [],
"Categories": [
"redundancy"
],
"DependsOn": [],
"RelatedTo": [],
"Notes": ""

View File

@@ -25,7 +25,9 @@
"Url": "https://aws.amazon.com/es/blogs/networking-and-content-delivery/deployment-models-for-aws-network-firewall/"
}
},
"Categories": [],
"Categories": [
"redundancy"
],
"DependsOn": [],
"RelatedTo": [],
"Notes": ""

View File

@@ -23,7 +23,9 @@
"Url": "https://aws.amazon.com/rds/features/multi-az/"
}
},
"Categories": [],
"Categories": [
"redundancy"
],
"DependsOn": [],
"RelatedTo": [],
"Notes": ""

View File

@@ -0,0 +1,32 @@
{
"Provider": "aws",
"CheckID": "rds_cluster_protected_by_backup_plan",
"CheckTitle": "Check if RDS clusters are protected by a backup plan.",
"CheckType": [
"Software and Configuration Checks, AWS Security Best Practices"
],
"ServiceName": "rds",
"SubServiceName": "",
"ResourceIdTemplate": "arn:aws:rds:region:account-id:db-cluster",
"Severity": "medium",
"ResourceType": "AwsRdsDbInstance",
"Description": "Check if RDS clusters are protected by a backup plan.",
"Risk": "Without a backup plan, RDS clusters are vulnerable to data loss, accidental deletion, or corruption. This could lead to significant operational disruptions or loss of critical data.",
"RelatedUrl": "https://docs.aws.amazon.com/aws-backup/latest/devguide/assigning-resources.html",
"Remediation": {
"Code": {
"CLI": "aws backup create-backup-plan --backup-plan , aws backup tag-resource --resource-arn <rds-cluster-arn> --tags Key=backup,Value=true",
"NativeIaC": "",
"Other": "https://docs.aws.amazon.com/securityhub/latest/userguide/rds-controls.html#rds-26",
"Terraform": ""
},
"Recommendation": {
"Text": "Create a backup plan for the RDS cluster to protect it from data loss, accidental deletion, or corruption.",
"Url": "https://docs.aws.amazon.com/aws-backup/latest/devguide/assigning-resources.html"
}
},
"Categories": [],
"DependsOn": [],
"RelatedTo": [],
"Notes": ""
}

View File

@@ -0,0 +1,33 @@
from prowler.lib.check.models import Check, Check_Report_AWS
from prowler.providers.aws.services.backup.backup_client import backup_client
from prowler.providers.aws.services.rds.rds_client import rds_client
class rds_cluster_protected_by_backup_plan(Check):
def execute(self):
findings = []
for db_cluster_arn, db_cluster in rds_client.db_clusters.items():
report = Check_Report_AWS(self.metadata())
report.region = db_cluster.region
report.resource_id = db_cluster.id
report.resource_arn = db_cluster_arn
report.resource_tags = db_cluster.tags
report.status = "FAIL"
report.status_extended = (
f"RDS Cluster {db_cluster.id} is not protected by a backup plan."
)
if (
db_cluster_arn in backup_client.protected_resources
or f"arn:{rds_client.audited_partition}:rds:*:*:cluster:*"
in backup_client.protected_resources
or "*" in backup_client.protected_resources
):
report.status = "PASS"
report.status_extended = (
f"RDS Cluster {db_cluster.id} is protected by a backup plan."
)
findings.append(report)
return findings

View File

@@ -23,7 +23,9 @@
"Url": "https://aws.amazon.com/rds/features/multi-az/"
}
},
"Categories": [],
"Categories": [
"redundancy"
],
"DependsOn": [],
"RelatedTo": [],
"Notes": ""

View File

@@ -25,7 +25,9 @@
"Url": "https://docs.aws.amazon.com/vpc/latest/userguide/configure-subnets.html"
}
},
"Categories": [],
"Categories": [
"redundancy"
],
"DependsOn": [],
"RelatedTo": [],
"Notes": ""

View File

@@ -411,7 +411,7 @@ class GcpProvider(Provider):
@staticmethod
def get_projects(
credentials: Credentials, organization_id: str
credentials: Credentials, organization_id: str = None
) -> dict[str, GCPProject]:
"""
Get the projects accessible by the provided credentials. If an organization ID is provided, only the projects under that organization are returned.

View File

@@ -1443,6 +1443,18 @@ aws:
)
assert connection.error.code == 1015
@mock_aws
def test_test_connection_generic_exception(self):
with patch(
"prowler.providers.aws.aws_provider.AwsProvider.setup_session",
side_effect=Exception(),
):
connection = AwsProvider.test_connection(raise_on_exception=False)
assert isinstance(connection, Connection)
assert not connection.is_connected
assert isinstance(connection.error, Exception)
@mock_aws
def test_create_sts_session(self):
current_session = session.Session()

View File

@@ -0,0 +1,416 @@
from unittest import mock
from moto import mock_aws
from tests.providers.aws.utils import (
AWS_ACCOUNT_NUMBER,
AWS_REGION_US_EAST_1,
set_mocked_aws_provider,
)
class Test_rds_cluster_protected_by_backup_plan:
@mock_aws
def test_rds_no_clusters(self):
from prowler.providers.aws.services.backup.backup_service import Backup
from prowler.providers.aws.services.rds.rds_service import RDS
aws_provider = set_mocked_aws_provider([AWS_REGION_US_EAST_1])
with mock.patch(
"prowler.providers.common.provider.Provider.get_global_provider",
return_value=aws_provider,
):
with mock.patch(
"prowler.providers.aws.services.rds.rds_cluster_protected_by_backup_plan.rds_cluster_protected_by_backup_plan.rds_client",
new=RDS(aws_provider),
), mock.patch(
"prowler.providers.aws.services.rds.rds_cluster_protected_by_backup_plan.rds_cluster_protected_by_backup_plan.backup_client",
new=Backup(aws_provider),
):
# Test Check
from prowler.providers.aws.services.rds.rds_cluster_protected_by_backup_plan.rds_cluster_protected_by_backup_plan import (
rds_cluster_protected_by_backup_plan,
)
check = rds_cluster_protected_by_backup_plan()
result = check.execute()
assert len(result) == 0
@mock_aws
def test_rds_cluster_no_existing_backup_plans(self):
cluster = mock.MagicMock()
backup = mock.MagicMock()
from prowler.providers.aws.services.rds.rds_service import DBCluster
arn = f"arn:aws:rds:{AWS_REGION_US_EAST_1}:{AWS_ACCOUNT_NUMBER}:db:db-cluster-1"
cluster.db_clusters = {
arn: DBCluster(
id="db-cluster-1",
arn=f"arn:aws:rds:{AWS_REGION_US_EAST_1}:{AWS_ACCOUNT_NUMBER}:db:db-cluster-1",
endpoint="db-cluster-1.c9akciq32.rds.amazonaws.com",
backtrack=1,
parameter_group="test",
engine_version="13.3",
status="available",
public=False,
encrypted=True,
deletion_protection=False,
auto_minor_version_upgrade=True,
multi_az=False,
username="admin",
iam_auth=False,
name="db-cluster-1",
region="us-east-1",
cluster_class="db.m1.small",
engine="aurora-postgres",
allocated_storage=10,
tags=[],
)
}
aws_provider = set_mocked_aws_provider([AWS_REGION_US_EAST_1])
with mock.patch(
"prowler.providers.common.provider.Provider.get_global_provider",
return_value=aws_provider,
):
with mock.patch(
"prowler.providers.aws.services.rds.rds_cluster_protected_by_backup_plan.rds_cluster_protected_by_backup_plan.rds_client",
new=cluster,
), mock.patch(
"prowler.providers.aws.services.rds.rds_client.rds_client",
new=cluster,
), mock.patch(
"prowler.providers.aws.services.rds.rds_cluster_protected_by_backup_plan.rds_cluster_protected_by_backup_plan.backup_client",
new=backup,
), mock.patch(
"prowler.providers.aws.services.backup.backup_client.backup_client",
new=backup,
):
# Test Check
from prowler.providers.aws.services.rds.rds_cluster_protected_by_backup_plan.rds_cluster_protected_by_backup_plan import (
rds_cluster_protected_by_backup_plan,
)
check = rds_cluster_protected_by_backup_plan()
result = check.execute()
assert len(result) == 1
assert result[0].status == "FAIL"
assert (
result[0].status_extended
== "RDS Cluster db-cluster-1 is not protected by a backup plan."
)
assert result[0].resource_id == "db-cluster-1"
assert result[0].region == AWS_REGION_US_EAST_1
assert (
result[0].resource_arn
== f"arn:aws:rds:{AWS_REGION_US_EAST_1}:{AWS_ACCOUNT_NUMBER}:db:db-cluster-1"
)
assert result[0].resource_tags == []
def test_rds_cluster_without_backup_plan(self):
cluster = mock.MagicMock()
backup = mock.MagicMock()
from prowler.providers.aws.services.rds.rds_service import DBCluster
arn = f"arn:aws:rds:{AWS_REGION_US_EAST_1}:{AWS_ACCOUNT_NUMBER}:db:db-cluster-1"
cluster.db_clusters = {
arn: DBCluster(
id="db-cluster-1",
arn=f"arn:aws:rds:{AWS_REGION_US_EAST_1}:{AWS_ACCOUNT_NUMBER}:db:db-cluster-1",
endpoint="db-cluster-1.c9akciq32.rds.amazonaws.com",
backtrack=1,
parameter_group="test",
engine_version="13.3",
status="available",
public=False,
encrypted=True,
deletion_protection=False,
auto_minor_version_upgrade=True,
multi_az=False,
username="admin",
iam_auth=False,
name="db-cluster-1",
region="us-east-1",
cluster_class="db.m1.small",
engine="aurora-postgres",
allocated_storage=10,
tags=[],
)
}
backup.protected_resources = [
f"arn:aws:rds:{AWS_REGION_US_EAST_1}:{AWS_ACCOUNT_NUMBER}:db:db-master-2"
]
aws_provider = set_mocked_aws_provider([AWS_REGION_US_EAST_1])
with mock.patch(
"prowler.providers.common.provider.Provider.get_global_provider",
return_value=aws_provider,
):
with mock.patch(
"prowler.providers.aws.services.rds.rds_cluster_protected_by_backup_plan.rds_cluster_protected_by_backup_plan.rds_client",
new=cluster,
), mock.patch(
"prowler.providers.aws.services.rds.rds_client.rds_client",
new=cluster,
), mock.patch(
"prowler.providers.aws.services.rds.rds_cluster_protected_by_backup_plan.rds_cluster_protected_by_backup_plan.backup_client",
new=backup,
), mock.patch(
"prowler.providers.aws.services.backup.backup_client.backup_client",
new=backup,
):
# Test Check
from prowler.providers.aws.services.rds.rds_cluster_protected_by_backup_plan.rds_cluster_protected_by_backup_plan import (
rds_cluster_protected_by_backup_plan,
)
check = rds_cluster_protected_by_backup_plan()
result = check.execute()
assert len(result) == 1
assert result[0].status == "FAIL"
assert (
result[0].status_extended
== "RDS Cluster db-cluster-1 is not protected by a backup plan."
)
assert result[0].resource_id == "db-cluster-1"
assert result[0].region == AWS_REGION_US_EAST_1
assert (
result[0].resource_arn
== f"arn:aws:rds:{AWS_REGION_US_EAST_1}:{AWS_ACCOUNT_NUMBER}:db:db-cluster-1"
)
assert result[0].resource_tags == []
def test_rds_cluster_with_backup_plan(self):
cluster = mock.MagicMock()
from prowler.providers.aws.services.rds.rds_service import DBCluster
arn = f"arn:aws:rds:{AWS_REGION_US_EAST_1}:{AWS_ACCOUNT_NUMBER}:db:db-cluster-1"
cluster.db_clusters = {
arn: DBCluster(
id="db-cluster-1",
arn=f"arn:aws:rds:{AWS_REGION_US_EAST_1}:{AWS_ACCOUNT_NUMBER}:db:db-cluster-1",
endpoint="db-cluster-1.c9akciq32.rds.amazonaws.com",
backtrack=1,
parameter_group="test",
engine_version="13.3",
status="available",
public=False,
encrypted=True,
deletion_protection=False,
auto_minor_version_upgrade=True,
multi_az=False,
username="admin",
iam_auth=False,
name="db-cluster-1",
region="us-east-1",
cluster_class="db.m1.small",
engine="aurora-postgres",
allocated_storage=10,
tags=[],
)
}
backup = mock.MagicMock()
backup.protected_resources = [arn]
aws_provider = set_mocked_aws_provider([AWS_REGION_US_EAST_1])
with mock.patch(
"prowler.providers.common.provider.Provider.get_global_provider",
return_value=aws_provider,
):
with mock.patch(
"prowler.providers.aws.services.rds.rds_cluster_protected_by_backup_plan.rds_cluster_protected_by_backup_plan.rds_client",
new=cluster,
), mock.patch(
"prowler.providers.aws.services.rds.rds_client.rds_client",
new=cluster,
), mock.patch(
"prowler.providers.aws.services.rds.rds_cluster_protected_by_backup_plan.rds_cluster_protected_by_backup_plan.backup_client",
new=backup,
), mock.patch(
"prowler.providers.aws.services.backup.backup_client.backup_client",
new=backup,
):
# Test Check
from prowler.providers.aws.services.rds.rds_cluster_protected_by_backup_plan.rds_cluster_protected_by_backup_plan import (
rds_cluster_protected_by_backup_plan,
)
check = rds_cluster_protected_by_backup_plan()
result = check.execute()
assert len(result) == 1
assert result[0].status == "PASS"
assert (
result[0].status_extended
== "RDS Cluster db-cluster-1 is protected by a backup plan."
)
assert result[0].resource_id == "db-cluster-1"
assert result[0].region == AWS_REGION_US_EAST_1
assert (
result[0].resource_arn
== f"arn:aws:rds:{AWS_REGION_US_EAST_1}:{AWS_ACCOUNT_NUMBER}:db:db-cluster-1"
)
assert result[0].resource_tags == []
def test_rds_cluster_with_backup_plan_via_cluster_wildcard(self):
cluster = mock.MagicMock()
cluster.audited_partition = "aws"
from prowler.providers.aws.services.rds.rds_service import DBCluster
arn = "arn:aws:rds:*:*:cluster:*"
cluster.db_clusters = {
f"arn:aws:rds:{AWS_REGION_US_EAST_1}:{AWS_ACCOUNT_NUMBER}:db:db-cluster-1": DBCluster(
id="db-cluster-1",
arn=f"arn:aws:rds:{AWS_REGION_US_EAST_1}:{AWS_ACCOUNT_NUMBER}:db:db-cluster-1",
endpoint="db-cluster-1.c9akciq32.rds.amazonaws.com",
backtrack=1,
parameter_group="test",
engine_version="13.3",
status="available",
public=False,
encrypted=True,
deletion_protection=False,
auto_minor_version_upgrade=True,
multi_az=False,
username="admin",
iam_auth=False,
name="db-cluster-1",
region="us-east-1",
cluster_class="db.m1.small",
engine="aurora-postgres",
allocated_storage=10,
tags=[],
)
}
backup = mock.MagicMock()
backup.protected_resources = [arn]
aws_provider = set_mocked_aws_provider([AWS_REGION_US_EAST_1])
with mock.patch(
"prowler.providers.common.provider.Provider.get_global_provider",
return_value=aws_provider,
):
with mock.patch(
"prowler.providers.aws.services.rds.rds_cluster_protected_by_backup_plan.rds_cluster_protected_by_backup_plan.rds_client",
new=cluster,
), mock.patch(
"prowler.providers.aws.services.rds.rds_client.rds_client",
new=cluster,
), mock.patch(
"prowler.providers.aws.services.rds.rds_cluster_protected_by_backup_plan.rds_cluster_protected_by_backup_plan.backup_client",
new=backup,
), mock.patch(
"prowler.providers.aws.services.backup.backup_client.backup_client",
new=backup,
):
# Test Check
from prowler.providers.aws.services.rds.rds_cluster_protected_by_backup_plan.rds_cluster_protected_by_backup_plan import (
rds_cluster_protected_by_backup_plan,
)
check = rds_cluster_protected_by_backup_plan()
result = check.execute()
assert len(result) == 1
assert result[0].status == "PASS"
assert (
result[0].status_extended
== "RDS Cluster db-cluster-1 is protected by a backup plan."
)
assert result[0].resource_id == "db-cluster-1"
assert result[0].region == AWS_REGION_US_EAST_1
assert (
result[0].resource_arn
== f"arn:aws:rds:{AWS_REGION_US_EAST_1}:{AWS_ACCOUNT_NUMBER}:db:db-cluster-1"
)
assert result[0].resource_tags == []
def test_rds_cluster_with_backup_plan_via_all_wildcard(self):
cluster = mock.MagicMock()
from prowler.providers.aws.services.rds.rds_service import DBCluster
arn = "*"
cluster.db_clusters = {
f"arn:aws:rds:{AWS_REGION_US_EAST_1}:{AWS_ACCOUNT_NUMBER}:db:db-cluster-1": DBCluster(
id="db-cluster-1",
arn=f"arn:aws:rds:{AWS_REGION_US_EAST_1}:{AWS_ACCOUNT_NUMBER}:db:db-cluster-1",
endpoint="db-cluster-1.c9akciq32.rds.amazonaws.com",
backtrack=1,
parameter_group="test",
engine_version="13.3",
status="available",
public=False,
encrypted=True,
deletion_protection=False,
auto_minor_version_upgrade=True,
multi_az=False,
username="admin",
iam_auth=False,
name="db-cluster-1",
region="us-east-1",
cluster_class="db.m1.small",
engine="aurora-postgres",
allocated_storage=10,
tags=[],
)
}
backup = mock.MagicMock()
backup.protected_resources = [arn]
aws_provider = set_mocked_aws_provider([AWS_REGION_US_EAST_1])
with mock.patch(
"prowler.providers.common.provider.Provider.get_global_provider",
return_value=aws_provider,
):
with mock.patch(
"prowler.providers.aws.services.rds.rds_cluster_protected_by_backup_plan.rds_cluster_protected_by_backup_plan.rds_client",
new=cluster,
), mock.patch(
"prowler.providers.aws.services.rds.rds_client.rds_client",
new=cluster,
), mock.patch(
"prowler.providers.aws.services.rds.rds_cluster_protected_by_backup_plan.rds_cluster_protected_by_backup_plan.backup_client",
new=backup,
), mock.patch(
"prowler.providers.aws.services.backup.backup_client.backup_client",
new=backup,
):
# Test Check
from prowler.providers.aws.services.rds.rds_cluster_protected_by_backup_plan.rds_cluster_protected_by_backup_plan import (
rds_cluster_protected_by_backup_plan,
)
check = rds_cluster_protected_by_backup_plan()
result = check.execute()
assert len(result) == 1
assert result[0].status == "PASS"
assert (
result[0].status_extended
== "RDS Cluster db-cluster-1 is protected by a backup plan."
)
assert result[0].resource_id == "db-cluster-1"
assert result[0].region == AWS_REGION_US_EAST_1
assert (
result[0].resource_arn
== f"arn:aws:rds:{AWS_REGION_US_EAST_1}:{AWS_ACCOUNT_NUMBER}:db:db-cluster-1"
)
assert result[0].resource_tags == []