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(AWS): Lightsail new service and checks #3919

Merged
merged 29 commits into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
38ee8e2
feat(aws): New lightsail service
puchy22 May 3, 2024
f522367
feat(lightsail): New check to ensure there is no public instances
puchy22 May 3, 2024
6caec65
feat(lightsail): New check to ensure there is no unnecesary ports open
puchy22 May 3, 2024
9f03689
feat(lightsail): New check to ensure that snapshots are automated
puchy22 May 3, 2024
2ae203b
feat(lightsail): New check to ensure that database is not public
puchy22 May 3, 2024
1e00349
test(lightsail): Test the service
puchy22 May 6, 2024
7da1a9c
test(lightsail): delete unnecesary mock_aws
puchy22 May 7, 2024
fb6b976
chore(lightsail): Indicate the return type of functions
puchy22 May 7, 2024
92676ad
test(lightsail): add testing for open unnecesary ports
puchy22 May 7, 2024
eaa848e
test(lightsail): add testing for automatic snapshots for instances
puchy22 May 10, 2024
6bcfd7f
test(lightsail): add testing for public databases checks
puchy22 May 10, 2024
7fb558f
chore(lightsail): Change ID instance attribute
puchy22 May 13, 2024
c5073b9
test(lightsail): add testing for public IP
puchy22 May 13, 2024
fb9ff1b
chore(lightsail): Improve service performance
puchy22 May 13, 2024
dcbe671
chore(lightsail): Adapt checks to dict and adds IDs
puchy22 May 13, 2024
f09cebe
test(lightsail): Fit to new dict usage
puchy22 May 13, 2024
e26e82f
chore(lightsail): Change region in models and add static IPs to service
puchy22 May 15, 2024
a65df5f
feat(lightsail): New check to ensure not unusing statics IPs
puchy22 May 15, 2024
e5e10ef
test(lightsail): New tests for unused static IPs
puchy22 May 15, 2024
1232b6b
chore(safety): ignore pip vulnerability (#4007)
sergargar May 15, 2024
d3077f1
feat(lightsail) Add new check related with public access
puchy22 May 15, 2024
cddcf04
test(lightsail): Delete tests from olf checks
puchy22 May 15, 2024
069c794
fix(lightsail): Add services can be audited by arn
puchy22 May 15, 2024
9432415
fix(lightsail): Fix no instances in auto snapshots check
puchy22 May 16, 2024
851edf6
chore(aws): Update number of checks and services
puchy22 May 16, 2024
ece951c
chore(lightsail): Improve status extended output
puchy22 May 16, 2024
271e05e
test(lightsail): Adapt status extended
puchy22 May 16, 2024
9962d4d
chore(lightsail): Add what instance is attached to the static IP
puchy22 May 16, 2024
c31fb31
Merge branch 'master' into lightsail_basic_checks
sergargar May 16, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,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 | 322 | 62 -> `prowler aws --list-services` | 28 -> `prowler aws --list-compliance` | 7 -> `prowler aws --list-categories` |
| GCP | 77 | 13 -> `prowler gcp --list-services` | 2 -> `prowler gcp --list-compliance` | 2 -> `prowler gcp --list-categories`|
| Azure | 127 | 16 -> `prowler azure --list-services` | 3 -> `prowler azure --list-compliance` | 2 -> `prowler azure --list-categories` |
| AWS | 326 | 63 -> `prowler aws --list-services` | 28 -> `prowler aws --list-compliance` | 6 -> `prowler aws --list-categories` |
| GCP | 75 | 11 -> `prowler gcp --list-services` | 1 -> `prowler gcp --list-compliance` | 2 -> `prowler gcp --list-categories`|
| Azure | 127 | 16 -> `prowler azure --list-services` | 2 -> `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
Expand Down
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from prowler.providers.aws.services.lightsail.lightsail_service import Lightsail
from prowler.providers.common.common import get_global_provider

lightsail_client = Lightsail(get_global_provider())
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"Provider": "aws",
"CheckID": "lightsail_database_public",
"CheckTitle": "Check if the database has the public mode.",
"CheckType": [
"Infrastructure Security"
],
"ServiceName": "lightsail",
"SubServiceName": "database",
"ResourceIdTemplate": "arn:partition:lightsail:region:account:RelationalDatabase/database-id",
"Severity": "high",
"ResourceType": "",
"Description": "The database is in public mode, which means it is exposed to the internet.",
"Risk": "This can lead to unauthorized access to the database.",
"RelatedUrl": "https://docs.aws.amazon.com/lightsail/latest/userguide/amazon-lightsail-databases.html",
"Remediation": {
"Code": {
"CLI": "",
"NativeIaC": "",
"Other": "",
"Terraform": ""
},
"Recommendation": {
"Text": "Change the database to private mode.",
"Url": ""
}
},
"Categories": [
"internet-exposed"
],
"DependsOn": [],
"RelatedTo": [],
"Notes": ""
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from prowler.lib.check.models import Check, Check_Report_AWS
from prowler.providers.aws.services.lightsail.lightsail_client import lightsail_client


class lightsail_database_public(Check):
def execute(self):
findings = []

for arn_database, database in lightsail_client.databases.items():
report = Check_Report_AWS(self.metadata())
report.region = database.region
report.resource_id = database.id
report.resource_arn = arn_database
report.resource_tags = database.tags
report.status = "FAIL"
report.status_extended = f"Database '{database.name}' is public."

if not database.public_access:
report.status = "PASS"
report.status_extended = f"Database '{database.name}' is not public."

findings.append(report)

return findings
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"Provider": "aws",
"CheckID": "lightsail_instance_automated_snapshots",
"CheckTitle": "Check if instances have automated snapshots enabled",
"CheckType": [
"Infrastructure Security"
],
"ServiceName": "lightsail",
"SubServiceName": "",
"ResourceIdTemplate": "arn:partition:lightsail:region:account:Instance/instance-id",
"Severity": "medium",
"ResourceType": "Instance",
"Description": "Amazon Lightsail automatically creates daily snapshots of your instances. These snapshots are used for automatic backups and are stored at no additional cost. It is recommended to enable automatic snapshots for your Lightsail instances.",
"Risk": "If automatic snapshots are not enabled, you may lose data in case of accidental deletion or corruption.",
"RelatedUrl": "https://docs.aws.amazon.com/lightsail/latest/userguide/amazon-lightsail-configuring-automatic-snapshots.html",
"Remediation": {
"Code": {
"CLI": "",
"NativeIaC": "",
"Other": "",
"Terraform": ""
},
"Recommendation": {
"Text": "The automatic snapshot is a best practice to protect your data. It is recommended to enable automatic snapshots for your Lightsail instances.",
"Url": "https://docs.aws.amazon.com/lightsail/latest/userguide/amazon-lightsail-changing-automatic-snapshot-time.html"
}
},
"Categories": [],
"DependsOn": [],
"RelatedTo": [],
"Notes": ""
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from prowler.lib.check.models import Check, Check_Report_AWS
from prowler.providers.aws.services.lightsail.lightsail_client import lightsail_client


class lightsail_instance_automated_snapshots(Check):
def execute(self):
findings = []
for arn_instance, instance in lightsail_client.instances.items():
report = Check_Report_AWS(self.metadata())
report.region = instance.region
report.resource_id = instance.id
report.resource_arn = arn_instance
report.resource_tags = instance.tags
report.status = "FAIL"
report.status_extended = (
f"Instance '{instance.name}' does not have automated snapshots enabled."
)

if instance.auto_snapshot:
report.status = "PASS"
report.status_extended = (
f"Instance '{instance.name}' has automated snapshots enabled."
)

findings.append(report)

return findings
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"Provider": "aws",
"CheckID": "lightsail_instance_public",
"CheckTitle": "Ensure that Lightsail instances are not publicly accessible",
"CheckType": [],
"ServiceName": "lightsail",
"SubServiceName": "instance",
"ResourceIdTemplate": "arn:partition:lightsail:region:account:Instance/instance-id",
"Severity": "high",
"ResourceType": "Instance",
"Description": "Ensure that Lightsail instances are not publicly accessible",
"Risk": "If an instance is publicly accessible, it can be accessed by anyone on the internet. This can lead to unauthorized access to the instance and its data.",
"RelatedUrl": "https://docs.aws.amazon.com/lightsail/latest/userguide/understanding-public-ip-and-private-ip-addresses-in-amazon-lightsail.html#ipv4-addresses",
"Remediation": {
"Code": {
"CLI": "",
"NativeIaC": "",
"Other": "",
"Terraform": ""
},
"Recommendation": {
"Text": "We recommend that you disable public access to the instance and use a VPN or a bastion host to access the instance securely.",
"Url": ""
}
},
"Categories": [],
"DependsOn": [],
"RelatedTo": [],
"Notes": ""
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from prowler.lib.check.models import Check, Check_Report_AWS
from prowler.providers.aws.services.lightsail.lightsail_client import lightsail_client


class lightsail_instance_public(Check):
def execute(self) -> Check_Report_AWS:
findings = []

for arn_instance, instance in lightsail_client.instances.items():
report = Check_Report_AWS(self.metadata())
report.region = instance.region
report.resource_id = instance.id
report.resource_arn = arn_instance
report.resource_tags = instance.tags
report.status = "PASS"
report.status_extended = (
f"Instance '{instance.name}' is not publicly exposed."
)

open_public_ports = [
port for port in instance.ports if port.access_type == "public"
]

if instance.public_ip != "" and len(open_public_ports) > 0:
report.status = "FAIL"
report.status_extended = f"Instance '{instance.name}' is publicly exposed. The open ports are: {', '.join(open_port.range for open_port in open_public_ports)}"

findings.append(report)

return findings