feat(neptune): add new check neptune_cluster_snapshot_encrypted (#5058)

Co-authored-by: Sergio Garcia <38561120+sergargar@users.noreply.github.com>
This commit is contained in:
Daniel Barranquero
2024-09-17 19:16:43 +02:00
committed by GitHub
parent 5fb2d7c3ce
commit 1ece8bbcd6
4 changed files with 167 additions and 0 deletions
@@ -0,0 +1,34 @@
{
"Provider": "aws",
"CheckID": "neptune_cluster_snapshot_encrypted",
"CheckTitle": "Check if Neptune DB cluster snapshots are encrypted at rest.",
"CheckType": [
"Software and Configuration Checks/AWS Security Best Practices"
],
"ServiceName": "neptune",
"SubServiceName": "",
"ResourceIdTemplate": "arn:aws:rds:region:account-id:cluster-snapshot:db-cluster-snapshot-identifier",
"Severity": "medium",
"ResourceType": "AwsRdsDbClusterSnapshot",
"Description": "This check ensures that Neptune DB cluster snapshots are encrypted at rest to protect sensitive data from unauthorized access.",
"Risk": "If Neptune DB cluster snapshots are not encrypted, sensitive data might be exposed in case of unauthorized access, leading to potential data breaches and non-compliance with data protection regulations.",
"RelatedUrl": "https://docs.aws.amazon.com/neptune/latest/userguide/backup-restore-create-snapshot.html",
"Remediation": {
"Code": {
"CLI": "aws rds copy-db-cluster-snapshot --source-db-cluster-snapshot-identifier <source-snapshot> --target-db-cluster-snapshot-identifier <encrypted-snapshot> --kms-key-id <kms-key-id>",
"NativeIaC": "",
"Other": "https://docs.aws.amazon.com/securityhub/latest/userguide/neptune-controls.html#neptune-6",
"Terraform": ""
},
"Recommendation": {
"Text": "Ensure that all Neptune DB cluster snapshots are encrypted at rest by enabling encryption on the cluster before creating snapshots or by copying unencrypted snapshots to encrypted ones.",
"Url": "https://docs.aws.amazon.com/neptune/latest/userguide/backup-restore-create-snapshot.html"
}
},
"Categories": [
"encryption"
],
"DependsOn": [],
"RelatedTo": [],
"Notes": ""
}
@@ -0,0 +1,26 @@
from prowler.lib.check.models import Check, Check_Report_AWS
from prowler.providers.aws.services.neptune.neptune_client import neptune_client
class neptune_cluster_snapshot_encrypted(Check):
def execute(self):
findings = []
for snapshot in neptune_client.db_cluster_snapshots:
report = Check_Report_AWS(self.metadata())
report.region = snapshot.region
report.resource_id = snapshot.id
report.resource_arn = snapshot.arn
report.resource_tags = snapshot.tags
report.status = "FAIL"
report.status_extended = (
f"Neptune Cluster Snapshot {snapshot.id} is not encrypted at rest."
)
if snapshot.encrypted:
report.status = "PASS"
report.status_extended = (
f"Neptune Cluster Snapshot {snapshot.id} is encrypted at rest."
)
findings.append(report)
return findings
@@ -0,0 +1,107 @@
from unittest import mock
from prowler.providers.aws.services.neptune.neptune_service import ClusterSnapshot
from tests.providers.aws.utils import AWS_ACCOUNT_NUMBER, AWS_REGION_US_EAST_1
class Test_neptune_cluster_snapshot_encrypted:
def test_neptune_no_snapshots(self):
neptune_client = mock.MagicMock()
neptune_client.db_cluster_snapshots = []
with mock.patch(
"prowler.providers.aws.services.neptune.neptune_service.Neptune",
new=neptune_client,
), mock.patch(
"prowler.providers.aws.services.neptune.neptune_cluster_snapshot_encrypted.neptune_cluster_snapshot_encrypted.neptune_client",
new=neptune_client,
):
# Test Check
from prowler.providers.aws.services.neptune.neptune_cluster_snapshot_encrypted.neptune_cluster_snapshot_encrypted import (
neptune_cluster_snapshot_encrypted,
)
check = neptune_cluster_snapshot_encrypted()
result = check.execute()
assert len(result) == 0
def test_neptune_snapshot_not_encrypted(self):
neptune_client = mock.MagicMock
snapshot_arn = f"arn:aws:rds:{AWS_REGION_US_EAST_1}:{AWS_ACCOUNT_NUMBER}:cluster-snapshot:snapshot-1"
neptune_client.db_cluster_snapshots = [
ClusterSnapshot(
arn=snapshot_arn,
id="snapshot-1",
cluster_id="cluster-1",
region=AWS_REGION_US_EAST_1,
encrypted=False,
tags=[],
)
]
with mock.patch(
"prowler.providers.aws.services.neptune.neptune_service.Neptune",
new=neptune_client,
), mock.patch(
"prowler.providers.aws.services.neptune.neptune_cluster_snapshot_encrypted.neptune_cluster_snapshot_encrypted.neptune_client",
new=neptune_client,
):
# Test Check
from prowler.providers.aws.services.neptune.neptune_cluster_snapshot_encrypted.neptune_cluster_snapshot_encrypted import (
neptune_cluster_snapshot_encrypted,
)
check = neptune_cluster_snapshot_encrypted()
result = check.execute()
assert len(result) == 1
assert result[0].status == "FAIL"
assert (
result[0].status_extended
== "Neptune Cluster Snapshot snapshot-1 is not encrypted at rest."
)
assert result[0].resource_id == "snapshot-1"
assert result[0].region == AWS_REGION_US_EAST_1
assert result[0].resource_arn == snapshot_arn
assert result[0].resource_tags == []
def test_neptune_snapshot_encrypted(self):
neptune_client = mock.MagicMock
snapshot_arn = f"arn:aws:rds:{AWS_REGION_US_EAST_1}:{AWS_ACCOUNT_NUMBER}:cluster-snapshot:snapshot-1"
neptune_client.db_cluster_snapshots = [
ClusterSnapshot(
arn=snapshot_arn,
id="snapshot-1",
cluster_id="cluster-1",
region=AWS_REGION_US_EAST_1,
encrypted=True,
tags=[],
)
]
with mock.patch(
"prowler.providers.aws.services.neptune.neptune_service.Neptune",
new=neptune_client,
), mock.patch(
"prowler.providers.aws.services.neptune.neptune_cluster_snapshot_encrypted.neptune_cluster_snapshot_encrypted.neptune_client",
new=neptune_client,
):
# Test Check
from prowler.providers.aws.services.neptune.neptune_cluster_snapshot_encrypted.neptune_cluster_snapshot_encrypted import (
neptune_cluster_snapshot_encrypted,
)
check = neptune_cluster_snapshot_encrypted()
result = check.execute()
assert len(result) == 1
assert result[0].status == "PASS"
assert (
result[0].status_extended
== "Neptune Cluster Snapshot snapshot-1 is encrypted at rest."
)
assert result[0].resource_id == "snapshot-1"
assert result[0].region == AWS_REGION_US_EAST_1
assert result[0].resource_arn == snapshot_arn
assert result[0].resource_tags == []