-
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
Changes from 11 commits
c3ff8c3
52a4224
8ea0807
4d9d8f3
74786c7
c8d3954
e1da46b
49dae85
b9e698f
42829a3
629ecff
ca090d8
ee08174
9546adf
9697ead
e797248
b4dafb0
cf645a7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
{ | ||
"Provider": "aws", | ||
"CheckID": "acm_certificates_with_secure_key_algorithms", | ||
"CheckTitle": "Check if ACM Certificates use a secure key algorithm", | ||
"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 key algorithm (RSA 2048 bits or more, or ECDSA 256 bits or more). For example certificates that use RSA_1024 can be compromised.", | ||
"Risk": "Certificates with weak RSA or ECDSA keys can be compromised.", | ||
"RelatedUrl": "https://docs.aws.amazon.com/acm/latest/userguide/acm-certificate.html", | ||
"Remediation": { | ||
"Code": { | ||
"CLI": "", | ||
"NativeIaC": "", | ||
"Other": "", | ||
"Terraform": "" | ||
}, | ||
"Recommendation": { | ||
"Text": "Ensure that all ACM certificates use a secure key algorithm. 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/acm/latest/userguide/gs.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. Thanks for the changes @MarioRgzLpz ! However, I prefer the SecurityHub link here since we can map the check to the Security Hub one, and in that link there is the actual remediation of the check. 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. Allright added in commit ca090d8 |
||
} | ||
}, | ||
"Categories": [], | ||
"DependsOn": [], | ||
"RelatedTo": [], | ||
"Notes": "" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
from prowler.lib.check.models import Check, Check_Report_AWS | ||
from prowler.providers.aws.services.acm.acm_client import acm_client | ||
|
||
|
||
class acm_certificates_with_secure_key_algorithms(Check): | ||
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} uses a secure key algorithm." | ||
if certificate.key_algorithm in acm_client.audit_config.get( | ||
"insecure_algorithms", ["RSA_1024"] | ||
): | ||
report.status = "FAIL" | ||
report.status_extended = f"ACM Certificate {certificate.id} for {certificate.name} does not use a secure key algorithm." | ||
findings.append(report) | ||
|
||
return findings |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -262,6 +262,9 @@ def mock_prowler_get_latest_release(_, **kwargs): | |||||
], | ||||||
"check_rds_instance_replicas": False, | ||||||
"days_to_expire_threshold": 7, | ||||||
"insecure_algorithms": [ | ||||||
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.
Suggested change
|
||||||
"RSA_1024", | ||||||
], | ||||||
"eks_required_log_types": [ | ||||||
"api", | ||||||
"audit", | ||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -271,6 +271,11 @@ aws: | |||||
# AWS ACM Configuration | ||||||
# aws.acm_certificates_expiration_check | ||||||
days_to_expire_threshold: 7 | ||||||
# aws.acm_certificates_rsa_key_length | ||||||
insecure_algorithms: | ||||||
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.
Suggested change
|
||||||
[ | ||||||
"RSA_1024", | ||||||
] | ||||||
|
||||||
# AWS EKS Configuration | ||||||
# aws.eks_control_plane_logging_all_types_enabled | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
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_with_secure_key_algorithms: | ||
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_with_secure_key_algorithms.acm_certificates_with_secure_key_algorithms import ( | ||
acm_certificates_with_secure_key_algorithms, | ||
) | ||
|
||
check = acm_certificates_with_secure_key_algorithms() | ||
result = check.execute() | ||
|
||
assert len(result) == 0 | ||
|
||
def test_acm_certificate_secure_algorithm(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, | ||
) | ||
] | ||
|
||
acm_client.audit_config = {"insecure_algorithm": ["RSA_1024"]} | ||
|
||
with mock.patch( | ||
"prowler.providers.aws.services.acm.acm_service.ACM", | ||
new=acm_client, | ||
): | ||
# Test Check | ||
from prowler.providers.aws.services.acm.acm_certificates_with_secure_key_algorithms.acm_certificates_with_secure_key_algorithms import ( | ||
acm_certificates_with_secure_key_algorithms, | ||
) | ||
|
||
check = acm_certificates_with_secure_key_algorithms() | ||
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} uses a secure key algorithm." | ||
) | ||
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_insecure_algorithm(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, | ||
) | ||
] | ||
|
||
acm_client.audit_config = {"insecure_algorithm": ["RSA_1024"]} | ||
|
||
with mock.patch( | ||
"prowler.providers.aws.services.acm.acm_service.ACM", | ||
new=acm_client, | ||
): | ||
# Test Check | ||
from prowler.providers.aws.services.acm.acm_certificates_with_secure_key_algorithms.acm_certificates_with_secure_key_algorithms import ( | ||
acm_certificates_with_secure_key_algorithms, | ||
) | ||
|
||
check = acm_certificates_with_secure_key_algorithms() | ||
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} does not use a secure key algorithm." | ||
) | ||
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 == [] |
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.
Could you elaborate a bit on this information to make it clear why the certificates could be compromised