-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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(acm): Add new check for insecure algorithms in certificates #4551
Merged
MrCloudSec
merged 18 commits into
prowler-cloud:master
from
MarioRgzLpz:PRWLR-4239-add-new-acm-check-for-rsa-key-length-in-certificates
Aug 7, 2024
Merged
Changes from 4 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
c3ff8c3
chore(acm): Add RSA key length check
MarioRgzLpz 52a4224
test(acm): Add RSA key length check tests
MarioRgzLpz 8ea0807
test(acm): Add the new atributte key_algorithm to old tests
MarioRgzLpz 4d9d8f3
feat(acm): Add a list of insecure algorithms instead of verifying onl…
MarioRgzLpz 74786c7
fix(acm): Change the URLs for the SecurityHub ones
MarioRgzLpz c8d3954
feat(acm): Make the insecure algorithm a configurable list by default…
MarioRgzLpz e1da46b
refactor(acm): I change the check name to a more suitable one
MarioRgzLpz 49dae85
fix(acm): Add the eks_rquire_log_types in config_test to resolve merg…
MarioRgzLpz b9e698f
Merge branch 'master' into PRWLR-4239-add-new-acm-check-for-rsa-key-l…
MrCloudSec 42829a3
refactor(acm): I change the name of the check and some texts like the…
MarioRgzLpz 629ecff
Merge branch
MarioRgzLpz ca090d8
chore(acm): Change the recommendation url to the SecurityHub one
MarioRgzLpz ee08174
chore(acm): Change insecure_algorithm to insecure_key_algorithm in th…
MarioRgzLpz 9546adf
chore(acm): Change method _list_certificates so it returns all key al…
MarioRgzLpz 9697ead
chore(acm): Added logic for checking only in use certificates and swa…
MarioRgzLpz e797248
Merge branch 'prowler-cloud:master' into PRWLR-4239-add-new-acm-check…
MarioRgzLpz b4dafb0
Merge branch 'prowler-cloud:master' into PRWLR-4239-add-new-acm-check…
MarioRgzLpz cf645a7
chore(acm): Add the key algorithm in the status extended and fix the …
MarioRgzLpz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Empty file.
32 changes: 32 additions & 0 deletions
32
...ervices/acm/acm_certificates_rsa_key_length/acm_certificates_rsa_key_length.metadata.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
{ | ||
"Provider": "aws", | ||
"CheckID": "acm_certificates_rsa_key_length", | ||
"CheckTitle": "Check if ACM Certificates use a secure RSA key size", | ||
"CheckType": [ | ||
"Data Protection" | ||
], | ||
"ServiceName": "acm", | ||
"SubServiceName": "", | ||
"ResourceIdTemplate": "arn:partition:acm:region:account-id:certificate/resource-id", | ||
"Severity": "high", | ||
"ResourceType": "AwsCertificateManagerCertificate", | ||
"Description": "Check if ACM Certificates use a secure RSA key size", | ||
"Risk": "Certificates with weak RSA keys can be compromised.", | ||
"RelatedUrl": "https://docs.aws.amazon.com/es_es/acm/latest/userguide/acm-certificate.html", | ||
"Remediation": { | ||
"Code": { | ||
"CLI": "", | ||
"NativeIaC": "", | ||
"Other": "", | ||
"Terraform": "" | ||
}, | ||
"Recommendation": { | ||
"Text": "Ensure that all ACM certificates use RSA keys of at least 2048 bits. If any certificates use smaller keys, regenerate them with a secure key size and update any systems that rely on these certificates.", | ||
"Url": "https://docs.aws.amazon.com/es_es/acm/latest/userguide/acm-certificate.html" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here too, since the SecurityHub link also contains the Remediation. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added in commit 74786c7 |
||
} | ||
}, | ||
"Categories": [], | ||
"DependsOn": [], | ||
"RelatedTo": [], | ||
"Notes": "" | ||
} |
26 changes: 26 additions & 0 deletions
26
...iders/aws/services/acm/acm_certificates_rsa_key_length/acm_certificates_rsa_key_length.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
from prowler.lib.check.models import Check, Check_Report_AWS | ||
from prowler.providers.aws.services.acm.acm_client import acm_client | ||
|
||
|
||
class acm_certificates_rsa_key_length(Check): | ||
insecure_algorithms = ["RSA_1024"] | ||
|
||
def execute(self): | ||
findings = [] | ||
for certificate in acm_client.certificates: | ||
report = Check_Report_AWS(self.metadata()) | ||
report.region = certificate.region | ||
report.resource_id = certificate.id | ||
report.resource_details = certificate.name | ||
report.resource_arn = certificate.arn | ||
report.resource_tags = certificate.tags | ||
|
||
report.status = "PASS" | ||
report.status_extended = f"ACM Certificate {certificate.id} for {certificate.name} meet minimum key size requirements." | ||
|
||
if certificate.key_algorithm in self.insecure_algorithms: | ||
report.status = "FAIL" | ||
report.status_extended = f"ACM Certificate {certificate.id} for {certificate.name} uses RSA_1024 which is not secure enough." | ||
findings.append(report) | ||
|
||
return findings |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
117 changes: 117 additions & 0 deletions
117
.../aws/services/acm/acm_certificates_rsa_key_length/acm_certificates_rsa_key_length_test.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
import uuid | ||
from unittest import mock | ||
|
||
from prowler.providers.aws.services.acm.acm_service import Certificate | ||
|
||
AWS_REGION = "us-east-1" | ||
AWS_ACCOUNT_NUMBER = "123456789012" | ||
|
||
|
||
class Test_acm_certificates_rsa_key_length: | ||
def test_no_acm_certificates(self): | ||
acm_client = mock.MagicMock | ||
acm_client.certificates = [] | ||
|
||
with mock.patch( | ||
"prowler.providers.aws.services.acm.acm_service.ACM", | ||
new=acm_client, | ||
): | ||
# Test Check | ||
from prowler.providers.aws.services.acm.acm_certificates_rsa_key_length.acm_certificates_rsa_key_length import ( | ||
acm_certificates_rsa_key_length, | ||
) | ||
|
||
check = acm_certificates_rsa_key_length() | ||
result = check.execute() | ||
|
||
assert len(result) == 0 | ||
|
||
def test_acm_certificate_valid_key_length(self): | ||
certificate_id = str(uuid.uuid4()) | ||
certificate_arn = f"arn:aws:acm:{AWS_REGION}:{AWS_ACCOUNT_NUMBER}:certificate/{certificate_id}" | ||
certificate_name = "test-certificate.com" | ||
certificate_type = "AMAZON_ISSUED" | ||
certificate_key_algorithm = "RSA_2048" | ||
|
||
acm_client = mock.MagicMock | ||
acm_client.certificates = [ | ||
Certificate( | ||
arn=certificate_arn, | ||
id=certificate_id, | ||
name=certificate_name, | ||
type=certificate_type, | ||
key_algorithm=certificate_key_algorithm, | ||
expiration_days=365, | ||
transparency_logging=True, | ||
in_use=True, | ||
region=AWS_REGION, | ||
) | ||
] | ||
|
||
with mock.patch( | ||
"prowler.providers.aws.services.acm.acm_service.ACM", | ||
new=acm_client, | ||
): | ||
# Test Check | ||
from prowler.providers.aws.services.acm.acm_certificates_rsa_key_length.acm_certificates_rsa_key_length import ( | ||
acm_certificates_rsa_key_length, | ||
) | ||
|
||
check = acm_certificates_rsa_key_length() | ||
result = check.execute() | ||
|
||
assert len(result) == 1 | ||
assert result[0].status == "PASS" | ||
assert ( | ||
result[0].status_extended | ||
== f"ACM Certificate {certificate_id} for {certificate_name} meet minimum key size requirements." | ||
) | ||
assert result[0].resource_id == certificate_id | ||
assert result[0].resource_arn == certificate_arn | ||
assert result[0].region == AWS_REGION | ||
assert result[0].resource_tags == [] | ||
|
||
def test_acm_certificate_short_RSA_key(self): | ||
certificate_id = str(uuid.uuid4()) | ||
certificate_arn = f"arn:aws:acm:{AWS_REGION}:{AWS_ACCOUNT_NUMBER}:certificate/{certificate_id}" | ||
certificate_name = "test-certificate.com" | ||
certificate_type = "AMAZON_ISSUED" | ||
certificate_key_algorithm = "RSA_1024" | ||
|
||
acm_client = mock.MagicMock | ||
acm_client.certificates = [ | ||
Certificate( | ||
arn=certificate_arn, | ||
id=certificate_id, | ||
name=certificate_name, | ||
type=certificate_type, | ||
key_algorithm=certificate_key_algorithm, | ||
expiration_days=365, | ||
transparency_logging=False, | ||
in_use=True, | ||
region=AWS_REGION, | ||
) | ||
] | ||
|
||
with mock.patch( | ||
"prowler.providers.aws.services.acm.acm_service.ACM", | ||
new=acm_client, | ||
): | ||
# Test Check | ||
from prowler.providers.aws.services.acm.acm_certificates_rsa_key_length.acm_certificates_rsa_key_length import ( | ||
acm_certificates_rsa_key_length, | ||
) | ||
|
||
check = acm_certificates_rsa_key_length() | ||
result = check.execute() | ||
|
||
assert len(result) == 1 | ||
assert result[0].status == "FAIL" | ||
assert ( | ||
result[0].status_extended | ||
== f"ACM Certificate {certificate_id} for {certificate_name} uses RSA_1024 which is not secure enough." | ||
) | ||
assert result[0].resource_id == certificate_id | ||
assert result[0].resource_arn == certificate_arn | ||
assert result[0].region == AWS_REGION | ||
assert result[0].resource_tags == [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please, can you add here the Security Hub link?
https://docs.aws.amazon.com/securityhub/latest/userguide/acm-controls.html#acm-2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added in commit 74786c7