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(acm): Add new check for insecure algorithms in certificates #4551

Conversation

MarioRgzLpz
Copy link
Contributor

@MarioRgzLpz MarioRgzLpz commented Jul 26, 2024

Context

In order to enhance the security measures and ensure compliance with best practices in cryptographic operations, we are introducing a new check within the AWS Certificate Manager (ACM) framework. This new check specifically focuses on verifying that the algorithm used in the certificate is secure enough. By default it will check that RSA_1024 is not used as it is not considered a best practice. Algorithms chosen as insecure can be configured by the user to allow them to harden the certificates.

Description

I added acm_certificates_with_secure_key_algorithms check with his respective unit test. In order to do the check I modified the acm_service model Certificate adding the key_algorithm as str. I also modified the config.yaml to add the new insecure_algorithms parameter.

License

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@MarioRgzLpz MarioRgzLpz requested review from a team as code owners July 26, 2024 08:04
@github-actions github-actions bot added the provider/aws Issues/PRs related with the AWS provider label Jul 26, 2024
report.status = "PASS"
report.status_extended = f"ACM Certificate {certificate.id} for {certificate.name} meet minimum key size requirements."

if certificate.key_algorithm == "RSA_1024":
Copy link
Member

@jfagoagas jfagoagas Jul 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a comment about this, we should be able to configure the list of algorithms that are not secure enough for this check to pass.

I did not reviewed the PR but took a quick look at it. Great work 👏

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added in commit 4d9d8f3

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I was not clear enough. My point was to be able to configure the list of algorithms using Prowler configuration. You can see how could it be implemented at https://docs.prowler.com/projects/prowler-open-source/en/latest/developer-guide/checks/#using-the-audit-config

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thought about it at first but I wasn't sure if that was what you was asking about. Added in commit c8d3954

Copy link

codecov bot commented Jul 26, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 89.07%. Comparing base (6c3e451) to head (cf645a7).
Report is 523 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4551      +/-   ##
==========================================
- Coverage   89.08%   89.07%   -0.01%     
==========================================
  Files         910      911       +1     
  Lines       27741    27763      +22     
==========================================
+ Hits        24713    24731      +18     
- Misses       3028     3032       +4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

"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",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added in commit 74786c7

},
"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"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here too, since the SecurityHub link also contains the Remediation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added in commit 74786c7

@jfagoagas
Copy link
Member

What if we create a generic check regardless the algorithm? So we can use it for RSA, ECDSA or whatever.

@sergargar @puchy22 @MarioRgzLpz

@puchy22
Copy link
Member

puchy22 commented Jul 29, 2024

What if we create a generic check regardless the algorithm? So we can use it for RSA, ECDSA or whatever.

@sergargar @puchy22 @MarioRgzLpz

All other algorithms allowed by AWS are secure, except for RSA 1024 bits, which is not considered a best practice. Creating a generic check is a good idea, as it will future-proof the system by allowing for the inclusion of new algorithms that may fall out of best practice over time.

@MarioRgzLpz MarioRgzLpz changed the title feat(acm): Add new check for RSA key length in certificates feat(acm): Add new check for insecure algorithms in certificates Jul 29, 2024
report.resource_tags = certificate.tags

report.status = "PASS"
report.status_extended = f"ACM Certificate {certificate.id} for {certificate.name} meet minimum key size requirements."
Copy link
Member

@MrCloudSec MrCloudSec Jul 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
report.status_extended = f"ACM Certificate {certificate.id} for {certificate.name} meet minimum key size requirements."
report.status_extended = f"ACM Certificate {certificate.id} for {certificate.name} uses a secure key algorithm."

{
"Provider": "aws",
"CheckID": "acm_certificates_insecure_algorithms",
"CheckTitle": "Check if ACM Certificates use a secure RSA key size",
Copy link
Member

@MrCloudSec MrCloudSec Jul 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"CheckTitle": "Check if ACM Certificates use a secure RSA key size",
"CheckTitle": "Check if ACM Certificates use a secure key algorithm",

"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",
Copy link
Member

@MrCloudSec MrCloudSec Jul 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"Description": "Check if ACM Certificates use a secure RSA key size",
"Description": "Check if ACM Certificates use a secure key algorithm",

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you elaborate it more? Mention for example what is considered to be a secure key algorithm :)

"insecure_algorithms", ["RSA_1024"]
):
report.status = "FAIL"
report.status_extended = f"ACM Certificate {certificate.id} for {certificate.name} uses a not secure key length."
Copy link
Member

@MrCloudSec MrCloudSec Jul 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
report.status_extended = f"ACM Certificate {certificate.id} for {certificate.name} uses a not secure key length."
report.status_extended = f"ACM Certificate {certificate.id} for {certificate.name} does not use a secure key algorithm."

@@ -0,0 +1,32 @@
{
"Provider": "aws",
"CheckID": "acm_certificates_insecure_algorithms",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"CheckID": "acm_certificates_insecure_algorithms",
"CheckID": "acm_certificates_with_secure_key_algorithms",

"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/securityhub/latest/userguide/acm-controls.html#acm-2",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"RelatedUrl": "https://docs.aws.amazon.com/securityhub/latest/userguide/acm-controls.html#acm-2",
"RelatedUrl": "https://docs.aws.amazon.com/acm/latest/userguide/acm-certificate.html",

Copy link
Member

@MrCloudSec MrCloudSec left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MarioRgzLpz please, review my last comments. Thanks!

@MarioRgzLpz
Copy link
Contributor Author

@sergargar All the changes you requested done in commit 42829a3. I changed the Recommendation URL to the AWS one that guides you on how to change the algorithm on a certificate.

},
"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"
Copy link
Member

Choose a reason for hiding this comment

The 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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Allright added in commit ca090d8

Copy link
Member

@puchy22 puchy22 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please also change the naming convention for ACM methods to follow the standard naming convention.

"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.",
Copy link
Member

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

@@ -262,6 +262,9 @@ def mock_prowler_get_latest_release(_, **kwargs):
],
"check_rds_instance_replicas": False,
"days_to_expire_threshold": 7,
"insecure_algorithms": [
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"insecure_algorithms": [
"insecure_key_algorithms": [

@@ -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:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
insecure_algorithms:
insecure_key_algorithms:

…e config, add some details in the description and risk in the metadata and rename the service methods to comply with Python convention
@MarioRgzLpz
Copy link
Contributor Author

@puchy22 Everything you requested done in commit ee08174

MrCloudSec
MrCloudSec previously approved these changes Jul 31, 2024
Copy link
Member

@MrCloudSec MrCloudSec left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👏🏼

Copy link
Member

@puchy22 puchy22 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job!!🥇

Copy link
Member

@puchy22 puchy22 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add the logic of unused resources to the check with unused certificates.

@jfagoagas jfagoagas added the no-merge Please, DO NOT MERGE this PR. label Aug 1, 2024
@MrCloudSec MrCloudSec removed the no-merge Please, DO NOT MERGE this PR. label Aug 1, 2024
…gorithms including ECDSA and all key size RSA
…pped KeyAlgorithm_Size to KeyAlgorithm-Size as this is the format in which certificates are returned
@MarioRgzLpz
Copy link
Contributor Author

Please add the logic of unused resources to the check with unused certificates.

@puchy22 added in commit 9697ead

report.resource_tags = certificate.tags

report.status = "PASS"
report.status_extended = f"ACM Certificate {certificate.id} for {certificate.name} uses a secure key algorithm."
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add in the status extended the key algorithm at the end within parenthesis, please?

"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."
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

@MarioRgzLpz
Copy link
Contributor Author

@sergargar All done here cf645a7

Copy link
Member

@MrCloudSec MrCloudSec left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR!

@MrCloudSec MrCloudSec requested a review from puchy22 August 7, 2024 11:39
Copy link
Member

@puchy22 puchy22 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job @MarioRgzLpz !! 🥇

@MrCloudSec MrCloudSec merged commit 1b18aef into prowler-cloud:master Aug 7, 2024
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
provider/aws Issues/PRs related with the AWS provider
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants