ACM Certificates Should Have Minimum RSA Length
More Info:
Ensure ACM certificate RSA length is minimum of 2048
Risk Level
High
Address
Security
Compliance Standards
- APRA CPS 234 (Australia)
- BSI C5 (Germany)
- Brazil LGPD
- CCPA / CPRA (California)
- CIS Critical Security Controls v8
- CMMC 2.0
- CSA Cloud Controls Matrix v4
- Cloudanix Best Practice
- DPDPA
- Digital Operational Resilience Act (EU)
- ISO/IEC 27017
- ISO/IEC 27018
- ISO/IEC 27701
- KSA PDPL
- MAS Technology Risk Management (Singapore)
- MITRE ATT&CK (Cloud)
- NIS2 Directive
- NIST SP 800-171
- NYDFS 23 NYCRR 500
- SWIFT Customer Security Controls Framework
- Sarbanes-Oxley IT General Controls
- StateRAMP
- UK NCSC Cyber Assessment Framework
Triage and Remediation
- Cause
- Remediation
Check Cause
Using Console
- Sign in to the AWS Management Console.
- Navigate to the API Gateway console. You can do this by typing "API Gateway" into the search bar and selecting it from the dropdown menu.
- Once in the API Gateway console, select the API you want to check.
- In the API's settings, look for the ACM Certificate section. Here, you can see the RSA length of the certificate. If the RSA length is less than the minimum required length, then there is a misconfiguration.
Using CLI
-
First, you need to list all the API Gateways in your AWS account. You can do this by using the following AWS CLI command:
aws apigateway get-rest-apis --region your-regionReplace 'your-region' with the region you want to check. This command will return a list of all the API Gateways in the specified region.
-
Next, for each API Gateway, you need to get the details of the associated ACM certificate. You can do this by using the following AWS CLI command:
aws apigateway get-domain-names --region your-regionThis command will return a list of all the domain names associated with each API Gateway. Each domain name will have an associated ACM certificate.
-
Now, for each ACM certificate, you need to get the details of the certificate. You can do this by using the following AWS CLI command:
aws acm describe-certificate --certificate-arn your-certificate-arn --region your-regionReplace 'your-certificate-arn' with the ARN of the certificate you want to check. This command will return the details of the specified certificate.
-
Finally, you need to check the RSA length of the certificate. You can do this by looking at the 'KeyAlgorithm' field in the output of the previous command. If the 'KeyAlgorithm' field is 'RSA_2048', then the RSA length of the certificate is 2048 bits. If the 'KeyAlgorithm' field is 'RSA_1024', then the RSA length of the certificate is 1024 bits. If the RSA length is less than 2048 bits, then the certificate is misconfigured.
Using Python
-
Install the necessary Python libraries: Before you start, make sure you have the necessary Python libraries installed. You will need 'boto3' for AWS SDK for Python and 'botocore' for low-level, core functionality of AWS SDK for Python. You can install these libraries using pip:
pip install boto3 botocore -
Import the necessary libraries and initialize the AWS service: Import the necessary Python libraries and initialize the AWS service you want to use. In this case, we are using 'boto3' to interact with AWS API Gateway and ACM (AWS Certificate Manager).
import boto3# Create a client for the AWS service.apigateway = boto3.client('apigateway')acm = boto3.client('acm') -
Get the list of API Gateways and their associated ACM Certificates: Use the 'get_rest_apis' function to get the list of API Gateways. Then, for each API Gateway, get the associated ACM Certificate using the 'get_domain_name' function.
# Get the list of API Gateways.api_gateways = apigateway.get_rest_apis()['items']for api_gateway in api_gateways:# Get the domain name associated with the API Gateway.domain_name = apigateway.get_domain_name(domainName=api_gateway['name'])# Get the ACM Certificate associated with the domain name.certificate_arn = domain_name['domainName']['certificateArn']certificate = acm.describe_certificate(CertificateArn=certificate_arn) -
Check the RSA length of the ACM Certificate: The RSA length of the ACM Certificate can be found in the 'KeyAlgorithm' field of the certificate description. If the RSA length is less than the minimum required length, print a warning message.
# Check the RSA length of the ACM Certificate.if 'RSA' in certificate['Certificate']['KeyAlgorithm']:rsa_length = int(certificate['Certificate']['KeyAlgorithm'].split('_')[1])if rsa_length < 2048:print(f"Warning: The ACM Certificate for API Gateway {api_gateway['name']} has an RSA length of {rsa_length}, which is less than the minimum required length of 2048.")
This script will help you detect if any ACM Certificates associated with API Gateways have an RSA length less than the minimum required length.
Remediation
Using Console
To remediate the ACM certificate with minimum RSA length for AWS API Gateway using the AWS console, you can follow these steps:
-
Login to AWS Console: Go to the AWS Management Console (https://aws.amazon.com/) and log in to your AWS account.
-
Navigate to ACM: In the AWS Management Console, search for "ACM" in the services search bar and click on "AWS Certificate Manager" to open the ACM dashboard.
-
Select the Certificate: In the ACM dashboard, locate and select the certificate that is associated with your API Gateway.
-
Check RSA Key Length: Check the RSA key length of the selected certificate. Ensure that the RSA key length meets the minimum requirement. The minimum RSA key length recommended is 2048 bits.
-
Update Certificate: If the RSA key length is less than 2048 bits, you will need to update the certificate with a new RSA key of at least 2048 bits.
-
Reissue Certificate: To update the RSA key length of the certificate, you will need to reissue the certificate with a new RSA key. Click on the "Actions" dropdown menu and select "Reissue certificate".
-
Select RSA Key Length: In the reissue certificate wizard, select the RSA key length of at least 2048 bits.
-
Review and Confirm: Review the details of the reissued certificate and click on the "Reissue" button to confirm and reissue the certificate with the new RSA key length.
-
Update API Gateway: Once the certificate is reissued with the new RSA key length, you will need to update the API Gateway to use the newly reissued certificate.
-
Update API Gateway Integration: Go to the API Gateway console, select your API, and update the integration settings to use the newly reissued certificate.
By following these steps, you will be able to remediate the ACM certificate with minimum RSA length for AWS API Gateway using the AWS console.
Using CLI
To remediate the ACM certificate with minimum RSA length for AWS API Gateway using AWS CLI, follow these steps:
- List ACM Certificates: First, you need to list all the ACM certificates in your AWS account to identify the certificate that needs to be updated. Run the following AWS CLI command to list all ACM certificates:
aws acm list-certificates
-
Get Certificate ARN: Identify the ARN of the ACM certificate that is associated with your API Gateway. Note down the ARN as you will need it for the next steps.
-
Update Certificate: Run the following AWS CLI command to update the ACM certificate with the desired RSA key length (e.g., 2048 bits):
aws acm update-certificate --certificate-arn <CERTIFICATE_ARN> --key-spec RSA_2048
Replace <CERTIFICATE_ARN> with the ARN of the ACM certificate that you identified in step 2.
- Verify Update: To verify that the certificate has been updated successfully, you can describe the certificate using the following AWS CLI command:
aws acm describe-certificate --certificate-arn <CERTIFICATE_ARN>
Ensure that the KeyAlgorithm is now set to RSA_2048.
By following these steps, you can remediate the ACM certificate with the minimum RSA key length for AWS API Gateway using AWS CLI.
Using Python
To remediate the misconfiguration of ACM Certificates not having the minimum RSA length in AWS API Gateway using Python, follow these steps:
-
Get a list of ACM certificates in use:
- Use the AWS SDK for Python (Boto3) to list all the ACM certificates in use in your AWS account.
- You can use the
list_certificates()method from theacmclient.
-
Check the RSA key length of each certificate:
- For each certificate, use the
describe_certificate()method to get detailed information about the certificate. - Check the RSA key length of the certificate. Ensure that it meets the minimum required length (e.g., 2048 bits).
- For each certificate, use the
-
Update certificates with insufficient RSA key length:
- For certificates that do not meet the minimum RSA key length requirement, you will need to request a new certificate with a sufficient key length.
- Use the
request_certificate()method to request a new certificate with the required RSA key length. - Make sure to update the API Gateway to use the new certificate once it is issued.
-
Update API Gateway to use the new certificate:
- Update the API Gateway configuration to use the newly issued certificate.
- You can use the
update_domain_name()method from theapigatewayclient to update the certificate for the custom domain name associated with your API Gateway.
-
Automate the remediation process:
- To ensure that all ACM certificates used by API Gateway meet the minimum RSA key length requirement, consider automating the above steps using Python scripts and AWS Lambda functions.
- You can schedule this automation to run periodically to check and update any newly issued certificates as well.
By following these steps and automating the process using Python scripts and AWS SDK, you can remediate the misconfiguration of ACM Certificates not having the minimum RSA length in AWS API Gateway.
Using Terraform
# Strong ACM certificate (minimum RSA 2048-bit) for use with API Gateway
resource "aws_acm_certificate" "api_gateway_cert" {
domain_name = "PRIMARY_DOMAIN_NAME" # e.g. "api.example.com"
subject_alternative_names = ["SAN_1", "SAN_2"] # optional; remove or adjust as needed
validation_method = "DNS"
# Key must be at least 2048 bits
key_algorithm = "RSA_2048"
lifecycle {
create_before_destroy = true
}
}
# DNS validation records for the certificate
resource "aws_route53_record" "api_gateway_cert_validation" {
for_each = {
for dvo in aws_acm_certificate.api_gateway_cert.domain_validation_options :
dvo.domain_name => {
name = dvo.resource_record_name
type = dvo.resource_record_type
record = dvo.resource_record_value
}
}
zone_id = "ROUTE53_HOSTED_ZONE_ID" # replace with your hosted zone ID
name = each.value.name
type = each.value.type
ttl = 300
records = [each.value.record]
}
resource "aws_acm_certificate_validation" "api_gateway_cert_validation" {
certificate_arn = aws_acm_certificate.api_gateway_cert.arn
validation_record_fqdns = [for r in aws_route53_record.api_gateway_cert_validation : r.fqdn]
}
# API Gateway custom domain using the strong ACM certificate (REST APIs)
resource "aws_api_gateway_domain_name" "api_domain" {
domain_name = "PRIMARY_DOMAIN_NAME" # must match the ACM cert domain or a SAN
regional_certificate_arn = aws_acm_certificate_validation.api_gateway_cert_validation.certificate_arn
endpoint_configuration {
types = ["REGIONAL"]
}
}
Changing an existing ACM certificate’s key_algorithm to RSA_2048 forces replacement of the certificate resource; plan for a new certificate, DNS validation, and then switching the API Gateway domain to the new certificate ARN before deleting the old certificate (if the old one is not Terraform-managed, its deletion must be done manually in the ACM console or via CLI as warned).
For verification, terraform plan should show:
aws_acm_certificate.api_gateway_certcreated (and any old weaker certificate resource destroyed if you replaced it),aws_acm_certificate_validation.api_gateway_cert_validationcreated/updated,aws_api_gateway_domain_name.api_domainupdated to use the new validated certificate ARN.